feat(frontend): finished login form with validation

This commit is contained in:
2025-02-21 09:16:07 -06:00
parent d939332499
commit 9719451580
25 changed files with 551 additions and 230 deletions

View File

@@ -0,0 +1,52 @@
interface User {
id: number;
username: string;
role: keyof Roles;
}
interface Roles {
[roleName: string]: RolePermissions;
}
interface RolePermissions {
[moduleName: string]: Feature[];
}
type Feature = string;
const rolePermissions: Roles = {
admin: {
production: ["view", "manage", "update", "admin"],
logistics: ["view", "manage", "update", "admin"],
quality: ["view", "request", "manage", "update", "admin"],
forklift: ["view", "manage", "update", "admin"],
admin: ["view", "view_logs", "manage", "update", "admin"],
},
manager: {
production: ["view", "manage"],
logistics: ["view", "manage"],
quality: ["view", "manage"],
forklift: ["view", "manage"],
admin: ["view_logs"],
},
supervisor: {
production: ["view", "update"],
logistics: ["view", "update"],
quality: ["view", "update"],
forklift: ["view"],
admin: [],
},
user: {
production: ["view"],
logistics: ["view"],
quality: ["view"],
forklift: [],
admin: [],
},
};
// user will need access to the module.
// users role will determine there visual access
export function hasAccess(user: User | null, moduleName: string, feature: Feature): boolean {
return user?.role ? rolePermissions[user.role]?.[moduleName]?.includes(feature) || false : false;
}