diff --git a/client/src/App.tsx b/client/src/App.tsx index 759613c..e423f29 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -4,6 +4,7 @@ import Inventory from './pages/Inventory.tsx'; import Users from './pages/Users.tsx'; import { BrowserRouter, Routes, Route, Navigate } from 'react-router'; import { RequireAuth } from '@features/auth/RequireAuth'; +import { RequireAdmin } from '@features/auth/RequireAdmin'; const App = () => { return ( @@ -24,7 +25,14 @@ const App = () => { element={} /> } /> - } /> + + + + } + /> } /> diff --git a/client/src/features/ChangeUserRoleModal/ChangeUserRoleModal.tsx b/client/src/features/ChangeUserRoleModal/ChangeUserRoleModal.tsx index 432c9b9..fa1190f 100644 --- a/client/src/features/ChangeUserRoleModal/ChangeUserRoleModal.tsx +++ b/client/src/features/ChangeUserRoleModal/ChangeUserRoleModal.tsx @@ -1,5 +1,5 @@ import { useState } from 'react'; -import type { UserResource, UpdateUserResponse } from '@foodstoragemanager/schema'; +import { toRole, type UserResource, type UpdateUserResponse, type Role } from '@foodstoragemanager/schema'; import { getSchemaClient } from '@lib/schemaClient'; interface ChangeUserRoleModalProps { @@ -9,8 +9,8 @@ interface ChangeUserRoleModalProps { } export const ChangeUserRoleModal = ({ user, onRoleChanged, onCancel }: ChangeUserRoleModalProps) => { - const currentRole = user.role?.[0] ?? ''; - const [selectedRole, setSelectedRole] = useState(currentRole); + const currentRole: Role = toRole(user.role); + const [selectedRole, setSelectedRole] = useState(currentRole); const [isSubmitting, setIsSubmitting] = useState(false); const [error, setError] = useState(null); @@ -28,7 +28,7 @@ export const ChangeUserRoleModal = ({ user, onRoleChanged, onCancel }: ChangeUse const client = getSchemaClient(); const payload: UpdateUserResponse = await client.updateUser(user._id, { - role: selectedRole === '' ? undefined : (selectedRole as 'admin' | 'staff' | 'volunteer'), + role: selectedRole, }); if ('error' in payload) { @@ -45,9 +45,7 @@ export const ChangeUserRoleModal = ({ user, onRoleChanged, onCancel }: ChangeUse } }; - const currentRoleDisplay = currentRole - ? currentRole[0].toUpperCase() + currentRole.slice(1).toLowerCase() - : 'No Role'; + const currentRoleDisplay = `${currentRole[0].toUpperCase()}${currentRole.slice(1).toLowerCase()}`; return (
@@ -75,12 +73,11 @@ export const ChangeUserRoleModal = ({ user, onRoleChanged, onCancel }: ChangeUse handleInputChange('role', event.target.value)} + className="w-full rounded-md border border-gray-300 px-3 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500" + required + > + + + + +
+
{onCancel && (