From b3c8b7fc67122a97068b7d96f3716ab64680f8f0 Mon Sep 17 00:00:00 2001 From: Maximilian Harz Date: Wed, 25 Jun 2025 20:50:34 +0200 Subject: [PATCH] Add config and invite api --- frontend/.env | 6 ++- frontend/src/App.tsx | 1 + frontend/src/api/inviteApi.ts | 69 +++++++++++++++++++++++++++++++++++ frontend/src/config/index.ts | 7 ++++ frontend/tsconfig.json | 10 ++++- 5 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 frontend/src/api/inviteApi.ts create mode 100644 frontend/src/config/index.ts diff --git a/frontend/.env b/frontend/.env index cb285291..b6b98fb1 100644 --- a/frontend/.env +++ b/frontend/.env @@ -1 +1,5 @@ -VITE_OPEN_COLLECTIVE_API_KEY=your_key \ No newline at end of file +VITE_OPEN_COLLECTIVE_API_KEY=your_key + +VITE_API_URL=https://api.utopia-lab.org +VITE_VALIDATE_INVITE_FLOW_ID=01d61db0-25aa-4bfa-bc24-c6a8f208a455 +VITE_REDEEM_INVITE_FLOW_ID=todo diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 82dc26f8..f0de565d 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -175,6 +175,7 @@ function App() { }> + } /> } /> } /> { + try { + const response = await fetch( + `${config.apiUrl}/flows/trigger/${config.validateInviteFlowId}/${inviteId}`, + { + method: 'GET', + mode: 'cors', + headers: { + 'Content-Type': 'application/json', + }, + }, + ) + + if (!response.ok) { + return null + } + + const data = (await response.json()) as InvitingProfileResponse + + return data.id + } catch (error: unknown) { + // eslint-disable-next-line no-console + console.error('Error fetching inviting profile:', error) + if (error instanceof Error && error.message) { + throw new Error(error.message) + } else { + throw new Error('An unknown error occurred while fetching the inviting profile.') + } + } + } + + async validateInvite(inviteId: string): Promise { + const invitingProfileId = await this.getInvitingProfileId(inviteId) + + return invitingProfileId !== null + } + + async redeemInvite(inviteId: string): Promise { + try { + const response = await fetch( + `${config.apiUrl}/flows/trigger/${config.redeemInviteFlowId}/${inviteId}`, + { + method: 'GET', + mode: 'cors', + headers: { + 'Content-Type': 'application/json', + }, + }, + ) + + return response.ok + } catch (error: unknown) { + // eslint-disable-next-line no-console + console.error('Error fetching inviting profile:', error) + if (error instanceof Error && error.message) { + throw new Error(error.message) + } else { + throw new Error('An unknown error occurred while fetching the inviting profile.') + } + } + } +} diff --git a/frontend/src/config/index.ts b/frontend/src/config/index.ts new file mode 100644 index 00000000..c908112c --- /dev/null +++ b/frontend/src/config/index.ts @@ -0,0 +1,7 @@ +export const config = { + apiUrl: String(import.meta.env.VITE_API_URL ?? 'https://api.utopia-lab.org'), + validateInviteFlowId: String( + import.meta.env.VITE_VALIDATE_INVITE_FLOW_ID ?? '01d61db0-25aa-4bfa-bc24-c6a8f208a455', + ), + redeemInviteFlowId: String(import.meta.env.VITE_REDEEM_INVITE_FLOW_ID ?? 'todo'), +} diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json index 9720a1eb..f7d59d5e 100644 --- a/frontend/tsconfig.json +++ b/frontend/tsconfig.json @@ -17,8 +17,14 @@ "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true + "noFallthroughCasesInSwitch": true, + + /* Paths */ + "baseUrl": ".", + "paths": { + "@/*": ["src/*"], + } }, - "include": ["src"], + "include": ["src"], "references": [{ "path": "./tsconfig.node.json" }] }