Skip to content

Commit 0981218

Browse files
committed
basic salesforce integration
1 parent 1c8d455 commit 0981218

3 files changed

Lines changed: 148 additions & 4 deletions

File tree

devconnect/src/common/components/ba/destino/destino.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const Destino = ({ content, events }: { content: any; events: any }) => {
9595

9696
<div className="flex flex-col items-center justify-center gap-16 mb-24 overflow-hidden">
9797
<HowToApply content={content} />
98-
{/* <EventsList content={content} events={events} /> */}
98+
<EventsList content={content} events={events} />
9999
</div>
100100
</div>
101101
)

devconnect/src/common/components/ba/destino/event-table.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,15 @@ const tableColumns: Array<TableColumn> = [
116116
render: item => {
117117
if (!item.Social) return null
118118

119+
let socialFormatted = item.Social
120+
121+
if (socialFormatted.startsWith('@')) {
122+
socialFormatted = socialFormatted.slice(1)
123+
}
124+
119125
return (
120-
<Link className="bolda" href={item.Social} indicateExternal>
121-
{item.Social}
126+
<Link className="bolda" href={`https://x.com/@${socialFormatted}`} indicateExternal>
127+
{socialFormatted}
122128
</Link>
123129
)
124130
},

devconnect/src/pages/destino.tsx

Lines changed: 139 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { SEO } from 'common/components/SEO'
88
const DestinoPage = ({ content, events }: { content: any; events: any }) => {
99
const { data }: { data: any } = useTina(content)
1010

11+
console.log(events, 'EVENTS')
12+
1113
return (
1214
<>
1315
<SEO
@@ -22,6 +24,134 @@ const DestinoPage = ({ content, events }: { content: any; events: any }) => {
2224
)
2325
}
2426

27+
const fetchFromSalesforce = async (apiUrl: string) => {
28+
console.log(
29+
process.env.SF_CONSUMER_KEY,
30+
process.env.SF_CONSUMER_SECRET,
31+
process.env.SF_USERNAME,
32+
process.env.SF_PASSWORD,
33+
process.env.SF_SECURITY_TOKEN,
34+
'CREDENTIALS'
35+
)
36+
37+
/*
38+
3
39+
40+
Had the same error (SalesForce 2020). Under Manage Connected Apps, I had to make sure my selected OAuth Scopes were as follows
41+
42+
Access and manage your data (api)
43+
Provide access to your data via the Web (web)
44+
Allow access to your unique identifier (openid)
45+
*/
46+
47+
// Replace this with proper Salesforce API call
48+
const fetchSalesforceData = async () => {
49+
// Auth with Connected App credentials
50+
// const auth = await fetch('https://ef-esp.lightning.force.com/services/oauth2/token', {
51+
const auth = await fetch('https://login.salesforce.com/services/oauth2/token', {
52+
method: 'POST',
53+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
54+
body: new URLSearchParams({
55+
grant_type: 'password',
56+
client_id: process.env.SF_CONSUMER_KEY || '',
57+
client_secret: process.env.SF_CONSUMER_SECRET || '',
58+
username: process.env.SF_USERNAME || '',
59+
password: process.env.SF_PASSWORD || '' + (process.env.SF_SECURITY_TOKEN || ''),
60+
}),
61+
// method: 'POST',
62+
// headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
63+
// body: new URLSearchParams({
64+
// grant_type: 'client_credentials',
65+
// client_id: process.env.SF_CONSUMER_KEY || '',
66+
// client_secret: process.env.SF_CONSUMER_SECRET || '',
67+
// }),
68+
})
69+
70+
const authData = await auth.json()
71+
72+
console.log(authData, 'AUTH')
73+
74+
const { access_token, instance_url } = authData
75+
76+
console.log(access_token, instance_url, 'ACCESS TOKEN AND INSTANCE URL')
77+
78+
/*
79+
Project_Name__c
80+
Estimated_Number_of_Attendees__c: 40,
81+
Event_Location__c: 'Jardín de Lolita',
82+
Target_Audience__c: 'People building web3 products, and people interested in learning more about blockchain technology and the different opportunities.',
83+
Sponsorship_Details__c: 'The purpose of the event is going to be a meetup where builders, contributors, researchers and people interested in web3 and blockchain technology can learn more about projects that are having real-world positive impact in LATAM, and future projects which need development. It is going to have the support from other communities such as Dojo Coding and Web3 Mentorhood.'
84+
Sponsorship_Topics__c: 'Stablecoins, how they can enable cross-border payment for countries or communities in nation-wide problems\n' +
85+
'\n' +
86+
'Community building, how can blockchain and tokenization enable community-driven organizations. (RISE San José)\n' +
87+
'\n' +
88+
'Zero Knowledge proofs "Crash Course", how do they work and real world use-cases.\n' +
89+
'\n' +
90+
'Identity, how can digital identities be private and enable trustless voting systems (ZK Firma Digital)\n' +
91+
'\n' +
92+
'ReFi, how are projects and communities giving back to the world',
93+
Type_of_Event__c: 'Meetup',
94+
Sponsorship_Date__c: '2025-07-12',
95+
Company: 'Ethereum Costa Rica',
96+
Time_Zone__c: 'GMT–06:00 Central Standard Time (America/El_Salvador)',
97+
Team_Profile__c: 'Main and official Ethereum community in Costa Rica, in charge of sponsoring and organizing community-led events to promote the adoption of blockchain technologies and encouraging developers to contribute to core protocol development, research and open source projects.',
98+
99+
*/
100+
101+
// Query for PGR_Destino_Devconnect filtered leads
102+
// const query = encodeURIComponent(`SELECT Name FROM Lead WHERE LeadSource = 'PGR_Destino_Devconnect'`)
103+
// const query = encodeURIComponent(
104+
// `SELECT FIELDS(ALL) FROM Lead WHERE Proactive_Community_Grants_Round__c = 'Destino Devconnect' LIMIT 5`
105+
// )
106+
const query = encodeURIComponent(
107+
`SELECT FIELDS(ALL) FROM Opportunity WHERE Proactive_Community_Grants_Round__c = 'Destino Devconnect' LIMIT 200`
108+
)
109+
// const query = encodeURIComponent(
110+
// `SELECT Name FROM Lead WHERE Proactive_Community_Grants_Round__c = 'Destino Devconnect' LIMIT 5`
111+
// )
112+
const response = await fetch(`${instance_url}/services/data/v59.0/query?q=${query}`, {
113+
headers: { Authorization: `Bearer ${access_token}` },
114+
})
115+
116+
console.log(response, 'RESPONSE')
117+
118+
const responseJson = await response.json()
119+
120+
console.log(responseJson, 'RESPONSE JSON')
121+
122+
const { records } = responseJson
123+
124+
// Format to match your events data structure
125+
return records.map((record: any) => ({
126+
...record,
127+
Name: record.Name,
128+
Date: {
129+
startDate: record.Sponsorship_Date__c,
130+
endDate: record.Sponsorship_Date__c,
131+
},
132+
Location: record.Event_Location__c,
133+
['Type of Event']: record.Type_of_Event__c,
134+
Social: record.Twitter_Handle__c,
135+
Link: record.Sponsorship_Link__c,
136+
Team: record.Company || '',
137+
}))
138+
}
139+
140+
let events
141+
142+
try {
143+
events = await fetchSalesforceData()
144+
} catch (error) {
145+
console.error('Error fetching Salesforce data:', error)
146+
// Fall back to mock data if API call fails
147+
events = [
148+
// ... existing mock events ...
149+
]
150+
}
151+
152+
return events
153+
}
154+
25155
export async function getStaticProps({ locale }: { locale: string }) {
26156
const path = locale === 'en' ? 'destino_devconnect.mdx' : locale + '/destino_devconnect.mdx'
27157
const content = await client.queries.pages({ relativePath: path })
@@ -82,12 +212,20 @@ export async function getStaticProps({ locale }: { locale: string }) {
82212
},
83213
]
84214

215+
const apiUrl = 'https://ef-esp.lightning.force.com/lightning/o/Lead/list?filterName=PGR_Destino_Devconnect'
216+
// I need to use salesforce to get the events data
217+
// const events = await fetch('https://devconnect.org/api/events')
218+
// const eventsData = await events.json()
219+
220+
const eventsTest = await fetchFromSalesforce(apiUrl)
221+
85222
return {
86223
props: {
87224
translations,
88225
locale,
89226
content,
90-
events,
227+
events: eventsTest,
228+
// eventsTest,
91229
},
92230
revalidate: 1 * 60 * 60, // 60 minutes, in seconds
93231
}

0 commit comments

Comments
 (0)