From cfca03806628c61a23627be6e37c8739fc8765d7 Mon Sep 17 00:00:00 2001 From: elforjani3 Date: Wed, 3 Mar 2021 16:40:23 +0200 Subject: [PATCH] feat(vendor): add contact duplicate. --- .../Vendors/VendorForm/VendorForm.js | 6 ++--- .../Vendors/VendorForm/VendorFormProvider.js | 19 ++++++++++++++- .../Vendors/VendorsLanding/VendorsTable.js | 15 ++++++++++-- .../Vendors/VendorsLanding/components.js | 7 +++++- client/src/lang/en/index.js | 6 +++++ client/src/routes/dashboard.js | 23 +++++++++++++++++-- 6 files changed, 67 insertions(+), 9 deletions(-) diff --git a/client/src/containers/Vendors/VendorForm/VendorForm.js b/client/src/containers/Vendors/VendorForm/VendorForm.js index db2b916de..eeaf20a2b 100644 --- a/client/src/containers/Vendors/VendorForm/VendorForm.js +++ b/client/src/containers/Vendors/VendorForm/VendorForm.js @@ -69,11 +69,11 @@ function VendorForm({ // #withSettings baseCurrency, }) { - // Vendor form context. const { vendorId, vendor, + contactDuplicate, createVendorMutate, editVendorMutate, setSubmitPayload, @@ -94,9 +94,9 @@ function VendorForm({ () => ({ ...defaultInitialValues, currency_code: baseCurrency, - ...transformToForm(vendor, defaultInitialValues), + ...transformToForm(vendor || contactDuplicate, defaultInitialValues), }), - [vendor, baseCurrency], + [vendor, contactDuplicate, baseCurrency], ); useEffect(() => { diff --git a/client/src/containers/Vendors/VendorForm/VendorFormProvider.js b/client/src/containers/Vendors/VendorForm/VendorFormProvider.js index e559846b9..cd3052e85 100644 --- a/client/src/containers/Vendors/VendorForm/VendorFormProvider.js +++ b/client/src/containers/Vendors/VendorForm/VendorFormProvider.js @@ -1,8 +1,12 @@ import React, { useState, createContext } from 'react'; +import { omit, pick } from 'lodash'; +import { useLocation } from 'react-router-dom'; import DashboardInsider from 'components/Dashboard/DashboardInsider'; import { useVendor, + useContact, useCurrencies, + useCustomer, useCreateVendor, useEditVendor, } from 'hooks/query'; @@ -13,6 +17,8 @@ const VendorFormContext = createContext(); * Vendor form provider. */ function VendorFormProvider({ vendorId, ...props }) { + const { state } = useLocation(); + // Handle fetch Currencies data table const { data: currencies, isFetching: isCurrenciesLoading } = useCurrencies(); @@ -21,6 +27,16 @@ function VendorFormProvider({ vendorId, ...props }) { enabled: !!vendorId, }); + const contactId = state?.action; + + // Handle fetch contact duplicate details. + const { data: contactDuplicate, isFetching: isContactLoading } = useContact( + contactId, + { + enabled: !!contactId, + }, + ); + // Create and edit vendor mutations. const { mutateAsync: createVendorMutate } = useCreateVendor(); const { mutateAsync: editVendorMutate } = useEditVendor(); @@ -32,6 +48,7 @@ function VendorFormProvider({ vendorId, ...props }) { vendorId, currencies, vendor, + contactDuplicate: { ...omit(contactDuplicate, ['opening_balance_at']) }, submitPayload, createVendorMutate, @@ -41,7 +58,7 @@ function VendorFormProvider({ vendorId, ...props }) { return ( diff --git a/client/src/containers/Vendors/VendorsLanding/VendorsTable.js b/client/src/containers/Vendors/VendorsLanding/VendorsTable.js index d02d7bdbf..18efd3718 100644 --- a/client/src/containers/Vendors/VendorsLanding/VendorsTable.js +++ b/client/src/containers/Vendors/VendorsLanding/VendorsTable.js @@ -11,6 +11,7 @@ import { useVendorsListContext } from './VendorsListProvider'; import withVendorsActions from './withVendorsActions'; import withVendors from './withVendors'; import withAlertsActions from 'containers/Alert/withAlertActions'; +import withDialogActions from 'containers/Dialog/withDialogActions'; import { compose } from 'utils'; import { ActionsMenu, useVendorsTableColumns } from './components'; @@ -27,6 +28,8 @@ function VendorsTable({ // #withAlertsActions openAlert, + // #withDialogActions + openDialog, }) { // Vendors list context. const { @@ -34,7 +37,7 @@ function VendorsTable({ pagination, isVendorsFetching, isVendorsLoading, - isEmptyStatus + isEmptyStatus, } = useVendorsListContext(); // Vendors table columns. @@ -53,6 +56,12 @@ function VendorsTable({ openAlert('vendor-delete', { vendorId: id }); }; + // Handle contact duplicate . + const handleContactDuplicate = ({ id }) => { + openDialog('contact-duplicate', { + contactId: id, + }); + }; // Handle fetch data once the page index, size or sort by of the table change. const handleFetchData = React.useCallback( ({ pageSize, pageIndex, sortBy }) => { @@ -67,7 +76,7 @@ function VendorsTable({ // Display empty status instead of the table. if (isEmptyStatus) { - return + return ; } return ( @@ -94,6 +103,7 @@ function VendorsTable({ payload={{ onEdit: handleEditVendor, onDelete: handleDeleteVendor, + onDuplicate: handleContactDuplicate, }} /> ); @@ -102,5 +112,6 @@ function VendorsTable({ export default compose( withVendorsActions, withAlertsActions, + withDialogActions, withVendors(({ vendorsTableState }) => ({ vendorsTableState })), )(VendorsTable); diff --git a/client/src/containers/Vendors/VendorsLanding/components.js b/client/src/containers/Vendors/VendorsLanding/components.js index 66c651aa6..a737ba63c 100644 --- a/client/src/containers/Vendors/VendorsLanding/components.js +++ b/client/src/containers/Vendors/VendorsLanding/components.js @@ -17,7 +17,7 @@ import { safeCallback, firstLettersArgs } from 'utils'; */ export function ActionsMenu({ row: { original }, - payload: { onEdit, onDelete }, + payload: { onEdit, onDelete, onDuplicate }, }) { const { formatMessage } = useIntl(); @@ -33,6 +33,11 @@ export function ActionsMenu({ text={formatMessage({ id: 'edit_vendor' })} onClick={safeCallback(onEdit, original)} /> + } + text={formatMessage({ id: 'duplicate' })} + onClick={safeCallback(onDuplicate, original)} + /> } text={formatMessage({ id: 'delete_vendor' })} diff --git a/client/src/lang/en/index.js b/client/src/lang/en/index.js index 8dc555168..bdcfb955a 100644 --- a/client/src/lang/en/index.js +++ b/client/src/lang/en/index.js @@ -990,4 +990,10 @@ export default { convert_to_invoice: 'Convert to Invoice', sale_estimate_is_already_converted_to_invoice: 'Sale estimate is already converted to invoice.', + duplicate: 'Duplicate', + are_you_sure_want_to_duplicate: + 'Are you sure want to duplicate this contact, which contact type?', + contact_type: 'Contact Type', + duplicate_contact: 'Duplicate Contact', + contact_type_: 'Contact type', }; diff --git a/client/src/routes/dashboard.js b/client/src/routes/dashboard.js index 7ea5bb2aa..91a19f710 100644 --- a/client/src/routes/dashboard.js +++ b/client/src/routes/dashboard.js @@ -4,7 +4,6 @@ import { formatMessage } from 'services/intl'; // const BASE_URL = '/dashboard'; export default [ - // Accounts. { path: `/accounts`, @@ -132,7 +131,7 @@ export default [ hotkey: 'shift+5', pageTitle: formatMessage({ id: 'trial_balance_sheet' }), backLink: true, - sidebarShrink: true + sidebarShrink: true, }, { path: `/financial-reports/profit-loss-sheet`, @@ -254,6 +253,16 @@ export default [ hotkey: 'shift+c', pageTitle: formatMessage({ id: 'customers_list' }), }, + { + path: `/customers/contact_duplicate=/:id`, + component: lazy(() => + import('containers/Customers/CustomerForm/CustomerFormPage'), + ), + name: 'duplicate-customer', + breadcrumb: 'Duplicate Customer', + pageTitle: formatMessage({ id: 'new_customer' }), + backLink: true, + }, // Vendors { @@ -286,6 +295,16 @@ export default [ hotkey: 'shift+v', pageTitle: formatMessage({ id: 'vendors_list' }), }, + { + path: `/vendors/contact_duplicate=/:id`, + component: lazy(() => + import('containers/Vendors/VendorForm/VendorFormPage'), + ), + name: 'duplicate-vendor', + breadcrumb: 'Duplicate Vendor', + pageTitle: formatMessage({ id: 'new_vendor' }), + backLink: true, + }, // Estimates {