Implement availability management in Scheduling component
- Added functionality to load user availability from the database on component mount. - Integrated create and delete availability features with the backend. - Refactored event handling to manage availability slots dynamically. - Updated supabase.ts to include methods for fetching, creating, and deleting availability records.
This commit is contained in:
@@ -976,3 +976,68 @@ export const phaseDraftManagement = {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Conductor Availability Management
|
||||
export interface ConductorAvailability {
|
||||
id: string
|
||||
user_id: string
|
||||
available_from: string
|
||||
available_to: string
|
||||
notes?: string | null
|
||||
status: 'active' | 'cancelled'
|
||||
created_at: string
|
||||
updated_at: string
|
||||
created_by: string
|
||||
}
|
||||
|
||||
export interface CreateAvailabilityRequest {
|
||||
available_from: string
|
||||
available_to: string
|
||||
notes?: string
|
||||
}
|
||||
|
||||
export const availabilityManagement = {
|
||||
async getMyAvailability(): Promise<ConductorAvailability[]> {
|
||||
const { data: { user }, error: authError } = await supabase.auth.getUser()
|
||||
if (authError || !user) throw new Error('User not authenticated')
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('conductor_availability')
|
||||
.select('*')
|
||||
.eq('user_id', user.id)
|
||||
.eq('status', 'active')
|
||||
.order('available_from', { ascending: true })
|
||||
|
||||
if (error) throw error
|
||||
return data
|
||||
},
|
||||
|
||||
async createAvailability(request: CreateAvailabilityRequest): Promise<ConductorAvailability> {
|
||||
const { data: { user }, error: authError } = await supabase.auth.getUser()
|
||||
if (authError || !user) throw new Error('User not authenticated')
|
||||
|
||||
const { data, error } = await supabase
|
||||
.from('conductor_availability')
|
||||
.insert({
|
||||
user_id: user.id,
|
||||
available_from: request.available_from,
|
||||
available_to: request.available_to,
|
||||
notes: request.notes,
|
||||
created_by: user.id
|
||||
})
|
||||
.select()
|
||||
.single()
|
||||
|
||||
if (error) throw error
|
||||
return data
|
||||
},
|
||||
|
||||
async deleteAvailability(id: string): Promise<void> {
|
||||
const { error } = await supabase
|
||||
.from('conductor_availability')
|
||||
.update({ status: 'cancelled' })
|
||||
.eq('id', id)
|
||||
|
||||
if (error) throw error
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user