diff --git a/client/src/containers/Customers/Customer.js b/client/src/containers/Customers/Customer.js index c0f263f57..edf1552f2 100644 --- a/client/src/containers/Customers/Customer.js +++ b/client/src/containers/Customers/Customer.js @@ -2,22 +2,25 @@ import React, { useCallback } from 'react'; import { useParams, useHistory } from 'react-router-dom'; import { useQuery } from 'react-query'; -import DashboardInsider from 'components/Dashboard/DashboardInsider'; import CustomerForm from 'containers/Customers/CustomerForm'; +import DashboardInsider from 'components/Dashboard/DashboardInsider'; -import withDashboardActions from 'containers/Dashboard/withDashboardActions'; import withCustomersActions from './withCustomersActions'; +import withCurrenciesActions from 'containers/Currencies/withCurrenciesActions'; import { compose } from 'utils'; function Customer({ - // #withDashboardActions - changePageTitle, + // // #withDashboardActions + // changePageTitle, - formik, + // formik, //#withCustomersActions requestFetchCustomers, requestFetchCustomer, + + // #wihtCurrenciesActions + requestFetchCurrencies, }) { const { id } = useParams(); const history = useHistory(); @@ -32,7 +35,11 @@ function Customer({ (key, customerId) => requestFetchCustomer(customerId), { enabled: id && id }, ); - + // Handle fetch Currencies data table + const fetchCurrencies = useQuery('currencies', () => + requestFetchCurrencies(), + ); + const handleFormSubmit = useCallback( (payload) => { payload.redirect && history.push('/customers'); @@ -46,7 +53,11 @@ function Customer({ return ( - + {/*------------ Billing Address country -----------*/} - + {/*------------ Billing Address 1 -----------*/} } className={'form-group--address_line_1'} @@ -67,7 +67,7 @@ const CustomerBillingAddress = ({ {...getFieldProps('billing_address_1')} /> - + {/*------------ Billing Address 2 -----------*/} } className={'form-group--journal-number'} @@ -90,7 +90,7 @@ const CustomerBillingAddress = ({ {...getFieldProps('billing_address_2')} /> - + {/*------------ Billing Address city -----------*/} } className={'form-group--journal-number'} @@ -116,7 +116,7 @@ const CustomerBillingAddress = ({ {...getFieldProps('billing_address_city')} /> - + {/*------------ Billing Address state -----------*/} } className={'form-group--journal-number'} @@ -142,47 +142,47 @@ const CustomerBillingAddress = ({ {...getFieldProps('billing_address_state')} /> - + {/*------------ Billing Address postcode -----------*/} } intent={ - errors.billing_address_zipcode && - touched.billing_address_zipcode && + errors.billing_address_postcode && + touched.billing_address_postcode && Intent.DANGER } inline={true} helperText={ } > - + {/*------------ Billing Address phone -----------*/} } intent={ - errors.shipping_phone && touched.shipping_phone && Intent.DANGER + errors.billing_address_phone && touched.billing_address_phone && Intent.DANGER } inline={true} helperText={ - + } > @@ -191,7 +191,7 @@ const CustomerBillingAddress = ({

- + {/*------------ Shipping Address country -----------*/} } className={'form-group--journal-number'} @@ -217,7 +217,7 @@ const CustomerBillingAddress = ({ {...getFieldProps('shipping_address_country')} /> - + {/*------------ Shipping Address 1 -----------*/} } className={'form-group--journal-number'} @@ -240,7 +240,7 @@ const CustomerBillingAddress = ({ {...getFieldProps('billing_address_1')} /> - + {/*------------ Shipping Address 2 -----------*/} } className={'form-group--journal-number'} @@ -263,7 +263,7 @@ const CustomerBillingAddress = ({ {...getFieldProps('billing_address_2')} /> - + {/*------------ Shipping Address city -----------*/} } className={'form-group--journal-number'} @@ -289,7 +289,7 @@ const CustomerBillingAddress = ({ {...getFieldProps('shipping_address_city')} /> - + {/*------------ Shipping Address state -----------*/} } className={'form-group--journal-number'} @@ -315,47 +315,47 @@ const CustomerBillingAddress = ({ {...getFieldProps('shipping_address_state')} /> - + {/*------------ Shipping Address postcode -----------*/} } intent={ - errors.shipping_address_zipcode && - touched.shipping_address_zipcode && + errors.shipping_address_postcode && + touched.shipping_address_postcode && Intent.DANGER } inline={true} helperText={ } > - + {/*------------ Shipping Address phone -----------*/} } intent={ - errors.shipping_phone && touched.shipping_phone && Intent.DANGER + errors.shipping_address_phone && touched.shipping_address_phone && Intent.DANGER } inline={true} helperText={ - + } > diff --git a/client/src/containers/Customers/CustomerFinancialPanel.js b/client/src/containers/Customers/CustomerFinancialPanel.js index 548165c64..71edb0189 100644 --- a/client/src/containers/Customers/CustomerFinancialPanel.js +++ b/client/src/containers/Customers/CustomerFinancialPanel.js @@ -1,4 +1,4 @@ -import React, { useCallback } from 'react'; +import React, { useCallback, useState } from 'react'; import moment from 'moment'; import classNames from 'classnames'; import { FormGroup, Intent, Position, Classes } from '@blueprintjs/core'; @@ -6,52 +6,86 @@ import { DateInput } from '@blueprintjs/datetime'; import { ErrorMessage, MoneyInputGroup, - CurrenciesSelectList, + CurrencySelectList, Row, Col, } from 'components'; import { FormattedMessage as T } from 'react-intl'; -import { momentFormatter, tansformDateValue } from 'utils'; -export default function CustomerFinancialPanel({ +import withCurrencies from 'containers/Currencies/withCurrencies'; + +import { compose, momentFormatter, tansformDateValue } from 'utils'; + +function CustomerFinancialPanel({ setFieldValue, errors, touched, values, + + // #withCurrencies + currenciesList, + + customerId, }) { + const [selectedItems, setSelectedItems] = useState(); + const handleDateChange = useCallback( (date) => { const formatted = moment(date).format('YYYY-MM-DD'); - setFieldValue('payment_date', formatted); + setFieldValue('opening_balance_at', formatted); }, [setFieldValue], ); + const handleMoneyInputChange = useCallback( + (e, value) => { + setFieldValue('opening_balance', value); + }, + [setFieldValue], + ); + + const onItemsSelect = useCallback( + (filedName) => { + return (filed) => { + setSelectedItems({ + ...selectedItems, + [filedName]: filed, + }); + setFieldValue(filedName, filed.currency_code); + }; + }, + [setFieldValue, selectedItems], + ); return (
+ {/*------------ Opening balance at -----------*/} } className={classNames('form-group--select-list', Classes.FILL)} intent={ - errors.opening_balance_date && - touched.opening_balance_date && + errors.opening_balance_at && + touched.opening_balance_at && Intent.DANGER } inline={true} helperText={ - + } > - + {/*------------ Opening balance -----------*/} } className={classNames('form-group--opening-balance', Classes.FILL)} @@ -63,12 +97,14 @@ export default function CustomerFinancialPanel({ - + {/*------------ Currency -----------*/} } className={classNames( @@ -78,10 +114,20 @@ export default function CustomerFinancialPanel({ )} inline={true} > - + {/* */} +
); } + +export default compose( + withCurrencies(({ currenciesList }) => ({ currenciesList })), +)(CustomerFinancialPanel); diff --git a/client/src/containers/Customers/CustomerFloatingActions.js b/client/src/containers/Customers/CustomerFloatingActions.js index 645bf4561..8af9af147 100644 --- a/client/src/containers/Customers/CustomerFloatingActions.js +++ b/client/src/containers/Customers/CustomerFloatingActions.js @@ -15,8 +15,8 @@ export default function CustomerFloatingActions({ return (
- - + + ); } diff --git a/client/src/containers/Customers/CustomerFormAfterPrimarySection.js b/client/src/containers/Customers/CustomerFormAfterPrimarySection.js index 4b9608320..25e3436f8 100644 --- a/client/src/containers/Customers/CustomerFormAfterPrimarySection.js +++ b/client/src/containers/Customers/CustomerFormAfterPrimarySection.js @@ -31,12 +31,8 @@ export default function CustomerFormAfterPrimarySection({ /> - {/*------------ Customer email -----------*/} + {/*------------ Phone number -----------*/} - } className={'form-group--phone-number'} label={} inline={true} @@ -49,8 +45,8 @@ export default function CustomerFormAfterPrimarySection({ /> diff --git a/client/src/containers/Customers/CustomerFormPrimarySection.js b/client/src/containers/Customers/CustomerFormPrimarySection.js index 2b8c22371..f649c288a 100644 --- a/client/src/containers/Customers/CustomerFormPrimarySection.js +++ b/client/src/containers/Customers/CustomerFormPrimarySection.js @@ -32,15 +32,20 @@ export default function CustomerFormPrimarySection({ ); // Handle salutation field select. - const handleSalutationSelect = useCallback((salutation) => { - setFieldValue('salutation', salutation.label); - }, [setFieldValue]); + const handleSalutationSelect = useCallback( + (salutation) => { + setFieldValue('salutation', salutation.label); + }, + [setFieldValue], + ); // Handle display name field select. - const handleDisplayNameSelect = useCallback((displayName) => { - setFieldValue('display_name', displayName.label); - }, [setFieldValue]); - + const handleDisplayNameSelect = useCallback( + (displayName) => { + setFieldValue('display_name', displayName.label); + }, + [setFieldValue], + ); return (
{/**-----------Customer type. -----------*/} @@ -58,6 +63,7 @@ export default function CustomerFormPrimarySection({ diff --git a/client/src/containers/Customers/CustomerTable.js b/client/src/containers/Customers/CustomerTable.js index 308f77840..909d682b0 100644 --- a/client/src/containers/Customers/CustomerTable.js +++ b/client/src/containers/Customers/CustomerTable.js @@ -10,14 +10,12 @@ import { } from '@blueprintjs/core'; import { FormattedMessage as T, useIntl } from 'react-intl'; -import DataTable from 'components/DataTable'; -import Icon from 'components/Icon'; -import { Money } from 'components'; import { useUpdateEffect } from 'hooks'; import LoadingIndicator from 'components/LoadingIndicator'; -import withCustomers from './withCustomers'; +import { DataTable, Icon, Money } from 'components'; +import withCustomers from './withCustomers'; import { compose, firstLettersArgs, saveInvoke } from 'utils'; const AvatarCell = (row) => { @@ -25,13 +23,13 @@ const AvatarCell = (row) => { }; const CustomerTable = ({ - loading, - //#withCustomers customers, customersLoading, + customerPagination, - //#props + //#OwnProps + loading, onEditCustomer, onDeleteCustomer, onFetchData, @@ -80,18 +78,21 @@ const CustomerTable = ({ ); // Renders actions table cell. - const renderActionsCell = useMemo(() => ({ cell }) => ( - -