This commit is contained in:
ghost2023
2026-06-16 15:45:58 +03:00
parent cf3db76bb1
commit 17dfce0d18
3 changed files with 33 additions and 32 deletions

View File

@@ -322,7 +322,12 @@ export default function NewBookingPage() {
)} )}
{step === 6 && <StepDocuments form={form} />} {step === 6 && <StepDocuments form={form} />}
{step === 7 && ( {step === 7 && (
<Step8Review form={form} setStep={setStep} direction={direction!} /> <Step8Review
form={form}
setStep={setStep}
direction={direction!}
referenceData={referenceData}
/>
)} )}
</Box> </Box>

View File

@@ -58,14 +58,7 @@ export function Step4Route({
}, [yardOptions, destinationYard]); }, [yardOptions, destinationYard]);
console.log({ yardOptions, originYard, destinationYard }); console.log({ yardOptions, originYard, destinationYard });
const destData = useMemo(() => { const destData = useMemo(() => {
return yardOptions return yardOptions.filter((o) => o.value !== originYard);
.filter((o) => o.value !== originYard)
.filter((d) => {
const origin = referenceData?.yard.find((y) => y.id === originYard);
if (!origin) return true;
return true;
});
}, [yardOptions, originYard]); }, [yardOptions, originYard]);
const direction = getRouteDirection( const direction = getRouteDirection(

View File

@@ -1,5 +1,5 @@
import { Controller, type UseFormReturn } from "react-hook-form"; import { Controller, type UseFormReturn } from "react-hook-form";
import { Box, Card, Checkbox, SimpleGrid, Text, Textarea, Title } from "@mantine/core"; import { Box, Card, Checkbox, SimpleGrid, Text, Textarea } from "@mantine/core";
import { import {
BookingFormInputValues, BookingFormInputValues,
BOOKING_DOCS_SETTING, BOOKING_DOCS_SETTING,
@@ -9,19 +9,28 @@ import {
import { StepHeader } from "./shared"; import { StepHeader } from "./shared";
import type { Freight } from "@/types"; import type { Freight } from "@/types";
type BookingForm = UseFormReturn<BookingFormInputValues, any, BookingFormValues>; type BookingForm = UseFormReturn<
BookingFormInputValues,
any,
BookingFormValues
>;
export function Step8Review({ export function Step8Review({
form, form,
setStep, setStep,
direction, direction,
referenceData,
}: { }: {
form: BookingForm; form: BookingForm;
setStep: (step: number) => void; setStep: (step: number) => void;
direction: Freight.ScheduleTradeDirection; direction: Freight.ScheduleTradeDirection;
referenceData?: Freight.BookingReferenceData;
}) { }) {
const values = form.watch(); const values = form.watch();
const errors = form.formState.errors; const errors = form.formState.errors;
const serviceType = referenceData?.service.find(
(s) => s.id === values.serviceTypeId,
);
function Row({ function Row({
label, label,
@@ -56,17 +65,17 @@ export function Step8Review({
const containerSummary = const containerSummary =
values.cargoType === "container" && values.containers.length > 0 values.cargoType === "container" && values.containers.length > 0
? values.containers ? values.containers
.filter((c) => +c.qty > 0) .filter((c) => +c.qty > 0)
.map((c) => `${c.qty} × ${c.type}`) .map((c) => `${c.qty} × ${c.type}`)
.join(", ") .join(", ")
: ""; : "";
const totalVgm = const totalVgm =
values.cargoType === "container" values.cargoType === "container"
? values.containers.reduce( ? values.containers.reduce(
(sum, c) => sum + (+c.qty || 0) * (+c.vgm || 0), (sum, c) => sum + (+c.qty || 0) * (+c.vgm || 0),
0, 0,
) )
: 0; : 0;
const documents = (values.documents ?? {}) as BookingDocuments; const documents = (values.documents ?? {}) as BookingDocuments;
@@ -99,7 +108,13 @@ export function Step8Review({
py="sm" py="sm"
className="border-b border-[var(--mantine-color-gray-2)] bg-gray-50/60" className="border-b border-[var(--mantine-color-gray-2)] bg-gray-50/60"
> >
<Text size="xs" fw={600} tt="uppercase" c="dimmed" className="tracking-wider"> <Text
size="xs"
fw={600}
tt="uppercase"
c="dimmed"
className="tracking-wider"
>
{title} {title}
</Text> </Text>
</Box> </Box>
@@ -124,17 +139,7 @@ export function Step8Review({
value={values.contractType === "new" ? "New Contract" : "Renewal"} value={values.contractType === "new" ? "New Contract" : "Renewal"}
target={1} target={1}
/> />
<Row <Row label="Service" value={serviceType?.name ?? ""} target={2} />
label="Service"
value={
values.serviceType === "rail"
? "Rail Only"
: values.serviceType === "rail_forwarding"
? "Rail + Forwarding"
: ""
}
target={2}
/>
</ReviewCard> </ReviewCard>
<ReviewCard title="First & Last Mile"> <ReviewCard title="First & Last Mile">
@@ -260,9 +265,7 @@ export function Step8Review({
} }
checked={field.value} checked={field.value}
onChange={(e) => field.onChange(e.currentTarget.checked)} onChange={(e) => field.onChange(e.currentTarget.checked)}
error={ error={fieldState.error?.message ?? errors.termsAccepted?.message}
fieldState.error?.message ?? errors.termsAccepted?.message
}
color="edr-green" color="edr-green"
radius="sm" radius="sm"
/> />