feat(collection-pool): sequential bulk-assign PATCH
This commit is contained in:
parent
75a111a334
commit
c5731a1206
1 changed files with 50 additions and 3 deletions
|
|
@ -355,10 +355,57 @@ export default function CollectionPoolPage() {
|
|||
const [bulkBusy, setBulkBusy] = useState(false);
|
||||
|
||||
const handleBulkAssignSubmit = useCallback(
|
||||
async (_payload: AssignDriverSubmitPayload) => {
|
||||
// Full implementation in Task 9.
|
||||
async (payload: AssignDriverSubmitPayload) => {
|
||||
if (!bulkAssignDialog) return;
|
||||
const { driverId, date } = payload;
|
||||
const { rowIds, supplierName } = bulkAssignDialog;
|
||||
|
||||
setBulkBusy(true);
|
||||
try {
|
||||
const pb = getPocketBase();
|
||||
let successCount = 0;
|
||||
let firstError: string | null = null;
|
||||
|
||||
// Sequential, not parallel: any failure leaves earlier
|
||||
// successes committed (matches the single-row PATCH semantics).
|
||||
for (const id of rowIds) {
|
||||
try {
|
||||
await pb.collection("order_items").update(id, {
|
||||
item_status: "assigned",
|
||||
drv_id: driverId,
|
||||
drv_status: "assigned",
|
||||
assigned_at: `${date}T00:00:00.000Z`,
|
||||
} as Partial<OrderItem>);
|
||||
successCount++;
|
||||
} catch (err) {
|
||||
if (!firstError) {
|
||||
firstError = err instanceof Error ? err.message : String(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Clear selections for this supplier on success (partial or full).
|
||||
setSelectedIds((prev) => {
|
||||
const next = new Set(prev);
|
||||
for (const id of rowIds) next.delete(id);
|
||||
return next;
|
||||
});
|
||||
closeBulkAssign();
|
||||
|
||||
if (firstError) {
|
||||
toast.error(
|
||||
`Assigned ${successCount} of ${rowIds.length} stops at ${supplierName || "supplier"}. First error: ${firstError}`,
|
||||
);
|
||||
} else {
|
||||
toast.success(`Assigned ${successCount} stops at ${supplierName || "supplier"}.`);
|
||||
}
|
||||
|
||||
await load();
|
||||
} finally {
|
||||
setBulkBusy(false);
|
||||
}
|
||||
},
|
||||
[],
|
||||
[bulkAssignDialog, closeBulkAssign, load],
|
||||
);
|
||||
|
||||
const handleToggleReady = useCallback(
|
||||
|
|
|
|||
Loading…
Reference in a new issue