mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
re-structure to monorepo.
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
|
||||
import WarehouseActivateForm from './WarehouseActivateForm';
|
||||
import { WarehouseActivateFormProvider } from './WarehouseActivateFormProvider';
|
||||
|
||||
export default function WarehouseActivateDialogContent({
|
||||
// #ownProps
|
||||
dialogName,
|
||||
}) {
|
||||
return (
|
||||
<WarehouseActivateFormProvider dialogName={dialogName}>
|
||||
<WarehouseActivateForm />
|
||||
</WarehouseActivateFormProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// @ts-nocheck
|
||||
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,27 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
import { Form } from 'formik';
|
||||
import { Classes } from '@blueprintjs/core';
|
||||
import WarehouseActivateFormFloatingActions from './WarehouseActivateFormFloatingActions';
|
||||
|
||||
/**
|
||||
* Warehouse activate form content.
|
||||
*/
|
||||
export default function WarehouseActivateFormContent() {
|
||||
return (
|
||||
<Form>
|
||||
<div className={Classes.DIALOG_BODY}>
|
||||
<p class="paragraph">
|
||||
{intl.getHTML('warehouse_activate.dialog_paragraph')}
|
||||
</p>
|
||||
|
||||
<ul class="paragraph list">
|
||||
<li>{intl.get('warehouse_activate.dialog_paragraph.line_1')}</li>
|
||||
<li>{intl.get('warehouse_activate.dialog_paragraph.line_2')}</li>
|
||||
</ul>
|
||||
</div>
|
||||
<WarehouseActivateFormFloatingActions />
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// @ts-nocheck
|
||||
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={'warehouses.activate_button'} />}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export default compose(withDialogActions)(WarehouseActivateFormFloatingActions);
|
||||
@@ -0,0 +1,31 @@
|
||||
// @ts-nocheck
|
||||
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 } = useActivateWarehouses();
|
||||
|
||||
// State provider.
|
||||
const provider = {
|
||||
activateWarehouses,
|
||||
dialogName,
|
||||
};
|
||||
|
||||
return (
|
||||
<DialogContent>
|
||||
<WarehouseActivateContext.Provider value={provider} {...props} />
|
||||
</DialogContent>
|
||||
);
|
||||
}
|
||||
|
||||
const useWarehouseActivateContext = () =>
|
||||
React.useContext(WarehouseActivateContext);
|
||||
|
||||
export { WarehouseActivateFormProvider, useWarehouseActivateContext };
|
||||
@@ -0,0 +1,32 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { Dialog, DialogSuspense, FormattedMessage as T } from '@/components';
|
||||
import withDialogRedux from '@/components/DialogReduxConnect';
|
||||
|
||||
import { compose } from '@/utils';
|
||||
|
||||
const WarehouseActivateDialogContent = React.lazy(
|
||||
() => import('./WarehouseActivateDialogContent'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Warehouse activate dialog.
|
||||
*/
|
||||
function WarehouseActivateDialog({ dialogName, payload: {}, isOpen }) {
|
||||
return (
|
||||
<Dialog
|
||||
name={dialogName}
|
||||
title={<T id={'warehouse_actviate.dialog.label'} />}
|
||||
isOpen={isOpen}
|
||||
canEscapeJeyClose={true}
|
||||
autoFocus={true}
|
||||
className={'dialog--warehouse-activate'}
|
||||
>
|
||||
<DialogSuspense>
|
||||
<WarehouseActivateDialogContent dialogName={dialogName} />
|
||||
</DialogSuspense>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogRedux())(WarehouseActivateDialog);
|
||||
Reference in New Issue
Block a user