diff --git a/apps/edr-freight-web/backoffice/src/pages/warehouses/EDRLastMileReturnsPage.tsx b/apps/edr-freight-web/backoffice/src/pages/warehouses/EDRLastMileReturnsPage.tsx index 455d64d61..4c38841f8 100644 --- a/apps/edr-freight-web/backoffice/src/pages/warehouses/EDRLastMileReturnsPage.tsx +++ b/apps/edr-freight-web/backoffice/src/pages/warehouses/EDRLastMileReturnsPage.tsx @@ -43,11 +43,6 @@ interface TruckReturn { containers: ReturnContainer[]; } -const RETURN_FACILITIES = [ - { value: "Addis Ababa", label: "Addis Ababa" }, - { value: "Djibouti", label: "Djibouti" }, - { value: "Other", label: "Other" }, -]; export default function EDRLastMileReturnsPage() { const { toast } = useToast(); @@ -286,21 +281,35 @@ interface EmptyContainerReturnModalProps { function EmptyContainerReturnModal({ opened, onClose, truck, onSubmit, loading }: EmptyContainerReturnModalProps) { const [selectedContainers, setSelectedContainers] = useState([]); const [returnDate, setReturnDate] = useState(new Date().toISOString().split("T")[0]); - const [facility, setFacility] = useState(null); - const [yard, setYard] = useState(""); + const [warehouse, setWarehouse] = useState(null); const [condition, setCondition] = useState(""); const [handoverNote, setHandoverNote] = useState(""); + const { data: warehousesResponse } = useQuery({ + queryKey: ["warehouses-list"], + queryFn: async () => { + return await warehouseService.list({}); + }, + }); + + const warehouses = (warehousesResponse as any)?.data ?? warehousesResponse ?? []; + const warehouseOptions = Array.isArray(warehouses) ? warehouses.map((wh: any) => ({ + value: wh.id, + label: `${wh.name} ${wh.code ? `(${wh.code})` : ""}`, + })) : []; + + const selectedWarehouse = warehouse && Array.isArray(warehouses) ? warehouses.find((wh: any) => wh.id === warehouse) : null; + const handleSubmit = () => { - if (!truck || !selectedContainers.length || !facility) return; + if (!truck || !selectedContainers.length || !warehouse) return; const containers = truck.containers .filter((c) => selectedContainers.includes(c.containerNumber)) .map((c) => ({ containerNumber: c.containerNumber, returnDate, - facility, - yard: yard || undefined, + facility: selectedWarehouse?.name || warehouse, + yard: selectedWarehouse?.code || undefined, zone: undefined, condition: condition || undefined, handoverNote: handoverNote || undefined, @@ -345,19 +354,13 @@ function EmptyContainerReturnModal({ opened, onClose, truck, onSubmit, loading }