Skip to content

Commit

Permalink
fix: code cleanup + case handling of roles cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
thomhickey committed Dec 3, 2024
1 parent 460ea15 commit 6f21de9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/backend/routers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const createUserSchema = z.object({
first_name: z.string(),
last_name: z.string(),
email: z.string().email(),
role: z.string().transform((role) => role.toUpperCase() as Roles),
role: z.string(),
});

const roleValues = ROLE_OPTIONS.map((r) => r.value) as [string, ...string[]];
Expand Down Expand Up @@ -170,11 +170,11 @@ export const user = router({
email: z.string().email(),
role: z.enum(roleValues).transform((role) => {
switch (role) {
case "ADMIN":
case "admin":
return UserType.Admin;
case "CASE_MANAGER":
case "case_manager":
return UserType.CaseManager;
case "PARA":
case "para":
return UserType.Para;
default:
return UserType.User;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/admin/[user_id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const ViewUserPage = () => {

useEffect(() => {
if (user?.role) {
setSelectedRole(user.role.toUpperCase());
setSelectedRole(user.role);
}
}, [user?.role]);

Expand Down
2 changes: 1 addition & 1 deletion src/pages/admin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const AdminHome: React.FC = () => {
try {
await createUserMutation.mutateAsync({
...userData,
role: userData.role || "PARA",
role: userData.role || "para",
});
} catch (error) {
console.error(error);
Expand Down
8 changes: 4 additions & 4 deletions src/types/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ export enum UserType {
}

export const ROLE_OPTIONS = [
{ label: "User", value: "USER" },
{ label: "Para", value: "PARA" },
{ label: "Case Manager", value: "CASE_MANAGER" },
{ label: "Admin", value: "ADMIN" },
{ label: "User", value: UserType.User },
{ label: "Para", value: UserType.Para },
{ label: "Case Manager", value: UserType.CaseManager },
{ label: "Admin", value: UserType.Admin },
] as const;

export type Roles = (typeof ROLE_OPTIONS)[number]["value"];
Expand Down

0 comments on commit 6f21de9

Please sign in to comment.