mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
chrone: sperate client and server to different repos.
This commit is contained in:
81
src/containers/Dialogs/InviteUserDialog/InviteUserForm.js
Normal file
81
src/containers/Dialogs/InviteUserDialog/InviteUserForm.js
Normal file
@@ -0,0 +1,81 @@
|
||||
import React from 'react';
|
||||
import { Formik } from 'formik';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import { pick, snakeCase } from 'lodash';
|
||||
import intl from 'react-intl-universal';
|
||||
import { AppToaster } from 'components';
|
||||
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
|
||||
import { InviteUserFormSchema } from './InviteUserDialog.schema';
|
||||
import InviteUserFormContent from './InviteUserFormContent';
|
||||
import { useInviteUserFormContext } from './InviteUserFormProvider';
|
||||
|
||||
import { transformApiErrors } from './utils';
|
||||
|
||||
import { compose, objectKeysTransform } from 'utils';
|
||||
|
||||
function InviteUserForm({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
|
||||
|
||||
const {
|
||||
dialogName,
|
||||
isEditMode,
|
||||
inviteUserMutate,
|
||||
userId,
|
||||
} = useInviteUserFormContext();
|
||||
|
||||
const initialValues = {
|
||||
status: 1,
|
||||
...(isEditMode &&
|
||||
pick(
|
||||
objectKeysTransform(userId, snakeCase),
|
||||
Object.keys(InviteUserFormSchema.fields),
|
||||
)),
|
||||
};
|
||||
|
||||
const handleSubmit = (values, { setSubmitting, setErrors }) => {
|
||||
const form = { ...values };
|
||||
|
||||
// Handle close the dialog after success response.
|
||||
const afterSubmit = () => {
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
const onSuccess = ({ response }) => {
|
||||
AppToaster.show({
|
||||
message: intl.get('teammate_invited_to_organization_account'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
afterSubmit(response);
|
||||
};
|
||||
|
||||
// Handle the response error.
|
||||
const onError = (error) => {
|
||||
const {
|
||||
response: {
|
||||
data: { errors },
|
||||
},
|
||||
} = error;
|
||||
|
||||
const errorsTransformed = transformApiErrors(errors);
|
||||
|
||||
setErrors({ ...errorsTransformed });
|
||||
setSubmitting(false);
|
||||
};
|
||||
inviteUserMutate(form).then(onSuccess).catch(onError);
|
||||
};
|
||||
|
||||
return (
|
||||
<Formik
|
||||
validationSchema={InviteUserFormSchema}
|
||||
initialValues={initialValues}
|
||||
onSubmit={handleSubmit}
|
||||
>
|
||||
<InviteUserFormContent />
|
||||
</Formik>
|
||||
);
|
||||
}
|
||||
export default compose(withDialogActions)(InviteUserForm);
|
||||
Reference in New Issue
Block a user