-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into justinxue/bre-27-implement-date-and-time-sel…
…ection
- Loading branch information
Showing
56 changed files
with
2,673 additions
and
425 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import supabase from '@/api/supabase/createClient'; | ||
|
||
export async function handleSignUp( | ||
email: string, | ||
password: string, | ||
): Promise<{ success: boolean; message: string }> { | ||
try { | ||
const { data, error } = await supabase.auth.signUp({ email, password }); | ||
|
||
if (error) { | ||
return { success: false, message: `Sign-up failed: ${error.message}` }; | ||
} | ||
|
||
const user = data.user; | ||
if (!user) { | ||
return { | ||
success: false, | ||
message: 'Sign-up failed: User was not created.', | ||
}; | ||
} | ||
|
||
const { error: insertError } = await supabase.from('volunteers').insert([ | ||
{ | ||
user_id: user.id, | ||
email, | ||
first_name: '', | ||
last_name: '', | ||
phone_number: '', | ||
notifications_opt_in: true, // default value | ||
}, | ||
]); | ||
|
||
if (insertError) { | ||
return { | ||
success: false, | ||
message: `Error storing user data: ${insertError.message}`, | ||
}; | ||
} | ||
|
||
return { success: true, message: 'Sign-up successful!' }; | ||
} catch (err) { | ||
if (err instanceof Error) { | ||
return { success: false, message: `Sign-up failed: ${err.message}` }; | ||
} | ||
return { | ||
success: false, | ||
message: 'Sign-up failed: An unknown error occurred.', | ||
}; | ||
} | ||
} | ||
|
||
export async function handleSignIn( | ||
email: string, | ||
password: string, | ||
): Promise<{ success: boolean; message: string }> { | ||
try { | ||
const { error: signInError } = await supabase.auth.signInWithPassword({ | ||
email, | ||
password, | ||
}); | ||
|
||
if (signInError) { | ||
return { | ||
success: false, | ||
message: `Login failed: ${signInError.message}`, | ||
}; | ||
} | ||
|
||
const { data: sessionData, error: sessionError } = | ||
await supabase.auth.getSession(); | ||
|
||
if (sessionError || !sessionData?.session) { | ||
return { | ||
success: false, | ||
message: 'Failed to retrieve session information after login.', | ||
}; | ||
} | ||
|
||
const user_id = sessionData.session.user.id; | ||
|
||
const userExists = await checkUserExists(user_id, 'volunteer'); | ||
|
||
if (!userExists) { | ||
return { success: false, message: 'User not found in volunteers table.' }; | ||
} | ||
|
||
return { success: true, message: 'Login successful!' }; | ||
} catch (err) { | ||
if (err instanceof Error) { | ||
return { success: false, message: `Login failed: ${err.message}` }; | ||
} | ||
return { | ||
success: false, | ||
message: 'Login failed: An unknown error occurred.', | ||
}; | ||
} | ||
} | ||
|
||
export async function checkUserExists( | ||
userId: string, | ||
userType: 'volunteer' | 'facility', | ||
): Promise<boolean> { | ||
try { | ||
const table = userType === 'volunteer' ? 'volunteers' : 'facilities'; | ||
|
||
const { data, error } = await supabase | ||
.from(table) | ||
.select('user_id') | ||
.eq('user_id', userId) | ||
.single(); | ||
|
||
if (error || !data) { | ||
return false; | ||
} | ||
return true; | ||
} catch (err) { | ||
console.error('Error checking user existence:', err); | ||
return false; | ||
} | ||
} |
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,30 @@ | ||
import { UUID } from 'crypto'; | ||
import supabase from '../createClient'; | ||
|
||
// fetches an event by its event_id | ||
export async function fetchFacilityById(facility_id: string) { | ||
const { data, error } = await supabase | ||
.from('facilities') | ||
.select('*') | ||
.eq('facility_id', facility_id) | ||
.single(); | ||
if (error) { | ||
throw new Error(error.message); | ||
} | ||
|
||
return data; | ||
} | ||
|
||
export async function fetchFacilityContactByID(facility_id: UUID) { | ||
const { data, error } = await supabase | ||
.from('facility_contacts') | ||
.select('*') | ||
.eq('facility_id', facility_id) | ||
.single(); | ||
|
||
if (error) { | ||
throw new Error(error.message); | ||
} | ||
|
||
return data; | ||
} |
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,45 @@ | ||
import { GeneralInfo, Preferences } from '@/utils/onboardingContext'; | ||
import supabase from '../createClient'; | ||
|
||
export async function submitOnboardingData( | ||
generalInfo: GeneralInfo, | ||
preferences: Preferences, | ||
): Promise<void> { | ||
try { | ||
const { data: volunteerData, error: volunteerError } = await supabase | ||
.from('volunteers') | ||
.insert([ | ||
{ | ||
first_name: generalInfo.firstName, | ||
last_name: generalInfo.lastName, | ||
phone_number: generalInfo.phoneNumber, | ||
}, | ||
]); | ||
|
||
if (volunteerError) | ||
throw new Error(`Volunteer data error: ${volunteerError.message}`); | ||
|
||
const { data: preferencesData, error: preferencesError } = await supabase | ||
.from('volunteer_preferences') | ||
.insert([ | ||
{ | ||
facility_type: preferences.facilityType, | ||
city: preferences.location, | ||
audience: preferences.audience, | ||
instruments: preferences.preferredEquipment, | ||
type_of_act: preferences.typeOfAct, | ||
genre: preferences.genre, | ||
}, | ||
]); | ||
|
||
if (preferencesError) | ||
throw new Error(`Preferences data error: ${preferencesError.message}`); | ||
|
||
console.log('Onboarding data submitted successfully:', { | ||
volunteerData, | ||
preferencesData, | ||
}); | ||
} catch (error) { | ||
console.error('Error submitting onboarding data:', error); | ||
} | ||
} |
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,28 @@ | ||
import { UUID } from 'crypto'; | ||
import supabase from '../createClient'; | ||
|
||
export async function fetchPerformer(event_id: UUID) { | ||
const { data, error } = await supabase | ||
.from('event_signups') | ||
.select('*') | ||
.eq('event_id', event_id) | ||
.eq('role', 'PERFORMER') | ||
.eq('is_accepted', true) | ||
.single(); | ||
|
||
if (error) { | ||
throw new Error(error.message); | ||
} | ||
|
||
const { data: performer, error: performererror } = await supabase | ||
.from('volunteers') | ||
.select('*') | ||
.eq('user_id', data.user_id) | ||
.single(); | ||
|
||
if (performererror) { | ||
throw new Error(performererror.message); | ||
} | ||
|
||
return performer; | ||
} |
Oops, something went wrong.