From 9c6deb59e6be24a144af99fe85326293333c7de3 Mon Sep 17 00:00:00 2001 From: Nuxgrid Date: Sat, 18 Jul 2026 22:36:36 +0200 Subject: [PATCH] chore: build --- .../src/screens/admin/DeliveryScreen.tsx | 142 ++++++++++++------ 1 file changed, 93 insertions(+), 49 deletions(-) diff --git a/frontend-admin/src/screens/admin/DeliveryScreen.tsx b/frontend-admin/src/screens/admin/DeliveryScreen.tsx index 77ccbcc3..13ccfc6d 100644 --- a/frontend-admin/src/screens/admin/DeliveryScreen.tsx +++ b/frontend-admin/src/screens/admin/DeliveryScreen.tsx @@ -90,14 +90,17 @@ export default function DeliveryScreen() { weeks: LoginHistoryWeek[]; } | null>(null); const [loginHistoryLoading, setLoginHistoryLoading] = useState(false); + const loginHistoryRequestRef = useRef(0); const fetchLoginHistory = async ( username: string, year: number, month: number, ) => { + const requestId = ++loginHistoryRequestRef.current; setLoginHistoryLoading(true); const res = await getLivreurLoginHistory(username, year, month); + if (requestId !== loginHistoryRequestRef.current) return; setLoginHistoryModal({ username, year: res.year, @@ -113,7 +116,7 @@ export default function DeliveryScreen() { }; const changeLoginHistoryMonth = (delta: number) => { - if (!loginHistoryModal) return; + if (!loginHistoryModal || loginHistoryLoading) return; let year = loginHistoryModal.year; let month = loginHistoryModal.month + delta; if (month < 1) { @@ -123,6 +126,13 @@ export default function DeliveryScreen() { month = 1; year += 1; } + const now = new Date(); + if ( + year > now.getFullYear() || + (year === now.getFullYear() && month > now.getMonth() + 1) + ) { + return; + } fetchLoginHistory(loginHistoryModal.username, year, month); }; @@ -1159,54 +1169,88 @@ export default function DeliveryScreen() { - - changeLoginHistoryMonth(-1)} - > - - - - {loginHistoryModal && - new Date( - loginHistoryModal.year, - loginHistoryModal.month - 1, - 1, - ) - .toLocaleDateString("fr-FR", { - month: "long", - year: "numeric", - }) - .replace(/^./, (c) => - c.toUpperCase(), - )} - - changeLoginHistoryMonth(1)} - > - - - + {(() => { + const now = new Date(); + const isCurrentMonth = + !!loginHistoryModal && + loginHistoryModal.year === + now.getFullYear() && + loginHistoryModal.month === + now.getMonth() + 1; + const canGoBack = !loginHistoryLoading; + const canGoForward = + !loginHistoryLoading && !isCurrentMonth; + return ( + + + changeLoginHistoryMonth(-1) + } + hitSlop={8} + > + + + + {loginHistoryModal && + new Date( + loginHistoryModal.year, + loginHistoryModal.month - + 1, + 1, + ) + .toLocaleDateString( + "fr-FR", + { + month: "long", + year: "numeric", + }, + ) + .replace(/^./, (c) => + c.toUpperCase(), + )} + + + changeLoginHistoryMonth(1) + } + hitSlop={8} + > + + + + ); + })()} {loginHistoryLoading ? (