const fetchContainers = () = {
const fetchContainers = () = {
} from "primereact";
import axios from "axios";
import { FixedSizeList as List } from "react-window";
import "primereact/resources/themes/saga-blue/theme.css";
import "primereact/resources/primereact.min.css";
import "primeicons/primeicons.css";
import {InputNumber} from "primereact/inputnumber";
useEffect(() => {
fetchData();
}, []);
const getAuthConfig = () => ({
headers: {
Authorization: `Bearer ${localStorage.getItem("jwtToken")}`,
},
});
saveRequest.then((response) => {
fetchData();
updateState({ deliveryOrderDialog: false, deliveryOrder:
emptyDeliveryOrder, shipSchedules: [], containers: [] });
toast.current.show({
severity: "success",
summary: "Successful",
detail: state.deliveryOrder.id ? "Lệnh giao hàng đã được cập
nhật" : "Lệnh giao hàng đã được tạo",
life: 3000,
});
});
}
};
checked={state.deliveryOrder.shipScheduleContainerMap[shipSchedule.id]?.includes(st
ate.containers[index].containerCode)}
onChange={(e) => onContainerCheckboxChange(e,
shipSchedule.id, state.containers[index].containerCode)}
/>
<label htmlFor={`container_$
{state.containers[index].containerCode}`}>{state.containers[index].containerCode}</
label>
</div>
)}
</List>
</div>
));
};
// Join all container codes into a single string or format them as you
prefer
return containers.join(', ');
};
return (
<div>
<Toast ref={toast} />
<div className="card">
<Toolbar
className="mb-4"
left={() => (
<Button
label="Thêm"
icon="pi pi-plus"
onClick={() => updateState({
deliveryOrderDialog: true,
deliveryOrder: emptyDeliveryOrder, // Reset to
empty form
shipSchedules: [], // Reset shipSchedules
containers: [] // Reset containers
})}
/>
)}
right={() => <Button label="Xuất Excel" icon="pi pi-upload"
onClick={() => dt.current.exportCSV()} />}
/>
<DataTable
ref={dt}
value={state.deliveryOrders}
selection={state.selectedDeliveryOrders}
onSelectionChange={(e) => updateState({ selectedDeliveryOrders:
e.value })}
dataKey="id"
paginator
rows={10}
globalFilter={state.globalFilter}
header={<div className="flex align-items-center justify-
content-between"><h4 className="m-0">Quản lý lệnh giao hàng</h4><InputText
type="search" onInput={(e) => updateState({ globalFilter: e.target.value })}
placeholder="Tìm kiếm..." /></div>}
>
<Column selectionMode="multiple" exportable={false}></Column>
<Column field="orderNumber" header="Mã đơn hàng"
sortable></Column>
<Column field="customerId" header="Tên khách hàng"
body={(rowData) => state.customers.find((c) => c.id ===
rowData.customerId)?.username || "unknown"} sortable></Column>
<Column field="scheduleId" header="Mã lịch trình"
body={(rowData) => state.schedules.find((s) => s.id ===
rowData.scheduleId)?.codeSchedule || "unknown"} sortable></Column>
<Column header="Ngày đặt hàng" body={(rowData) => new
Date(rowData.orderDate).toLocaleString()} sortable></Column>
<Column header="Ngày giao hàng" body={(rowData) => new
Date(rowData.deliveryDate).toLocaleString()} sortable></Column>
<Column field="totalAmount" header="Tổng tiền"
sortable></Column>
<Column field="status" header="Trạng thái" sortable></Column>
<Column header="Containers" body={renderContainers} />
<Column body={(rowData) =>
<>
<Button
icon="pi pi-pencil"
className="p-button-rounded p-button-success mr-2"
onClick={() => {
// Set the selected order data, including
containers, to the state
updateState({
deliveryOrder: { ...rowData }, // Copy all
fields from the selected row
deliveryOrderDialog: true, // Open the
dialog
shipSchedules:
Object.keys(rowData.shipScheduleContainerMap).map((id) => ({
id: parseInt(id),
containers:
rowData.shipScheduleContainerMap[id],
})), // Set the ship schedules for
rendering containers
});
}}
/>
<Button
icon="pi pi-trash"
className="p-button-rounded p-button-warning"
onClick={() => updateState({
deliveryOrder: rowData,
deleteDeliveryOrderDialog: true,
})}
/>
</>
} exportable={false}>
</Column>
</DataTable>
</div>