diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index a58e2d8..200d577 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -5,7 +5,9 @@ import { useAuth } from 'src/services/auth'; import Gravatar from 'react-gravatar'; import { Link, useLocation } from 'react-router-dom'; import clsx from 'clsx'; -import { CurrentUserModal } from './components/CurrentUserModal'; +import _ from 'lodash'; + +import { UserModal } from '../UserModal'; const navigation = [ { name: 'Dashboard', to: '/dashboard', requiresAdmin: false }, @@ -29,14 +31,20 @@ interface HeaderProps {} const Header: React.FC = () => { const [currentUserModal, setCurrentUserModal] = useState(false); + const [currentUserId, setCurrentUserId] = useState(null); const { logOut, currentUser, isAdmin } = useAuth(); const { pathname } = useLocation(); - const currentUserModalOpen = () => { + const currentUserModalOpen = (id: any) => { + setCurrentUserId(id); setCurrentUserModal(true); }; - const currentUserModalClose = () => setCurrentUserModal(false); + + const currentUserModalClose = () => { + setCurrentUserModal(false); + setCurrentUserId(null); + }; const navigationItems = filterNavigationByDashboardRole(isAdmin); @@ -106,7 +114,7 @@ const Header: React.FC = () => { {({ active }) => ( currentUserModalOpen()} + onClick={() => currentUserModalOpen(currentUser?.id)} className={classNames( active ? 'bg-gray-100 cursor-pointer' : '', 'block px-4 py-2 text-sm text-gray-700 cursor-pointer', @@ -119,7 +127,7 @@ const Header: React.FC = () => { {({ active }) => ( logOut()} + onClick={logOut} className={classNames( active ? 'bg-gray-100 cursor-pointer' : '', 'block px-4 py-2 text-sm text-gray-700 cursor-pointer', @@ -160,7 +168,7 @@ const Header: React.FC = () => { )} - + ); }; diff --git a/src/components/Header/components/CurrentUserModal/CurrentUserModal.tsx b/src/components/Header/components/CurrentUserModal/CurrentUserModal.tsx deleted file mode 100644 index aaa29c2..0000000 --- a/src/components/Header/components/CurrentUserModal/CurrentUserModal.tsx +++ /dev/null @@ -1,168 +0,0 @@ -import _ from 'lodash'; -import React, { useEffect } from 'react'; -import { useFieldArray, useForm } from 'react-hook-form'; -import { Modal } from 'src/components'; -import { Input, Select } from 'src/components/Form'; -import { useAuth } from 'src/services/auth'; -import { User, UserRole, useUsers } from 'src/services/users'; -import { appAccessList, initialUserForm } from './consts'; -import { UserModalProps } from './types'; - -export const CurrentUserModal = ({ open, onClose, user }: UserModalProps) => { - const { editUserById, userModalLoading } = useUsers(); - const { isAdmin } = useAuth(); - - const { control, reset, handleSubmit } = useForm({ - defaultValues: initialUserForm, - }); - - const { fields } = useFieldArray({ - control, - name: 'app_roles', - }); - - useEffect(() => { - if (user && !_.isEmpty(user)) { - reset(user); - } - - return () => { - reset(initialUserForm); - }; - }, [user, reset]); - - const handleSave = async () => { - try { - if (user) { - await handleSubmit((data) => editUserById(data))(); - } - - onClose(); - } catch (e: any) { - // Continue - } - }; - - const handleKeyPress = (e: any) => { - if (e.key === 'Enter' || e.key === 'NumpadEnter') { - handleSave(); - } - }; - - const handleClose = () => { - onClose(); - }; - - return ( - -
-
-
-
-

Profile

-
- -
-
- -
- -
- -
- - {isAdmin && ( - <> -
- {fields - .filter((field) => field.name === 'dashboard') - .map((item, index) => ( - */} - -
- -
-
- - )} -
-
- - {isAdmin && ( -
-
-

App Access

-
- -
-
-
    - {fields.map((item, index) => { - if (item.name === 'dashboard') { - return null; - } - - return ( -
  • -
    -
    - {item.name -

    - {_.find(appAccessList, ['name', item.name!])?.label} -

    -
    -
    -