diff --git a/public/locale/en.json b/public/locale/en.json index 6ad1723fd1c..e707ddf098c 100644 --- a/public/locale/en.json +++ b/public/locale/en.json @@ -1341,6 +1341,7 @@ "no_plots_configured": "No plots configured", "no_policy_added": "No Insurance Policy Added", "no_policy_found": "No Insurance Policy Found for this Patient", + "no_practitioners_found": "No practicioners found", "no_presets": "No Presets", "no_questionnaire_responses": "No Questionnaire Responses", "no_questionnaires_found": "No questionnaires found", diff --git a/src/pages/Appointments/BookAppointment.tsx b/src/pages/Appointments/BookAppointment.tsx index 3fa5aae0a65..5a670f81e16 100644 --- a/src/pages/Appointments/BookAppointment.tsx +++ b/src/pages/Appointments/BookAppointment.tsx @@ -1,6 +1,6 @@ import { useMutation, useQuery } from "@tanstack/react-query"; import { navigate } from "raviger"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { toast } from "sonner"; @@ -53,6 +53,21 @@ export default function BookAppointment(props: Props) { }); const resource = resourcesQuery.data?.users.find((r) => r.id === resourceId); + useEffect(() => { + const users = resourcesQuery.data?.users; + if (!users) { + return; + } + + if (users.length === 1) { + setResourceId(users[0].id); + } + + if (users.length === 0) { + toast.error(t("no_practitioners_found")); + } + }, [resourcesQuery.data?.users]); + const { mutateAsync: createAppointment } = useMutation({ mutationFn: mutate(scheduleApis.slots.createAppointment, { pathParams: { @@ -114,7 +129,7 @@ export default function BookAppointment(props: Props) { onValueChange={(value) => setResourceId(value)} > - + {resource && (