seahaven-ap/src/mocks/approval-policies.ts
Adam Moussa fd903c6367
feat(settings): add settings and approvals POC shells (AP-7) (#8)
* feat(settings): add settings and approvals POC shells (AP-7)

Add app shell nav plus mock settings CRUD routes and an approvals inbox so the POC demo path works without an API.

* fix(build): generate router types before tsc

CI failed because src/router.ts is gitignored and tsc ran before Vite created it.
2026-08-10 22:00:51 +00:00

58 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { areMocksEnabled } from "@/mocks/env";
import type { MockUserRole } from "@/mocks/users";
export type MockApprovalPolicy = {
id: string;
name: string;
amountThreshold: number;
approverRole: MockUserRole;
};
const seedPolicies: MockApprovalPolicy[] = [
{
id: "policy-1",
name: "Standard under $1,000",
amountThreshold: 1000,
approverRole: "approver",
},
{
id: "policy-2",
name: "Elevated $1,000–$5,000",
amountThreshold: 5000,
approverRole: "approver",
},
{
id: "policy-3",
name: "Executive over $5,000",
amountThreshold: 5000.01,
approverRole: "admin",
},
];
let policyStore: MockApprovalPolicy[] = seedPolicies.map((policy) => ({ ...policy }));
export function getMockApprovalPolicies(): MockApprovalPolicy[] {
if (!areMocksEnabled()) {
return [];
}
return policyStore.map((policy) => ({ ...policy }));
}
export function getMockApprovalPolicy(id: string): MockApprovalPolicy | undefined {
return getMockApprovalPolicies().find((policy) => policy.id === id);
}
export function upsertMockApprovalPolicy(policy: MockApprovalPolicy): MockApprovalPolicy {
const index = policyStore.findIndex((row) => row.id === policy.id);
const next = { ...policy };
if (index === -1) {
policyStore = [...policyStore, next];
} else {
policyStore = [...policyStore.slice(0, index), next, ...policyStore.slice(index + 1)];
}
return { ...next };
}
export function resetMockApprovalPolicies(): void {
policyStore = seedPolicies.map((policy) => ({ ...policy }));
}