date issue 4

This commit is contained in:
2025-05-19 08:05:29 +05:30
parent be19ab6666
commit 490c6a22c1
2 changed files with 14 additions and 10 deletions

View File

@@ -257,20 +257,19 @@ export function AppointmentForm({
: `Appointment with ${selectedStaff?.name}`; : `Appointment with ${selectedStaff?.name}`;
} }
// 👇 Use current date if none provided const formattedDate = format(data.date, "yyyy-MM-dd");
const appointmentDate = data.date ? new Date(data.date) : new Date(); console.log(
"Updating with date:",
if (isNaN(appointmentDate.getTime())) { data.date,
console.error("Invalid date:", data.date); format(data.date, "yyyy-MM-dd")
return; );
}
onSubmit({ onSubmit({
...data, ...data,
title, title,
notes, notes,
patientId, patientId,
date: format(appointmentDate, "yyyy-MM-dd"), date: formattedDate,
startTime: data.startTime, startTime: data.startTime,
endTime: data.endTime, endTime: data.endTime,
}); });

View File

@@ -371,10 +371,15 @@ export default function AppointmentsPage() {
const handleAppointmentSubmit = ( const handleAppointmentSubmit = (
appointmentData: InsertAppointment | UpdateAppointment appointmentData: InsertAppointment | UpdateAppointment
) => { ) => {
// Make sure the date is for the selected date
const updatedData = { const updatedData = {
...appointmentData, ...appointmentData,
date: format(selectedDate, "yyyy-MM-dd"), date: format(
appointmentData.date instanceof Date
? appointmentData.date
: new Date(appointmentData.date),
"yyyy-MM-dd"
),
}; };
// Check if we're editing an existing appointment with a valid ID // Check if we're editing an existing appointment with a valid ID