updates on the deliveries page and status updates as well
This commit is contained in:
@@ -33,6 +33,7 @@ import { currency, exportRows, km as formatKm, matchesQuery, orDash, useDebounce
|
||||
/* `other` is not declared here — it is appended only when rows actually land
|
||||
in it, so the strip never carries a permanently empty tab. */
|
||||
const STATUS_TABS = [
|
||||
{ value: 'all', label: 'All', countKey: 'total' },
|
||||
{ value: 'pending', label: 'Pending', countKey: 'uncoveredLength' },
|
||||
{ value: 'accepted', label: 'Accepted', countKey: 'assignedLength' },
|
||||
{ value: 'arrived', label: 'Arrived', countKey: 'arrivedLength' },
|
||||
@@ -60,26 +61,8 @@ const SETTABLE_STATUSES = [
|
||||
];
|
||||
|
||||
export default function Deliveries() {
|
||||
// Unscoped by default. `fetchDeliveries` treats a blank from/to as "no
|
||||
// bound" (see queries.js — `if (!startdate && !enddate) return true`), and
|
||||
// it filters on `orderdate` (the booking's creation day), never on when a
|
||||
// row was last touched. Defaulting this range to today meant the Pending/
|
||||
// Accepted/Arrived/Picked/Active tabs — an outstanding-work QUEUE, not a
|
||||
// day's log — only showed a booking that was also *created* today.
|
||||
// Reassign an order that came in yesterday and it's still correctly
|
||||
// "Pending" work, but it dropped off the board the moment you did it,
|
||||
// reading as "I just assigned it and it's not there." Same "state vs
|
||||
// flow" distinction this app already draws elsewhere for orders. Delivered/
|
||||
// Cancelled stay meaningful to scope by date — the operator narrows via
|
||||
// the date inputs same as before.
|
||||
const [range, setRange] = useState({ from: '', to: '' });
|
||||
const [tab, setTab] = useState('pending');
|
||||
// 'all' rather than the wave matching the current clock hour: a batch is a
|
||||
// slice of ONE day, so "jump to the slot matching right now" only means
|
||||
// something once the date range above is scoped to a single day. With the
|
||||
// range unscoped by default, defaulting the batch too would silently hide
|
||||
// almost everything — a booking created three days ago at 11am has no
|
||||
// relationship to "the slot matching right now" on a different day.
|
||||
const [tab, setTab] = useState('all');
|
||||
const [batch, setBatch] = useState('all');
|
||||
const [search, setSearch] = useState('');
|
||||
const debouncedSearch = useDebouncedValue(search);
|
||||
@@ -144,7 +127,10 @@ export default function Deliveries() {
|
||||
const base = STATUS_TABS.map((entry) => ({
|
||||
value: entry.value,
|
||||
label: entry.label,
|
||||
count: batchRows.filter((row) => String(row.orderstatus || '').toLowerCase() === entry.value).length,
|
||||
count:
|
||||
entry.value === 'all'
|
||||
? batchRows.length
|
||||
: batchRows.filter((row) => String(row.orderstatus || '').toLowerCase() === entry.value).length,
|
||||
}));
|
||||
/* A row whose status matches no tab used to be counted nowhere and shown
|
||||
nowhere. It gets its own tab, but only when one actually exists. */
|
||||
@@ -154,7 +140,9 @@ export default function Deliveries() {
|
||||
|
||||
const rows = useMemo(() => {
|
||||
const scoped =
|
||||
tab === 'other'
|
||||
tab === 'all'
|
||||
? batchRows
|
||||
: tab === 'other'
|
||||
? unmapped
|
||||
: batchRows.filter((row) => {
|
||||
const status = String(row.orderstatus || '').toLowerCase();
|
||||
@@ -164,7 +152,17 @@ export default function Deliveries() {
|
||||
return scoped.filter((row) =>
|
||||
matchesQuery(
|
||||
row,
|
||||
['orderid', 'deliverycustomer', 'ridername', 'pickupaddress', 'deliveryaddress', 'tenantname'],
|
||||
[
|
||||
'orderid',
|
||||
'bookingno',
|
||||
'bookingid',
|
||||
'consignmentid',
|
||||
'deliverycustomer',
|
||||
'ridername',
|
||||
'pickupaddress',
|
||||
'deliveryaddress',
|
||||
'tenantname',
|
||||
],
|
||||
debouncedSearch
|
||||
)
|
||||
);
|
||||
@@ -252,7 +250,7 @@ export default function Deliveries() {
|
||||
sortable: true,
|
||||
cell: (row) => (
|
||||
<div className="flex flex-col items-start gap-0.5">
|
||||
<StatusBadge status={row.orderstatus} dot size="sm" />
|
||||
<StatusBadge status={row.consignmentstatus || row.orderstatus} dot size="sm" />
|
||||
{/* Where the value came from. Without this, a row reading "Active"
|
||||
while the booking still says Converted_To_Consignment looks
|
||||
exactly like a bug. */}
|
||||
@@ -643,7 +641,7 @@ function OrderDetailDrawer({ row, onClose }) {
|
||||
<Surface variant="subtle" padding="sm" radius="lg">
|
||||
<dl className="grid grid-cols-2 gap-3">
|
||||
{[
|
||||
['Status', row?.orderstatus ? <StatusBadge status={row.orderstatus} size="sm" /> : '—'],
|
||||
['Status', row ? <StatusBadge status={row.consignmentstatus || row.orderstatus} size="sm" /> : '—'],
|
||||
['Rider', orDash(row?.ridername)],
|
||||
['Customer', orDash(row?.deliverycustomer)],
|
||||
['Contact', orDash(row?.deliverycontactno)],
|
||||
|
||||
Reference in New Issue
Block a user