mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
chrone: sperate client and server to different repos.
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
import React from 'react';
|
||||
import moment from 'moment';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import { Formik } from 'formik';
|
||||
import { omit, get } from 'lodash';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
import 'style/pages/Items/ItemAdjustmentDialog.scss';
|
||||
|
||||
import { AppToaster } from 'components';
|
||||
import { CreateInventoryAdjustmentFormSchema } from './InventoryAdjustmentForm.schema';
|
||||
|
||||
import InventoryAdjustmentFormContent from './InventoryAdjustmentFormContent';
|
||||
import { useInventoryAdjContext } from './InventoryAdjustmentFormProvider';
|
||||
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
import { compose } from 'utils';
|
||||
|
||||
const defaultInitialValues = {
|
||||
date: moment(new Date()).format('YYYY-MM-DD'),
|
||||
type: 'decrement',
|
||||
adjustment_account_id: '',
|
||||
item_id: '',
|
||||
reason: '',
|
||||
cost: '',
|
||||
quantity: '',
|
||||
reference_no: '',
|
||||
quantity_on_hand: '',
|
||||
publish: '',
|
||||
};
|
||||
|
||||
/**
|
||||
* Inventory adjustment form.
|
||||
*/
|
||||
function InventoryAdjustmentForm({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
const {
|
||||
dialogName,
|
||||
item,
|
||||
itemId,
|
||||
submitPayload,
|
||||
createInventoryAdjMutate,
|
||||
} = useInventoryAdjContext();
|
||||
|
||||
// Initial form values.
|
||||
const initialValues = {
|
||||
...defaultInitialValues,
|
||||
item_id: itemId,
|
||||
quantity_on_hand: get(item, 'quantity_on_hand', 0),
|
||||
};
|
||||
|
||||
// Handles the form submit.
|
||||
const handleFormSubmit = (values, { setSubmitting, setErrors }) => {
|
||||
const form = {
|
||||
...omit(values, ['quantity_on_hand', 'new_quantity', 'action']),
|
||||
publish: submitPayload.publish,
|
||||
};
|
||||
setSubmitting(true);
|
||||
createInventoryAdjMutate(form)
|
||||
.then(() => {
|
||||
closeDialog(dialogName);
|
||||
|
||||
AppToaster.show({
|
||||
message: intl.get('the_make_adjustment_has_been_created_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
})
|
||||
.finally(() => {
|
||||
setSubmitting(true);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Formik
|
||||
validationSchema={CreateInventoryAdjustmentFormSchema}
|
||||
initialValues={initialValues}
|
||||
onSubmit={handleFormSubmit}
|
||||
>
|
||||
<InventoryAdjustmentFormContent />
|
||||
</Formik>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogActions)(InventoryAdjustmentForm);
|
||||
Reference in New Issue
Block a user