mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
fix: role field in invite & User dialog.
This commit is contained in:
@@ -3,7 +3,7 @@ import intl from 'react-intl-universal';
|
|||||||
|
|
||||||
const Schema = Yup.object().shape({
|
const Schema = Yup.object().shape({
|
||||||
email: Yup.string().email().required().label(intl.get('email')),
|
email: Yup.string().email().required().label(intl.get('email')),
|
||||||
role_name: Yup.string().required().label(intl.get('roles.label.role_name_')),
|
role_id: Yup.string().required().label(intl.get('roles.label.role_name_')),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const InviteUserFormSchema = Schema;
|
export const InviteUserFormSchema = Schema;
|
||||||
|
|||||||
@@ -19,12 +19,12 @@ function InviteUserFormContent({
|
|||||||
closeDialog,
|
closeDialog,
|
||||||
}) {
|
}) {
|
||||||
const { isSubmitting } = useFormikContext();
|
const { isSubmitting } = useFormikContext();
|
||||||
const { isEditMode, dialogName } = useInviteUserFormContext();
|
const { isEditMode, dialogName, roles } = useInviteUserFormContext();
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
closeDialog(dialogName);
|
closeDialog(dialogName);
|
||||||
};
|
};
|
||||||
|
console.log(roles, 'XX');
|
||||||
return (
|
return (
|
||||||
<Form>
|
<Form>
|
||||||
<div className={CLASSES.DIALOG_BODY}>
|
<div className={CLASSES.DIALOG_BODY}>
|
||||||
@@ -46,27 +46,26 @@ function InviteUserFormContent({
|
|||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
{/* ----------- Role name ----------- */}
|
{/* ----------- Role name ----------- */}
|
||||||
<FastField name={'role_name'}>
|
<FastField name={'role_id'}>
|
||||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||||
<FormGroup
|
<FormGroup
|
||||||
label={<T id={'roles.label.role_name'} />}
|
label={<T id={'roles.label.role_name'} />}
|
||||||
labelInfo={<FieldRequiredHint />}
|
labelInfo={<FieldRequiredHint />}
|
||||||
helperText={<ErrorMessage name="role_name" />}
|
helperText={<ErrorMessage name="role_id" />}
|
||||||
className={classNames(CLASSES.FILL, 'form-group--role_name')}
|
className={classNames(CLASSES.FILL, 'form-group--role_name')}
|
||||||
intent={inputIntent({ error, touched })}
|
intent={inputIntent({ error, touched })}
|
||||||
>
|
>
|
||||||
<ListSelect
|
<ListSelect
|
||||||
items={[]}
|
items={roles}
|
||||||
// onItemSelect={(item) => {
|
onItemSelect={({ id }) => {
|
||||||
// form.setFieldValue('role_name', item.role_id);
|
form.setFieldValue('role_id', id);
|
||||||
// }}
|
}}
|
||||||
selectedItem={value}
|
selectedItem={value}
|
||||||
selectedItemProp={'role_id '}
|
selectedItemProp={'id'}
|
||||||
// textProp={'role_name'}
|
textProp={'name'}
|
||||||
// labelProp={'role_id '}
|
// labelProp={'id '}
|
||||||
popoverProps={{ minimal: true }}
|
popoverProps={{ minimal: true }}
|
||||||
intent={inputIntent({ error, touched })}
|
intent={inputIntent({ error, touched })}
|
||||||
// filterable={false}
|
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { createContext } from 'react';
|
import React, { createContext } from 'react';
|
||||||
import { useCreateInviteUser, useUsers } from 'hooks/query';
|
import { useCreateInviteUser, useUsers, useRoles } from 'hooks/query';
|
||||||
import { DialogContent } from 'components';
|
import { DialogContent } from 'components';
|
||||||
|
|
||||||
const InviteUserFormContext = createContext();
|
const InviteUserFormContext = createContext();
|
||||||
@@ -14,6 +14,9 @@ function InviteUserFormProvider({ userId, isEditMode, dialogName, ...props }) {
|
|||||||
// fetch users list.
|
// fetch users list.
|
||||||
const { isLoading: isUsersLoading } = useUsers();
|
const { isLoading: isUsersLoading } = useUsers();
|
||||||
|
|
||||||
|
// fetch roles list.
|
||||||
|
const { data: roles, isLoading: isRolesLoading } = useRoles();
|
||||||
|
|
||||||
// Provider state.
|
// Provider state.
|
||||||
const provider = {
|
const provider = {
|
||||||
inviteUserMutate,
|
inviteUserMutate,
|
||||||
@@ -21,10 +24,14 @@ function InviteUserFormProvider({ userId, isEditMode, dialogName, ...props }) {
|
|||||||
userId,
|
userId,
|
||||||
isUsersLoading,
|
isUsersLoading,
|
||||||
isEditMode,
|
isEditMode,
|
||||||
|
roles,
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DialogContent isLoading={isUsersLoading} name={'invite-form'}>
|
<DialogContent
|
||||||
|
isLoading={isUsersLoading || isRolesLoading}
|
||||||
|
name={'invite-form'}
|
||||||
|
>
|
||||||
<InviteUserFormContext.Provider value={provider} {...props} />
|
<InviteUserFormContext.Provider value={provider} {...props} />
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ const Schema = Yup.object().shape({
|
|||||||
.matches()
|
.matches()
|
||||||
.required()
|
.required()
|
||||||
.label(intl.get('phone_number_')),
|
.label(intl.get('phone_number_')),
|
||||||
role_name: Yup.string().required().label(intl.get('roles.label.role_name_')),
|
role_id: Yup.string().required().label(intl.get('roles.label.role_name_')),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const UserFormSchema = Schema;
|
export const UserFormSchema = Schema;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ function UserFormContent({
|
|||||||
closeDialog,
|
closeDialog,
|
||||||
}) {
|
}) {
|
||||||
const { isSubmitting } = useFormikContext();
|
const { isSubmitting } = useFormikContext();
|
||||||
const { dialogName } = useUserFormContext();
|
const { dialogName, roles } = useUserFormContext();
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
closeDialog(dialogName);
|
closeDialog(dialogName);
|
||||||
@@ -89,24 +89,26 @@ function UserFormContent({
|
|||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
{/* ----------- Role name ----------- */}
|
{/* ----------- Role name ----------- */}
|
||||||
<FastField name={'role_name'}>
|
<FastField name={'role_id'}>
|
||||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||||
<FormGroup
|
<FormGroup
|
||||||
label={<T id={'roles.label.role_name'} />}
|
label={<T id={'roles.label.role_name'} />}
|
||||||
labelInfo={<FieldRequiredHint />}
|
labelInfo={<FieldRequiredHint />}
|
||||||
className={classNames('form-group--role_name', CLASSES.FILL)}
|
helperText={<ErrorMessage name="role_id" />}
|
||||||
|
className={classNames(CLASSES.FILL, 'form-group--role_name')}
|
||||||
intent={inputIntent({ error, touched })}
|
intent={inputIntent({ error, touched })}
|
||||||
>
|
>
|
||||||
<ListSelect
|
<ListSelect
|
||||||
items={[]}
|
items={roles}
|
||||||
// onItemSelect={(item) => {
|
onItemSelect={({ id }) => {
|
||||||
// form.setFieldValue('role_name', item.role_id);
|
form.setFieldValue('role_id', id);
|
||||||
// }}
|
}}
|
||||||
selectedItem={value}
|
selectedItem={value}
|
||||||
selectedItemProp={'role_id '}
|
selectedItemProp={'id'}
|
||||||
// textProp={'role_name'}
|
textProp={'name'}
|
||||||
// labelProp={'role_id '}
|
// labelProp={'id '}
|
||||||
popoverProps={{ minimal: true }}
|
popoverProps={{ minimal: true }}
|
||||||
|
intent={inputIntent({ error, touched })}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { createContext, useContext } from 'react';
|
import React, { createContext, useContext } from 'react';
|
||||||
import { useEditUser, useUser } from 'hooks/query';
|
import { useEditUser, useUser, useRoles } from 'hooks/query';
|
||||||
|
|
||||||
import { DialogContent } from 'components';
|
import { DialogContent } from 'components';
|
||||||
|
|
||||||
@@ -17,6 +17,9 @@ function UserFormProvider({ userId, dialogName, ...props }) {
|
|||||||
enabled: !!userId,
|
enabled: !!userId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// fetch roles list.
|
||||||
|
const { data: roles, isLoading: isRolesLoading } = useRoles();
|
||||||
|
|
||||||
const isEditMode = userId;
|
const isEditMode = userId;
|
||||||
|
|
||||||
// Provider state.
|
// Provider state.
|
||||||
@@ -28,10 +31,14 @@ function UserFormProvider({ userId, dialogName, ...props }) {
|
|||||||
EditUserMutate,
|
EditUserMutate,
|
||||||
|
|
||||||
isEditMode,
|
isEditMode,
|
||||||
|
roles,
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DialogContent isLoading={isUserLoading} name={'user-form'}>
|
<DialogContent
|
||||||
|
isLoading={isUserLoading || isRolesLoading}
|
||||||
|
name={'user-form'}
|
||||||
|
>
|
||||||
<UserFormContext.Provider value={provider} {...props} />
|
<UserFormContext.Provider value={provider} {...props} />
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -28,8 +28,6 @@ export function ActionsMenu({
|
|||||||
row: { original },
|
row: { original },
|
||||||
payload: { onEdit, onInactivate, onActivate, onDelete, onResendInvitation },
|
payload: { onEdit, onInactivate, onActivate, onDelete, onResendInvitation },
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Menu>
|
<Menu>
|
||||||
<If condition={original.invite_accepted_at}>
|
<If condition={original.invite_accepted_at}>
|
||||||
@@ -111,8 +109,6 @@ function FullNameAccessor(user) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const useUsersListColumns = () => {
|
export const useUsersListColumns = () => {
|
||||||
|
|
||||||
|
|
||||||
return React.useMemo(
|
return React.useMemo(
|
||||||
() => [
|
() => [
|
||||||
{
|
{
|
||||||
@@ -134,11 +130,17 @@ export const useUsersListColumns = () => {
|
|||||||
width: 150,
|
width: 150,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'phone_number',
|
id: 'role_name',
|
||||||
Header: intl.get('phone_number'),
|
Header: intl.get('roles.column.role_name'),
|
||||||
accessor: 'phone_number',
|
accessor: 'role.name',
|
||||||
width: 120,
|
width: 120,
|
||||||
},
|
},
|
||||||
|
// {
|
||||||
|
// id: 'phone_number',
|
||||||
|
// Header: intl.get('phone_number'),
|
||||||
|
// accessor: 'phone_number',
|
||||||
|
// width: 120,
|
||||||
|
// },
|
||||||
{
|
{
|
||||||
id: 'status',
|
id: 'status',
|
||||||
Header: 'Status',
|
Header: 'Status',
|
||||||
|
|||||||
Reference in New Issue
Block a user