58 lines
2.3 KiB
JavaScript
58 lines
2.3 KiB
JavaScript
/**
|
||
* Shared delivery/delivery-group utilities.
|
||
* Single source of truth for isPickupOrder, getErrorMessage, normalizeNom, and STATUS_LABELS.
|
||
*/
|
||
|
||
// ── Pickup detection ──────────────────────────────────────────────────────
|
||
|
||
/**
|
||
* Returns true if the order group is a pickup (self-pickup) order.
|
||
* Uses canonical deliveryStatus field (mapper normalizes both delivery_status variants).
|
||
*/
|
||
export const isPickupOrder = (order) =>
|
||
order?.deliveryType === "pickup" ||
|
||
order?.deliveryStatus === "pickup" ||
|
||
order?.delivery_status === "pickup";
|
||
|
||
// ── Error messages ────────────────────────────────────────────────────────
|
||
|
||
export const getErrorMessage = (error, fallbackMessage) => {
|
||
if (!error) {
|
||
return fallbackMessage;
|
||
}
|
||
if (error instanceof Error) {
|
||
return error.message || fallbackMessage;
|
||
}
|
||
if (typeof error === "string") {
|
||
return error || fallbackMessage;
|
||
}
|
||
return error?.message || fallbackMessage;
|
||
};
|
||
|
||
// ── Nom normalisation ──────────────────────────────────────────────────────
|
||
|
||
/**
|
||
* 1C escapes backslashes: "СФ Т\\ЕА-33584" → normalise for comparison.
|
||
*/
|
||
export const normalizeNom = (nom) => {
|
||
if (!nom) return "";
|
||
return String(nom).replace(/\\\\/g, "\\").trim();
|
||
};
|
||
|
||
// ── Status labels ─────────────────────────────────────────────────────────
|
||
|
||
export const DELIVERY_STATUS_LABELS = {
|
||
pending_confirmation: "Ожидает подтверждения",
|
||
requires_address: "Требуется адрес",
|
||
agreed: "Согласовано",
|
||
driver_assigned: "Водитель назначен",
|
||
loaded: "Загружен",
|
||
on_route: "В пути",
|
||
delivered: "Доставлено",
|
||
problem: "Проблема",
|
||
cancelled: "Отменено",
|
||
pickup: "Самовывоз",
|
||
};
|
||
|
||
export const getOrderGroupDeliveryStatusLabel = (status) =>
|
||
DELIVERY_STATUS_LABELS[status] || status || "Ожидает подтверждения"; |