Skip to content

Commit

Permalink
Moved departments to Array and fixed the await in a forEach
Browse files Browse the repository at this point in the history
  • Loading branch information
Spectralo committed Jan 11, 2025
1 parent 7f5cee8 commit 926a785
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 134 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,6 @@
"eslint": "8.57.0",
"eslint-config-next": "14.1.0",
"prettier": "^3.2.5"
}
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
78 changes: 40 additions & 38 deletions pages/api/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,52 @@ export async function fetchTeam() {
const current = []
const acknowledged = []

teamMembers.forEach(async member => {
const currentmember = {
name: member.Name,
bio: member.Bio || null,
department: member.Department,
role: member.Role,
bio_hackfoundation: null,
pronouns: null,
slack_id: member['Slack ID'] || null,
slack_display_name: '',
avatar: member['Override Avatar'] || null,
avatar_id: '',
email: member.Email || null,
website: member.Website || null
}
for (const member of teamMembers) {
for (const department of member.Department) {
const currentmember = {
name: member.Name,
bio: member.Bio || null,
department: department,
role: member.Role,
bio_hackfoundation: null,
pronouns: null,
slack_id: member['Slack ID'] || null,
slack_display_name: '',
avatar: member['Override Avatar'] || null,
avatar_id: '',
email: member.Email || null,
website: member.Website || null
}

if (process.env.SLACK_API_TOKEN) {
const slackData = await fetch(
'https://hackclub.slack.com/api/users.profile.get?user=' +
record.fields['Slack ID'],
{
method: 'POST',
headers: {
'content-type': 'multipart/form-data; boundary=----orpheus',
cookie: process.env.SLACK_API_COOKIE
},
body: `------orpheus\r\nContent-Disposition: form-data; name=\"token\"\r\n\r\n${process.env.SLACK_API_TOKEN}\r\n------orpheus\r\nContent-Disposition: form-data; name=\"user\"\r\n\r\n${record.fields['Slack ID']}\r\n------orpheus\r\n`
}
).then(r => r.json())
if (process.env.SLACK_API_TOKEN) {
const slackData = await fetch(
'https://hackclub.slack.com/api/users.profile.get?user=' +
member['Slack ID'],
{
method: 'POST',
headers: {
'content-type': 'multipart/form-data; boundary=----orpheus',
cookie: process.env.SLACK_API_COOKIE
},
body: `------orpheus\r\nContent-Disposition: form-data; name=\"token\"\r\n\r\n${process.env.SLACK_API_TOKEN}\r\n------orpheus\r\nContent-Disposition: form-data; name=\"user\"\r\n\r\n${member['Slack ID']}\r\n------orpheus\r\n`
}
).then(r => r.json())

if (slackData.ok) {
if (!currentmember.avatar == null) {
member.avatar = `https://ca.slack-edge.com/T0266FRGM-${record.fields['Slack ID']}-${slackData.profile.avatar_hash}-128`
if (slackData.ok) {
if (!currentmember.avatar == null) {
currentmember.avatar = `https://ca.slack-edge.com/T0266FRGM-${member['Slack ID']}-${slackData.profile.avatar_hash}-128`
}
currentmember.pronouns = slackData.profile.pronouns
}
member.pronouns = slackData.profile.pronouns
}
}

if (member['Acknowledged']) {
acknowledged.push(currentmember)
} else {
current.push(currentmember)
if (member['Acknowledged']) {
acknowledged.push(currentmember)
} else {
current.push(currentmember)
}
}
})
}

return { current, acknowledged }
}
2 changes: 1 addition & 1 deletion pages/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ export default function Team({ team }) {
>
<Grid columns={[1, 2, null, 4]} gap={2} m={10}>
{team.current
?.filter(member => member.department === 'Welcomers')
?.filter(member => member.department === 'Welcoming')
.map(member => (
<Bio
img={member.avatar}
Expand Down
Loading

0 comments on commit 926a785

Please sign in to comment.