From da67217d748f2f6a5735b09055f875a76e4c3433 Mon Sep 17 00:00:00 2001 From: "a.bouhuolia" Date: Wed, 10 Nov 2021 20:49:50 +0200 Subject: [PATCH] feat: quick create action on select/suggest items fields. --- src/common/drawers.js | 4 + src/components/AccountsSelectList.js | 87 ++++++--- src/components/AccountsSuggestField.js | 98 ++++++---- src/components/ContactSelecetList.js | 11 +- src/components/Contacts/ContactSelectField.js | 86 +++++++++ .../Contacts/CustomerSelectField.js | 116 ++++++++++++ src/components/Contacts/VendorSelectField.js | 115 ++++++++++++ src/components/Contacts/index.js | 5 + src/components/Contacts/utils.js | 43 +++++ src/components/Dashboard/DashboardContent.js | 2 - .../DataTableCells/AccountsListFieldCell.js | 4 + .../DataTableCells/ItemsListCell.js | 13 +- src/components/Drawer/Drawer.js | 3 +- src/components/Drawer/DrawerProvider.js | 16 ++ src/components/DrawersContainer.js | 10 +- src/components/ItemsSuggestField.js | 118 +++++++++---- src/components/index.js | 1 + .../Accounting/MakeJournal/components.js | 1 + .../CustomerForm/CustomerFloatingActions.js | 22 ++- .../Customers/CustomerForm/CustomerForm.js | 154 +--------------- .../CustomerForm/CustomerFormFormik.js | 127 +++++++++++++ .../CustomerForm/CustomerFormPage.js | 76 ++++++-- .../CustomerForm/CustomerFormProvider.js | 20 +-- .../Customers/CustomerForm/utils.js | 38 ++++ .../QuickPaymentMadeFormFields.js | 2 +- .../QuickCreateCustomerDrawerContent.js | 25 +++ .../QuickCustomerFormDrawer.js | 65 +++++++ .../QuickCreateCustomerDrawer/index.js | 35 ++++ .../QuickCreateItemDrawerContent.js | 25 +++ .../QuickCreateItemDrawerForm.js | 86 +++++++++ .../Drawers/QuickCreateItemDrawer/index.js | 37 ++++ .../QuickVendorFormDrawer.js | 85 +++++++++ .../QuickWriteVendorDrawerContent.js | 25 +++ .../Drawers/QuickWriteVendorDrawer/index.js | 36 ++++ src/containers/Entries/components.js | 5 +- src/containers/Entries/utils.js | 9 + .../ExpenseForm/ExpenseFormHeaderFields.js | 8 +- .../Expenses/ExpenseForm/components.js | 1 + src/containers/Items/ItemForm.js | 167 ++++++++---------- src/containers/Items/ItemFormBody.js | 4 +- .../Items/ItemFormFloatingActions.js | 23 +-- src/containers/Items/ItemFormFormik.js | 112 ++++++++++++ src/containers/Items/ItemFormPage.js | 14 +- src/containers/Items/ItemFormProvider.js | 36 ++-- src/containers/Items/utils.js | 5 +- .../Bills/BillForm/BillFormHeaderFields.js | 7 +- .../PaymentMadeFormHeaderFields.js | 7 +- .../EstimateForm/EstimateFormHeaderFields.js | 7 +- .../InvoiceForm/InvoiceFormHeaderFields.js | 10 +- .../PaymentReceiveHeaderFields.js | 7 +- .../ReceiptForm/ReceiptFormHeaderFields.js | 8 +- .../VendorForm/VendorFloatingActions.js | 27 +-- .../{VendorForm.js => VendorFormFormik.js} | 90 +++------- .../Vendors/VendorForm/VendorFormPage.js | 63 +++++-- .../Vendors/VendorForm/VendorFormProvider.js | 24 ++- src/containers/Vendors/VendorForm/utils.js | 36 ++++ src/style/pages/Customers/Form.scss | 157 ++++++++++++++++ .../pages/Items/{PageForm.scss => Form.scss} | 20 +-- src/style/pages/SaleInvoice/PageForm.scss | 9 +- .../PageForm.scss => Vendors/Form.scss} | 19 +- src/style/pages/Vendors/PageForm.scss | 164 +---------------- 61 files changed, 1885 insertions(+), 745 deletions(-) create mode 100644 src/components/Contacts/ContactSelectField.js create mode 100644 src/components/Contacts/CustomerSelectField.js create mode 100644 src/components/Contacts/VendorSelectField.js create mode 100644 src/components/Contacts/index.js create mode 100644 src/components/Contacts/utils.js create mode 100644 src/components/Drawer/DrawerProvider.js create mode 100644 src/containers/Customers/CustomerForm/CustomerFormFormik.js create mode 100644 src/containers/Customers/CustomerForm/utils.js create mode 100644 src/containers/Drawers/QuickCreateCustomerDrawer/QuickCreateCustomerDrawerContent.js create mode 100644 src/containers/Drawers/QuickCreateCustomerDrawer/QuickCustomerFormDrawer.js create mode 100644 src/containers/Drawers/QuickCreateCustomerDrawer/index.js create mode 100644 src/containers/Drawers/QuickCreateItemDrawer/QuickCreateItemDrawerContent.js create mode 100644 src/containers/Drawers/QuickCreateItemDrawer/QuickCreateItemDrawerForm.js create mode 100644 src/containers/Drawers/QuickCreateItemDrawer/index.js create mode 100644 src/containers/Drawers/QuickWriteVendorDrawer/QuickVendorFormDrawer.js create mode 100644 src/containers/Drawers/QuickWriteVendorDrawer/QuickWriteVendorDrawerContent.js create mode 100644 src/containers/Drawers/QuickWriteVendorDrawer/index.js create mode 100644 src/containers/Items/ItemFormFormik.js rename src/containers/Vendors/VendorForm/{VendorForm.js => VendorFormFormik.js} (63%) create mode 100644 src/containers/Vendors/VendorForm/utils.js create mode 100644 src/style/pages/Customers/Form.scss rename src/style/pages/Items/{PageForm.scss => Form.scss} (85%) rename src/style/pages/{Customers/PageForm.scss => Vendors/Form.scss} (91%) diff --git a/src/common/drawers.js b/src/common/drawers.js index 449f51485..3a1b21032 100644 --- a/src/common/drawers.js +++ b/src/common/drawers.js @@ -10,4 +10,8 @@ export const DRAWERS = { BILL_DRAWER: 'bill-drawer', INVENTORY_ADJUSTMENT_DRAWER: 'inventory-adjustment-drawer', CASHFLOW_TRNASACTION_DRAWER: 'cashflow-transaction-drawer', + + QUICK_WRITE_VENDOR: 'quick-write-vendor', + QUICK_CREATE_CUSTOMER: 'quick-create-customer', + QUICK_CREATE_ITEM: 'quick-create-item', }; diff --git a/src/components/AccountsSelectList.js b/src/components/AccountsSelectList.js index 75a7d3e09..9ed337284 100644 --- a/src/components/AccountsSelectList.js +++ b/src/components/AccountsSelectList.js @@ -1,13 +1,55 @@ import React, { useCallback, useState, useEffect, useMemo } from 'react'; import { MenuItem, Button } from '@blueprintjs/core'; import { Select } from '@blueprintjs/select'; -import { MenuItemNestedText, FormattedMessage as T } from 'components'; +import * as R from 'ramda'; import classNames from 'classnames'; + +import { MenuItemNestedText, FormattedMessage as T } from 'components'; import { filterAccountsByQuery } from './utils'; import { nestedArrayToflatten } from 'utils'; import { CLASSES } from 'common/classes'; -export default function AccountsSelectList({ +import withDialogActions from 'containers/Dialog/withDialogActions'; + +// Create new account renderer. +const createNewItemRenderer = (query, active, handleClick) => { + return ( + + ); +}; + +// Create new item from the given query string. +const createNewItemFromQuery = (name) => { + return { + name, + }; +}; + +// Filters accounts items. +const filterAccountsPredicater = (query, account, _index, exactMatch) => { + const normalizedTitle = account.name.toLowerCase(); + const normalizedQuery = query.toLowerCase(); + + if (exactMatch) { + return normalizedTitle === normalizedQuery; + } else { + return `${account.code} ${normalizedTitle}`.indexOf(normalizedQuery) >= 0; + } +}; + +/** + * Accounts select list. + */ +function AccountsSelectList({ + // #withDialogActions + openDialog, + + // #ownProps accounts, initialAccountId, selectedAccountId, @@ -21,6 +63,8 @@ export default function AccountsSelectList({ filterByNormal, filterByRootTypes, + allowCreate, + buttonProps = {}, }) { const flattenAccounts = useMemo( @@ -51,6 +95,7 @@ export default function AccountsSelectList({ [initialAccountId, filteredAccounts], ); + // Select account item. const [selectedAccount, setSelectedAccount] = useState( initialAccount || null, ); @@ -76,31 +121,25 @@ export default function AccountsSelectList({ ); }, []); - const onAccountSelect = useCallback( + // Handle the account item select. + const handleAccountSelect = useCallback( (account) => { - setSelectedAccount({ ...account }); - onAccountSelected && onAccountSelected(account); - }, - [setSelectedAccount, onAccountSelected], - ); - - // Filters accounts items. - const filterAccountsPredicater = useCallback( - (query, account, _index, exactMatch) => { - const normalizedTitle = account.name.toLowerCase(); - const normalizedQuery = query.toLowerCase(); - - if (exactMatch) { - return normalizedTitle === normalizedQuery; + if (account.id) { + setSelectedAccount({ ...account }); + onAccountSelected && onAccountSelected(account); } else { - return ( - `${account.code} ${normalizedTitle}`.indexOf(normalizedQuery) >= 0 - ); + openDialog('account-form'); } }, - [], + [setSelectedAccount, onAccountSelected, openDialog], ); + // Maybe inject new item props to select component. + const maybeCreateNewItemRenderer = allowCreate ? createNewItemRenderer : null; + const maybeCreateNewItemFromQuery = allowCreate + ? createNewItemFromQuery + : null; + return ( } />} + itemRenderer={handleContactRenderer} + itemPredicate={itemPredicate} + filterable={true} + disabled={disabled} + onItemSelect={handleContactSelect} + popoverProps={{ minimal: true, usePortal: !popoverFill }} + className={classNames(CLASSES.FORM_GROUP_LIST_SELECT, { + [CLASSES.SELECT_LIST_FILL_POPOVER]: popoverFill, + })} + inputProps={{ + placeholder: intl.get('filter_'), + }} + {...restProps} + > + +