@@ -12,26 +12,50 @@ import UserScheduleSettingsView from './UserScheduleSettingsView';
1212import UserScheduleSettingsEdit from './UserScheduleSettingsEdit' ;
1313import PageBlock from '../../../layouts/PageBlock' ;
1414import { User } from 'shared' ;
15- import { useUserScheduleSettings } from '../../../hooks/users.hooks' ;
15+ import { useUpdateUserScheduleSettings , useUserScheduleSettings } from '../../../hooks/users.hooks' ;
1616import LoadingIndicator from '../../../components/LoadingIndicator' ;
1717import ErrorPage from '../../ErrorPage' ;
18+ import { useToast } from '../../../hooks/toasts.hooks' ;
1819
1920export interface ScheduleSettingsFormInput {
20- email : string ;
21- zoomLink : string ;
21+ personalGmail : string ;
22+ personalZoomLink : string ;
23+ }
24+
25+ export interface ScheduleSettingsPayload extends ScheduleSettingsFormInput {
26+ availability : number [ ] ;
2227}
2328
2429const UserScheduleSettings = ( { user } : { user : User } ) => {
2530 const [ edit , setEdit ] = useState ( false ) ;
31+ const toast = useToast ( ) ;
2632
2733 const { data, isLoading, isError, error } = useUserScheduleSettings ( user . userId ) ;
34+ const {
35+ mutateAsync : updateUserScheduleSettings ,
36+ isLoading : updateUserScheduleSettingsIsLoading ,
37+ isError : updateUserScheduleSettingsIsError ,
38+ error : updateUserScheduleSettingsError
39+ } = useUpdateUserScheduleSettings ( ) ;
2840
29- if ( ! data || isLoading ) return < LoadingIndicator /> ;
41+ if ( ! data || isLoading || updateUserScheduleSettingsIsLoading ) return < LoadingIndicator /> ;
3042
3143 if ( isError ) return < ErrorPage error = { error } message = { error . message } /> ;
44+ if ( updateUserScheduleSettingsIsError )
45+ return < ErrorPage error = { updateUserScheduleSettingsError ! } message = { updateUserScheduleSettingsError ?. message } /> ;
3246
33- const handleConfirm = async ( payload : { email : string ; zoomLink : string ; availabilities : number [ ] } ) => {
47+ const handleConfirm = async ( payload : ScheduleSettingsPayload ) => {
3448 setEdit ( false ) ;
49+ try {
50+ await updateUserScheduleSettings ( {
51+ drScheduleSettingsId : data . drScheduleSettingsId ,
52+ ...payload
53+ } ) ;
54+ } catch ( e ) {
55+ if ( e instanceof Error ) {
56+ toast . error ( e . message ) ;
57+ }
58+ }
3559 } ;
3660
3761 return (
0 commit comments