mirror of
https://github.com/Sea-Haven-Industries/seahaven-ap.git
synced 2026-10-07 16:18:53 +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.
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { areMocksEnabled } from "@/mocks/env";
|
|
|
|
export type MockDepartment = {
|
|
id: string;
|
|
code: string;
|
|
name: string;
|
|
};
|
|
|
|
const seedDepartments: MockDepartment[] = [
|
|
{ id: "dept-1", code: "OPS", name: "Operations" },
|
|
{ id: "dept-2", code: "FIN", name: "Finance" },
|
|
{ id: "dept-3", code: "ENG", name: "Engineering" },
|
|
{ id: "dept-4", code: "ADM", name: "Administration" },
|
|
];
|
|
|
|
let departmentStore: MockDepartment[] = seedDepartments.map((department) => ({ ...department }));
|
|
|
|
export function getMockDepartments(): MockDepartment[] {
|
|
if (!areMocksEnabled()) {
|
|
return [];
|
|
}
|
|
return departmentStore.map((department) => ({ ...department }));
|
|
}
|
|
|
|
export function getMockDepartment(id: string): MockDepartment | undefined {
|
|
return getMockDepartments().find((department) => department.id === id);
|
|
}
|
|
|
|
export function upsertMockDepartment(department: MockDepartment): MockDepartment {
|
|
const index = departmentStore.findIndex((row) => row.id === department.id);
|
|
const next = { ...department };
|
|
if (index === -1) {
|
|
departmentStore = [...departmentStore, next];
|
|
} else {
|
|
departmentStore = [
|
|
...departmentStore.slice(0, index),
|
|
next,
|
|
...departmentStore.slice(index + 1),
|
|
];
|
|
}
|
|
return { ...next };
|
|
}
|
|
|
|
export function resetMockDepartments(): void {
|
|
departmentStore = seedDepartments.map((department) => ({ ...department }));
|
|
}
|