From 229eeaf1427463fbc8028a758a16e92c9bfcd020 Mon Sep 17 00:00:00 2001 From: elforjani3 Date: Sun, 22 Nov 2020 15:42:18 +0200 Subject: [PATCH] Fix: Add prepend and money field group to customer & vendors --- .../Customers/CustomerFinancialPanel.js | 51 ++++++++++--------- .../src/containers/Customers/CustomerForm.js | 8 +++ .../Vendors/VendorFinanicalPanelTab.js | 40 ++++++++++----- client/src/containers/Vendors/VendorForm.js | 8 +++ 4 files changed, 69 insertions(+), 38 deletions(-) diff --git a/client/src/containers/Customers/CustomerFinancialPanel.js b/client/src/containers/Customers/CustomerFinancialPanel.js index c8a0d39c8..295479938 100644 --- a/client/src/containers/Customers/CustomerFinancialPanel.js +++ b/client/src/containers/Customers/CustomerFinancialPanel.js @@ -1,9 +1,15 @@ import React, { useCallback, useState } from 'react'; import classNames from 'classnames'; -import { FormGroup, Position, Classes } from '@blueprintjs/core'; +import { FormGroup, Position, Classes, ControlGroup } from '@blueprintjs/core'; import { DateInput } from '@blueprintjs/datetime'; import { FastField, ErrorMessage } from 'formik'; -import { MoneyInputGroup, CurrencySelectList, Row, Col } from 'components'; +import { + MoneyInputGroup, + InputPrependText, + CurrencySelectList, + Row, + Col, +} from 'components'; import { FormattedMessage as T } from 'react-intl'; import withCurrencies from 'containers/Currencies/withCurrencies'; @@ -21,20 +27,7 @@ function CustomerFinancialPanel({ customerId, }) { - const [selectedItems, setSelectedItems] = useState(); - const onItemsSelect = useCallback( - (filedName) => { - return (filed) => { - setSelectedItems({ - ...selectedItems, - [filedName]: filed, - }); - // setFieldValue(filedName, filed.currency_code); - }; - }, - [selectedItems], - ); return (
@@ -52,7 +45,6 @@ function CustomerFinancialPanel({ @@ -62,7 +54,12 @@ function CustomerFinancialPanel({ {/*------------ Opening balance -----------*/} - {({ field, field: { value }, meta: { error, touched } }) => ( + {({ + form: { values }, + field, + field: { value }, + meta: { error, touched }, + }) => ( } className={classNames( @@ -72,13 +69,15 @@ function CustomerFinancialPanel({ intent={inputIntent({ error, touched })} inline={true} > - + + + + )} @@ -98,7 +97,9 @@ function CustomerFinancialPanel({ { + form.setFieldValue('currency_code', currency.currency_code); + }} disabled={customerId} /> diff --git a/client/src/containers/Customers/CustomerForm.js b/client/src/containers/Customers/CustomerForm.js index 8c0d5ac62..ffbddf34e 100644 --- a/client/src/containers/Customers/CustomerForm.js +++ b/client/src/containers/Customers/CustomerForm.js @@ -20,6 +20,7 @@ import withCustomerDetail from 'containers/Customers/withCustomerDetail'; import withCustomersActions from 'containers/Customers/withCustomersActions'; import withMediaActions from 'containers/Media/withMediaActions'; import withCustomers from 'containers/Customers//withCustomers'; +import withSettings from 'containers/Settings/withSettings'; import useMedia from 'hooks/useMedia'; import { compose, transformToForm } from 'utils'; @@ -73,6 +74,9 @@ function CustomerForm({ // #withCustomerDetail customer, + // #withSettings + baseCurrency, + // #withCustomersActions requestSubmitCustomer, requestEditCustomer, @@ -151,6 +155,7 @@ function CustomerForm({ const initialValues = useMemo( () => ({ ...defaultInitialValues, + currency_code: baseCurrency, ...transformToForm(customer, defaultInitialValues), }), [customer, defaultInitialValues], @@ -271,6 +276,9 @@ export default compose( withCustomers(({ customers }) => ({ customers, })), + withSettings(({ organizationSettings }) => ({ + baseCurrency: organizationSettings?.baseCurrency, + })), withDashboardActions, withCustomersActions, withMediaActions, diff --git a/client/src/containers/Vendors/VendorFinanicalPanelTab.js b/client/src/containers/Vendors/VendorFinanicalPanelTab.js index d4b15ef79..86929939e 100644 --- a/client/src/containers/Vendors/VendorFinanicalPanelTab.js +++ b/client/src/containers/Vendors/VendorFinanicalPanelTab.js @@ -1,9 +1,15 @@ import React from 'react'; import classNames from 'classnames'; -import { FormGroup, Position, Classes } from '@blueprintjs/core'; +import { FormGroup, ControlGroup, Position, Classes } from '@blueprintjs/core'; import { DateInput } from '@blueprintjs/datetime'; import { FastField, ErrorMessage } from 'formik'; -import { MoneyInputGroup, CurrencySelectList, Row, Col } from 'components'; +import { + MoneyInputGroup, + InputPrependText, + CurrencySelectList, + Row, + Col, +} from 'components'; import { FormattedMessage as T } from 'react-intl'; import withCurrencies from 'containers/Currencies/withCurrencies'; @@ -50,7 +56,12 @@ function VendorFinanicalPanelTab({ {/*------------ Opening balance -----------*/} - {({ field, field: { value }, meta: { error, touched } }) => ( + {({ + form: { values }, + field, + field: { value }, + meta: { error, touched }, + }) => ( } className={classNames( @@ -60,16 +71,19 @@ function VendorFinanicalPanelTab({ intent={inputIntent({ error, touched })} inline={true} > - + + + + )} diff --git a/client/src/containers/Vendors/VendorForm.js b/client/src/containers/Vendors/VendorForm.js index 923c28a89..23b760735 100644 --- a/client/src/containers/Vendors/VendorForm.js +++ b/client/src/containers/Vendors/VendorForm.js @@ -22,6 +22,7 @@ import VendorFloatingActions from './VendorFloatingActions'; import withDashboardActions from 'containers/Dashboard/withDashboardActions'; import withVendorDetail from './withVendorDetail'; import withVendorActions from './withVendorActions'; +import withSettings from 'containers/Settings/withSettings'; import { compose, transformToForm } from 'utils'; @@ -73,6 +74,9 @@ function VendorForm({ requestSubmitVendor, requestEditVendor, + // #withSettings + baseCurrency, + // #OwnProps vendorId, }) { @@ -88,6 +92,7 @@ function VendorForm({ const initialValues = useMemo( () => ({ ...defaultInitialValues, + currency_code: baseCurrency, ...transformToForm(vendor, defaultInitialValues), }), [defaultInitialValues], @@ -181,5 +186,8 @@ function VendorForm({ export default compose( withVendorDetail(), withDashboardActions, + withSettings(({ organizationSettings }) => ({ + baseCurrency: organizationSettings?.baseCurrency, + })), withVendorActions, )(VendorForm);