source: petify-frontend/src/api/clinicApplications.ts

Last change on this file was fa32d0f, checked in by veronika-ils <ilioskaveronika@…>, 4 hours ago

Added form for clinics

  • Property mode set to 100644
File size: 1.0 KB
Line 
1function getBaseUrl(): string {
2 const base = (import.meta.env.VITE_API_BASE_URL as string | undefined) ?? ''
3 return base.replace(/\/$/, '')
4}
5
6function joinUrl(base: string, path: string): string {
7 if (!base) return path
8 return `${base}${path.startsWith('/') ? '' : '/'}${path}`
9}
10
11export type ClinicApplicationRequest = {
12 name: string
13 email: string
14 phone: string
15 city: string
16 address: string
17}
18
19export async function submitClinicApplication(payload: ClinicApplicationRequest): Promise<any> {
20 const url = joinUrl(getBaseUrl(), '/api/clinic-applications')
21 const res = await fetch(url, {
22 method: 'POST',
23 headers: {
24 'Content-Type': 'application/json',
25 Accept: 'application/json',
26 },
27 body: JSON.stringify(payload),
28 })
29
30 const contentType = res.headers.get('content-type') || ''
31 const data = contentType.includes('application/json') ? await res.json() : null
32
33 if (!res.ok) {
34 throw new Error(data?.error || `Failed to submit clinic application (${res.status})`)
35 }
36
37 return data
38}
Note: See TracBrowser for help on using the repository browser.