last mile

This commit is contained in:
natib21
2026-06-20 13:14:39 +00:00
parent 6462ea8ad1
commit 7dedd3ea6f

View File

@@ -1,9 +1,7 @@
import { useMemo, useState } from "react"; import { useMemo, useState } from "react";
import { import {
ArrowRight, ArrowRight,
Check,
Eye, Eye,
Filter,
MoreHorizontal, MoreHorizontal,
RefreshCw, RefreshCw,
Truck, Truck,
@@ -217,6 +215,22 @@ const LastMilePage = () => {
} }
}; };
const statusCounts = useMemo(() => {
const counts: Record<StatusFilter, number> = {
ALL: jobs.length,
PAYMENT_PENDING: 0,
READY_TO_TRANSIT: 0,
DELIVERED: 0,
ASSIGNED: 0,
UNASSIGNED: 0,
};
for (const job of jobs) {
counts[job.deliveryStatus] += 1;
counts[job.status] += 1;
}
return counts;
}, [jobs]);
const filteredJobs = useMemo(() => { const filteredJobs = useMemo(() => {
const term = search.trim().toLowerCase(); const term = search.trim().toLowerCase();
return jobs.filter((job) => { return jobs.filter((job) => {
@@ -433,46 +447,40 @@ const LastMilePage = () => {
> >
<Stack gap={0}> <Stack gap={0}>
<Box px="md" pt="md" pb="sm" w="100%"> <Box px="md" pt="md" pb="sm" w="100%">
<Group justify="space-between" wrap="wrap"> <Stack gap="sm">
<Group gap="sm" wrap="wrap"> <Group justify="space-between" wrap="wrap">
<TextInput <TextInput
placeholder="Search deliveries…" placeholder="Search deliveries…"
value={search} value={search}
onChange={(e) => setSearch(e.currentTarget.value)} onChange={(e) => setSearch(e.currentTarget.value)}
w={260} w={260}
/> />
<Menu position="bottom-start" width={200} withinPortal> <Button
<Menu.Target> leftSection={<Truck size={16} />}
<Button variant="default" leftSection={<Filter size={16} />}> onClick={() => openAssign(null)}
{FILTER_OPTIONS.find((o) => o.value === statusFilter)?.label ?? >
"All statuses"} Assign Mile
</Button> </Button>
</Menu.Target>
<Menu.Dropdown>
{FILTER_OPTIONS.map((option) => (
<Menu.Item
key={option.value}
rightSection={
statusFilter === option.value ? <Check size={14} /> : null
}
onClick={() => {
setStatusFilter(option.value);
setPagination((p) => ({ ...p, pageIndex: 0 }));
}}
>
{option.label}
</Menu.Item>
))}
</Menu.Dropdown>
</Menu>
</Group> </Group>
<Button <Group gap="xs" wrap="wrap">
leftSection={<Truck size={16} />} {FILTER_OPTIONS.map((option) => {
onClick={() => openAssign(null)} const active = statusFilter === option.value;
> return (
Assign Mile <Button
</Button> key={option.value}
</Group> size="xs"
variant={active ? "filled" : "default"}
onClick={() => {
setStatusFilter(option.value);
setPagination((p) => ({ ...p, pageIndex: 0 }));
}}
>
{option.label} ({statusCounts[option.value]})
</Button>
);
})}
</Group>
</Stack>
</Box> </Box>
<DataTable <DataTable