mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-02 01:33:12 +00:00
Show work-order uplift requests read-only in the Vendor Portal
Revise and Withdraw now appear only on uplift requests the vendor raised. Requests raised from the work order stay visible without either control.
This commit is contained in:
parent
7c665464f8
commit
70f8b303b5
3 changed files with 65 additions and 2 deletions
|
|
@ -35,8 +35,10 @@ export function UpliftRequestCard({
|
|||
onCancelRevise,
|
||||
}: UpliftRequestCardProps) {
|
||||
const [revising, setRevising] = useState(false);
|
||||
const canWithdraw = !locked && canAct && WITHDRAWABLE_STATUSES.has(request.status);
|
||||
const canRevise = !locked && canAct && request.status === "ChangesRequested";
|
||||
// Requests raised from the work order are visible but read-only to the vendor.
|
||||
const ownRequest = request.raisedByVendor !== false;
|
||||
const canWithdraw = !locked && canAct && ownRequest && WITHDRAWABLE_STATUSES.has(request.status);
|
||||
const canRevise = !locked && canAct && ownRequest && request.status === "ChangesRequested";
|
||||
|
||||
return (
|
||||
<div className="vp-uplift-row">
|
||||
|
|
|
|||
|
|
@ -66,6 +66,8 @@ export interface VendorPortalUpliftRequest {
|
|||
requestedNTE: number;
|
||||
currentNTE?: number;
|
||||
vendorReason?: string;
|
||||
/** False when the request was raised from the work order; the vendor cannot revise or withdraw it. */
|
||||
raisedByVendor?: boolean;
|
||||
requestedAt?: string;
|
||||
decidedAt?: string;
|
||||
decidedByName?: string;
|
||||
|
|
|
|||
59
src/test/app/v/uplift-request-card.test.tsx
Normal file
59
src/test/app/v/uplift-request-card.test.tsx
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
import { render, screen } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { UpliftRequestCard } from "@/app/v/[token]/dispatch/_components/uplift-request-card";
|
||||
import type { VendorPortalUpliftRequest } from "@/domain/vendor-portal/types/vendor-portal";
|
||||
|
||||
function request(overrides: Partial<VendorPortalUpliftRequest> = {}): VendorPortalUpliftRequest {
|
||||
return {
|
||||
id: 7,
|
||||
status: "Pending",
|
||||
requestedNTE: 1500,
|
||||
currentNTE: 1000,
|
||||
vendorReason: "Extra parts",
|
||||
raisedByVendor: true,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
function renderCard(req: VendorPortalUpliftRequest) {
|
||||
return render(
|
||||
<UpliftRequestCard
|
||||
request={req}
|
||||
locked={false}
|
||||
canAct
|
||||
uploadingPercent={undefined}
|
||||
submitting={false}
|
||||
errorMessage=""
|
||||
onWithdraw={vi.fn()}
|
||||
onRevise={vi.fn()}
|
||||
onCancelRevise={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
}
|
||||
|
||||
describe("UpliftRequestCard actions", () => {
|
||||
it("offers Withdraw on a pending request the vendor raised", () => {
|
||||
renderCard(request({ status: "Pending" }));
|
||||
|
||||
expect(screen.getByRole("button", { name: /withdraw request/i })).toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: /revise/i })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("offers Withdraw and Revise when changes are requested on a request the vendor raised", () => {
|
||||
renderCard(request({ status: "ChangesRequested" }));
|
||||
|
||||
expect(screen.getByRole("button", { name: /withdraw request/i })).toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: /revise/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it.each(["Pending", "ChangesRequested"])(
|
||||
"shows a %s request raised from the work order read-only",
|
||||
(status) => {
|
||||
renderCard(request({ status, raisedByVendor: false, requestedNTE: 90, currentNTE: 600 }));
|
||||
|
||||
expect(screen.getByText(status)).toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: /withdraw request/i })).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("button", { name: /revise/i })).not.toBeInTheDocument();
|
||||
},
|
||||
);
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue