fix: remove hardcoded clinic list, fetch from platform dynamically

Appointment form clinic dropdown was hardcoded to 3 "Global Hospital"
branches. Replaced with a GraphQL query to { clinics } so each
workspace shows its own clinics. If no clinics are configured, the
dropdown is empty instead of showing wrong data.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-10 16:46:30 +05:30
parent 0fc9375729
commit 05de50f796

View File

@@ -35,11 +35,8 @@ type AppointmentFormProps = {
type DoctorRecord = { id: string; name: string; department: string; clinic: string };
const clinicItems = [
{ id: 'koramangala', label: 'Global Hospital - Koramangala' },
{ id: 'whitefield', label: 'Global Hospital - Whitefield' },
{ id: 'indiranagar', label: 'Global Hospital - Indiranagar' },
];
// Clinics are fetched dynamically from the platform — no hardcoded list.
// If the workspace has no clinics configured, the dropdown shows empty.
const genderItems = [
{ id: 'male', label: 'Male' },
@@ -97,6 +94,7 @@ export const AppointmentForm = ({
const [age, setAge] = useState('');
const [gender, setGender] = useState<string | null>(null);
const [clinic, setClinic] = useState<string | null>(null);
const [clinicItems, setClinicItems] = useState<Array<{ id: string; label: string }>>([]);
const [department, setDepartment] = useState<string | null>(existingAppointment?.department ?? null);
const [doctor, setDoctor] = useState<string | null>(existingAppointment?.doctorId ?? null);
const [date, setDate] = useState(() => {
@@ -125,6 +123,18 @@ export const AppointmentForm = ({
// `clinic` field anymore. We pull the full visit-slot list via the
// doctorVisitSlots reverse relation so the agent can see which
// clinics + days this doctor covers in the picker.
// Fetch clinics from platform
useEffect(() => {
if (!isOpen) return;
apiClient.graphql<{ clinics: { edges: Array<{ node: { id: string; clinicName: string } }> } }>(
`{ clinics(first: 50) { edges { node { id clinicName } } } }`,
).then(data => {
setClinicItems(
data.clinics.edges.map(e => ({ id: e.node.id, label: e.node.clinicName || 'Unnamed Clinic' })),
);
}).catch(() => {});
}, [isOpen]);
useEffect(() => {
if (!isOpen) return;
apiClient.graphql<{ doctors: { edges: Array<{ node: any }> } }>(