import { Button, Card, message, notification } from "antd"; import { CopyOutlined, EditOutlined, SendOutlined } from "@ant-design/icons"; import { useState } from "react"; import ShiftAndCoDriverEditModal from "./ShiftAndCoDriverEditModal"; import { taskController } from "../../../API/LayoutApi/tasks"; interface ShiftDataTabProps { recordTask?: any; } const ShiftDataTab: React.FC = ({ recordTask }) => { const [isModalOpen, setIsModalOpen] = useState(false); const shiftInfo = { shiftDate: recordTask?.shift_date, shiftLocation: recordTask?.shift_location ?? null, cycleDate: recordTask?.cycle_date, cycleLocation: recordTask?.cycle_location ?? null, pickUpDate: recordTask?.pickup_date, pickUpTime: recordTask?.pickup_time, pickUpLocation: recordTask?.pickup_location ?? null, }; const coDriverInfo = { driverName: recordTask?.driver_name ?? null, coDriverName: recordTask?.co_driver_name ?? null, coDriverPickUpDate: recordTask?.co_driver_pickup_date, coDriverPickUpTime: recordTask?.co_driver_pickup_time, coDriverPickUpLocation: recordTask?.co_driver_pickup_location ?? null, coDriverDropDate: recordTask?.co_driver_drop_date, coDriverDropTime: recordTask?.co_driver_drop_time, coDriverDropLocation: recordTask?.co_driver_drop_location ?? null, }; const buildTextBlock = (title: string, items: [string, string | null][]) => { const lines = items .filter(([, value]) => value) .map(([label, value]) => `${label}: ${value}`); return lines.length ? `${title}\n${lines.join("\n")}` : ""; }; const handleCopy = (lang: "en" | "ru") => { let text = ""; if (lang === "en") { text = [ buildTextBlock("SHIFT INFO ❗️❗️❗️", [ ["Shift Date", shiftInfo.shiftDate], ["Shift Location", shiftInfo.shiftLocation], ["Cycle Date", shiftInfo.cycleDate], ["Cycle Location", shiftInfo.cycleLocation], ["Pick up Date", shiftInfo.pickUpDate], ["Pick up Time", shiftInfo.pickUpTime], ["Pick Up Location", shiftInfo.pickUpLocation], ]), buildTextBlock("CO DRIVER INFO", [ ["Driver's name", coDriverInfo.driverName], ["Co-Driver's name", coDriverInfo.coDriverName], ["Co-driver pickup date", coDriverInfo.coDriverPickUpDate], ["Co-driver pickup time", coDriverInfo.coDriverPickUpTime], ["Co-driver pickup location", coDriverInfo.coDriverPickUpLocation], ["Co-driver drop date", coDriverInfo.coDriverDropDate], ["Co-driver drop time", coDriverInfo.coDriverDropTime], ["Co-driver drop location", coDriverInfo.coDriverDropLocation], ]), ] .filter(Boolean) .join("\n\n"); } else { text = [ buildTextBlock("ИНФОРМАЦИЯ О СМЕНЕ ❗️❗️❗️", [ ["Дата шифта", shiftInfo.shiftDate], ["Место шифта", shiftInfo.shiftLocation], ["Дата сайкла", shiftInfo.cycleDate], ["Место сайкла", shiftInfo.cycleLocation], ["Дата пикапа", shiftInfo.pickUpDate], ["Время пикапа", shiftInfo.pickUpTime], ["Место пикапа", shiftInfo.pickUpLocation], ]), buildTextBlock("ИНФОРМАЦИЯ О КО-ДРАЙВЕРЕ", [ ["Имя драйвера", coDriverInfo.driverName], ["Имя ко-драйвера", coDriverInfo.coDriverName], ["Дата пикапа ко-драйвера", coDriverInfo.coDriverPickUpDate], ["Время пикапа ко-драйвера", coDriverInfo.coDriverPickUpTime], ["Место пикапа ко-драйвера", coDriverInfo.coDriverPickUpLocation], ["Дата высадки ко-драйвера", coDriverInfo.coDriverDropDate], ["Время высадки ко-драйвера", coDriverInfo.coDriverDropTime], ["Место высадки ко-драйвера", coDriverInfo.coDriverDropLocation], ]), ] .filter(Boolean) .join("\n\n"); } if (!text) { message.warning("Nothing to copy!"); return; } navigator.clipboard .writeText(text) .then(() => message.success("Data copied successfully!")) .catch(() => message.error("Failed to copy!")); }; const handleSendTelegram = async () => { if (!recordTask?.id) return; try { await taskController.sendTelegram(recordTask.id); message.success("Message sent to Telegram successfully!"); } catch (error: any) { message.error( error?.response?.data?.message || "Failed to send message to Telegram." ); } }; return ( <> } style={{ width: "100%", marginBottom: 20 }} >

SHIFT INFO ❗️❗️❗️

Shift Date: {shiftInfo.shiftDate}

Shift Location: {shiftInfo.shiftLocation}

Cycle Date: {shiftInfo.cycleDate}

Cycle Location: {shiftInfo.cycleLocation}

Pick up Date: {shiftInfo.pickUpDate}

Pick up Time: {shiftInfo.pickUpTime}

Pick Up Location: {shiftInfo.pickUpLocation}

CO-DRIVER INFO

Driver's name: {coDriverInfo.driverName}

Co-driver's name: {coDriverInfo.coDriverName}

Co-driver pickup date: {coDriverInfo.coDriverPickUpDate}

Co-driver pickup time: {coDriverInfo.coDriverPickUpTime}

Co-driver pickup location: {coDriverInfo.coDriverPickUpLocation}

Co-driver drop date: {coDriverInfo.coDriverDropDate}

Co-driver drop time: {coDriverInfo.coDriverDropTime}

Co-driver drop location: {coDriverInfo.coDriverDropLocation}

} onClick={() => handleCopy("ru")}> Copy } style={{ width: "100%" }} >

ИНФОРМАЦИЯ О СМЕНЕ ❗️❗️❗️

Дата шифта: {shiftInfo.shiftDate}

Место шифта: {shiftInfo.shiftLocation}

Дата сайкла: {shiftInfo.cycleDate}

Место сайкла: {shiftInfo.cycleLocation}

Дата пикапа: {shiftInfo.pickUpDate}

Время пикапа: {shiftInfo.pickUpTime}

Место пикапа: {shiftInfo.pickUpLocation}

ИНФОРМАЦИЯ О КО-ДРАЙВЕРЕ

Имя драйвера: {coDriverInfo.driverName}

Имя ко-драйвера: {coDriverInfo.coDriverName}

Дата пикапа ко-драйвера: {coDriverInfo.coDriverPickUpDate}

Время пикапа ко-драйвера: {coDriverInfo.coDriverPickUpTime}

Место пикапа ко-драйвера: {coDriverInfo.coDriverPickUpLocation}

Дата высадки ко-драйвера: {coDriverInfo.coDriverDropDate}

Время высадки ко-драйвера: {coDriverInfo.coDriverDropTime}

Место высадки ко-драйвера: {coDriverInfo.coDriverDropLocation}

setIsModalOpen(false)} /> ); }; export default ShiftDataTab;