Modify FE for No access role

- fix user settings modal - CurrentUserModal
- TODO: refactor UserModal and CurrentUserModal - it's same thing
This commit is contained in:
Davor 2022-05-27 21:28:34 +02:00
parent d0edc5b2bc
commit bc8db8d248
6 changed files with 48 additions and 17 deletions

View file

@ -83,6 +83,7 @@ export const CurrentUserModal = ({ open, onClose, user }: UserModalProps) => {
name={`app_roles.${index}.role`} name={`app_roles.${index}.role`}
label="Role" label="Role"
options={[ options={[
{ value: UserRole.NoAccess, name: 'No access' },
{ value: UserRole.Admin, name: 'Admin' }, { value: UserRole.Admin, name: 'Admin' },
{ value: UserRole.User, name: 'User' }, { value: UserRole.User, name: 'User' },
]} ]}
@ -121,9 +122,12 @@ export const CurrentUserModal = ({ open, onClose, user }: UserModalProps) => {
<div> <div>
<div className="flow-root mt-6"> <div className="flow-root mt-6">
<ul className="-my-5 divide-y divide-gray-200 "> <ul className="-my-5 divide-y divide-gray-200 ">
{fields {fields.map((item, index) => {
.filter((field) => field.name !== 'dashboard') if (item.name === 'dashboard') {
.map((item, index) => ( return null;
}
return (
<li className="py-4" key={item.name}> <li className="py-4" key={item.name}>
<div className="flex items-center space-x-4"> <div className="flex items-center space-x-4">
<div className="flex-shrink-0 flex-1 flex items-center"> <div className="flex-shrink-0 flex-1 flex items-center">
@ -142,6 +146,7 @@ export const CurrentUserModal = ({ open, onClose, user }: UserModalProps) => {
control={control} control={control}
name={`app_roles.${index}.role`} name={`app_roles.${index}.role`}
options={[ options={[
{ value: UserRole.NoAccess, name: 'No access' },
{ value: UserRole.Admin, name: 'Admin' }, { value: UserRole.Admin, name: 'Admin' },
{ value: UserRole.User, name: 'User' }, { value: UserRole.User, name: 'User' },
]} ]}
@ -149,7 +154,8 @@ export const CurrentUserModal = ({ open, onClose, user }: UserModalProps) => {
</div> </div>
</div> </div>
</li> </li>
))} );
})}
</ul> </ul>
</div> </div>
</div> </div>

View file

@ -12,7 +12,7 @@ export const appAccessList = [
label: 'Wordpress', label: 'Wordpress',
}, },
{ {
name: 'next-cloud', name: 'nextcloud',
image: '/assets/nextcloud.svg', image: '/assets/nextcloud.svg',
label: 'NextCloud', label: 'NextCloud',
}, },
@ -30,19 +30,19 @@ const initialAppRoles = [
}, },
{ {
name: 'wekan', name: 'wekan',
role: UserRole.User, role: UserRole.NoAccess,
}, },
{ {
name: 'wordpress', name: 'wordpress',
role: UserRole.User, role: UserRole.NoAccess,
}, },
{ {
name: 'next-cloud', name: 'nextcloud',
role: UserRole.User, role: UserRole.NoAccess,
}, },
{ {
name: 'zulip', name: 'zulip',
role: UserRole.User, role: UserRole.NoAccess,
}, },
]; ];

View file

@ -133,6 +133,7 @@ export const UserModal = ({ open, onClose, userId, setUserId }: UserModalProps)
name={`app_roles.${index}.role`} name={`app_roles.${index}.role`}
label="Role" label="Role"
options={[ options={[
{ value: UserRole.NoAccess, name: 'No access' },
{ value: UserRole.User, name: 'User' }, { value: UserRole.User, name: 'User' },
{ value: UserRole.Admin, name: 'Admin' }, { value: UserRole.Admin, name: 'Admin' },
]} ]}
@ -194,6 +195,7 @@ export const UserModal = ({ open, onClose, userId, setUserId }: UserModalProps)
control={control} control={control}
name={`app_roles.${index}.role`} name={`app_roles.${index}.role`}
options={[ options={[
{ value: UserRole.NoAccess, name: 'No Access' },
{ value: UserRole.User, name: 'User' }, { value: UserRole.User, name: 'User' },
{ value: UserRole.Admin, name: 'Admin' }, { value: UserRole.Admin, name: 'Admin' },
]} ]}

View file

@ -30,19 +30,19 @@ const initialAppRoles = [
}, },
{ {
name: 'wekan', name: 'wekan',
role: UserRole.User, role: UserRole.NoAccess,
}, },
{ {
name: 'wordpress', name: 'wordpress',
role: UserRole.User, role: UserRole.NoAccess,
}, },
{ {
name: 'nextcloud', name: 'nextcloud',
role: UserRole.User, role: UserRole.NoAccess,
}, },
{ {
name: 'zulip', name: 'zulip',
role: UserRole.User, role: UserRole.NoAccess,
}, },
]; ];

View file

@ -1,16 +1,38 @@
import { AppRoles, User, UserRole } from './types'; import { AppRoles, User, UserRole } from './types';
const transformRoleById = (roleId: any): UserRole => {
switch (roleId) {
case 1:
return UserRole.Admin;
case 2:
return UserRole.User;
default:
return UserRole.NoAccess;
}
};
const transformRoleIdByRole = (role: UserRole | null): number | null => {
switch (role) {
case UserRole.Admin:
return 1;
case UserRole.User:
return 2;
default:
return null;
}
};
export const transformAppRoles = (data: any): AppRoles => { export const transformAppRoles = (data: any): AppRoles => {
const resolvedAdminRole = data.role_id === 1 ? UserRole.Admin : UserRole.User; const userRole = transformRoleById(data.role_id);
return { return {
name: data.name ?? '', name: data.name ?? '',
role: resolvedAdminRole ?? UserRole.User, role: userRole,
}; };
}; };
export const transformRequestAppRoles = (data: AppRoles): any => { export const transformRequestAppRoles = (data: AppRoles): any => {
const resolvedRequestRole = data.role === UserRole.Admin ? 1 : null; const resolvedRequestRole = transformRoleIdByRole(data.role) ?? null;
return { return {
name: data.name ?? '', name: data.name ?? '',

View file

@ -13,6 +13,7 @@ export interface FormUser extends User {
} }
export enum UserRole { export enum UserRole {
NoAccess = 'no_access',
Admin = 'admin', Admin = 'admin',
User = 'user', User = 'user',
} }