From db16fe5a3721ef63fdfde84a4de2d2b714b8fc42 Mon Sep 17 00:00:00 2001 From: Valentino K Date: Tue, 17 May 2022 13:56:35 +0200 Subject: [PATCH] Fixes --- .../CurrentUserModal/CurrentUserModal.tsx | 14 +++----- .../components/CurrentUserModal/consts.ts | 33 +++++++++++++++++++ 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/components/Header/components/CurrentUserModal/CurrentUserModal.tsx b/src/components/Header/components/CurrentUserModal/CurrentUserModal.tsx index ca5732c..29a3c16 100644 --- a/src/components/Header/components/CurrentUserModal/CurrentUserModal.tsx +++ b/src/components/Header/components/CurrentUserModal/CurrentUserModal.tsx @@ -5,7 +5,7 @@ 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 } from './consts'; +import { appAccessList, initialUserForm } from './consts'; import { UserModalProps } from './types'; export const CurrentUserModal = ({ open, onClose, user }: UserModalProps) => { @@ -13,13 +13,7 @@ export const CurrentUserModal = ({ open, onClose, user }: UserModalProps) => { const { isAdmin } = useAuth(); const { control, reset, handleSubmit } = useForm({ - defaultValues: { - name: '', - email: '', - id: '', - app_roles: [], - status: '', - }, + defaultValues: initialUserForm, }); const { fields } = useFieldArray({ @@ -28,12 +22,12 @@ export const CurrentUserModal = ({ open, onClose, user }: UserModalProps) => { }); useEffect(() => { - if (user) { + if (user && !_.isEmpty(user)) { reset(user); } return () => { - reset({ name: '', email: '', id: '' }); + reset(initialUserForm); }; }, [user, reset]); diff --git a/src/components/Header/components/CurrentUserModal/consts.ts b/src/components/Header/components/CurrentUserModal/consts.ts index edcf83c..abda708 100644 --- a/src/components/Header/components/CurrentUserModal/consts.ts +++ b/src/components/Header/components/CurrentUserModal/consts.ts @@ -1,3 +1,5 @@ +import { UserRole } from 'src/services/users'; + export const appAccessList = [ { name: 'wekan', @@ -20,3 +22,34 @@ export const appAccessList = [ label: 'Zulip', }, ]; + +const initialAppRoles = [ + { + name: 'dashboard', + role: UserRole.User, + }, + { + name: 'wekan', + role: UserRole.User, + }, + { + name: 'wordpress', + role: UserRole.User, + }, + { + name: 'next-cloud', + role: UserRole.User, + }, + { + name: 'zulip', + role: UserRole.User, + }, +]; + +export const initialUserForm = { + id: '', + name: '', + email: '', + app_roles: initialAppRoles, + status: '', +};