feat(vendor): add contact duplicate.

This commit is contained in:
elforjani3
2021-03-03 16:40:23 +02:00
parent 7eca87215c
commit cfca038066
6 changed files with 67 additions and 9 deletions

View File

@@ -69,11 +69,11 @@ function VendorForm({
// #withSettings // #withSettings
baseCurrency, baseCurrency,
}) { }) {
// Vendor form context. // Vendor form context.
const { const {
vendorId, vendorId,
vendor, vendor,
contactDuplicate,
createVendorMutate, createVendorMutate,
editVendorMutate, editVendorMutate,
setSubmitPayload, setSubmitPayload,
@@ -94,9 +94,9 @@ function VendorForm({
() => ({ () => ({
...defaultInitialValues, ...defaultInitialValues,
currency_code: baseCurrency, currency_code: baseCurrency,
...transformToForm(vendor, defaultInitialValues), ...transformToForm(vendor || contactDuplicate, defaultInitialValues),
}), }),
[vendor, baseCurrency], [vendor, contactDuplicate, baseCurrency],
); );
useEffect(() => { useEffect(() => {

View File

@@ -1,8 +1,12 @@
import React, { useState, createContext } from 'react'; import React, { useState, createContext } from 'react';
import { omit, pick } from 'lodash';
import { useLocation } from 'react-router-dom';
import DashboardInsider from 'components/Dashboard/DashboardInsider'; import DashboardInsider from 'components/Dashboard/DashboardInsider';
import { import {
useVendor, useVendor,
useContact,
useCurrencies, useCurrencies,
useCustomer,
useCreateVendor, useCreateVendor,
useEditVendor, useEditVendor,
} from 'hooks/query'; } from 'hooks/query';
@@ -13,6 +17,8 @@ const VendorFormContext = createContext();
* Vendor form provider. * Vendor form provider.
*/ */
function VendorFormProvider({ vendorId, ...props }) { function VendorFormProvider({ vendorId, ...props }) {
const { state } = useLocation();
// Handle fetch Currencies data table // Handle fetch Currencies data table
const { data: currencies, isFetching: isCurrenciesLoading } = useCurrencies(); const { data: currencies, isFetching: isCurrenciesLoading } = useCurrencies();
@@ -21,6 +27,16 @@ function VendorFormProvider({ vendorId, ...props }) {
enabled: !!vendorId, 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. // Create and edit vendor mutations.
const { mutateAsync: createVendorMutate } = useCreateVendor(); const { mutateAsync: createVendorMutate } = useCreateVendor();
const { mutateAsync: editVendorMutate } = useEditVendor(); const { mutateAsync: editVendorMutate } = useEditVendor();
@@ -32,6 +48,7 @@ function VendorFormProvider({ vendorId, ...props }) {
vendorId, vendorId,
currencies, currencies,
vendor, vendor,
contactDuplicate: { ...omit(contactDuplicate, ['opening_balance_at']) },
submitPayload, submitPayload,
createVendorMutate, createVendorMutate,
@@ -41,7 +58,7 @@ function VendorFormProvider({ vendorId, ...props }) {
return ( return (
<DashboardInsider <DashboardInsider
loading={isVendorLoading || isCurrenciesLoading} loading={isVendorLoading || isContactLoading || isCurrenciesLoading}
name={'vendor-form'} name={'vendor-form'}
> >
<VendorFormContext.Provider value={provider} {...props} /> <VendorFormContext.Provider value={provider} {...props} />

View File

@@ -11,6 +11,7 @@ import { useVendorsListContext } from './VendorsListProvider';
import withVendorsActions from './withVendorsActions'; import withVendorsActions from './withVendorsActions';
import withVendors from './withVendors'; import withVendors from './withVendors';
import withAlertsActions from 'containers/Alert/withAlertActions'; import withAlertsActions from 'containers/Alert/withAlertActions';
import withDialogActions from 'containers/Dialog/withDialogActions';
import { compose } from 'utils'; import { compose } from 'utils';
import { ActionsMenu, useVendorsTableColumns } from './components'; import { ActionsMenu, useVendorsTableColumns } from './components';
@@ -27,6 +28,8 @@ function VendorsTable({
// #withAlertsActions // #withAlertsActions
openAlert, openAlert,
// #withDialogActions
openDialog,
}) { }) {
// Vendors list context. // Vendors list context.
const { const {
@@ -34,7 +37,7 @@ function VendorsTable({
pagination, pagination,
isVendorsFetching, isVendorsFetching,
isVendorsLoading, isVendorsLoading,
isEmptyStatus isEmptyStatus,
} = useVendorsListContext(); } = useVendorsListContext();
// Vendors table columns. // Vendors table columns.
@@ -53,6 +56,12 @@ function VendorsTable({
openAlert('vendor-delete', { vendorId: id }); 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. // Handle fetch data once the page index, size or sort by of the table change.
const handleFetchData = React.useCallback( const handleFetchData = React.useCallback(
({ pageSize, pageIndex, sortBy }) => { ({ pageSize, pageIndex, sortBy }) => {
@@ -67,7 +76,7 @@ function VendorsTable({
// Display empty status instead of the table. // Display empty status instead of the table.
if (isEmptyStatus) { if (isEmptyStatus) {
return <VendorsEmptyStatus /> return <VendorsEmptyStatus />;
} }
return ( return (
@@ -94,6 +103,7 @@ function VendorsTable({
payload={{ payload={{
onEdit: handleEditVendor, onEdit: handleEditVendor,
onDelete: handleDeleteVendor, onDelete: handleDeleteVendor,
onDuplicate: handleContactDuplicate,
}} }}
/> />
); );
@@ -102,5 +112,6 @@ function VendorsTable({
export default compose( export default compose(
withVendorsActions, withVendorsActions,
withAlertsActions, withAlertsActions,
withDialogActions,
withVendors(({ vendorsTableState }) => ({ vendorsTableState })), withVendors(({ vendorsTableState }) => ({ vendorsTableState })),
)(VendorsTable); )(VendorsTable);

View File

@@ -17,7 +17,7 @@ import { safeCallback, firstLettersArgs } from 'utils';
*/ */
export function ActionsMenu({ export function ActionsMenu({
row: { original }, row: { original },
payload: { onEdit, onDelete }, payload: { onEdit, onDelete, onDuplicate },
}) { }) {
const { formatMessage } = useIntl(); const { formatMessage } = useIntl();
@@ -33,6 +33,11 @@ export function ActionsMenu({
text={formatMessage({ id: 'edit_vendor' })} text={formatMessage({ id: 'edit_vendor' })}
onClick={safeCallback(onEdit, original)} onClick={safeCallback(onEdit, original)}
/> />
<MenuItem
icon={<Icon icon="duplicate-18" />}
text={formatMessage({ id: 'duplicate' })}
onClick={safeCallback(onDuplicate, original)}
/>
<MenuItem <MenuItem
icon={<Icon icon="trash-16" iconSize={16} />} icon={<Icon icon="trash-16" iconSize={16} />}
text={formatMessage({ id: 'delete_vendor' })} text={formatMessage({ id: 'delete_vendor' })}

View File

@@ -990,4 +990,10 @@ export default {
convert_to_invoice: 'Convert to Invoice', convert_to_invoice: 'Convert to Invoice',
sale_estimate_is_already_converted_to_invoice: sale_estimate_is_already_converted_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',
}; };

View File

@@ -4,7 +4,6 @@ import { formatMessage } from 'services/intl';
// const BASE_URL = '/dashboard'; // const BASE_URL = '/dashboard';
export default [ export default [
// Accounts. // Accounts.
{ {
path: `/accounts`, path: `/accounts`,
@@ -132,7 +131,7 @@ export default [
hotkey: 'shift+5', hotkey: 'shift+5',
pageTitle: formatMessage({ id: 'trial_balance_sheet' }), pageTitle: formatMessage({ id: 'trial_balance_sheet' }),
backLink: true, backLink: true,
sidebarShrink: true sidebarShrink: true,
}, },
{ {
path: `/financial-reports/profit-loss-sheet`, path: `/financial-reports/profit-loss-sheet`,
@@ -254,6 +253,16 @@ export default [
hotkey: 'shift+c', hotkey: 'shift+c',
pageTitle: formatMessage({ id: 'customers_list' }), 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 // Vendors
{ {
@@ -286,6 +295,16 @@ export default [
hotkey: 'shift+v', hotkey: 'shift+v',
pageTitle: formatMessage({ id: 'vendors_list' }), 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 // Estimates
{ {