add draft declaration

This commit is contained in:
Marshal
2026-08-23 19:02:33 +00:00
parent 58f88b74f8
commit 31fa313c66
10 changed files with 201 additions and 35 deletions

View File

@@ -280,7 +280,12 @@ function mapBookingToShipmentValues(
}>;
};
const values: Partial<ShipmentFormInputValues> = {
paymentCurrency: "ETB",
// Resubmit keeps the currency the customer already chose on this booking;
// a missing value falls back to empty so the choice is made deliberately.
paymentCurrency:
booking.paymentCurrency === "USD" || booking.paymentCurrency === "ETB"
? booking.paymentCurrency
: "",
withReturn: booking.equipmentReturn === "WITH_RETURN",
cargoDescription: b.cargoFreeText ?? "",
...(b.contractRouteId ? { contractRouteId: b.contractRouteId } : {}),
@@ -389,8 +394,9 @@ function NewShipmentBookingForm({
// Seed the equipment-return toggle from the contract; the customer can
// still flip it per shipment.
withReturn: contract.equipmentReturn === "WITH_RETURN",
// ponytail: ETB-only for now — preset since there is no other choice.
paymentCurrency: "ETB",
// Starts empty so the choice is deliberate (schema requires it).
// Intercity hides the field entirely, so it keeps the forced ETB.
paymentCurrency: contract.tradeDirection === "DOMESTIC" ? "ETB" : "",
},
resolver: zodResolver(
createShipmentFormSchema({

View File

@@ -9,12 +9,12 @@ import {
Loader,
NumberInput,
Paper,
SegmentedControl,
Stack,
Text,
Textarea,
Title,
} from "@mantine/core";
import { CurrencySelector } from "@edr/ui-common";
import { AlertCircle, ArrowLeft, CalendarDays, Send } from "lucide-react";
import toast from "react-hot-toast";
import type { Freight } from "@edr/types";
@@ -36,7 +36,10 @@ export default function NewShipmentRequestPage() {
const [bulkAmount, setBulkAmount] = useState<number | string>("");
// GL books this shipment on the customer's behalf, so the currency they want
// to be invoiced in has to be stated here — the contract itself quotes USD.
const [paymentCurrency, setPaymentCurrency] = useState<"USD" | "ETB">("USD");
// Starts empty so the billing-currency choice is deliberate — required at
// submit. Intercity/export are forced to ETB (server-enforced too).
const [paymentCurrency, setPaymentCurrency] = useState<"USD" | "ETB" | "">("");
const [currencyError, setCurrencyError] = useState<string | undefined>();
const [notes, setNotes] = useState("");
const { data: contract, isLoading } = useQuery({
@@ -114,10 +117,15 @@ export default function NewShipmentRequestPage() {
const hasOdd20ft = ft20Requested % 2 === 1;
const handleSubmit = () => {
if (!isIntercity && !isExport && !paymentCurrency) {
setCurrencyError("Select the billing currency for this shipment.");
return;
}
const dto: Freight.CreateBookingRequestDto = {
contractRouteId: route?.id,
scheduledDate: hasCustoms ? undefined : scheduledDate || undefined,
paymentCurrency: isIntercity || isExport ? "ETB" : paymentCurrency,
paymentCurrency:
isIntercity || isExport ? "ETB" : (paymentCurrency as "USD" | "ETB"),
notes: notes.trim() || undefined,
};
@@ -251,20 +259,15 @@ export default function NewShipmentRequestPage() {
? "Export shipments are invoiced in ETB."
: "Your contract is quoted in USD. Global Logistics will book this shipment and invoice you in the currency you pick here."}
</Text>
<SegmentedControl
<CurrencySelector
value={isIntercity || isExport ? "ETB" : paymentCurrency}
onChange={(v) => setPaymentCurrency(v as "USD" | "ETB")}
onChange={(v) => {
setPaymentCurrency(v);
setCurrencyError(undefined);
}}
disabled={isIntercity || isExport}
data={
isExport
? [{ label: "ETB", value: "ETB" }]
: [
{ label: "USD", value: "USD" },
{ label: "ETB", value: "ETB" },
]
}
color="teal"
radius={10}
allowUsd={!isIntercity && !isExport}
error={currencyError}
/>
</Box>