date issue 1

This commit is contained in:
2025-05-18 09:37:14 +05:30
parent 7d31ac2528
commit fdbc405890
4 changed files with 81 additions and 64 deletions

View File

@@ -432,11 +432,16 @@ export default function AppointmentsPage() {
// Get formatted date string for display // Get formatted date string for display
const formattedDate = format(selectedDate, "yyyy-MM-dd"); const formattedDate = format(selectedDate, "yyyy-MM-dd");
const selectedDateAppointments = appointments.filter((apt) => {
// Ensure apt.date is in 'yyyy-MM-dd' format before comparison const selectedDateAppointments = appointments.filter((appointment) => {
const appointmentDate = format(new Date(apt.date), "yyyy-MM-dd"); // Convert appointment.date to 'yyyy-MM-dd' string
return appointmentDate === formattedDate; const dateStr =
}); typeof appointment.date === "string"
? format(new Date(appointment.date), "yyyy-MM-dd")
: format(appointment.date, "yyyy-MM-dd");
return dateStr === formattedDate;
});
// Process appointments for the scheduler view // Process appointments for the scheduler view
const processedAppointments: ScheduledAppointment[] = const processedAppointments: ScheduledAppointment[] =

View File

@@ -1,6 +1,6 @@
import { useState, useRef} from "react"; import { useState, useRef } from "react";
import { useQuery, useMutation } from "@tanstack/react-query"; import { useQuery, useMutation } from "@tanstack/react-query";
import { format } from "date-fns"; import { format, parse } from "date-fns";
import { TopAppBar } from "@/components/layout/top-app-bar"; import { TopAppBar } from "@/components/layout/top-app-bar";
import { Sidebar } from "@/components/layout/sidebar"; import { Sidebar } from "@/components/layout/sidebar";
import { StatCard } from "@/components/ui/stat-card"; import { StatCard } from "@/components/ui/stat-card";
@@ -106,8 +106,6 @@ export default function Dashboard() {
const { user } = useAuth(); const { user } = useAuth();
const addPatientModalRef = useRef<AddPatientModalRef | null>(null); const addPatientModalRef = useRef<AddPatientModalRef | null>(null);
// Fetch patients // Fetch patients
const { data: patients = [], isLoading: isLoadingPatients } = useQuery< const { data: patients = [], isLoading: isLoadingPatients } = useQuery<
Patient[] Patient[]
@@ -191,30 +189,29 @@ export default function Dashboard() {
}, },
}); });
const deletePatientMutation = useMutation({ const deletePatientMutation = useMutation({
mutationFn: async (id: number) => { mutationFn: async (id: number) => {
const res = await apiRequest("DELETE", `/api/patients/${id}`); const res = await apiRequest("DELETE", `/api/patients/${id}`);
return; return;
}, },
onSuccess: () => { onSuccess: () => {
setIsDeletePatientOpen(false); setIsDeletePatientOpen(false);
queryClient.invalidateQueries({ queryKey: ["/api/patients/"] }); queryClient.invalidateQueries({ queryKey: ["/api/patients/"] });
toast({ toast({
title: "Success", title: "Success",
description: "Patient deleted successfully!", description: "Patient deleted successfully!",
variant: "default", variant: "default",
}); });
}, },
onError: (error) => { onError: (error) => {
console.log(error) console.log(error);
toast({ toast({
title: "Error", title: "Error",
description: `Failed to delete patient: ${error.message}`, description: `Failed to delete patient: ${error.message}`,
variant: "destructive", variant: "destructive",
}); });
}, },
}); });
const toggleMobileMenu = () => { const toggleMobileMenu = () => {
setIsMobileMenuOpen(!isMobileMenuOpen); setIsMobileMenuOpen(!isMobileMenuOpen);
@@ -262,16 +259,16 @@ export default function Dashboard() {
}; };
const handleConfirmDeletePatient = async () => { const handleConfirmDeletePatient = async () => {
if (currentPatient) { if (currentPatient) {
deletePatientMutation.mutate(currentPatient.id); deletePatientMutation.mutate(currentPatient.id);
} else { } else {
toast({ toast({
title: "Error", title: "Error",
description: "No patient selected for deletion.", description: "No patient selected for deletion.",
variant: "destructive", variant: "destructive",
}); });
} }
}; };
const isLoading = const isLoading =
isLoadingPatients || isLoadingPatients ||
@@ -362,8 +359,13 @@ export default function Dashboard() {
const today = format(new Date(), "yyyy-MM-dd"); const today = format(new Date(), "yyyy-MM-dd");
const todaysAppointments = appointments.filter((appointment) => { const todaysAppointments = appointments.filter((appointment) => {
const appointmentDate = format(new Date(appointment.date), "yyyy-MM-dd"); // Convert appointment.date to 'yyyy-MM-dd' string
return appointmentDate === today; const dateStr =
typeof appointment.date === "string"
? format(new Date(appointment.date), "yyyy-MM-dd")
: format(appointment.date, "yyyy-MM-dd");
return dateStr === today;
}); });
// Count completed appointments today // Count completed appointments today
@@ -453,19 +455,23 @@ export default function Dashboard() {
</h3> </h3>
<div className="text-sm text-gray-500 flex items-center space-x-2"> <div className="text-sm text-gray-500 flex items-center space-x-2">
<span> <span>
{new Date( <span>
`${appointment.date.toString().slice(0, 10)}T${appointment.startTime}:00` {`${format(
).toLocaleTimeString([], { parse(
hour: "2-digit", `${format(new Date(appointment.date), "yyyy-MM-dd")} ${appointment.startTime}`,
minute: "2-digit", "yyyy-MM-dd HH:mm",
})}{" "} new Date()
-{" "} ),
{new Date( "hh:mm a"
`${appointment.date.toString().slice(0, 10)}T${appointment.endTime}:00` )} - ${format(
).toLocaleTimeString([], { parse(
hour: "2-digit", `${format(new Date(appointment.date), "yyyy-MM-dd")} ${appointment.endTime}`,
minute: "2-digit", "yyyy-MM-dd HH:mm",
})} new Date()
),
"hh:mm a"
)}`}
</span>
</span> </span>
<span>•</span> <span>•</span>
<span> <span>
@@ -560,9 +566,8 @@ export default function Dashboard() {
isOpen={isDeletePatientOpen} isOpen={isDeletePatientOpen}
onConfirm={handleConfirmDeletePatient} onConfirm={handleConfirmDeletePatient}
onCancel={() => setIsDeletePatientOpen(false)} onCancel={() => setIsDeletePatientOpen(false)}
patientName={currentPatient?.name} entityName={currentPatient?.name}
/> />
</div> </div>
</main> </main>
</div> </div>
@@ -612,9 +617,15 @@ export default function Dashboard() {
<div className="mt-2 space-y-2"> <div className="mt-2 space-y-2">
<p> <p>
<span className="text-gray-500">Date of Birth:</span>{" "} <span className="text-gray-500">Date of Birth:</span>{" "}
{new Date( <span className="text-gray-500">Date of Birth:</span>{" "}
currentPatient.dateOfBirth {format(
).toLocaleDateString()} parse(
currentPatient.dateOfBirth,
"yyyy-MM-dd",
new Date()
),
"PPP"
)}
</p> </p>
<p> <p>
<span className="text-gray-500">Gender:</span>{" "} <span className="text-gray-500">Gender:</span>{" "}

View File

@@ -425,7 +425,7 @@ export default function PatientsPage() {
isOpen={isDeletePatientOpen} isOpen={isDeletePatientOpen}
onConfirm={handleConfirmDeletePatient} onConfirm={handleConfirmDeletePatient}
onCancel={() => setIsDeletePatientOpen(false)} onCancel={() => setIsDeletePatientOpen(false)}
patientName={currentPatient?.name} entityName={currentPatient?.name}
/> />
</CardContent> </CardContent>
</Card> </Card>

View File

@@ -5,3 +5,4 @@ node_modules
#these two are autogenerated with command, db:generate #these two are autogenerated with command, db:generate
generated/prisma/ generated/prisma/
shared shared
prisma/migrations