From 9adcbae75200276cbdbd308f26784561e6f0f831 Mon Sep 17 00:00:00 2001 From: Femke Reunes Date: Mon, 29 Jun 2026 07:58:47 +0200 Subject: [PATCH] ARC-3691: add useCallbacks to make date selection work --- .../views/MaintenanceAlertsEditForm.tsx | 166 +++++++++--------- 1 file changed, 85 insertions(+), 81 deletions(-) diff --git a/ui/src/react-admin/modules/maintenance-alerts/views/MaintenanceAlertsEditForm.tsx b/ui/src/react-admin/modules/maintenance-alerts/views/MaintenanceAlertsEditForm.tsx index 49ed7db2..aeb69769 100644 --- a/ui/src/react-admin/modules/maintenance-alerts/views/MaintenanceAlertsEditForm.tsx +++ b/ui/src/react-admin/modules/maintenance-alerts/views/MaintenanceAlertsEditForm.tsx @@ -92,81 +92,89 @@ const MaintenanceAlertsEditForm: FunctionComponent { - if (newFromDate) { - const oldFromDate: Date | null = currentMaintenanceAlert?.fromDate - ? parseAsIsoWithoutTimezone(currentMaintenanceAlert.fromDate) - : null; - setCurrentMaintenanceAlert({ - ...currentMaintenanceAlert, - fromDate: new Date( - newFromDate.getFullYear(), - newFromDate.getMonth(), - newFromDate.getDate(), - oldFromDate?.getHours() || 0, - oldFromDate?.getMinutes() || 0 - ).toISOString(), - }); - } - // biome-ignore lint/suspicious/noExplicitAny: TODO fix - }) as any; - - const handleNewFromTime = ((newFromTime: Date | null) => { - if (newFromTime) { - const oldFromDate: Date = currentMaintenanceAlert?.fromDate - ? parseAsIsoWithoutTimezone(currentMaintenanceAlert.fromDate) - : new Date(); - setCurrentMaintenanceAlert({ - ...currentMaintenanceAlert, - fromDate: new Date( - oldFromDate?.getFullYear(), - oldFromDate?.getMonth(), - oldFromDate?.getDate(), - newFromTime.getHours(), - newFromTime.getMinutes() - ).toISOString(), - }); - } - // biome-ignore lint/suspicious/noExplicitAny: TODO fix - }) as any; - - const handleNewUntilDate = ((newUntilDate: Date | null) => { - if (newUntilDate) { - const oldUntilDate: Date | null = currentMaintenanceAlert?.untilDate - ? parseAsIsoWithoutTimezone(currentMaintenanceAlert.untilDate) - : null; - setCurrentMaintenanceAlert({ - ...currentMaintenanceAlert, - untilDate: new Date( - newUntilDate.getFullYear(), - newUntilDate.getMonth(), - newUntilDate.getDate(), - oldUntilDate?.getHours() || 23, - oldUntilDate?.getMinutes() || 59 - ).toISOString(), - }); - } - // biome-ignore lint/suspicious/noExplicitAny: TODO fix - }) as any; - - const handleNewUntilTime = ((newUntilTime: Date | null) => { - if (newUntilTime) { - const oldUntilDate: Date = currentMaintenanceAlert?.untilDate - ? parseAsIsoWithoutTimezone(currentMaintenanceAlert.untilDate) - : new Date(); - setCurrentMaintenanceAlert({ - ...currentMaintenanceAlert, - untilDate: new Date( - oldUntilDate?.getFullYear(), - oldUntilDate?.getMonth(), - oldUntilDate?.getDate(), - newUntilTime.getHours(), - newUntilTime.getMinutes() - ).toISOString(), - }); - } - // biome-ignore lint/suspicious/noExplicitAny: TODO fix - }) as any; + const handleNewFromDate = useCallback( + (newFromDate: Date | null) => { + if (newFromDate) { + const oldFromDate: Date | null = currentMaintenanceAlert?.fromDate + ? parseAsIsoWithoutTimezone(currentMaintenanceAlert.fromDate) + : null; + setCurrentMaintenanceAlert({ + ...currentMaintenanceAlert, + fromDate: new Date( + newFromDate.getFullYear(), + newFromDate.getMonth(), + newFromDate.getDate(), + oldFromDate?.getHours() || 0, + oldFromDate?.getMinutes() || 0 + ).toISOString(), + }); + } + }, + [currentMaintenanceAlert] + ); + + const handleNewFromTime = useCallback( + (newFromTime: Date | null) => { + if (newFromTime) { + const oldFromDate: Date = currentMaintenanceAlert?.fromDate + ? parseAsIsoWithoutTimezone(currentMaintenanceAlert.fromDate) + : new Date(); + setCurrentMaintenanceAlert({ + ...currentMaintenanceAlert, + fromDate: new Date( + oldFromDate?.getFullYear(), + oldFromDate?.getMonth(), + oldFromDate?.getDate(), + newFromTime.getHours(), + newFromTime.getMinutes() + ).toISOString(), + }); + } + }, + [currentMaintenanceAlert] + ); + + const handleNewUntilDate = useCallback( + (newUntilDate: Date | null) => { + if (newUntilDate) { + const oldUntilDate: Date | null = currentMaintenanceAlert?.untilDate + ? parseAsIsoWithoutTimezone(currentMaintenanceAlert.untilDate) + : null; + setCurrentMaintenanceAlert({ + ...currentMaintenanceAlert, + untilDate: new Date( + newUntilDate.getFullYear(), + newUntilDate.getMonth(), + newUntilDate.getDate(), + oldUntilDate?.getHours() || 23, + oldUntilDate?.getMinutes() || 59 + ).toISOString(), + }); + } + }, + [currentMaintenanceAlert] + ); + + const handleNewUntilTime = useCallback( + (newUntilTime: Date | null) => { + if (newUntilTime) { + const oldUntilDate: Date = currentMaintenanceAlert?.untilDate + ? parseAsIsoWithoutTimezone(currentMaintenanceAlert.untilDate) + : new Date(); + setCurrentMaintenanceAlert({ + ...currentMaintenanceAlert, + untilDate: new Date( + oldUntilDate?.getFullYear(), + oldUntilDate?.getMonth(), + oldUntilDate?.getDate(), + newUntilTime.getHours(), + newUntilTime.getMinutes() + ).toISOString(), + }); + } + }, + [currentMaintenanceAlert] + ); const isFormValid = useCallback((): boolean => { try { @@ -435,9 +443,7 @@ const MaintenanceAlertsEditForm: FunctionComponent @@ -482,9 +488,7 @@ const MaintenanceAlertsEditForm: FunctionComponent