Fixes
This commit is contained in:
parent
4d5a59e615
commit
db16fe5a37
2 changed files with 37 additions and 10 deletions
|
@ -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<User>({
|
||||
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]);
|
||||
|
||||
|
|
|
@ -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: '',
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue