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}`;
}
// 👇 Use current date if none provided
const appointmentDate = data.date ? new Date(data.date) : new Date();
if (isNaN(appointmentDate.getTime())) {
console.error("Invalid date:", data.date);
return;
}
const formattedDate = format(data.date, "yyyy-MM-dd");
console.log(
"Updating with date:",
data.date,
format(data.date, "yyyy-MM-dd")
);
onSubmit({
...data,
title,
notes,
patientId,
date: format(appointmentDate, "yyyy-MM-dd"),
date: formattedDate,
startTime: data.startTime,
endTime: data.endTime,
});

View File

@@ -371,10 +371,15 @@ export default function AppointmentsPage() {
const handleAppointmentSubmit = (
appointmentData: InsertAppointment | UpdateAppointment
) => {
// Make sure the date is for the selected date
const updatedData = {
...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