mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
feat: add warehouse selection to empty container returns form
Replace manual facility/yard input with warehouse dropdown. Form fetches available warehouses and auto-populates facility (warehouse name) and yard (warehouse code) from selection, eliminating manual entry. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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<string[]>([]);
|
||||
const [returnDate, setReturnDate] = useState<string>(new Date().toISOString().split("T")[0]);
|
||||
const [facility, setFacility] = useState<string | null>(null);
|
||||
const [yard, setYard] = useState<string>("");
|
||||
const [warehouse, setWarehouse] = useState<string | null>(null);
|
||||
const [condition, setCondition] = useState<string>("");
|
||||
const [handoverNote, setHandoverNote] = useState<string>("");
|
||||
|
||||
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 }
|
||||
</div>
|
||||
|
||||
<Select
|
||||
label="Return Facility"
|
||||
placeholder="Select facility"
|
||||
value={facility}
|
||||
onChange={setFacility}
|
||||
data={RETURN_FACILITIES}
|
||||
label="Return Warehouse"
|
||||
placeholder="Select warehouse for container return"
|
||||
value={warehouse}
|
||||
onChange={setWarehouse}
|
||||
data={warehouseOptions}
|
||||
required
|
||||
/>
|
||||
|
||||
<TextInput
|
||||
label="Yard"
|
||||
placeholder="e.g., Yard A"
|
||||
value={yard}
|
||||
onChange={(e) => setYard(e.currentTarget.value)}
|
||||
searchable
|
||||
/>
|
||||
|
||||
<TextInput
|
||||
@@ -390,7 +393,7 @@ function EmptyContainerReturnModal({ opened, onClose, truck, onSubmit, loading }
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleSubmit}
|
||||
disabled={!selectedContainers.length || !facility}
|
||||
disabled={!selectedContainers.length || !warehouse}
|
||||
loading={loading}
|
||||
>
|
||||
{selectedContainers.length > 1 ? "Bulk" : "Single"} Return ({selectedContainers.length})
|
||||
|
||||
Reference in New Issue
Block a user