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:
parent
c86e0e1ea6
commit
052e5e7e86
|
|
@ -58,7 +58,7 @@ const CalendarWidget = ({
|
|||
}) => {
|
||||
return (
|
||||
<div className={layoutClassName}>
|
||||
<div className={calendarClassName}>
|
||||
<div className={(calendarClassName || "") + " relative"}>
|
||||
<Button
|
||||
variant="ghost"
|
||||
aria-label={label}
|
||||
|
|
|
|||
|
|
@ -616,11 +616,19 @@ export const OrderDetailPanel = ({
|
|||
setIsSavingShipment(false);
|
||||
}
|
||||
}, [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 existingDeliveryDate = fromDateKey(order?.deliveryDate);
|
||||
const fallbackDate = fromDateKey(minSelectableDateKey) || new Date();
|
||||
const sourceDate = existingDeliveryDate && isFutureDeliveryDate(toDateKey(existingDeliveryDate))
|
||||
const sourceDate = existingDeliveryDate
|
||||
? existingDeliveryDate
|
||||
: fallbackDate;
|
||||
|
||||
|
|
@ -635,7 +643,10 @@ export const OrderDetailPanel = ({
|
|||
}),
|
||||
[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(() => {
|
||||
setSelectedDriverId(order?.assignedDriverId || "");
|
||||
|
|
@ -645,7 +656,10 @@ export const OrderDetailPanel = ({
|
|||
React.useEffect(() => {
|
||||
const normalizedDeliveryDate = normalizeDateForInput(order?.deliveryDate);
|
||||
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);
|
||||
const selectedDate = fromDateKey(selectedDateKey) || new Date();
|
||||
setCurrentMonth(startOfMonth(selectedDate));
|
||||
|
|
|
|||
Loading…
Reference in New Issue