mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 15:20:34 +00:00
Merge branch 'featrue/roles-permission' of https://github.com/bigcapitalhq/client into featrue/roles-permission
This commit is contained in:
@@ -10,6 +10,7 @@ import withDialogActions from 'containers/Dialog/withDialogActions';
|
|||||||
import { UserFormSchema } from './UserForm.schema';
|
import { UserFormSchema } from './UserForm.schema';
|
||||||
import UserFormContent from './UserFormContent';
|
import UserFormContent from './UserFormContent';
|
||||||
import { useUserFormContext } from './UserFormProvider';
|
import { useUserFormContext } from './UserFormProvider';
|
||||||
|
import { transformErrors } from './utils';
|
||||||
|
|
||||||
import { compose, objectKeysTransform } from 'utils';
|
import { compose, objectKeysTransform } from 'utils';
|
||||||
|
|
||||||
@@ -20,13 +21,10 @@ function UserForm({
|
|||||||
// #withDialogActions
|
// #withDialogActions
|
||||||
closeDialog,
|
closeDialog,
|
||||||
}) {
|
}) {
|
||||||
const {
|
const [calloutCode, setCalloutCode] = React.useState([]);
|
||||||
dialogName,
|
|
||||||
user,
|
const { dialogName, user, userId, isEditMode, EditUserMutate } =
|
||||||
userId,
|
useUserFormContext();
|
||||||
isEditMode,
|
|
||||||
EditUserMutate,
|
|
||||||
} = useUserFormContext();
|
|
||||||
|
|
||||||
const initialValues = {
|
const initialValues = {
|
||||||
...(isEditMode &&
|
...(isEditMode &&
|
||||||
@@ -59,7 +57,7 @@ function UserForm({
|
|||||||
data: { errors },
|
data: { errors },
|
||||||
},
|
},
|
||||||
} = error;
|
} = error;
|
||||||
|
transformErrors(errors, { setErrors, setCalloutCode });
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -72,7 +70,7 @@ function UserForm({
|
|||||||
initialValues={initialValues}
|
initialValues={initialValues}
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
>
|
>
|
||||||
<UserFormContent />
|
<UserFormContent calloutCode={calloutCode} />
|
||||||
</Formik>
|
</Formik>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,16 +15,18 @@ import { ListSelect, FieldRequiredHint } from 'components';
|
|||||||
import { useUserFormContext } from './UserFormProvider';
|
import { useUserFormContext } from './UserFormProvider';
|
||||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
|
import { UserFormCalloutAlerts } from './components';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User form content.
|
* User form content.
|
||||||
*/
|
*/
|
||||||
function UserFormContent({
|
function UserFormContent({
|
||||||
|
calloutCode,
|
||||||
// #withDialogActions
|
// #withDialogActions
|
||||||
closeDialog,
|
closeDialog,
|
||||||
}) {
|
}) {
|
||||||
const { isSubmitting } = useFormikContext();
|
const { isSubmitting } = useFormikContext();
|
||||||
const { dialogName, roles } = useUserFormContext();
|
const { dialogName, roles, isAuth } = useUserFormContext();
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
closeDialog(dialogName);
|
closeDialog(dialogName);
|
||||||
@@ -33,6 +35,8 @@ function UserFormContent({
|
|||||||
return (
|
return (
|
||||||
<Form>
|
<Form>
|
||||||
<div className={Classes.DIALOG_BODY}>
|
<div className={Classes.DIALOG_BODY}>
|
||||||
|
<UserFormCalloutAlerts calloutCodes={calloutCode} />
|
||||||
|
|
||||||
{/* ----------- Email ----------- */}
|
{/* ----------- Email ----------- */}
|
||||||
<FastField name={'email'}>
|
<FastField name={'email'}>
|
||||||
{({ field, meta: { error, touched } }) => (
|
{({ field, meta: { error, touched } }) => (
|
||||||
@@ -109,6 +113,7 @@ function UserFormContent({
|
|||||||
// labelProp={'id '}
|
// labelProp={'id '}
|
||||||
popoverProps={{ minimal: true }}
|
popoverProps={{ minimal: true }}
|
||||||
intent={inputIntent({ error, touched })}
|
intent={inputIntent({ error, touched })}
|
||||||
|
disabled={isAuth}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
import React, { createContext, useContext } from 'react';
|
import React, { createContext, useContext } from 'react';
|
||||||
import { useEditUser, useUser, useRoles } from 'hooks/query';
|
import {
|
||||||
|
useEditUser,
|
||||||
|
useUser,
|
||||||
|
useRoles,
|
||||||
|
useAuthenticatedAccount,
|
||||||
|
} from 'hooks/query';
|
||||||
|
|
||||||
import { DialogContent } from 'components';
|
import { DialogContent } from 'components';
|
||||||
|
|
||||||
@@ -20,10 +25,18 @@ function UserFormProvider({ userId, dialogName, ...props }) {
|
|||||||
// fetch roles list.
|
// fetch roles list.
|
||||||
const { data: roles, isLoading: isRolesLoading } = useRoles();
|
const { data: roles, isLoading: isRolesLoading } = useRoles();
|
||||||
|
|
||||||
|
// Retrieve authenticated user information.
|
||||||
|
const {
|
||||||
|
data: { id },
|
||||||
|
} = useAuthenticatedAccount();
|
||||||
|
|
||||||
const isEditMode = userId;
|
const isEditMode = userId;
|
||||||
|
|
||||||
|
const isAuth = user.system_user_id == id
|
||||||
|
|
||||||
// Provider state.
|
// Provider state.
|
||||||
const provider = {
|
const provider = {
|
||||||
|
isAuth,
|
||||||
userId,
|
userId,
|
||||||
dialogName,
|
dialogName,
|
||||||
|
|
||||||
|
|||||||
14
src/containers/Dialogs/UserFormDialog/components.js
Normal file
14
src/containers/Dialogs/UserFormDialog/components.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import intl from 'react-intl-universal';
|
||||||
|
import { includes } from 'lodash';
|
||||||
|
import { Callout, Intent } from '@blueprintjs/core';
|
||||||
|
|
||||||
|
export const UserFormCalloutAlerts = ({ calloutCodes }) => {
|
||||||
|
return [
|
||||||
|
includes(calloutCodes, 200) && (
|
||||||
|
<Callout icon={null} intent={Intent.DANGER}>
|
||||||
|
{intl.get('roles.error.you_cannot_change_your_own_role')}
|
||||||
|
</Callout>
|
||||||
|
),
|
||||||
|
];
|
||||||
|
};
|
||||||
@@ -1,15 +1,13 @@
|
|||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { Intent } from '@blueprintjs/core';
|
|
||||||
import { AppToaster } from 'components';
|
|
||||||
|
|
||||||
// handle delete errors.
|
// handle delete errors.
|
||||||
export const transformErrors = (errors) => {
|
export const transformErrors = (errors, { setErrors, setCalloutCode }) => {
|
||||||
if (
|
if (
|
||||||
errors.find((error) => error.type === 'CANNOT_AUTHORIZED_USER_MUTATE_ROLE')
|
errors.find((error) => error.type === 'CANNOT_AUTHORIZED_USER_MUTATE_ROLE')
|
||||||
) {
|
) {
|
||||||
AppToaster.show({
|
setCalloutCode([200]);
|
||||||
message: intl.get('roles.error.you_cannot_change_your_own_role'),
|
setErrors({
|
||||||
intent: Intent.DANGER,
|
role_id: intl.get('roles.error.you_cannot_change_your_own_role'),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,6 +20,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.bp3-callout {
|
||||||
|
font-size: 13px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
.bp3-dialog-footer {
|
.bp3-dialog-footer {
|
||||||
.bp3-button {
|
.bp3-button {
|
||||||
min-width: 75px;
|
min-width: 75px;
|
||||||
|
|||||||
Reference in New Issue
Block a user