diff --git a/apps/edr-freight-web/backoffice/src/pages/bookings/NewBookingPage.tsx b/apps/edr-freight-web/backoffice/src/pages/bookings/NewBookingPage.tsx index a1de7dc3e..489e324e8 100644 --- a/apps/edr-freight-web/backoffice/src/pages/bookings/NewBookingPage.tsx +++ b/apps/edr-freight-web/backoffice/src/pages/bookings/NewBookingPage.tsx @@ -13,7 +13,6 @@ import { SegmentedControl, Select, Stack, - Switch, Text, TextInput, ThemeIcon, @@ -84,6 +83,8 @@ interface ContainerLine { containerTypeId: string | null; quantity: number; vgmPerUnitTons: number; + /** Physical container numbers, one per unit (index < quantity; blanks allowed). */ + containerNumbers: string[]; } let lineCounter = 0; @@ -92,6 +93,7 @@ const newLine = (): ContainerLine => ({ containerTypeId: null, quantity: 1, vgmPerUnitTons: 20, + containerNumbers: [], }); const fmtTons = (n: number) => @@ -165,9 +167,8 @@ export default function NewBookingPage() { const navigate = useNavigate(); const queryClient = useQueryClient(); - const [isGovernment, setIsGovernment] = useState(false); - const [companyId, setCompanyId] = useState(null); - // Government bookings bill to a real government company + an explicit profile. + // This page creates GOVERNMENT bookings only — commercial customers book + // through the portal. Bills to a government company + an explicit profile. const [govCompanyId, setGovCompanyId] = useState(null); const [govProfileId, setGovProfileId] = useState(null); // Container freight only for now — bulk is disabled on this page. @@ -186,16 +187,6 @@ export default function NewBookingPage() { queryFn: () => bookingsService.getReferenceData() as Promise, }); - const { data: companiesPage, isLoading: companiesLoading } = useQuery({ - queryKey: ["companies", "list"], - queryFn: () => customersService.list({ page: 1, pageSize: 1000 }), - }); - - const companyOptions = (companiesPage?.items ?? []).map((c) => ({ - value: c.id, - label: c.name || c.email || c.tin || c.id, - })); - // Active government companies (kind=government) the booking can bill to. const { data: govCompaniesPage, isLoading: govCompaniesLoading } = useQuery({ queryKey: ["companies", "government", "active"], @@ -206,7 +197,6 @@ export default function NewBookingPage() { kind: "government", status: "active", }), - enabled: isGovernment, }); const govCompanies = govCompaniesPage?.items ?? []; @@ -338,7 +328,7 @@ export default function NewBookingPage() { !sameYard && Boolean(serviceTypeId) && departureSatisfied && - (isGovernment ? Boolean(govCompanyId && govProfileId) : Boolean(companyId)) && + Boolean(govCompanyId && govProfileId) && allLinesValid && !hasOdd20ft; @@ -350,9 +340,9 @@ export default function NewBookingPage() { const createMutation = useMutation({ mutationFn: () => bookingsService.create({ - isGovernment, - companyId: isGovernment ? govCompanyId || undefined : companyId || undefined, - companyProfileId: isGovernment ? govProfileId || undefined : undefined, + isGovernment: true, + companyId: govCompanyId || undefined, + companyProfileId: govProfileId || undefined, freightType: "CONTAINER", contractType: "NEW", equipmentReturn: "NA", @@ -369,20 +359,19 @@ export default function NewBookingPage() { containerTypeId: l.containerTypeId, quantity: l.quantity, vgmPerUnitTons: l.vgmPerUnitTons, + containerNumbers: l.containerNumbers + .map((n) => n.trim()) + .filter(Boolean), })), }), onSuccess: async (booking) => { - if (isGovernment) { - // The server already expedited + generated the contract at creation; - // this call is an idempotent no-op that doubles as a retry if that - // best-effort step failed. - await bookingsService.governmentExpedite(booking.id); - toast.success( - "Government booking created — contract generated, priority scheduling queued", - ); - } else { - toast.success("Booking created as draft"); - } + // The server already expedited + generated the contract at creation; + // this call is an idempotent no-op that doubles as a retry if that + // best-effort step failed. + await bookingsService.governmentExpedite(booking.id); + toast.success( + "Government booking created — contract generated, priority scheduling queued", + ); void queryClient.invalidateQueries({ queryKey: ["bookings"] }); navigate(`/dashboard/booking-requests/${booking.id}`); }, @@ -414,55 +403,38 @@ export default function NewBookingPage() { {/* LEFT — form */} - - - setIsGovernment(e.currentTarget.checked)} + + + - - )} - +