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
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(() => {

View File

@@ -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 (
<DashboardInsider
loading={isVendorLoading || isCurrenciesLoading}
loading={isVendorLoading || isContactLoading || isCurrenciesLoading}
name={'vendor-form'}
>
<VendorFormContext.Provider value={provider} {...props} />

View File

@@ -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 <VendorsEmptyStatus />
return <VendorsEmptyStatus />;
}
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);

View File

@@ -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)}
/>
<MenuItem
icon={<Icon icon="duplicate-18" />}
text={formatMessage({ id: 'duplicate' })}
onClick={safeCallback(onDuplicate, original)}
/>
<MenuItem
icon={<Icon icon="trash-16" iconSize={16} />}
text={formatMessage({ id: 'delete_vendor' })}

View File

@@ -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',
};

View File

@@ -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
{