- Fix shipping line mapping to use ID instead of name in EditBookingPage and NewBookingPage

This commit is contained in:
marshal
2026-06-19 01:07:05 +03:00
parent 1a3d85e46a
commit 72b63c319e
4 changed files with 24 additions and 22 deletions

View File

@@ -6,7 +6,7 @@ import {
useMemo,
useState,
} from "react";
import { ChevronDown, Train } from "lucide-react";
import { ChevronDown } from "lucide-react";
import { Box, Stack, Text } from "@mantine/core";
import type { SidebarItem, SidebarSection } from "./types";
@@ -226,8 +226,10 @@ const FreightSidebar = ({
return (
<Box component="aside" className="fsb-aside">
<div className="fsb-brand">
<div className="fsb-logo">
<Train size={23} color="white" strokeWidth={2.1} />
<div className="">
<img src="assets/edr-logo.png" alt="EDR Freight" className="h-7 w-auto brightness-0 invert sm:h-9" />
{/* <Train size={23} color="white" strokeWidth={2.1} /> */}
</div>
<Stack gap={1} style={{ minWidth: 0, position: "relative", zIndex: 1 }}>
<Text

View File

@@ -136,7 +136,7 @@ function mapBookingToFormValues(
cargoWeight: String(booking.cargoTotalWeightVgm ?? ""),
isHazardous: booking.isHazardous ?? false,
isRefrigerated: booking.isRefrigerated ?? false,
shippingLine: (booking as any).shippingLine?.name ?? "",
shippingLine: (booking as any).shippingLine?.id ?? "",
consolidationEnabled: booking.allowConsolidation ?? false,
paymentCurrency:
booking.paymentCurrency === "ETB" ? "ETB" : "USD",
@@ -360,10 +360,14 @@ export default function EditBookingPage() {
const shippingLineOptions = useMemo(() => {
if (!referenceData?.shipping_line) return [];
return referenceData.shipping_line.map((sl) => ({
value: sl.name,
label: sl.name,
}));
const seen = new Set<string>();
return referenceData.shipping_line
.filter((sl) => {
if (seen.has(sl.id)) return false;
seen.add(sl.id);
return true;
})
.map((sl) => ({ value: sl.id, label: sl.name }));
}, [referenceData]);
const setDocument = (key: string, file: File | null) => {
@@ -376,12 +380,8 @@ export default function EditBookingPage() {
};
const handleSubmit = form.handleSubmit((data) => {
const shippingLines = referenceData?.shipping_line ?? [];
const containerGroups = referenceData?.containers ?? [];
const findShippingLineId = (name: string): string | undefined =>
shippingLines.find((l) => l.name === name)?.id;
const cargoTypePath = data.cargoTypePath ?? [];
const cargoTypeId =
data.cargoType === "container" ? undefined : (cargoTypePath[1] ?? "");
@@ -456,7 +456,7 @@ export default function EditBookingPage() {
? { lastMileDeliveryAddress: data.lastMile.deliveryAddress }
: {}),
...(data.shippingLine
? { shippingLineId: findShippingLineId(data.shippingLine) }
? { shippingLineId: data.shippingLine }
: {}),
};

View File

@@ -231,13 +231,9 @@ export default function NewBookingPage() {
)
: Number(data.cargoWeight || 0);
const shippingLines = referenceData?.shipping_line ?? [];
const cargoTree = referenceData?.cargo_type ?? [];
const containerGroups = referenceData?.containers ?? [];
const findShippingLineId = (name: string): string | undefined =>
shippingLines.find((l) => l.name === name)?.id;
const findContainerTypeId = (name: string): string => {
for (const group of containerGroups) {
const ct = group.types.find((t) => t.name === name);
@@ -308,7 +304,7 @@ export default function NewBookingPage() {
? { lastMileDeliveryAddress: data.lastMile.deliveryAddress }
: {}),
...(data.shippingLine
? { shippingLineId: findShippingLineId(data.shippingLine) }
? { shippingLineId: data.shippingLine }
: {}),
...(cargoFreeText ? { cargoFreeText } : {}),
};

View File

@@ -35,10 +35,14 @@ export function Step4Route({
const shippingLineOptions = useMemo(() => {
if (!referenceData?.shipping_line) return [];
return referenceData.shipping_line.map((sl) => ({
value: sl.name,
label: sl.name,
}));
const seen = new Set<string>();
return referenceData.shipping_line
.filter((sl) => {
if (seen.has(sl.id)) return false;
seen.add(sl.id);
return true;
})
.map((sl) => ({ value: sl.id, label: sl.name }));
}, [referenceData]);
const originData = useMemo(() => {