mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-03 11:33:22 +00:00
fix(work-orders): use the saved work order type for uplift allowance
The create API uses the saved type, so an unsaved draft must not change the allowance.
This commit is contained in:
parent
94aa7a1d66
commit
52934dc959
2 changed files with 8 additions and 14 deletions
|
|
@ -20,28 +20,23 @@ type SlideOverState = ReturnType<typeof useWorkOrderSlideOver>;
|
|||
|
||||
function SlideOverUpliftsPanel({
|
||||
tab,
|
||||
editing,
|
||||
infoSource,
|
||||
activeDraft,
|
||||
upliftCreatePending,
|
||||
onUpliftCreatePendingChange,
|
||||
}: {
|
||||
tab: SlideOverTab;
|
||||
editing: boolean;
|
||||
infoSource: WorkOrderTableRow | null | undefined;
|
||||
activeDraft: WorkOrderTableRow | null | undefined;
|
||||
upliftCreatePending: boolean;
|
||||
onUpliftCreatePendingChange?: (pending: boolean) => void;
|
||||
}) {
|
||||
const visible = tab === "uplifts";
|
||||
if (infoSource == null || (!visible && !upliftCreatePending)) return null;
|
||||
const source = editing && activeDraft != null ? activeDraft : infoSource;
|
||||
return (
|
||||
<div hidden={!visible}>
|
||||
<SlideOverUpliftsTab
|
||||
workOrderId={infoSource.id}
|
||||
workOrderType={source.type}
|
||||
status={source.status}
|
||||
workOrderType={infoSource.type}
|
||||
status={infoSource.status}
|
||||
onCreatePendingChange={onUpliftCreatePendingChange}
|
||||
/>
|
||||
</div>
|
||||
|
|
@ -174,9 +169,7 @@ export function WorkOrderSlideOverTabs({
|
|||
|
||||
<SlideOverUpliftsPanel
|
||||
tab={tab}
|
||||
editing={Boolean(state.editing)}
|
||||
infoSource={infoSource}
|
||||
activeDraft={activeDraft}
|
||||
upliftCreatePending={Boolean(state.upliftCreatePending)}
|
||||
onUpliftCreatePendingChange={state.setUpliftCreatePending}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -142,10 +142,11 @@ function renderUplifts(state: SlideOverState) {
|
|||
}
|
||||
|
||||
describe("WorkOrderSlideOverTabs Uplifts draft", () => {
|
||||
it("uses the unsaved Info type for the auto-approval allowance", () => {
|
||||
it("keeps the saved work order type for the allowance while Info is unsaved", () => {
|
||||
renderUplifts(upliftsState(true, { type: "PM" }, { type: "Emergency" }));
|
||||
|
||||
expect(screen.getByText(/\$5,000 left to auto-approve/i)).toBeInTheDocument();
|
||||
expect(screen.getByText(/\$500 left to auto-approve/i)).toBeInTheDocument();
|
||||
expect(screen.queryByText(/\$5,000 left to auto-approve/i)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps the persisted allowance when the slide-over is not editing", () => {
|
||||
|
|
@ -155,11 +156,11 @@ describe("WorkOrderSlideOverTabs Uplifts draft", () => {
|
|||
expect(screen.queryByText(/\$5,000 left to auto-approve/i)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("closes uplift requests from an unsaved completed status", () => {
|
||||
it("keeps uplift requests open when only the unsaved Info status is completed", () => {
|
||||
renderUplifts(upliftsState(true, { status: "Scheduled" }, { status: "Completed" }));
|
||||
|
||||
expect(screen.getByText(/uplifts can no longer be requested/i)).toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: /request uplift/i })).not.toBeInTheDocument();
|
||||
expect(screen.queryByText(/uplifts can no longer be requested/i)).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: /request uplift/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps the request form when a completed status exists only on an inactive draft", () => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue