Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | 67x 9x 9x 9x 9x 9x 9x 2x 1x | import { useMedicalSpecialties } from '@/features/appointments/api/appointments.hooks'
import { useBabies } from '@/features/babies/api/babies.hooks'
import {
useCoGuardiansState,
useCreateSpecialist,
useUpdateSpecialist,
} from '../api/specialists.hooks'
import type { Specialist } from '../api/specialists.schemas'
import { SpecialistEditor } from './SpecialistEditor'
interface Props {
open: boolean
specialist: Specialist | null
currentUserId: string | undefined
onOpenChange: (open: boolean) => void
}
export function SpecialistDialog(props: Props) {
return props.open ? <ConnectedEditor key={props.specialist?.id ?? 'new'} {...props} /> : null
}
function ConnectedEditor({ specialist, currentUserId, onOpenChange }: Props) {
const babies = useBabies()
const guardians = useCoGuardiansState(currentUserId)
const specialties = useMedicalSpecialties()
const create = useCreateSpecialist()
const update = useUpdateSpecialist()
return (
<SpecialistEditor
specialist={specialist}
babies={babies.data ?? []}
guardians={guardians.data}
specialties={specialties.data ?? []}
babiesLoading={babies.isPending}
babiesError={babies.isError}
guardiansLoading={guardians.isPending}
guardiansError={guardians.isError}
specialtiesLoading={specialties.isPending}
specialtiesError={specialties.isError}
retryBabies={() => {
void babies.refetch()
}}
retryGuardians={guardians.retry}
retrySpecialties={() => {
void specialties.refetch()
}}
onOpenChange={onOpenChange}
onSave={async (input) => {
if (specialist) await update.mutateAsync({ specialistId: specialist.id, input })
else await create.mutateAsync(input)
}}
/>
)
}
|