mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 07:15:45 +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[];
|
containers: ReturnContainer[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const RETURN_FACILITIES = [
|
|
||||||
{ value: "Addis Ababa", label: "Addis Ababa" },
|
|
||||||
{ value: "Djibouti", label: "Djibouti" },
|
|
||||||
{ value: "Other", label: "Other" },
|
|
||||||
];
|
|
||||||
|
|
||||||
export default function EDRLastMileReturnsPage() {
|
export default function EDRLastMileReturnsPage() {
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
@@ -286,21 +281,35 @@ interface EmptyContainerReturnModalProps {
|
|||||||
function EmptyContainerReturnModal({ opened, onClose, truck, onSubmit, loading }: EmptyContainerReturnModalProps) {
|
function EmptyContainerReturnModal({ opened, onClose, truck, onSubmit, loading }: EmptyContainerReturnModalProps) {
|
||||||
const [selectedContainers, setSelectedContainers] = useState<string[]>([]);
|
const [selectedContainers, setSelectedContainers] = useState<string[]>([]);
|
||||||
const [returnDate, setReturnDate] = useState<string>(new Date().toISOString().split("T")[0]);
|
const [returnDate, setReturnDate] = useState<string>(new Date().toISOString().split("T")[0]);
|
||||||
const [facility, setFacility] = useState<string | null>(null);
|
const [warehouse, setWarehouse] = useState<string | null>(null);
|
||||||
const [yard, setYard] = useState<string>("");
|
|
||||||
const [condition, setCondition] = useState<string>("");
|
const [condition, setCondition] = useState<string>("");
|
||||||
const [handoverNote, setHandoverNote] = 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 = () => {
|
const handleSubmit = () => {
|
||||||
if (!truck || !selectedContainers.length || !facility) return;
|
if (!truck || !selectedContainers.length || !warehouse) return;
|
||||||
|
|
||||||
const containers = truck.containers
|
const containers = truck.containers
|
||||||
.filter((c) => selectedContainers.includes(c.containerNumber))
|
.filter((c) => selectedContainers.includes(c.containerNumber))
|
||||||
.map((c) => ({
|
.map((c) => ({
|
||||||
containerNumber: c.containerNumber,
|
containerNumber: c.containerNumber,
|
||||||
returnDate,
|
returnDate,
|
||||||
facility,
|
facility: selectedWarehouse?.name || warehouse,
|
||||||
yard: yard || undefined,
|
yard: selectedWarehouse?.code || undefined,
|
||||||
zone: undefined,
|
zone: undefined,
|
||||||
condition: condition || undefined,
|
condition: condition || undefined,
|
||||||
handoverNote: handoverNote || undefined,
|
handoverNote: handoverNote || undefined,
|
||||||
@@ -345,19 +354,13 @@ function EmptyContainerReturnModal({ opened, onClose, truck, onSubmit, loading }
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Select
|
<Select
|
||||||
label="Return Facility"
|
label="Return Warehouse"
|
||||||
placeholder="Select facility"
|
placeholder="Select warehouse for container return"
|
||||||
value={facility}
|
value={warehouse}
|
||||||
onChange={setFacility}
|
onChange={setWarehouse}
|
||||||
data={RETURN_FACILITIES}
|
data={warehouseOptions}
|
||||||
required
|
required
|
||||||
/>
|
searchable
|
||||||
|
|
||||||
<TextInput
|
|
||||||
label="Yard"
|
|
||||||
placeholder="e.g., Yard A"
|
|
||||||
value={yard}
|
|
||||||
onChange={(e) => setYard(e.currentTarget.value)}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextInput
|
<TextInput
|
||||||
@@ -390,7 +393,7 @@ function EmptyContainerReturnModal({ opened, onClose, truck, onSubmit, loading }
|
|||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
onClick={handleSubmit}
|
onClick={handleSubmit}
|
||||||
disabled={!selectedContainers.length || !facility}
|
disabled={!selectedContainers.length || !warehouse}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
>
|
>
|
||||||
{selectedContainers.length > 1 ? "Bulk" : "Single"} Return ({selectedContainers.length})
|
{selectedContainers.length > 1 ? "Bulk" : "Single"} Return ({selectedContainers.length})
|
||||||
|
|||||||
Reference in New Issue
Block a user