mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 17:38:12 +00:00
Merge pull request #458 from Tria-plc/freight_feature/usermanagement
refactor: remove gate pass granting logic from clearance services and UI
This commit is contained in:
@@ -14,7 +14,7 @@ import {
|
||||
Text,
|
||||
Textarea,
|
||||
} from "@mantine/core";
|
||||
import { DateInput, DateTimePicker } from "@mantine/dates";
|
||||
import { DateInput } from "@mantine/dates";
|
||||
import {
|
||||
AlertTriangle,
|
||||
CheckCircle2,
|
||||
@@ -397,15 +397,10 @@ export function ExportClearanceStepper({
|
||||
|
||||
<Stepper.Step
|
||||
label="Gate pass"
|
||||
description="GL Djibouti grants after arrival"
|
||||
description="Secured on the train schedule after arrival"
|
||||
icon={clearance.gatepassGranted ? <CheckCircle2 size={14} /> : <Truck size={14} />}
|
||||
>
|
||||
<GatepassStep
|
||||
bookingId={actionBookingId}
|
||||
clearance={clearance}
|
||||
canAct={showDj && canDj}
|
||||
onChanged={onChanged}
|
||||
/>
|
||||
<GatepassStep clearance={clearance} />
|
||||
</Stepper.Step>
|
||||
|
||||
<Stepper.Step
|
||||
@@ -491,27 +486,19 @@ function ConfirmExportReleaseFallback({
|
||||
);
|
||||
}
|
||||
|
||||
function GatepassStep({
|
||||
bookingId,
|
||||
clearance,
|
||||
canAct,
|
||||
onChanged,
|
||||
}: {
|
||||
bookingId: string | null;
|
||||
clearance: ClearanceViewLike;
|
||||
canAct: boolean;
|
||||
onChanged?: () => void;
|
||||
}) {
|
||||
const [opened, setOpened] = useState(false);
|
||||
const [at, setAt] = useState<Date | null>(new Date());
|
||||
const [loading, setLoading] = useState(false);
|
||||
/**
|
||||
* Gate pass status, read-only. Secured on the train schedule's "Save as
|
||||
* Secured" action (train-scheduling-v2) — clearance no longer grants it directly.
|
||||
*/
|
||||
function GatepassStep({ clearance }: { clearance: ClearanceViewLike }) {
|
||||
const scheduleId = clearance.train?.scheduleId ?? null;
|
||||
|
||||
if (clearance.gatepassGranted) {
|
||||
return (
|
||||
<StepStatus
|
||||
done
|
||||
pendingLabel=""
|
||||
doneLabel={`Gate pass granted${
|
||||
doneLabel={`Gate pass secured${
|
||||
clearance.gatepassAt ? ` · ${new Date(clearance.gatepassAt).toLocaleString()}` : ""
|
||||
}`}
|
||||
/>
|
||||
@@ -526,68 +513,21 @@ function GatepassStep({
|
||||
done={false}
|
||||
pendingLabel={
|
||||
arrived
|
||||
? "Train arrived — GL Djibouti can grant the gate pass."
|
||||
? "Train arrived — secure the gate pass on the train schedule."
|
||||
: "Available once the train arrives at Djibouti."
|
||||
}
|
||||
doneLabel=""
|
||||
/>
|
||||
{canAct && bookingId ? (
|
||||
<>
|
||||
<Button
|
||||
color="edr-green"
|
||||
leftSection={<Truck size={16} />}
|
||||
disabled={!arrived}
|
||||
onClick={() => {
|
||||
setAt(new Date());
|
||||
setOpened(true);
|
||||
}}
|
||||
>
|
||||
Grant gate pass
|
||||
</Button>
|
||||
<Modal
|
||||
opened={opened}
|
||||
onClose={() => setOpened(false)}
|
||||
title={<Text fw={700}>Grant gate pass</Text>}
|
||||
radius="md"
|
||||
size="sm"
|
||||
>
|
||||
<Stack gap="md">
|
||||
<DateTimePicker
|
||||
label="Gate pass time"
|
||||
value={at}
|
||||
onChange={(v) => setAt(v ? new Date(v) : null)}
|
||||
required
|
||||
/>
|
||||
<Group justify="flex-end">
|
||||
<Button variant="default" onClick={() => setOpened(false)} disabled={loading}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
color="edr-green"
|
||||
loading={loading}
|
||||
onClick={async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
await contractsService.grantGatepass(
|
||||
bookingId,
|
||||
(at ?? new Date()).toISOString(),
|
||||
);
|
||||
toast.success("Gate pass granted");
|
||||
setOpened(false);
|
||||
onChanged?.();
|
||||
} catch (e) {
|
||||
toast.error(e instanceof Error ? e.message : "Failed");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}}
|
||||
>
|
||||
Grant
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
</Modal>
|
||||
</>
|
||||
{scheduleId ? (
|
||||
<Button
|
||||
component="a"
|
||||
href={`/dashboard/operations/train-scheduling-v2/${scheduleId}`}
|
||||
variant="light"
|
||||
color="edr-green"
|
||||
leftSection={<Truck size={16} />}
|
||||
>
|
||||
Secure gate pass on train schedule
|
||||
</Button>
|
||||
) : null}
|
||||
</Stack>
|
||||
);
|
||||
|
||||
@@ -4,7 +4,6 @@ import {
|
||||
Badge,
|
||||
Button,
|
||||
Group,
|
||||
Modal,
|
||||
NumberInput,
|
||||
Paper,
|
||||
SegmentedControl,
|
||||
@@ -15,7 +14,6 @@ import {
|
||||
Text,
|
||||
TextInput,
|
||||
} from "@mantine/core";
|
||||
import { DateTimePicker } from "@mantine/dates";
|
||||
import { PhasedFileDropzone, PhasedMultiFileDropzone } from "@/components/contracts/PhasedFileDropzone";
|
||||
import {
|
||||
TransitPermitMultiUpload,
|
||||
@@ -536,17 +534,12 @@ export function PhasedClearanceActionPanel({
|
||||
|
||||
<Stepper.Step
|
||||
label="Gate pass"
|
||||
description="GL Djibouti grants after wagon allocation"
|
||||
description="Secured on the train schedule after wagon allocation"
|
||||
icon={
|
||||
clearance.gatepassGranted ? <CheckCircle2 size={14} /> : <Truck size={14} />
|
||||
}
|
||||
>
|
||||
<ImportGatepassStep
|
||||
bookingId={actionBookingId}
|
||||
clearance={clearance}
|
||||
canAct={showDj && canDj}
|
||||
onChanged={onChanged}
|
||||
/>
|
||||
<ImportGatepassStep clearance={clearance} />
|
||||
</Stepper.Step>
|
||||
|
||||
<Stepper.Step
|
||||
@@ -816,28 +809,19 @@ function ImportT1Section({
|
||||
);
|
||||
}
|
||||
|
||||
/** GL DJ grants the import gate pass once wagons are allocated (captures time). */
|
||||
function ImportGatepassStep({
|
||||
bookingId,
|
||||
clearance,
|
||||
canAct,
|
||||
onChanged,
|
||||
}: {
|
||||
bookingId: string | null;
|
||||
clearance: ClearanceViewLike;
|
||||
canAct: boolean;
|
||||
onChanged?: () => void;
|
||||
}) {
|
||||
const [opened, setOpened] = useState(false);
|
||||
const [at, setAt] = useState<Date | null>(new Date());
|
||||
const [loading, setLoading] = useState(false);
|
||||
/**
|
||||
* Gate pass status, read-only. Secured on the train schedule's "Save as
|
||||
* Secured" action (train-scheduling-v2) — clearance no longer grants it directly.
|
||||
*/
|
||||
function ImportGatepassStep({ clearance }: { clearance: ClearanceViewLike }) {
|
||||
const scheduleId = clearance.train?.scheduleId ?? null;
|
||||
|
||||
if (clearance.gatepassGranted) {
|
||||
return (
|
||||
<StepStatus
|
||||
done
|
||||
pendingLabel=""
|
||||
doneLabel={`Gate pass granted${
|
||||
doneLabel={`Gate pass secured${
|
||||
clearance.gatepassAt ? ` · ${new Date(clearance.gatepassAt).toLocaleString()}` : ""
|
||||
}`}
|
||||
/>
|
||||
@@ -852,68 +836,21 @@ function ImportGatepassStep({
|
||||
done={false}
|
||||
pendingLabel={
|
||||
wagonAllocated
|
||||
? "Wagons allocated — GL Djibouti can grant the gate pass."
|
||||
? "Wagons allocated — secure the gate pass on the train schedule."
|
||||
: "Available once wagons are allocated."
|
||||
}
|
||||
doneLabel=""
|
||||
/>
|
||||
{canAct && bookingId ? (
|
||||
<>
|
||||
<Button
|
||||
color="edr-green"
|
||||
leftSection={<Truck size={16} />}
|
||||
disabled={!wagonAllocated}
|
||||
onClick={() => {
|
||||
setAt(new Date());
|
||||
setOpened(true);
|
||||
}}
|
||||
>
|
||||
Grant gate pass
|
||||
</Button>
|
||||
<Modal
|
||||
opened={opened}
|
||||
onClose={() => setOpened(false)}
|
||||
title={<Text fw={700}>Grant gate pass</Text>}
|
||||
radius="md"
|
||||
size="sm"
|
||||
>
|
||||
<Stack gap="md">
|
||||
<DateTimePicker
|
||||
label="Gate pass time"
|
||||
value={at}
|
||||
onChange={(v) => setAt(v ? new Date(v) : null)}
|
||||
required
|
||||
/>
|
||||
<Group justify="flex-end">
|
||||
<Button variant="default" onClick={() => setOpened(false)} disabled={loading}>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
color="edr-green"
|
||||
loading={loading}
|
||||
onClick={async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
await contractsService.grantGatepass(
|
||||
bookingId,
|
||||
(at ?? new Date()).toISOString(),
|
||||
);
|
||||
toast.success("Gate pass granted");
|
||||
setOpened(false);
|
||||
onChanged?.();
|
||||
} catch (e) {
|
||||
toast.error(e instanceof Error ? e.message : "Failed");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}}
|
||||
>
|
||||
Grant
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
</Modal>
|
||||
</>
|
||||
{scheduleId ? (
|
||||
<Button
|
||||
component="a"
|
||||
href={`/dashboard/operations/train-scheduling-v2/${scheduleId}`}
|
||||
variant="light"
|
||||
color="edr-green"
|
||||
leftSection={<Truck size={16} />}
|
||||
>
|
||||
Secure gate pass on train schedule
|
||||
</Button>
|
||||
) : null}
|
||||
</Stack>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user