import React, { useState } from "react"; import { getAvailableTransitionsByRole, getOrderStatusComment, getStatusTone } from "../../constants/deliveryWorkflow"; import { getDeliveryCity, getDeliveryDay, getDeliveryHalfDay } from "../../services/driverDeliveries"; import { Badge } from "../UI/Badge"; import { Button } from "../UI/Button"; import { Panel } from "../UI/Panel"; const PROBLEM_REASONS = [ { value: "client_absent", label: "Клиент не принял", description: "Клиент отказался или не вышел на связь" }, { value: "damage", label: "Повреждение заказа", description: "Товар повреждён при транспортировке" }, { value: "wrong_address", label: "Неверный адрес", description: "Адрес доставки указан неверно" }, { value: "other", label: "Другое", description: "Иная причина проблемы доставки" }, ]; const ProblemReasonModal = ({ onSelect, onCancel }) => (
e.stopPropagation()}>

Причина проблемы

Укажите причину возникшей проблемы с доставкой.

{PROBLEM_REASONS.map((reason) => ( ))}
); const splitItem = (item) => { if (!item) { return { name: "Позиция", quantity: "" }; } if (typeof item === "string") { const [name, quantity] = item.split("|").map((part) => part.trim()); return { name: name || item, quantity: quantity || "", }; } if (typeof item === "object") { return { name: item.name || item.label || "Позиция", quantity: typeof item.quantity === "number" ? String(item.quantity) : item.quantity || "", }; } return { name: "Позиция", quantity: "" }; }; export const DriverDeliveryDetail = ({ order, onStatusChange }) => { const [showProblemModal, setShowProblemModal] = useState(false); if (!order) { return null; } const availableTransitions = getAvailableTransitionsByRole({ status: order.status, role: "driver", }); const orderItems = Array.isArray(order.items) ? order.items.map(splitItem) : []; const currentStatus = order.status; let actionButtons = []; if (currentStatus === "Назначен водитель") { actionButtons = [ { value: "Доставлен", label: "Доставлено" }, { value: "Проблема доставки", label: "Проблема" }, ]; } else if (currentStatus === "Доставлен") { actionButtons = [ { value: "Назначен водитель", label: "Вернуть в работу" }, ]; } else if (currentStatus === "Проблема доставки" || currentStatus === "Закрыт" || currentStatus === "Отменён") { actionButtons = []; } else { actionButtons = availableTransitions.map((status) => ({ value: status, label: status === "Проблема доставки" ? "Проблема" : status, })); } return (
{showProblemModal && ( { setShowProblemModal(false); onStatusChange?.("Проблема доставки", { reason: reasonValue, reasonLabel }); }} onCancel={() => setShowProblemModal(false)} /> )}

Доставка

{order.customer.address}

{order.orderNumber} · {order.customer.name}

{order.status}

{getOrderStatusComment(order.status)}

Клиент

{order.customer.name}

Телефон

{order.customer.phone}

Город

{getDeliveryCity(order)}

Интервал доставки

{getDeliveryDay(order)} · {getDeliveryHalfDay(order)}

Что везти

{orderItems.map((item) => (
{item.name} {item.quantity ? {item.quantity} : null}
))}

Комментарии для доставки

{order.orderNotes?.[0]?.text || "Дополнительных комментариев нет."}
{order.comments?.length ? (
{order.comments.join(". ")}
) : null}
{actionButtons.length > 0 && (

Быстрые действия

{actionButtons.map((btn) => ( ))}
)}
); };