import { Alert, Button, Group, Paper, Stack, Text } from "@mantine/core"; import { DateInput } from "@mantine/dates"; import { AlertTriangle, Pencil, Send } from "lucide-react"; import { useState } from "react"; import { Link } from "react-router-dom"; import toast from "react-hot-toast"; import { bookingsService } from "@/services/bookings.service"; export interface BookingChangesRequestedAlertProps { bookingId: string; reference?: string | null; /** Operations' note — what has to change before this can go back to them. */ note?: string | null; /** Shipment day the booking currently holds; the resubmit default. */ scheduledDate?: string | null; /** GL Ethiopia owns customs bookings, so only they get the resubmit control. */ canResubmit: boolean; /** Completion-form route for editing the cargo before resubmitting — * rendered only for resubmit-capable users when provided. */ editHref?: string; onResubmitted?: () => void; } /** * Operations sent a GL-created booking back for changes. * * The customer cannot act on this — GL created the booking on their behalf — so * the note and the way out both live here, on the page GL works from. Resubmit * re-requests operation on the chosen shipment day; the server re-checks the day * has a departure that can carry the cargo and refuses with the reason if not. */ export function BookingChangesRequestedAlert({ bookingId, reference, note, scheduledDate, canResubmit, editHref, onResubmitted, }: BookingChangesRequestedAlertProps) { const [day, setDay] = useState( scheduledDate ? new Date(scheduledDate) : null, ); const [sending, setSending] = useState(false); const resubmit = async () => { if (!day) return; setSending(true); try { await bookingsService.proceedToOperation(bookingId, day.toISOString()); toast.success("Sent back to Operations for review"); onResubmitted?.(); } catch { // The http interceptor already toasts the server's own reason (no // departure that day, no wagon that can carry the cargo, export train // full…) — a second toast here would just duplicate it. } finally { setSending(false); } }; return ( } title={`Operations returned booking ${reference ?? ""} for changes`.trim()} > {note ? ( What Operations asked for {note} ) : ( Operations returned this booking without a note — contact them for the detail before resubmitting. )} This booking was created by GL Ethiopia, so the customer cannot fix it. Make the correction Operations asked for, then send it back for review.{" "} Open the booking → {canResubmit ? ( setDay(v ? new Date(v) : null)} minDate={new Date()} size="sm" w={230} /> {editHref ? ( ) : null} ) : null} ); } export default BookingChangesRequestedAlert;