mirror of
https://github.com/Sea-Haven-Industries/seahaven-ap.git
synced 2026-10-03 18:53:13 +00:00
* 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.
58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
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 }));
|
||
}
|