mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 12:20:31 +00:00
feat(branche & warehouse activate) add api.
This commit is contained in:
@@ -1,43 +1,15 @@
|
||||
import React from 'react';
|
||||
import { Intent, Button, Callout, Classes } from '@blueprintjs/core';
|
||||
import { DialogContent, T } from 'components';
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
import BranchActivateForm from './BranchActivateForm';
|
||||
import { BranchActivateFormProvider } from './BranchActivateFormProvider';
|
||||
|
||||
function BranchActivateDialogContent({
|
||||
export default function BranchActivateDialogContent({
|
||||
// #ownProps
|
||||
dialogName,
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
// Handle close button click.
|
||||
const handleCancelBtnClick = () => {
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
return (
|
||||
<DialogContent>
|
||||
<div className={Classes.DIALOG_BODY}>
|
||||
<Callout icon={null} intent={Intent.PRIMARY}>
|
||||
Aute esse eiusmod dolore ipsum dolor sint qui proident pariatur
|
||||
proident fugiat ea ad aliquip.
|
||||
</Callout>
|
||||
</div>
|
||||
<div className={Classes.DIALOG_FOOTER}>
|
||||
<div className={Classes.DIALOG_FOOTER_ACTIONS}>
|
||||
<Button onClick={handleCancelBtnClick} style={{ minWidth: '85px' }}>
|
||||
<T id={'cancel'} />
|
||||
</Button>
|
||||
<Button
|
||||
intent={Intent.PRIMARY}
|
||||
style={{ minWidth: '95px' }}
|
||||
type="submit"
|
||||
>
|
||||
{<T id={'activate'} />}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
<BranchActivateFormProvider dialogName={dialogName}>
|
||||
<BranchActivateForm />
|
||||
</BranchActivateFormProvider>
|
||||
);
|
||||
}
|
||||
export default compose(withDialogActions)(BranchActivateDialogContent);
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
import { Formik } from 'formik';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
|
||||
import { AppToaster } from 'components';
|
||||
import { useBranchActivateContext } from './BranchActivateFormProvider';
|
||||
import BranchActivateFormContent from './BranchActivateFormContent';
|
||||
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Branch activate form.
|
||||
*/
|
||||
function BranchActivateForm({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
const { activateBranches, dialogName } = useBranchActivateContext();
|
||||
|
||||
// Initial form values
|
||||
const initialValues = {};
|
||||
|
||||
// Handles the form submit.
|
||||
const handleFormSubmit = (values, { setSubmitting, setErrors }) => {
|
||||
const form = {
|
||||
...values,
|
||||
};
|
||||
setSubmitting(true);
|
||||
// Handle request response success.
|
||||
const onSuccess = (response) => {
|
||||
AppToaster.show({
|
||||
message: intl.get('branch_activate.dialog_success_message'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
|
||||
// Handle request response errors.
|
||||
const onError = ({
|
||||
response: {
|
||||
data: { errors },
|
||||
},
|
||||
}) => {
|
||||
if (errors) {
|
||||
}
|
||||
setSubmitting(false);
|
||||
};
|
||||
activateBranches(form).then(onSuccess).catch(onError);
|
||||
};
|
||||
|
||||
return (
|
||||
<Formik
|
||||
initialValues={initialValues}
|
||||
onSubmit={handleFormSubmit}
|
||||
component={BranchActivateFormContent}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogActions)(BranchActivateForm);
|
||||
@@ -0,0 +1,21 @@
|
||||
import React from 'react';
|
||||
import { Form } from 'formik';
|
||||
import { Intent, Callout, Classes } from '@blueprintjs/core';
|
||||
import BranchActivateFormFloatingActions from './BranchActivateFormFloatingActions';
|
||||
|
||||
/**
|
||||
* Branch activate form content.
|
||||
*/
|
||||
export default function BranchActivateFormContent() {
|
||||
return (
|
||||
<Form>
|
||||
<div className={Classes.DIALOG_BODY}>
|
||||
<Callout icon={null} intent={Intent.PRIMARY}>
|
||||
Aute esse eiusmod dolore ipsum dolor sint qui proident pariatur
|
||||
proident fugiat ea ad aliquip.
|
||||
</Callout>
|
||||
</div>
|
||||
<BranchActivateFormFloatingActions />
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import React from 'react';
|
||||
import { Intent, Button, Classes } from '@blueprintjs/core';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { FormattedMessage as T } from 'components';
|
||||
|
||||
import { useBranchActivateContext } from './BranchActivateFormProvider';
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* branch activate form floating actions.
|
||||
*/
|
||||
function BranchActivateFormFloatingActions({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
// branch activate dialog context.
|
||||
const { dialogName } = useBranchActivateContext();
|
||||
|
||||
// Formik context.
|
||||
const { isSubmitting } = useFormikContext();
|
||||
|
||||
// Handle close button click.
|
||||
const handleCancelBtnClick = () => {
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={Classes.DIALOG_FOOTER}>
|
||||
<div className={Classes.DIALOG_FOOTER_ACTIONS}>
|
||||
<Button onClick={handleCancelBtnClick} style={{ minWidth: '85px' }}>
|
||||
<T id={'cancel'} />
|
||||
</Button>
|
||||
<Button
|
||||
intent={Intent.PRIMARY}
|
||||
loading={isSubmitting}
|
||||
style={{ minWidth: '95px' }}
|
||||
type="submit"
|
||||
>
|
||||
{<T id={'activate'} />}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogActions)(BranchActivateFormFloatingActions);
|
||||
@@ -0,0 +1,29 @@
|
||||
import React from 'react';
|
||||
|
||||
import { DialogContent } from 'components';
|
||||
import { useActivateBranches } from 'hooks/query';
|
||||
|
||||
const BranchActivateContext = React.createContext();
|
||||
|
||||
/**
|
||||
* Branch activate form provider.
|
||||
*/
|
||||
function BranchActivateFormProvider({ dialogName, ...props }) {
|
||||
const { mutateAsync: activateBranches, isLoading } = useActivateBranches();
|
||||
|
||||
// State provider.
|
||||
const provider = {
|
||||
activateBranches,
|
||||
dialogName,
|
||||
};
|
||||
|
||||
return (
|
||||
<DialogContent isLoading={isLoading}>
|
||||
<BranchActivateContext.Provider value={provider} {...props} />
|
||||
</DialogContent>
|
||||
);
|
||||
}
|
||||
|
||||
const useBranchActivateContext = () => React.useContext(BranchActivateContext);
|
||||
|
||||
export { BranchActivateFormProvider, useBranchActivateContext };
|
||||
@@ -1,48 +1,15 @@
|
||||
import React from 'react';
|
||||
import { Intent, Button, Callout, Classes } from '@blueprintjs/core';
|
||||
import { DialogContent, T } from 'components';
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
import WarehouseActivateForm from './WarehouseActivateForm';
|
||||
import { WarehouseActivateFormProvider } from './WarehouseActivateFormProvider';
|
||||
|
||||
/**
|
||||
* Warehouse activate dialog content.
|
||||
* @returns
|
||||
*/
|
||||
function WarehouseActivateDialogContent({
|
||||
export default function WarehouseActivateDialogContent({
|
||||
// #ownProps
|
||||
dialogName,
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
// Handle close button click.
|
||||
const handleCancelBtnClick = () => {
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
return (
|
||||
<DialogContent>
|
||||
<div className={Classes.DIALOG_BODY}>
|
||||
<Callout icon={null} intent={Intent.PRIMARY}>
|
||||
Aute esse eiusmod dolore ipsum dolor sint qui proident pariatur
|
||||
proident fugiat ea ad aliquip.
|
||||
</Callout>
|
||||
</div>
|
||||
<div className={Classes.DIALOG_FOOTER}>
|
||||
<div className={Classes.DIALOG_FOOTER_ACTIONS}>
|
||||
<Button onClick={handleCancelBtnClick} style={{ minWidth: '85px' }}>
|
||||
<T id={'cancel'} />
|
||||
</Button>
|
||||
<Button
|
||||
intent={Intent.PRIMARY}
|
||||
style={{ minWidth: '95px' }}
|
||||
type="submit"
|
||||
>
|
||||
{<T id={'activate'} />}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogContent>
|
||||
<WarehouseActivateFormProvider dialogName={dialogName}>
|
||||
<WarehouseActivateForm />
|
||||
</WarehouseActivateFormProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogActions)(WarehouseActivateDialogContent);
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
import { Formik } from 'formik';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
|
||||
import { AppToaster } from 'components';
|
||||
import { useWarehouseActivateContext } from './WarehouseActivateFormProvider';
|
||||
import WarehouseActivateFormContent from './WarehouseActivateFormContent';
|
||||
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* warehouse activate form.
|
||||
*/
|
||||
function WarehouseActivateForm({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
const { activateWarehouses, dialogName } = useWarehouseActivateContext();
|
||||
|
||||
// Initial form values
|
||||
const initialValues = {};
|
||||
|
||||
// Handles the form submit.
|
||||
const handleFormSubmit = (values, { setSubmitting, setErrors }) => {
|
||||
const form = {
|
||||
...values,
|
||||
};
|
||||
setSubmitting(true);
|
||||
// Handle request response success.
|
||||
const onSuccess = (response) => {
|
||||
AppToaster.show({
|
||||
message: intl.get('warehouse_activate.dialog_success_message'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
|
||||
// Handle request response errors.
|
||||
const onError = ({
|
||||
response: {
|
||||
data: { errors },
|
||||
},
|
||||
}) => {
|
||||
if (errors) {
|
||||
}
|
||||
setSubmitting(false);
|
||||
};
|
||||
activateWarehouses(form).then(onSuccess).catch(onError);
|
||||
};
|
||||
|
||||
return (
|
||||
<Formik
|
||||
initialValues={initialValues}
|
||||
onSubmit={handleFormSubmit}
|
||||
component={WarehouseActivateFormContent}
|
||||
/>
|
||||
);
|
||||
}
|
||||
export default compose(withDialogActions)(WarehouseActivateForm);
|
||||
@@ -0,0 +1,22 @@
|
||||
import React from 'react';
|
||||
import { Form } from 'formik';
|
||||
import { Intent, Callout, Classes } from '@blueprintjs/core';
|
||||
|
||||
import WarehouseActivateFormFloatingActions from './WarehouseActivateFormFloatingActions';
|
||||
|
||||
/**
|
||||
* warehouse activate form content.
|
||||
*/
|
||||
export default function WarehouseActivateFormContent() {
|
||||
return (
|
||||
<Form>
|
||||
<div className={Classes.DIALOG_BODY}>
|
||||
<Callout icon={null} intent={Intent.PRIMARY}>
|
||||
Aute esse eiusmod dolore ipsum dolor sint qui proident pariatur
|
||||
proident fugiat ea ad aliquip.
|
||||
</Callout>
|
||||
</div>
|
||||
<WarehouseActivateFormFloatingActions />
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import React from 'react';
|
||||
import { Intent, Button, Classes } from '@blueprintjs/core';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { FormattedMessage as T } from 'components';
|
||||
|
||||
import { useWarehouseActivateContext } from './WarehouseActivateFormProvider';
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* warehouse activate form floating actions.
|
||||
*/
|
||||
function WarehouseActivateFormFloatingActions({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
// warehouse activate dialog context.
|
||||
const { dialogName } = useWarehouseActivateContext();
|
||||
|
||||
// Formik context.
|
||||
const { isSubmitting } = useFormikContext();
|
||||
|
||||
// Handle close button click.
|
||||
const handleCancelBtnClick = () => {
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={Classes.DIALOG_FOOTER}>
|
||||
<div className={Classes.DIALOG_FOOTER_ACTIONS}>
|
||||
<Button onClick={handleCancelBtnClick} style={{ minWidth: '85px' }}>
|
||||
<T id={'cancel'} />
|
||||
</Button>
|
||||
<Button
|
||||
intent={Intent.PRIMARY}
|
||||
loading={isSubmitting}
|
||||
style={{ minWidth: '95px' }}
|
||||
type="submit"
|
||||
>
|
||||
{<T id={'activate'} />}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export default compose(withDialogActions)(WarehouseActivateFormFloatingActions);
|
||||
@@ -0,0 +1,31 @@
|
||||
import React from 'react';
|
||||
|
||||
import { DialogContent } from 'components';
|
||||
import { useActivateWarehouses } from 'hooks/query';
|
||||
|
||||
const WarehouseActivateContext = React.createContext();
|
||||
|
||||
/**
|
||||
* warehouse activate form provider.
|
||||
*/
|
||||
function WarehouseActivateFormProvider({ dialogName, ...props }) {
|
||||
const { mutateAsync: activateWarehouses, isLoading } =
|
||||
useActivateWarehouses();
|
||||
|
||||
// State provider.
|
||||
const provider = {
|
||||
activateWarehouses,
|
||||
dialogName,
|
||||
};
|
||||
|
||||
return (
|
||||
<DialogContent isLoading={isLoading}>
|
||||
<WarehouseActivateContext.Provider value={provider} {...props} />
|
||||
</DialogContent>
|
||||
);
|
||||
}
|
||||
|
||||
const useWarehouseActivateContext = () =>
|
||||
React.useContext(WarehouseActivateContext);
|
||||
|
||||
export { WarehouseActivateFormProvider, useWarehouseActivateContext };
|
||||
Reference in New Issue
Block a user