fix: calendar overlap + allow past dates for logistician

1. CalendarWidget: add relative to calendar container so absolute popup
   positions correctly (no more overlapping with other elements)
2. OrderDetailPanel: logistician/admin/manager can select past dates
   (3 months back) for retroactive delivery closing
3. canGoBack always true for logistician — can navigate to past months
4. Existing past delivery dates are preserved (not reset to tomorrow)
This commit is contained in:
root 2026-07-13 14:42:36 +00:00
parent c86e0e1ea6
commit 052e5e7e86
2 changed files with 19 additions and 5 deletions

View File

@ -58,7 +58,7 @@ const CalendarWidget = ({
}) => { }) => {
return ( return (
<div className={layoutClassName}> <div className={layoutClassName}>
<div className={calendarClassName}> <div className={(calendarClassName || "") + " relative"}>
<Button <Button
variant="ghost" variant="ghost"
aria-label={label} aria-label={label}

View File

@ -616,11 +616,19 @@ export const OrderDetailPanel = ({
setIsSavingShipment(false); setIsSavingShipment(false);
} }
}, [onSaveShipmentData, order?.id]); }, [onSaveShipmentData, order?.id]);
const minSelectableDateKey = React.useMemo(() => getNextSelectableDateKey(), []); const minSelectableDateKey = React.useMemo(() => {
// Logistician/admin can set past dates for retroactive delivery closing
if (["logistician", "admin", "mega_admin", "manager"].includes(userRole)) {
const past = new Date();
past.setMonth(past.getMonth() - 3);
return toDateKey(past);
}
return getNextSelectableDateKey();
}, [userRole]);
const [currentMonth, setCurrentMonth] = React.useState(() => { const [currentMonth, setCurrentMonth] = React.useState(() => {
const existingDeliveryDate = fromDateKey(order?.deliveryDate); const existingDeliveryDate = fromDateKey(order?.deliveryDate);
const fallbackDate = fromDateKey(minSelectableDateKey) || new Date(); const fallbackDate = fromDateKey(minSelectableDateKey) || new Date();
const sourceDate = existingDeliveryDate && isFutureDeliveryDate(toDateKey(existingDeliveryDate)) const sourceDate = existingDeliveryDate
? existingDeliveryDate ? existingDeliveryDate
: fallbackDate; : fallbackDate;
@ -635,7 +643,10 @@ export const OrderDetailPanel = ({
}), }),
[currentMonth], [currentMonth],
); );
const canGoBack = toDateKey(currentMonth) > toDateKey(startOfMonth(fromDateKey(minSelectableDateKey) || new Date())); const canGoBack = (() => {
if (["logistician", "admin", "mega_admin", "manager"].includes(userRole)) return true;
return toDateKey(currentMonth) > toDateKey(startOfMonth(fromDateKey(minSelectableDateKey) || new Date()));
})();
React.useEffect(() => { React.useEffect(() => {
setSelectedDriverId(order?.assignedDriverId || ""); setSelectedDriverId(order?.assignedDriverId || "");
@ -645,7 +656,10 @@ export const OrderDetailPanel = ({
React.useEffect(() => { React.useEffect(() => {
const normalizedDeliveryDate = normalizeDateForInput(order?.deliveryDate); const normalizedDeliveryDate = normalizeDateForInput(order?.deliveryDate);
const nextSelectableDateKey = getNextSelectableDateKey(); const nextSelectableDateKey = getNextSelectableDateKey();
const selectedDateKey = isFutureDeliveryDate(normalizedDeliveryDate) ? normalizedDeliveryDate : nextSelectableDateKey; const canUsePastDate = ["logistician", "admin", "mega_admin", "manager"].includes(userRole);
const selectedDateKey = (normalizedDeliveryDate && (canUsePastDate || isFutureDeliveryDate(normalizedDeliveryDate)))
? normalizedDeliveryDate
: nextSelectableDateKey;
setDeliveryDate(selectedDateKey); setDeliveryDate(selectedDateKey);
const selectedDate = fromDateKey(selectedDateKey) || new Date(); const selectedDate = fromDateKey(selectedDateKey) || new Date();
setCurrentMonth(startOfMonth(selectedDate)); setCurrentMonth(startOfMonth(selectedDate));