diff --git a/client/src/components/DialogsContainer.js b/client/src/components/DialogsContainer.js index 90693c190..9f8b32926 100644 --- a/client/src/components/DialogsContainer.js +++ b/client/src/components/DialogsContainer.js @@ -3,13 +3,13 @@ import React, { lazy } from 'react'; import AccountFormDialog from 'containers/Dialogs/AccountFormDialog'; import UserFormDialog from 'containers/Dialogs/UserFormDialog'; -// import ItemCategoryDialog from 'containers/Dialogs/ItemCategoryDialog'; +import ItemCategoryDialog from 'containers/Dialogs/ItemCategoryDialog'; import CurrencyFormDialog from 'containers/Dialogs/CurrencyFormDialog'; // import InviteUserDialog from 'containers/Dialogs/InviteUserDialog'; import ExchangeRateFormDialog from 'containers/Dialogs/ExchangeRateFormDialog'; import JournalNumberDialog from 'containers/Dialogs/JournalNumberDialog'; -import BillNumberDialog from 'containers/Dialogs/BillNumberDialog'; -import PaymentNumberDialog from 'containers/Dialogs/PaymentNumberDialog'; +// import BillNumberDialog from 'containers/Dialogs/BillNumberDialog'; +import PaymentReceiveNumberDialog from 'containers/Dialogs/PaymentReceiveNumberDialog'; import EstimateNumberDialog from 'containers/Dialogs/EstimateNumberDialog'; import ReceiptNumberDialog from 'containers/Dialogs/ReceiptNumberDialog'; import InvoiceNumberDialog from 'containers/Dialogs/InvoiceNumberDialog'; @@ -18,14 +18,15 @@ export default function DialogsContainer() {
- - + {/* */} + +
); -} +} \ No newline at end of file diff --git a/client/src/containers/Dialogs/ItemCategoryDialog.js b/client/src/containers/Dialogs/ItemCategoryDialog/ItemCategoryFormDialogContent.js similarity index 81% rename from client/src/containers/Dialogs/ItemCategoryDialog.js rename to client/src/containers/Dialogs/ItemCategoryDialog/ItemCategoryFormDialogContent.js index 4cb1d8635..f96b574dd 100644 --- a/client/src/containers/Dialogs/ItemCategoryDialog.js +++ b/client/src/containers/Dialogs/ItemCategoryDialog/ItemCategoryFormDialogContent.js @@ -8,61 +8,61 @@ import { TextArea, MenuItem, } from '@blueprintjs/core'; -import { Select } from '@blueprintjs/select'; import { pick } from 'lodash'; import * as Yup from 'yup'; -import { FormattedMessage as T, useIntl } from 'react-intl'; import { useFormik } from 'formik'; -import { compose } from 'utils'; import { useQuery, queryCache } from 'react-query'; +import { FormattedMessage as T, useIntl } from 'react-intl'; + import classNames from 'classnames'; -import { connect } from 'react-redux'; +import { + ListSelect, + AccountsSelectList, + FieldRequiredHint, + Hint, + AppToaster, + ErrorMessage, + DialogContent, +} from 'components'; -import AppToaster from 'components/AppToaster'; -import ErrorMessage from 'components/ErrorMessage'; -import { ListSelect, AccountsSelectList } from 'components'; - -import Dialog from 'components/Dialog'; -import withDialogActions from 'containers/Dialog/withDialogActions'; -import withDialogRedux from 'components/DialogReduxConnect'; +import withItemCategories from 'containers/Items/withItemCategories'; +import withItemCategoryDetail from 'containers/Items/withItemCategoryDetail'; +import withItemCategoriesActions from 'containers/Items/withItemCategoriesActions'; import withAccounts from 'containers/Accounts/withAccounts'; import withAccountsActions from 'containers/Accounts/withAccountsActions'; -import withItemCategoryDetail from 'containers/Items/withItemCategoryDetail'; -import withItemCategories from 'containers/Items/withItemCategories'; -import withItemCategoriesActions from 'containers/Items/withItemCategoriesActions'; -import Icon from 'components/Icon'; +import withDialogActions from 'containers/Dialog/withDialogActions'; +import { compose } from 'utils'; -function ItemCategoryDialog({ - dialogName, - payload = {}, - isOpen, - - // #withDialog - openDialog, +function ItemCategoryFormDialogContent({ + // #withDialogActions closeDialog, // #withItemCategoryDetail - itemCategoryId, itemCategory, // #withItemCategories categoriesList, + // #withItemCategoriesActions + requestSubmitItemCategory, + requestEditItemCategory, + requestFetchItemCategories, + //# withAccount accountsList, - // #withItemCategoriesActions - requestSubmitItemCategory, - requestFetchItemCategories, - requestEditItemCategory, - // #withAccountsActions requestFetchAccounts, + + // #ownProp + action, + itemCategoryId, + dialogName, }) { - const [selectedParentCategory, setParentCategory] = useState(null); const { formatMessage } = useIntl(); + const [selectedParentCategory, setParentCategory] = useState(null); const fetchList = useQuery(['items-categories-list'], () => requestFetchItemCategories(), @@ -101,34 +101,33 @@ function ItemCategoryDialog({ values, errors, touched, + isSubmitting, setFieldValue, handleSubmit, - resetForm, getFieldProps, - isSubmitting, } = useFormik({ enableReinitialize: true, - initialValues: { - ...(payload.action === 'edit' && - pick(itemCategory, Object.keys(initialValues))), - }, validationSchema, + initialValues: { + ...initialValues, + ...(action === 'edit' && pick(itemCategory, Object.keys(initialValues))), + }, onSubmit: (values, { setSubmitting }) => { const afterSubmit = () => { closeDialog(dialogName); queryCache.invalidateQueries('items-categories-list'); queryCache.invalidateQueries('accounts-list'); }; - if (payload.action === 'edit') { - requestEditItemCategory(payload.id, values) + if (action === 'edit') { + requestEditItemCategory(itemCategoryId, values) .then((response) => { - afterSubmit(response); AppToaster.show({ message: formatMessage({ id: 'the_item_category_has_been_successfully_edited', }), intent: Intent.SUCCESS, }); + afterSubmit(response); }) .catch((error) => { setSubmitting(false); @@ -136,13 +135,13 @@ function ItemCategoryDialog({ } else { requestSubmitItemCategory(values) .then((response) => { - afterSubmit(response); AppToaster.show({ message: formatMessage({ id: 'the_item_category_has_been_successfully_created', }), intent: Intent.SUCCESS, }); + afterSubmit(response); }) .catch((error) => { setSubmitting(false); @@ -150,6 +149,7 @@ function ItemCategoryDialog({ } }, }); + const filterItemCategory = useCallback( (query, category, _index, exactMatch) => { const normalizedTitle = category.name.toLowerCase(); @@ -182,12 +182,6 @@ function ItemCategoryDialog({ closeDialog(dialogName); }, [dialogName, closeDialog]); - // Handle the dialog opening. - const onDialogOpening = useCallback(() => { - fetchList.refetch(); - fetchAccounts.refetch(); - }, [fetchList, fetchAccounts]); - const onChangeParentCategory = useCallback( (parentCategory) => { setParentCategory(parentCategory); @@ -205,41 +199,15 @@ function ItemCategoryDialog({ [setFieldValue], ); - const onDialogClosed = useCallback(() => { - resetForm(); - closeDialog(dialogName); - }, [resetForm, closeDialog, dialogName]); - - const requiredSpan = useMemo(() => *, []); - const infoIcon = useMemo(() => , []); - return ( - - ) : ( - - ) - } - className={classNames( - { - 'dialog--loading': fetchList.isFetching || fetchAccounts.isFetching, - }, - 'dialog--category-form', - )} - isOpen={isOpen} - onClosed={onDialogClosed} - onOpening={onDialogOpening} - isLoading={fetchList.isFetching || fetchAccounts.isFetching} - onClose={handleClose} - > +
+ + {/* ----------- Category name ----------- */} } - labelInfo={requiredSpan} + labelInfo={FieldRequiredHint} className={'form-group--category-name'} intent={errors.name && touched.name && Intent.DANGER} helperText={} @@ -251,10 +219,10 @@ function ItemCategoryDialog({ {...getFieldProps('name')} /> - + {/* ----------- Parent Category ----------- */} } - labelInfo={infoIcon} + labelInfo={Hint} className={classNames( 'form-group--select-list', 'form-group--parent-category', @@ -286,7 +254,7 @@ function ItemCategoryDialog({ labelProp={'name'} /> - + {/* ----------- Description ----------- */} } className={'form-group--description'} @@ -302,8 +270,7 @@ function ItemCategoryDialog({ {...getFieldProps('description')} /> - - {/* cost account */} + {/* ----------- Cost account ----------- */} } inline={true} @@ -326,8 +293,7 @@ function ItemCategoryDialog({ selectedAccountId={values.cost_account_id} /> - - {/* sell Account */} + {/* ----------- Sell account ----------- */} } inline={true} @@ -350,7 +316,7 @@ function ItemCategoryDialog({ selectedAccountId={values.sell_account_id} /> - {/* inventory Account */} + {/* ----------- inventory account ----------- */} } inline={true} @@ -390,29 +356,16 @@ function ItemCategoryDialog({ type="submit" disabled={isSubmitting} > - {payload.action === 'edit' ? ( - - ) : ( - - )} + {action === 'edit' ? : }
-
+ ); } -const mapStateToProps = (state, props) => ({ - dialogName: 'item-category-form', - itemCategoryId: props?.payload?.id || null, -}); - -const withItemCategoryDialog = connect(mapStateToProps); - export default compose( - withDialogRedux(null, 'item-category-form'), - withItemCategoryDialog, withDialogActions, withItemCategoryDetail(), withItemCategories(({ categoriesList }) => ({ @@ -423,4 +376,4 @@ export default compose( })), withItemCategoriesActions, withAccountsActions, -)(ItemCategoryDialog); +)(ItemCategoryFormDialogContent); diff --git a/client/src/containers/Dialogs/ItemCategoryDialog/index.js b/client/src/containers/Dialogs/ItemCategoryDialog/index.js new file mode 100644 index 000000000..fd704d6aa --- /dev/null +++ b/client/src/containers/Dialogs/ItemCategoryDialog/index.js @@ -0,0 +1,46 @@ +import React, { lazy } from 'react'; +import { FormattedMessage as T, useIntl } from 'react-intl'; +import { Dialog, DialogSuspense } from 'components'; + +import withDialogRedux from 'components/DialogReduxConnect'; +import { compose } from 'utils'; + +const ItemCategoryFormDialogContent = lazy(() => + import('./ItemCategoryFormDialogContent'), +); + +/** + * Item Category form dialog. + */ +function ItemCategoryFormDialog({ + dialogName, + payload = { action: '', id: null }, + isOpen, +}) { + return ( + + ) : ( + + ) + } + className={'dialog--category-form'} + isOpen={isOpen} + autoFocus={true} + canEscapeKeyClose={true} + > + + + + + ); +} + +export default compose(withDialogRedux())(ItemCategoryFormDialog); diff --git a/client/src/containers/Dialogs/ItemFromDialog.js b/client/src/containers/Dialogs/ItemFromDialog.js deleted file mode 100644 index 9c9e88528..000000000 --- a/client/src/containers/Dialogs/ItemFromDialog.js +++ /dev/null @@ -1,138 +0,0 @@ -// import React, { useState } from 'react'; -// import { -// Button, -// Classes, -// FormGroup, -// InputGroup, -// Intent, -// TextArea, -// } from '@blueprintjs/core'; -// import * as Yup from 'yup'; -// import { FormattedMessage as T, useIntl } from 'react-intl'; -// import { useFormik } from 'formik'; -// import { compose } from 'utils'; -// import Dialog from 'components/Dialog'; -// import useAsync from 'hooks/async'; -// import AppToaster from 'components/AppToaster'; -// import withDialog from 'containers/Dialogs/withDialog'; -// import DialogReduxConnect from 'components/DialogReduxConnect'; -// // import ItemFormDialogConnect from 'connectors/ItemFormDialog.connect'; - -// function ItemFromDialog({ -// name, -// payload, -// isOpen, -// submitItemCategory, -// fetchCategory, -// openDialog, -// closeDialog, -// }) { -// const [state, setState] = useState({}); -// const { formatMessage } = useIntl(); -// const ValidationSchema = Yup.object().shape({ -// name: Yup.string().required().label(formatMessage({id:'category_name_'})), -// description: Yup.string().trim(), -// }); - -// const formik = useFormik({ -// enableReinitialize: true, -// initialValues: {}, -// validationSchema: ValidationSchema, -// onSubmit: (values) => { -// submitItemCategory({ values }) -// .then((response) => { -// AppToaster.show({ -// message: formatMessage({id:'the_category_has_been_successfully_created'}), -// }); -// }) -// .catch((error) => { -// alert(error.message); -// }); -// }, -// }); - -// const fetchHook = useAsync(async () => { -// await Promise.all([submitItemCategory]); -// }); - -// const handleClose = () => { -// closeDialog(name); -// }; - -// const onDialogOpening = () => { -// fetchHook.execute(); -// openDialog(name); -// }; -// const onDialogClosed = () => { -// // formik.resetForm(); -// closeDialog(name); -// }; - -// return ( -// : -// } -// className={{ -// 'dialog--loading': state.isLoading, -// 'dialog--item-form': true, -// }} -// isOpen={isOpen} -// onClosed={onDialogClosed} -// onOpening={onDialogOpening} -// isLoading={fetchHook.pending} -// > -//
-//
-// } -// className={'form-group--category-name'} -// intent={formik.errors.name && Intent.DANGER} -// helperText={formik.errors.name && formik.errors.name} -// inline={true} -// > -// -// -// } -// className={'form-group--description'} -// intent={formik.errors.description && Intent.DANGER} -// helperText={formik.errors.description && formik.errors.credential} -// inline={true} -// > -//