fix: driver_assigned status on assign + driver column in table
This commit is contained in:
parent
58dc110007
commit
470270118b
|
|
@ -15,6 +15,9 @@ const buildGroupSummary = (group) => {
|
||||||
const datePart = group.deliveryTime ? `${group.deliveryDate} · ${group.deliveryTime}` : group.deliveryDate;
|
const datePart = group.deliveryTime ? `${group.deliveryDate} · ${group.deliveryTime}` : group.deliveryDate;
|
||||||
parts.push(datePart);
|
parts.push(datePart);
|
||||||
}
|
}
|
||||||
|
if (group.assignedDriverName) {
|
||||||
|
parts.push(group.assignedDriverName);
|
||||||
|
}
|
||||||
|
|
||||||
return parts.join(" · ");
|
return parts.join(" · ");
|
||||||
};
|
};
|
||||||
|
|
@ -105,6 +108,7 @@ export const OrdersTable = ({
|
||||||
<th className="px-5 py-4 font-medium">Клиент</th>
|
<th className="px-5 py-4 font-medium">Клиент</th>
|
||||||
<th className="px-5 py-4 font-medium">Номера</th>
|
<th className="px-5 py-4 font-medium">Номера</th>
|
||||||
<th className="px-5 py-4 font-medium">Статус</th>
|
<th className="px-5 py-4 font-medium">Статус</th>
|
||||||
|
<th className="px-5 py-4 font-medium">Водитель</th>
|
||||||
<th className="px-5 py-4 font-medium">Дата доставки</th>
|
<th className="px-5 py-4 font-medium">Дата доставки</th>
|
||||||
<th className="px-5 py-4 font-medium">Готовность</th>
|
<th className="px-5 py-4 font-medium">Готовность</th>
|
||||||
<th className="px-5 py-4 font-medium">Обновлён</th>
|
<th className="px-5 py-4 font-medium">Обновлён</th>
|
||||||
|
|
@ -136,6 +140,9 @@ export const OrdersTable = ({
|
||||||
<td className="px-5 py-4">
|
<td className="px-5 py-4">
|
||||||
<Badge tone={getOrderGroupStatusTone(group)}>{getOrderGroupDisplayStatusLabel(group)}</Badge>
|
<Badge tone={getOrderGroupStatusTone(group)}>{getOrderGroupDisplayStatusLabel(group)}</Badge>
|
||||||
</td>
|
</td>
|
||||||
|
<td className="px-5 py-4 text-sm">
|
||||||
|
{group.assignedDriverName || <span className="text-[var(--color-text-muted)]">—</span>}
|
||||||
|
</td>
|
||||||
<td className="px-5 py-4 text-sm">
|
<td className="px-5 py-4 text-sm">
|
||||||
{group.deliveryDate ? (
|
{group.deliveryDate ? (
|
||||||
<span>{group.deliveryDate}{group.deliveryTime ? <span className="text-[var(--color-text-muted)]"> · {group.deliveryTime}</span> : ""}</span>
|
<span>{group.deliveryDate}{group.deliveryTime ? <span className="text-[var(--color-text-muted)]"> · {group.deliveryTime}</span> : ""}</span>
|
||||||
|
|
|
||||||
|
|
@ -232,11 +232,17 @@ export const assignDriverToOrderGroup = async ({
|
||||||
throw fetchCurrentError;
|
throw fetchCurrentError;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If status is 'agreed' or beyond, keep it — don't downgrade to 'driver_assigned'
|
// When assigning a driver, advance status to driver_assigned if currently agreed.
|
||||||
const keepStatus = ["agreed", "loaded", "on_route", "delivered"].includes(currentGroup.delivery_status);
|
// For loaded/on_route/delivered, keep existing status (driver reassigned mid-delivery).
|
||||||
|
// For pending/manual statuses, also set driver_assigned (driver chosen before formal agreement).
|
||||||
|
const currentStatus = currentGroup.delivery_status;
|
||||||
|
const ADVANCED_STATUSES = ["loaded", "on_route", "delivered"];
|
||||||
|
const newStatus = driverId
|
||||||
|
? (ADVANCED_STATUSES.includes(currentStatus) ? undefined : "driver_assigned")
|
||||||
|
: null; // removing driver → reset to pending
|
||||||
const updates = {
|
const updates = {
|
||||||
assigned_driver_id: driverId || null,
|
assigned_driver_id: driverId || null,
|
||||||
delivery_status: driverId && !keepStatus ? "driver_assigned" : undefined,
|
...(newStatus !== undefined && { delivery_status: newStatus }),
|
||||||
updated_at: new Date().toISOString(),
|
updated_at: new Date().toISOString(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue