diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index 0faf437..7b1c5a2 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 }, @@ -31,14 +33,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); @@ -110,7 +118,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', @@ -165,7 +173,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 29a3c16..0000000 --- a/src/components/Header/components/CurrentUserModal/CurrentUserModal.tsx +++ /dev/null @@ -1,162 +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 - .filter((field) => field.name !== 'dashboard') - .map((item, index) => ( -
  • -
    -
    - {item.name -

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

    -
    -
    -