-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
voting!
- Loading branch information
Showing
9 changed files
with
1,009 additions
and
371 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<script> | ||
// Your Slack OAuth URL | ||
const slackAuthUrl = `https://slack.com/oauth/v2/authorize?client_id=2210535565.6498112565286&scope=&user_scope=openid,email,profile&redirect_uri=https://trickortrace.hackclub.com/oauth/slack`; | ||
export function handleSlackSignIn() { | ||
// Redirect user to Slack's OAuth URL | ||
window.location.href = slackAuthUrl; | ||
} | ||
</script> | ||
|
||
<style> | ||
.slack-login-button { | ||
padding: 12px 24px; | ||
background-color: #4A154B; | ||
color: #fff; | ||
border: none; | ||
border-radius: 5px; | ||
text-decoration: none; | ||
font-size: 1.2rem; | ||
font-family: 'Roboto', sans-serif; | ||
transition: background-color 0.3s ease; | ||
} | ||
.slack-login-button:hover { | ||
background-color: #3a0d3b; | ||
} | ||
</style> | ||
|
||
<!-- Slack Sign-in Button --> | ||
<button class="slack-login-button" on:click={handleSlackSignIn}> | ||
Sign in with Slack | ||
</button> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { json } from '@sveltejs/kit'; | ||
import { NEW_AIRTABLE_KEY } from '$env/static/private'; | ||
|
||
const AIRTABLE_BASE_ID = 'app4Bs8Tjwvk5qcD4'; | ||
const SUBMISSIONS_TABLE_NAME = 'Submissions'; | ||
|
||
export async function GET() { | ||
const airtablekey = NEW_AIRTABLE_KEY; | ||
console.log('GET /api/submissions called with airtablekey'); | ||
|
||
if (!airtablekey || airtablekey === '' || airtablekey === 'undefined' || airtablekey === 'null') { | ||
console.error('Airtable API key is required'); | ||
return json({ error: 'Airtable API key is required' }, { status: 400 }); | ||
} | ||
|
||
try { | ||
const response = await fetch( | ||
`https://api.airtable.com/v0/${AIRTABLE_BASE_ID}/${SUBMISSIONS_TABLE_NAME}?fields%5B%5D=GitHub%20handle&fields%5B%5D=Description&fields%5B%5D=PR%20Link&fields%5B%5D=Screenshots&filterByFormula=AND(%7BStatus%7D%3D'Approved'%2C%7BTrick%20or%20Trace%7D%3D1)`, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${airtablekey}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
}, | ||
); | ||
|
||
const data: any = await response.json(); | ||
|
||
// if !data then return the raw response from Airtable | ||
if (!data || !data.records) { | ||
console.warn('No records found in Airtable response'); | ||
return json(data, { status: 200 }); | ||
} | ||
|
||
const rawSubmissions = data.records.map((record: any) => record); | ||
|
||
return json(rawSubmissions, { status: 200 }); | ||
} catch (error) { | ||
console.error('Error fetching data from Airtable:', error); | ||
return json({ error: 'Failed to fetch data from Airtable' }, { status: 500 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { json } from '@sveltejs/kit'; | ||
import type { RequestEvent } from '@sveltejs/kit'; | ||
|
||
export async function POST({ request }: RequestEvent) { | ||
try { | ||
const { votes, slackID, hashedSlackID } = await request.json(); | ||
|
||
if (!votes || !slackID || !hashedSlackID) { | ||
return json({ error: 'Missing required fields' }, { status: 400 }); | ||
} | ||
|
||
// Submit the votes to the external API | ||
for (const [submissionId, category] of Object.entries(votes)) { | ||
console.log('Sending vote to external API:', { submissionId, category, slackID, hashedSlackID }); | ||
|
||
const response = await fetch('https://blue-river-03bf.ryandilorenzo264.workers.dev/vote', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
submissionId, | ||
slackID, | ||
hashedSlackID, | ||
category, | ||
}), | ||
}); | ||
|
||
if (!response.ok) { | ||
const errorData = await response.json(); | ||
console.error('Failed to submit vote to external API:', errorData); | ||
throw new Error(errorData.error || 'Failed to submit vote to external API'); | ||
} | ||
|
||
console.log('Vote submitted to external API:', { submissionId, category }); | ||
} | ||
|
||
// Log the successful request | ||
console.log('Vote request:', { votes, slackID, hashedSlackID }); | ||
|
||
return json({ message: 'Votes submitted successfully' }, { status: 200 }); | ||
} catch (error) { | ||
console.error('Error submitting votes:', error); | ||
return json({ error: `Failed to submit votes: ${(error as Error).message}` }, { status: 500 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { redirect, json } from '@sveltejs/kit'; | ||
import type { RequestEvent } from '@sveltejs/kit'; | ||
|
||
export async function GET({ url }: RequestEvent) { | ||
const code = url.searchParams.get('code'); | ||
|
||
if (!code) { | ||
console.error('Missing code'); | ||
return json({ error: 'Missing code' }, { status: 400 }); | ||
} | ||
|
||
console.log('Sending code to OnBoard API...'); | ||
|
||
const payload = { | ||
slack_code: code, | ||
special_secret: "hello" | ||
}; | ||
console.log('Payload:', JSON.stringify(payload)); | ||
|
||
// Send the code to the OnBoard API | ||
const apiResponse = await fetch('https://api.onboard.limeskey.com', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(payload), | ||
}); | ||
|
||
const apiData = await apiResponse.json(); | ||
console.log('API response:', apiData); | ||
|
||
// Extract relevant info from the API response | ||
const slackID = apiData.slack.slack_id; | ||
const slackUsername = apiData.slack.username; | ||
const hash = apiData.hashed_secret; | ||
|
||
console.log('Slack ID:', slackID); | ||
console.log('Hash:', hash); | ||
console.log('Slack username:', slackUsername); | ||
|
||
// Redirect back to the voting page with the Slack ID and hash | ||
return redirect(302, `/showcase?slackID=${slackID}&hash=${hash}&slackUsername=${encodeURIComponent(slackUsername)}`); | ||
} |
Oops, something went wrong.