mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-09-30 10:23:11 +00:00
Add Template, Edit and Delete now follow the permissions the server computes for the signed-in user, role defaults plus their individual overrides, instead of role defaults alone. The actions stay hidden while the permissions load or when they fail to load.
17 lines
782 B
TypeScript
17 lines
782 B
TypeScript
import { z } from "zod";
|
|
import { apiGet } from "@/api/api";
|
|
import { API_PATHS } from "@/api/api-paths";
|
|
import { handleApiResponse } from "@/api/handle-api-response";
|
|
|
|
export const UNEXPECTED_PERMISSIONS_RESPONSE =
|
|
"The server sent an unexpected permissions response.";
|
|
|
|
const effectivePermissionsSchema = z.object({ permissions: z.array(z.string()) });
|
|
|
|
/** Keys the signed-in user holds after role defaults and their individual overrides. */
|
|
export async function getMyPermissions(): Promise<string[]> {
|
|
const data = await apiGet<unknown>(API_PATHS.teamMember.myPermissions);
|
|
const result = effectivePermissionsSchema.safeParse(handleApiResponse<unknown>(data));
|
|
if (!result.success) throw new Error(UNEXPECTED_PERMISSIONS_RESPONSE);
|
|
return result.data.permissions;
|
|
}
|