import { type Component, createEffect, createResource, For, Show, } from "solid-js"; import { useNavigate } from "@solidjs/router"; import { useAuth } from "@/context/AuthContext"; import { therapistApi } from "@/api/therapist"; import { patientApi } from "@/api/patient"; import TherapistCard from "@/components/TherapistCard"; import { UserType } from "@/enums/UserType"; const Therapists: Component = () => { const { user, isAuthenticated } = useAuth(); const navigate = useNavigate(); const [therapists] = createResource( isAuthenticated, async (authenticated) => { if (!authenticated) return []; const data = await therapistApi.getAllTherapists(); return data.sort((a, b) => { const slotsA = a.freeConsultationSlots?.length || 0; const slotsB = b.freeConsultationSlots?.length || 0; return slotsB - slotsA; }); }, ); const [currentTherapistId, { refetch: refetchCurrentTherapist }] = createResource(isAuthenticated, async (authenticated) => { if (!authenticated) return null; return await patientApi.getCurrentTherapist(); }); createEffect(() => { if (!isAuthenticated()) { navigate("/login", { replace: true }); return; } const currentUser = user(); if (currentUser?.userType !== UserType.PATIENT) { navigate("/", { replace: true }); } }); const handleTherapistChange = async () => await refetchCurrentTherapist(); return (

Find a Therapist

Browse our available therapists and their free consultation schedules

} > 0} fallback={

No therapists available

} >
{(therapist) => ( )}
); }; export default Therapists;