Skip to content

Commit f96df0e

Browse files
committed
display data beauty
1 parent 97636ec commit f96df0e

File tree

9 files changed

+153
-28
lines changed

9 files changed

+153
-28
lines changed

components/ProfileCard.js

+66-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import React from 'react';
22

3-
const ProfileCard = ({ data }) => {
3+
const ProfileCard = ({ data, organic_results }) => {
44
const { person } = data;
5-
5+
const scaleserp = organic_results;
6+
console.log(scaleserp);
67
return (
78
(person && (
89
<div className="max-w-7xl mx-auto bg-white shadow-lg rounded-lg overflow-hidden my-5">
@@ -25,20 +26,75 @@ const ProfileCard = ({ data }) => {
2526
{person.linkedin_url}
2627
</a>
2728
</p>
29+
{person.twitter_url && (
30+
<p>
31+
Twitter:{' '}
32+
<a
33+
href={person.twitter_url}
34+
className="text-blue-500 hover:underline"
35+
>
36+
{person.twitter_url}
37+
</a>
38+
</p>
39+
)}
40+
{person.functions && person.functions.length > 0 && (
41+
<div className="py-4">
42+
<div className="font-semibold">Professional Functions:</div>
43+
<ul className="list-disc pl-5">
44+
{person.functions.map((func, index) => (
45+
<li key={index} className="text-gray-800 my-2">
46+
{func}
47+
</li>
48+
))}
49+
</ul>
50+
</div>
51+
)}
2852
</div>
2953
<div>
3054
<div className="font-semibold">Employment History:</div>
3155
<ul className="list-disc pl-5 mb-4">
32-
{person.employment_history.map((job) => (
33-
<li key={job.id}>
34-
<p className="text-gray-800">
35-
{job.title} at {job.organization_name} ({job.start_date} -{' '}
36-
{job.end_date || 'Present'})
37-
</p>
38-
</li>
39-
))}
56+
{person.employment_history &&
57+
person.employment_history.map((job) => (
58+
<li key={job.id}>
59+
<p className="text-gray-800">
60+
{job.title} at {job.organization_name} ({job.start_date} -{' '}
61+
{job.end_date || 'Present'})
62+
</p>
63+
</li>
64+
))}
4065
</ul>
4166
</div>
67+
{scaleserp &&
68+
scaleserp.organic_results &&
69+
scaleserp.organic_results.length > 0 && (
70+
<div className="mt-8">
71+
<h2 className="text-xl font-semibold mb-4 text-gray-900">
72+
Recent News:
73+
</h2>
74+
<div className="space-y-4">
75+
{scaleserp.organic_results
76+
.slice(0, 4)
77+
.map((result, index) => (
78+
<div
79+
key={index}
80+
className="bg-white p-4 shadow rounded-lg transition duration-300 ease-in-out hover:shadow-md"
81+
>
82+
<a
83+
href={result.link}
84+
target="_blank"
85+
rel="noopener noreferrer"
86+
className="hover:text-blue-600 text-lg font-medium text-gray-900"
87+
>
88+
{result.title}
89+
</a>
90+
<p className="text-sm text-gray-600 mt-2">
91+
{result.snippet}
92+
</p>
93+
</div>
94+
))}
95+
</div>
96+
</div>
97+
)}
4298
</div>
4399
</div>
44100
)) || <div>No data found</div>

components/campaign-list.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ function ContactList({ searchTerm }: { searchTerm: string }) {
145145
<td className="px-6 py-4 whitespace-no-wrap text-sm leading-5 text-gray-700">
146146
<a
147147
href={`/campaign/${campaign.id}`}
148-
target="_blank"
149148
className="text-blue-500 hover:text-blue-800"
150149
>
151150
<FontAwesomeIcon

components/email-event-display.tsx

+9-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ interface Contact {
99
email: string;
1010
company: string;
1111
apolloData: string;
12+
scaleserpData: string;
1213
}
1314

1415
interface EmailEvent {
@@ -203,7 +204,14 @@ const EmailEventsDisplay: React.FC<EmailEventsDisplayProps> = ({
203204
) : null}
204205
{emailEvents.map((event) => (
205206
<div className="bg-white p-4 shadow rounded-lg mb-2">
206-
<div className="mb-4">
207+
{event.contact?.apolloData && (
208+
<ProfileCard
209+
data={JSON.parse(event.contact.apolloData)}
210+
organic_results={JSON.parse(event.contact.scaleserpData)}
211+
/>
212+
)}
213+
214+
<div className="mb-2 mt-4">
207215
<span className="text-gray-900 font-semibold">To:</span>
208216
<span className="text-gray-900 ml-2">{event.contact.email}</span>
209217
</div>
@@ -244,10 +252,6 @@ const EmailEventsDisplay: React.FC<EmailEventsDisplayProps> = ({
244252
</button>
245253
</div>
246254

247-
{event.contact?.apolloData && (
248-
<ProfileCard data={JSON.parse(event.contact.apolloData)} />
249-
)}
250-
251255
<hr className="border-t border-gray-300 my-4 mt-2" />
252256

253257
{/* <div className="text-gray-700">

components/utils/scaleserp.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const scaleSerpApiKey = process.env.SCALESERP_API_KEY;
2+
const url = 'https://api.scaleserp.com/search';
3+
const axios = require('axios');
4+
5+
if (!scaleSerpApiKey) {
6+
throw new Error('scaleSerpApiKey key not found');
7+
}
8+
9+
export const fetchNewsData = (data) => {
10+
const params = {
11+
api_key: scaleSerpApiKey,
12+
q: data
13+
};
14+
15+
return axios
16+
.get(url, { params })
17+
.then((response) => {
18+
return response.data;
19+
})
20+
.catch((error) => {
21+
console.log(error);
22+
throw error;
23+
});
24+
};
25+
26+
const scaleserp = {
27+
fetchNewsData
28+
};
29+
30+
export default scaleserp;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "Contact" ADD COLUMN "scaleserpData" JSONB;

pages/api/add/campaign.js

+32-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const axios = require('axios');
1212
const cheerio = require('cheerio');
1313
const prisma = require('../../../components/prisma-client');
1414
import apollo from '../../../components/utils/apollo';
15+
import scaleserp from '../../../components/utils/scaleserp';
1516
const maxTokens = 3000;
1617

1718
const fetchPageContent = async (url) => {
@@ -161,7 +162,7 @@ const generateCommonAttributes = async (key, templateContent, userPrompt) => {
161162
frequency_penalty: 0,
162163
presence_penalty: 0,
163164
max_tokens: 600,
164-
model: 'gpt-4'
165+
model: 'gpt-3.5-turbo-0125'
165166
});
166167

167168
return completion.choices[0].message.content;
@@ -215,6 +216,29 @@ const generateContent = async (
215216
});
216217
}
217218

219+
const scaleserpData =
220+
contact.scaleserpData !== null
221+
? contact.scaleserpData
222+
: JSON.stringify(
223+
await scaleserp.fetchNewsData(
224+
`latest+news+on+${contact.companyWebsite}`
225+
)
226+
);
227+
if (contact.scaleserpData === null) {
228+
await prisma.contact.update({
229+
where: {
230+
id: parseInt(contactId)
231+
},
232+
data: {
233+
scaleserpData: scaleserpData
234+
}
235+
});
236+
} else {
237+
}
238+
239+
const organic_results = JSON.parse(scaleserpData).organic_results
240+
? JSON.parse(scaleserpData).organic_results.slice(0, 5)
241+
: [];
218242
const personSenderData =
219243
user.apolloData !== null
220244
? user.apolloData
@@ -280,8 +304,14 @@ const generateContent = async (
280304
**The recipient should be interested in the email and should be willing to respond to it.
281305
**The recepient title is ${contact.jobTitle} and the company name is ${contact.company}
282306
**The sender name is ${creatorFirstName} ${creatorLastName} and the sender email is ${creatorEmail}
283-
**The summary of the company website is as follows:
307+
**Make sure to reason based on the company profile as per the website summary as follows:
308+
### start of summary
284309
${websiteSummary}
310+
### end of summary
311+
**Mention about a recent news or blogs to personalize from the following web results:
312+
### start of web data
313+
${organic_results}
314+
### end of web data
285315
**Make sure the number of words is between ${minWords} and ${maxWords}
286316
`;
287317

pages/api/contacts.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ export default async function handler(req, res) {
1515
try {
1616
let whereCondition = {};
1717

18-
if (orgId) {
19-
whereCondition = { orgId: orgId };
20-
} else if (contactId) {
18+
if (contactId) {
2119
whereCondition = { orgId: orgId, id: parseInt(contactId) };
20+
} else if (orgId) {
21+
whereCondition = { orgId: orgId };
2222
} else {
2323
res.status(400).json({ error: 'Missing required parameters' });
2424
}

pages/campaign/campaign-details.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ const CampaignDetails = ({ campaign_id: campaign_id }) => {
195195
</div>
196196
</div>
197197

198-
<h2 className="text-lg font-semibold mb-4">Generated Emails</h2>
199198
<div className="relative flex items-center w-full">
200199
{' '}
201200
<input
@@ -227,9 +226,17 @@ const CampaignDetails = ({ campaign_id: campaign_id }) => {
227226

228227
{emailEvents.length > 0 ? (
229228
<div className="space-y-6 mt-4">
229+
<hr className="border-t border-gray-300 my-4 mt-2" />
230230
{emailEvents.map((event) => (
231231
<div className="bg-white p-4 shadow rounded-lg mb-2">
232-
<div className="mb-4">
232+
{event.contact?.apolloData && event.contact?.scaleserpData && (
233+
<ProfileCard
234+
data={JSON.parse(event.contact.apolloData)}
235+
organic_results={JSON.parse(event.contact.scaleserpData)}
236+
/>
237+
)}
238+
239+
<div className="mb-2 mt-4">
233240
<span className="text-gray-900 font-semibold">To:</span>
234241
<span className="text-gray-900 ml-2">
235242
{event.contact.email}
@@ -272,10 +279,6 @@ const CampaignDetails = ({ campaign_id: campaign_id }) => {
272279
</button>
273280
</div>
274281

275-
{event.contact?.apolloData && (
276-
<ProfileCard data={JSON.parse(event.contact.apolloData)} />
277-
)}
278-
279282
<hr className="border-t border-gray-300 my-4 mt-2" />
280283

281284
{/* <div className="text-gray-700">
@@ -296,7 +299,7 @@ const CampaignDetails = ({ campaign_id: campaign_id }) => {
296299
))}
297300
</div>
298301
) : (
299-
<p>No email events found for this campaign.</p>
302+
<p>Loading...</p>
300303
)}
301304
</main>
302305
);

schema.prisma

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ model Contact {
3636
creatorEmail String?
3737
creatorName String?
3838
apolloData Json?
39+
scaleserpData Json?
3940
createdAt DateTime @default(now())
4041
updatedAt DateTime @updatedAt
4142
EmailEvent EmailEvent[]

0 commit comments

Comments
 (0)