mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2025-12-13 07:46:10 +00:00
Add config and invite api
This commit is contained in:
parent
d5e730134e
commit
b3c8b7fc67
@ -1 +1,5 @@
|
||||
VITE_OPEN_COLLECTIVE_API_KEY=your_key
|
||||
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
|
||||
|
||||
@ -175,6 +175,7 @@ function App() {
|
||||
<Quests />
|
||||
<Routes>
|
||||
<Route path='/*' element={<MapContainer map={map} layers={layers} />}>
|
||||
<Route path='invite' element={<InvitePage />} />
|
||||
<Route path='login' element={<LoginPage />} />
|
||||
<Route path='signup' element={<SignupPage />} />
|
||||
<Route
|
||||
|
||||
69
frontend/src/api/inviteApi.ts
Normal file
69
frontend/src/api/inviteApi.ts
Normal file
@ -0,0 +1,69 @@
|
||||
import { config } from '@/config'
|
||||
|
||||
interface InvitingProfileResponse {
|
||||
id: string
|
||||
}
|
||||
|
||||
export class inviteApi {
|
||||
async getInvitingProfileId(inviteId: string): Promise<string | null> {
|
||||
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<boolean> {
|
||||
const invitingProfileId = await this.getInvitingProfileId(inviteId)
|
||||
|
||||
return invitingProfileId !== null
|
||||
}
|
||||
|
||||
async redeemInvite(inviteId: string): Promise<boolean> {
|
||||
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.')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
7
frontend/src/config/index.ts
Normal file
7
frontend/src/config/index.ts
Normal file
@ -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'),
|
||||
}
|
||||
@ -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" }]
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user