From 72f5eacfec333924cb692d1453e13a8a221a608c Mon Sep 17 00:00:00 2001 From: RyamL1221 Date: Mon, 9 Dec 2024 13:09:45 -0500 Subject: [PATCH] added team.ts --- app/lib/api/team.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 app/lib/api/team.ts diff --git a/app/lib/api/team.ts b/app/lib/api/team.ts new file mode 100644 index 0000000..7339221 --- /dev/null +++ b/app/lib/api/team.ts @@ -0,0 +1,25 @@ +'use server'; + +import { ENDPOINTS } from './endpoints'; + +export async function UploadTeamSubmission(leaderEmail: string, data: any) { + const postBody = { + team_leader: leaderEmail, + team_members: data.team_members.filter(Boolean), + }; + + const resp = await fetch(ENDPOINTS.makeTeam, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(postBody), + }); + + if (resp.status !== 200) return { error: 'Non 200 response', response: '' }; + + const json = await resp.json(); + if (json.error) { + return { error: json.error, response: '' }; + } + + return { error: '', response: 'Successfully submitted team!' }; +}