feature: a minimal implementation of staff management is done.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
/** Feature groups for staff invite/edit UI — matches backend seed */
|
||||
export const STAFF_FEATURE_GROUPS = [
|
||||
{ label: 'Today', read: 'TAB_TODAY_READ', edit: 'TAB_TODAY_EDIT' },
|
||||
{ label: 'Patients', read: 'TAB_PATIENTS_READ', edit: 'TAB_PATIENTS_EDIT' },
|
||||
{ label: 'Appointments', read: 'TAB_APPOINTMENTS_READ', edit: 'TAB_APPOINTMENTS_EDIT' },
|
||||
{ label: 'Staff Management', read: 'TAB_STAFF_READ', edit: 'TAB_STAFF_EDIT' },
|
||||
{ label: 'Lab Management', read: 'TAB_LAB_READ', edit: 'TAB_LAB_EDIT' },
|
||||
{ label: 'Billing', read: 'TAB_BILLING_READ', edit: 'TAB_BILLING_EDIT' },
|
||||
{ label: 'Reports', read: 'TAB_REPORTS_READ', edit: 'TAB_REPORTS_EDIT' },
|
||||
] as const;
|
||||
|
||||
/** Map EDIT key -> { read, edit } for checkbox grid */
|
||||
export type FeaturePermState = Record<string, { read: boolean; edit: boolean }>;
|
||||
|
||||
export function emptyFeaturePermissionState(): FeaturePermState {
|
||||
const s: FeaturePermState = {};
|
||||
for (const g of STAFF_FEATURE_GROUPS) {
|
||||
s[g.edit] = { read: false, edit: false };
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
export function featureStateFromPermissionNames(names: string[]): FeaturePermState {
|
||||
const set = new Set(names);
|
||||
const s = emptyFeaturePermissionState();
|
||||
for (const g of STAFF_FEATURE_GROUPS) {
|
||||
const hasEdit = set.has(g.edit);
|
||||
const hasRead = set.has(g.read) || hasEdit;
|
||||
s[g.edit] = { read: hasRead, edit: hasEdit };
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
export function permissionNamesFromFeatureState(state: FeaturePermState): string[] {
|
||||
const out: string[] = [];
|
||||
for (const g of STAFF_FEATURE_GROUPS) {
|
||||
const cell = state[g.edit];
|
||||
if (!cell) continue;
|
||||
if (cell.edit) out.push(g.edit);
|
||||
else if (cell.read) out.push(g.read);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
Reference in New Issue
Block a user