diff --git a/client/src/containers/Customers/Customer.js b/client/src/containers/Customers/Customer.js
index edf1552f2..2bc2b9a5e 100644
--- a/client/src/containers/Customers/Customer.js
+++ b/client/src/containers/Customers/Customer.js
@@ -42,7 +42,7 @@ function Customer({
const handleFormSubmit = useCallback(
(payload) => {
- payload.redirect && history.push('/customers');
+
},
[history],
);
diff --git a/client/src/containers/Customers/CustomerAddressTabs.js b/client/src/containers/Customers/CustomerAddressTabs.js
index bc6e067b4..63f3824ed 100644
--- a/client/src/containers/Customers/CustomerAddressTabs.js
+++ b/client/src/containers/Customers/CustomerAddressTabs.js
@@ -1,16 +1,11 @@
import React from 'react';
-import { FormGroup, Intent, InputGroup, TextArea } from '@blueprintjs/core';
+import { FormGroup, InputGroup, TextArea } from '@blueprintjs/core';
import { Row, Col } from 'components';
import { FormattedMessage as T } from 'react-intl';
+import { FastField, ErrorMessage } from 'formik';
+import { inputIntent } from 'utils';
-import ErrorMessage from 'components/ErrorMessage';
-
-const CustomerBillingAddress = ({
- errors,
- touched,
- setFieldValue,
- getFieldProps,
-}) => {
+const CustomerBillingAddress = ({}) => {
return (
@@ -19,172 +14,105 @@ const CustomerBillingAddress = ({
{/*------------ Billing Address country -----------*/}
-
- }
- label={}
- >
-
-
+
+ {({ field, field: { value }, meta: { error, touched } }) => (
+ }
+ label={}
+ >
+
+
+ )}
+
+
{/*------------ Billing Address 1 -----------*/}
- }
- className={'form-group--address_line_1'}
- intent={
- errors.billing_address_1 &&
- touched.billing_address_1 &&
- Intent.DANGER
- }
- inline={true}
- helperText={
-
- }
- >
-
-
+
+ {({ field, field: { value }, meta: { error, touched } }) => (
+ }
+ className={'form-group--address_line_1'}
+ intent={inputIntent({ error, touched })}
+ inline={true}
+ helperText={}
+ >
+
+
+ )}
+
+
{/*------------ Billing Address 2 -----------*/}
- }
- className={'form-group--journal-number'}
- intent={
- errors.billing_address_2 &&
- touched.billing_address_2 &&
- Intent.DANGER
- }
- inline={true}
- helperText={
-
- }
- >
-
-
+
+ {({ field, field: { value }, meta: { error, touched } }) => (
+ }
+ className={'form-group--journal-number'}
+ intent={inputIntent({ error, touched })}
+ inline={true}
+ helperText={}
+ >
+
+
+ )}
+
{/*------------ Billing Address city -----------*/}
- }
- className={'form-group--journal-number'}
- intent={
- errors.billing_address_city &&
- touched.billing_address_city &&
- Intent.DANGER
- }
- inline={true}
- helperText={
-
- }
- >
-
-
+
+ {({ field, field: { value }, meta: { error, touched } }) => (
+ }
+ className={'form-group--journal-number'}
+ intent={inputIntent({ error, touched })}
+ inline={true}
+ helperText={}
+ >
+
+
+ )}
+
+
{/*------------ Billing Address state -----------*/}
- }
- className={'form-group--journal-number'}
- intent={
- errors.billing_address_state &&
- touched.billing_address_state &&
- Intent.DANGER
- }
- inline={true}
- helperText={
-
- }
- >
-
-
+
+ {({ field, field: { value }, meta: { error, touched } }) => (
+ }
+ className={'form-group--journal-number'}
+ intent={inputIntent({ error, touched })}
+ inline={true}
+ helperText={}
+ >
+
+
+ )}
+
{/*------------ Billing Address postcode -----------*/}
- }
- intent={
- errors.billing_address_postcode &&
- touched.billing_address_postcode &&
- Intent.DANGER
- }
- inline={true}
- helperText={
-
- }
- >
-
-
+
+ {({ field, field: { value }, meta: { error, touched } }) => (
+ }
+ intent={inputIntent({ error, touched })}
+ inline={true}
+ helperText={}
+ >
+
+
+ )}
+
+
{/*------------ Billing Address phone -----------*/}
- }
- intent={
- errors.billing_address_phone && touched.billing_address_phone && Intent.DANGER
- }
- inline={true}
- helperText={
-
- }
- >
-
-
+
+ {({ field, field: { value }, meta: { error, touched } }) => (
+ }
+ intent={inputIntent({ error, touched })}
+ inline={true}
+ helperText={}
+ >
+
+
+ )}
+
@@ -192,172 +120,107 @@ const CustomerBillingAddress = ({
{/*------------ Shipping Address country -----------*/}
- }
- className={'form-group--journal-number'}
- intent={
- errors.shipping_address_country &&
- touched.shipping_address_country &&
- Intent.DANGER
- }
- inline={true}
- helperText={
-
- }
- >
-
-
+
+ {({ field, field: { value }, meta: { error, touched } }) => (
+ }
+ className={'form-group--journal-number'}
+ intent={inputIntent({ error, touched })}
+ inline={true}
+ helperText={}
+ >
+
+
+ )}
+
+
{/*------------ Shipping Address 1 -----------*/}
- }
- className={'form-group--journal-number'}
- intent={
- errors.shipping_address_1 &&
- touched.shipping_address_1 &&
- Intent.DANGER
- }
- inline={true}
- helperText={
-
- }
- >
-
-
+
+ {({ field, field: { value }, meta: { error, touched } }) => (
+ }
+ className={'form-group--journal-number'}
+ intent={inputIntent({ error, touched })}
+ inline={true}
+ helperText={}
+ >
+
+
+ )}
+
+
{/*------------ Shipping Address 2 -----------*/}
- }
- className={'form-group--journal-number'}
- intent={
- errors.shipping_address_2 &&
- touched.shipping_address_2 &&
- Intent.DANGER
- }
- inline={true}
- helperText={
-
- }
- >
-
-
+
+ {({ field, field: { value }, meta: { error, touched } }) => (
+ }
+ className={'form-group--journal-number'}
+ intent={inputIntent({ error, touched })}
+ inline={true}
+ helperText={}
+ >
+
+
+ )}
+
+
{/*------------ Shipping Address city -----------*/}
- }
- className={'form-group--journal-number'}
- intent={
- errors.shipping_address_city &&
- touched.shipping_address_city &&
- Intent.DANGER
- }
- inline={true}
- helperText={
-
- }
- >
-
-
+
+ {({ field, field: { value }, meta: { error, touched } }) => (
+ }
+ className={'form-group--journal-number'}
+ intent={inputIntent({ error, touched })}
+ inline={true}
+ helperText={}
+ >
+
+
+ )}
+
+
{/*------------ Shipping Address state -----------*/}
- }
- className={'form-group--journal-number'}
- intent={
- errors.shipping_address_state &&
- touched.shipping_address_state &&
- Intent.DANGER
- }
- inline={true}
- helperText={
-
- }
- >
-
-
+
+ {({ field, field: { value }, meta: { error, touched } }) => (
+ }
+ className={'form-group--journal-number'}
+ intent={inputIntent({ error, touched })}
+ inline={true}
+ helperText={}
+ >
+
+
+ )}
+
+
{/*------------ Shipping Address postcode -----------*/}
- }
- intent={
- errors.shipping_address_postcode &&
- touched.shipping_address_postcode &&
- Intent.DANGER
- }
- inline={true}
- helperText={
-
- }
- >
-
-
+
+ {({ field, field: { value }, meta: { error, touched } }) => (
+ }
+ intent={inputIntent({ error, touched })}
+ inline={true}
+ helperText={}
+ >
+
+
+ )}
+
+
{/*------------ Shipping Address phone -----------*/}
- }
- intent={
- errors.shipping_address_phone && touched.shipping_address_phone && Intent.DANGER
- }
- inline={true}
- helperText={
-
- }
- >
-
-
+
+ {({ field, field: { value }, meta: { error, touched } }) => (
+ }
+ intent={inputIntent({ error, touched })}
+ inline={true}
+ helperText={}
+ >
+
+
+ )}
+
diff --git a/client/src/containers/Customers/CustomerFinancialPanel.js b/client/src/containers/Customers/CustomerFinancialPanel.js
index 71edb0189..bea09ca4d 100644
--- a/client/src/containers/Customers/CustomerFinancialPanel.js
+++ b/client/src/containers/Customers/CustomerFinancialPanel.js
@@ -1,27 +1,21 @@
import React, { useCallback, useState } from 'react';
-import moment from 'moment';
import classNames from 'classnames';
-import { FormGroup, Intent, Position, Classes } from '@blueprintjs/core';
+import { FormGroup, Position, Classes } from '@blueprintjs/core';
import { DateInput } from '@blueprintjs/datetime';
-import {
- ErrorMessage,
- MoneyInputGroup,
- CurrencySelectList,
- Row,
- Col,
-} from 'components';
+import { FastField, ErrorMessage } from 'formik';
+import { MoneyInputGroup, CurrencySelectList, Row, Col } from 'components';
import { FormattedMessage as T } from 'react-intl';
import withCurrencies from 'containers/Currencies/withCurrencies';
-import { compose, momentFormatter, tansformDateValue } from 'utils';
+import {
+ compose,
+ momentFormatter,
+ tansformDateValue,
+ inputIntent,
+} from 'utils';
function CustomerFinancialPanel({
- setFieldValue,
- errors,
- touched,
- values,
-
// #withCurrencies
currenciesList,
@@ -29,21 +23,6 @@ function CustomerFinancialPanel({
}) {
const [selectedItems, setSelectedItems] = useState();
- const handleDateChange = useCallback(
- (date) => {
- const formatted = moment(date).format('YYYY-MM-DD');
- setFieldValue('opening_balance_at', formatted);
- },
- [setFieldValue],
- );
-
- const handleMoneyInputChange = useCallback(
- (e, value) => {
- setFieldValue('opening_balance', value);
- },
- [setFieldValue],
- );
-
const onItemsSelect = useCallback(
(filedName) => {
return (filed) => {
@@ -51,77 +30,82 @@ function CustomerFinancialPanel({
...selectedItems,
[filedName]: filed,
});
- setFieldValue(filedName, filed.currency_code);
+ // setFieldValue(filedName, filed.currency_code);
};
},
- [setFieldValue, selectedItems],
+ [selectedItems],
);
return (
{/*------------ Opening balance at -----------*/}
- }
- className={classNames('form-group--select-list', Classes.FILL)}
- intent={
- errors.opening_balance_at &&
- touched.opening_balance_at &&
- Intent.DANGER
- }
- inline={true}
- helperText={
-
- }
- >
-
-
- {/*------------ Opening balance -----------*/}
- }
- className={classNames('form-group--opening-balance', Classes.FILL)}
- intent={
- errors.opening_balance && touched.opening_balance && Intent.DANGER
- }
- inline={true}
- >
-
-
- {/*------------ Currency -----------*/}
- }
- className={classNames(
- 'form-group--select-list',
- 'form-group--balance-currency',
- Classes.FILL,
+
+ {({ form, field: { value }, meta: { error, touched } }) => (
+ }
+ className={classNames('form-group--select-list', Classes.FILL)}
+ intent={inputIntent({ error, touched })}
+ inline={true}
+ helperText={}
+ >
+
+
)}
- inline={true}
- >
- {/* */}
-
-
+
+
+ {/*------------ Opening balance -----------*/}
+
+ {({ field, field: { value }, meta: { error, touched } }) => (
+ }
+ className={classNames(
+ 'form-group--opening-balance',
+ Classes.FILL,
+ )}
+ intent={inputIntent({ error, touched })}
+ inline={true}
+ >
+
+
+ )}
+
+
+ {/*------------ Currency -----------*/}
+
+ {({ form, field: { value }, meta: { error, touched } }) => (
+ }
+ className={classNames(
+ 'form-group--select-list',
+ 'form-group--balance-currency',
+ Classes.FILL,
+ )}
+ inline={true}
+ >
+
+
+ )}
+
diff --git a/client/src/containers/Customers/CustomerForm.js b/client/src/containers/Customers/CustomerForm.js
index bfa5fd523..d8244188b 100644
--- a/client/src/containers/Customers/CustomerForm.js
+++ b/client/src/containers/Customers/CustomerForm.js
@@ -1,6 +1,6 @@
import React, { useState, useMemo, useCallback, useEffect } from 'react';
import * as Yup from 'yup';
-import { useFormik } from 'formik';
+import { useFormik, Formik, Form } from 'formik';
import moment from 'moment';
import { Intent } from '@blueprintjs/core';
import { FormattedMessage as T, useIntl } from 'react-intl';
@@ -23,7 +23,7 @@ import withMediaActions from 'containers/Media/withMediaActions';
import withCustomers from 'containers/Customers//withCustomers';
import useMedia from 'hooks/useMedia';
-import { compose } from 'utils';
+import { compose, saveInvoke } from 'utils';
/**
* Customer form.
@@ -47,13 +47,12 @@ function CustomerForm({
requestDeleteMedia,
// #Props
+ customerId,
onFormSubmit,
onCancelForm,
}) {
const { formatMessage } = useIntl();
const history = useHistory();
- const [payload, setPayload] = useState({});
-
const {
setFiles,
saveMedia,
@@ -129,7 +128,7 @@ function CustomerForm({
billing_address_2: '',
billing_address_city: '',
billing_address_state: '',
- billing_address_postcode: null,
+ billing_address_postcode: '',
billing_address_phone: '',
shipping_address_country: '',
@@ -137,7 +136,7 @@ function CustomerForm({
shipping_address_2: '',
shipping_address_city: '',
shipping_address_state: '',
- shipping_address_postcode: null,
+ shipping_address_postcode: '',
shipping_address_phone: '',
opening_balance: '',
@@ -160,14 +159,6 @@ function CustomerForm({
[customer, defaultInitialValues],
);
- const saveInvokeSubmit = useCallback(
- (payload) => {
- onFormSubmit && onFormSubmit(payload);
- },
-
- [onFormSubmit],
- );
-
useEffect(() => {
customer && customer.id
? changePageTitle(formatMessage({ id: 'edit_customer' }))
@@ -178,7 +169,7 @@ function CustomerForm({
values,
{ setSubmitting, resetForm, setErrors },
) => {
- const formValues = { ...values, status: payload.publish };
+ const formValues = { ...values };
if (customer && customer.id) {
requestEditCustomer(customer.id, formValues)
.then((response) => {
@@ -190,7 +181,6 @@ function CustomerForm({
});
setSubmitting(false);
resetForm();
- saveInvokeSubmit({ action: 'update', ...payload });
})
.catch((errors) => {
setSubmitting(false);
@@ -205,7 +195,6 @@ function CustomerForm({
intent: Intent.SUCCESS,
});
setSubmitting(false);
- saveInvokeSubmit({ action: 'new', ...payload });
})
.catch((errors) => {
setSubmitting(false);
@@ -213,23 +202,6 @@ function CustomerForm({
}
};
- const {
- setFieldValue,
- getFieldProps,
- errors,
- values,
- touched,
- isSubmitting,
- handleSubmit,
- } = useFormik({
- enableReinitialize: true,
- validationSchema: validationSchema,
- initialValues: {
- ...initialValues,
- },
- onSubmit: handleFormSubmit,
- });
-
const initialAttachmentFiles = useMemo(() => {
return customer && customer.media
? customer.media.map((attach) => ({
@@ -254,65 +226,44 @@ function CustomerForm({
},
[setDeletedFiles, deletedFiles],
);
- const handleSubmitClick = useCallback(
- (payload) => {
- setPayload(payload);
- handleSubmit();
- },
- [setPayload, handleSubmit],
- );
-
const handleCancelClick = useCallback(
- (payload) => {
- onCancelForm && onCancelForm(payload);
+ (payload, event) => {
+
},
- [onCancelForm],
+ [],
);
return (
);
}
diff --git a/client/src/containers/Customers/CustomerFormAfterPrimarySection.js b/client/src/containers/Customers/CustomerFormAfterPrimarySection.js
index 25e3436f8..87ca54a4d 100644
--- a/client/src/containers/Customers/CustomerFormAfterPrimarySection.js
+++ b/client/src/containers/Customers/CustomerFormAfterPrimarySection.js
@@ -1,35 +1,26 @@
import React from 'react';
-import {
- FormGroup,
- Intent,
- InputGroup,
- ControlGroup,
-} from '@blueprintjs/core';
+import { FormGroup, InputGroup, ControlGroup } from '@blueprintjs/core';
+import { FastField, ErrorMessage } from 'formik';
import { FormattedMessage as T } from 'react-intl';
-import { ErrorMessage } from 'components';
+import { inputIntent } from 'utils';
-export default function CustomerFormAfterPrimarySection({
- setFieldValue,
- getFieldProps,
- errors,
- values,
- touched,
-}) {
+export default function CustomerFormAfterPrimarySection({}) {
return (
{/*------------ Customer email -----------*/}
- }
- className={'form-group--email'}
- label={}
- inline={true}
- >
-
-
+
+ {({ field, meta: { error, touched } }) => (
+ }
+ className={'form-group--email'}
+ label={}
+ inline={true}
+ >
+
+
+ )}
+
{/*------------ Phone number -----------*/}
-
-
-
+
+ {({ field, meta: { error, touched } }) => (
+
+ )}
+
+
+ {({ field, meta: { error, touched } }) => (
+
+ )}
+
{/*------------ Customer website -----------*/}
- }
- className={'form-group--website'}
- label={}
- inline={true}
- >
-
-
+
+ {({ field, meta: { error, touched } }) => (
+ }
+ className={'form-group--website'}
+ label={}
+ inline={true}
+ >
+
+
+ )}
+
);
}
diff --git a/client/src/containers/Customers/CustomerFormPrimarySection.js b/client/src/containers/Customers/CustomerFormPrimarySection.js
index f649c288a..46afad8a1 100644
--- a/client/src/containers/Customers/CustomerFormPrimarySection.js
+++ b/client/src/containers/Customers/CustomerFormPrimarySection.js
@@ -1,58 +1,27 @@
-import React, { useMemo, useCallback } from 'react';
+import React from 'react';
import classNames from 'classnames';
-import { FormGroup, Intent, InputGroup, ControlGroup } from '@blueprintjs/core';
+import { FormGroup, InputGroup, ControlGroup } from '@blueprintjs/core';
+import { FastField, Field, ErrorMessage } from 'formik';
import { FormattedMessage as T } from 'react-intl';
import {
Hint,
FieldRequiredHint,
SalutationList,
DisplayNameList,
- ErrorMessage,
- Row,
- Col,
} from 'components';
import CustomerTypeRadioField from 'containers/Customers/CustomerTypeRadioField';
import { CLASSES } from 'common/classes';
+import { inputIntent } from 'utils';
/**
* Customer form primary section.
*/
export default function CustomerFormPrimarySection({
- setFieldValue,
- getFieldProps,
- errors,
- values,
- touched,
}) {
- const handleCustomerTypeCahange = useCallback(
- (value) => {
- setFieldValue('customer_type', value);
- },
- [setFieldValue],
- );
-
- // Handle salutation field select.
- const handleSalutationSelect = useCallback(
- (salutation) => {
- setFieldValue('salutation', salutation.label);
- },
- [setFieldValue],
- );
-
- // Handle display name field select.
- const handleDisplayNameSelect = useCallback(
- (displayName) => {
- setFieldValue('display_name', displayName.label);
- },
- [setFieldValue],
- );
return (
{/**-----------Customer type. -----------*/}
-
+
{/**----------- Contact name -----------*/}
-
+ {({ form, field: { value }, meta: { error, touched } }) => (
+ {
+ form.setFieldValue('salutation', salutation.label);
+ }}
+ selectedItem={value}
+ popoverProps={{ minimal: true }}
+ className={classNames(
+ CLASSES.FORM_GROUP_LIST_SELECT,
+ CLASSES.FILL,
+ 'input-group--salutation-list',
+ 'select-list--fill-button',
+ )}
+ />
)}
- />
-
-
+
+
+
+ {({ field, meta: { error, touched } }) => (
+
+ )}
+
+
+
+ {({ field, meta: { error, touched } }) => (
+
+ )}
+
{/*----------- Company Name -----------*/}
- }
- intent={errors.company_name && touched.company_name && Intent.DANGER}
- helperText={
-
- }
- inline={true}
- >
-
-
+
+ {({ field, meta: { error, touched } }) => (
+ }
+ intent={inputIntent({ error, touched })}
+ helperText={}
+ inline={true}
+ >
+
+
+ )}
+
{/*----------- Display Name -----------*/}
-
- }
- label={
- <>
-
-
-
- >
- }
- className={classNames(CLASSES.FORM_GROUP_LIST_SELECT, CLASSES.FILL)}
- inline={true}
- >
-
-
+
+ {({ form, field: { value }, meta: { error, touched } }) => (
+ }
+ intent={inputIntent({ error, touched })}
+ label={
+ <>
+
+
+
+ >
+ }
+ className={classNames(CLASSES.FORM_GROUP_LIST_SELECT, CLASSES.FILL)}
+ inline={true}
+ >
+ {
+ form.setFieldValue('display_name', displayName.label);
+ }}
+ selectedItem={value}
+ popoverProps={{ minimal: true }}
+ />
+
+ )}
+
);
}
diff --git a/client/src/containers/Customers/CustomerNotePanel.js b/client/src/containers/Customers/CustomerNotePanel.js
index 32cd1f8e7..a258d5a08 100644
--- a/client/src/containers/Customers/CustomerNotePanel.js
+++ b/client/src/containers/Customers/CustomerNotePanel.js
@@ -1,27 +1,25 @@
import React from 'react';
import classNames from 'classnames';
-import { FormGroup, Intent, TextArea, Classes } from '@blueprintjs/core';
-import { Row, Col } from 'components';
+import { FormGroup, TextArea, Classes } from '@blueprintjs/core';
+import { FastField, ErrorMessage } from 'formik';
import { FormattedMessage as T } from 'react-intl';
-import ErrorMessage from 'components/ErrorMessage';
+import { inputIntent } from 'utils';
export default function CustomerNotePanel({ errors, touched, getFieldProps }) {
return (
- }
- className={classNames('form-group--note', Classes.FILL)}
- intent={errors.note && touched.note && Intent.DANGER}
- helperText={
-
- }
- >
-
-
+
+ {({ field, field: { value }, meta: { error, touched } }) => (
+ }
+ className={classNames('form-group--note', Classes.FILL)}
+ intent={inputIntent({ error, touched })}
+ helperText={}
+ >
+
+
+ )}
+
);
}
-
\ No newline at end of file
diff --git a/client/src/containers/Customers/CustomerTypeRadioField.js b/client/src/containers/Customers/CustomerTypeRadioField.js
index 9e0fb796b..39faef15c 100644
--- a/client/src/containers/Customers/CustomerTypeRadioField.js
+++ b/client/src/containers/Customers/CustomerTypeRadioField.js
@@ -2,8 +2,9 @@ import React from 'react';
import classNames from 'classnames';
import { RadioGroup, Radio, FormGroup } from '@blueprintjs/core';
import { FormattedMessage as T, useIntl } from 'react-intl';
+import { FastField } from 'formik';
-import { handleStringChange } from 'utils';
+import { handleStringChange, saveInvoke } from 'utils';
/**
* Customer type radio field.
@@ -13,20 +14,29 @@ export default function RadioCustomer(props) {
const { formatMessage } = useIntl();
return (
- }
- className={classNames('form-group--customer_type')}>
- {
- onChange && onChange(value);
- })}
- {...rest}
- >
-
-
-
-
+
+ {({ form, field: { value }, meta: { error, touched } }) => (
+ }
+ className={classNames('form-group--customer_type')}
+ >
+ {
+ saveInvoke(onChange, value);
+ form.setFieldValue('customer_type', value);
+ })}
+ selectedValue={value}
+ >
+
+
+
+
+ )}
+
);
}
diff --git a/client/src/containers/Customers/CustomersTabs.js b/client/src/containers/Customers/CustomersTabs.js
index 02a76273b..15a6331bf 100644
--- a/client/src/containers/Customers/CustomersTabs.js
+++ b/client/src/containers/Customers/CustomersTabs.js
@@ -15,8 +15,7 @@ export default function CustomersTabs({
customerId,
}) {
const { formatMessage } = useIntl();
- const [customer] = useState(customerId);
-
+
return (
- }
+ panel={
}
/>
- }
+ panel={
}
/>
- }
+ panel={
}
/>
{
+ const normalizedTitle = category.name.toLowerCase();
+ const normalizedQuery = query.toLowerCase();
+
+ if (exactMatch) {
+ return normalizedTitle === normalizedQuery;
+ } else {
+ return normalizedTitle.indexOf(normalizedQuery) >= 0;
+ }
+ },
+ [],
+ );
+
+ const parentCategoryItem = useCallback(
+ (category, { handleClick, modifiers, query }) => {
+ return (
+
+ );
+ },
+ [],
+ );
+
+ return (
+
+ );
+}
diff --git a/client/src/containers/Dialogs/ItemCategoryDialog/ItemCategoryFormDialogContent.js b/client/src/containers/Dialogs/ItemCategoryDialog/ItemCategoryFormDialogContent.js
index 201c62820..15d38be8e 100644
--- a/client/src/containers/Dialogs/ItemCategoryDialog/ItemCategoryFormDialogContent.js
+++ b/client/src/containers/Dialogs/ItemCategoryDialog/ItemCategoryFormDialogContent.js
@@ -1,27 +1,10 @@
-import React, { useState, useMemo, useCallback } from 'react';
-import {
- Button,
- Classes,
- FormGroup,
- InputGroup,
- Intent,
- TextArea,
- MenuItem,
-} from '@blueprintjs/core';
+import React, { useMemo } from 'react';
+import { Intent } from '@blueprintjs/core';
import * as Yup from 'yup';
-import { useFormik } from 'formik';
import { useQuery, queryCache } from 'react-query';
import { FormattedMessage as T, useIntl } from 'react-intl';
-import classNames from 'classnames';
-import {
- ListSelect,
- AccountsSelectList,
- FieldRequiredHint,
- Hint,
- AppToaster,
- ErrorMessage,
- DialogContent,
-} from 'components';
+import { Formik } from 'formik';
+import { AppToaster, DialogContent } from 'components';
import withItemCategories from 'containers/Items/withItemCategories';
import withItemCategoryDetail from 'containers/Items/withItemCategoryDetail';
@@ -32,6 +15,7 @@ import withAccountsActions from 'containers/Accounts/withAccountsActions';
import withDialogActions from 'containers/Dialog/withDialogActions';
import { compose, transformToForm } from 'utils';
+import ItemCategoryForm from './ItemCategoryForm';
const defaultInitialValues = {
name: '',
@@ -75,7 +59,6 @@ function ItemCategoryFormDialogContent({
const isNewMode = !itemCategoryId;
const { formatMessage } = useIntl();
- const [selectedParentCategory, setParentCategory] = useState(null);
// Fetches categories list.
const fetchCategoriesList = useQuery(['items-categories-list'], () =>
@@ -138,237 +121,24 @@ function ItemCategoryFormDialogContent({
}
};
- // Formik
- const {
- values,
- errors,
- touched,
- isSubmitting,
- setFieldValue,
- handleSubmit,
- getFieldProps,
- } = useFormik({
- enableReinitialize: true,
- validationSchema,
- initialValues,
- onSubmit: handleFormSubmit,
- });
-
- // Filters Item Categories list.
- const filterItemCategories = useCallback(
- (query, category, _index, exactMatch) => {
- const normalizedTitle = category.name.toLowerCase();
- const normalizedQuery = query.toLowerCase();
-
- if (exactMatch) {
- return normalizedTitle === normalizedQuery;
- } else {
- return normalizedTitle.indexOf(normalizedQuery) >= 0;
- }
- },
- [],
- );
-
- const parentCategoryItem = useCallback(
- (category, { handleClick, modifiers, query }) => {
- return (
-
- );
- },
- [],
- );
-
- // Handle the dialog closing.
- const handleClose = useCallback(() => {
- closeDialog(dialogName);
- }, [dialogName, closeDialog]);
-
- const onChangeParentCategory = useCallback(
- (parentCategory) => {
- setParentCategory(parentCategory);
- setFieldValue('parent_category_id', parentCategory.id);
- },
- [setFieldValue],
- );
-
- const onItemAccountSelect = useCallback(
- (filedName) => {
- return (account) => {
- setFieldValue(filedName, account.id);
- };
- },
- [setFieldValue],
- );
-
return (
-
+
+ {({ isSubmitting }) => (
+
+ )}
+
);
}
diff --git a/client/src/containers/Items/ItemForm.js b/client/src/containers/Items/ItemForm.js
index 09341f0cc..670a666fe 100644
--- a/client/src/containers/Items/ItemForm.js
+++ b/client/src/containers/Items/ItemForm.js
@@ -1,10 +1,9 @@
import React, { useMemo, useCallback, useEffect } from 'react';
import * as Yup from 'yup';
-import { useFormik, Formik, Form } from 'formik';
+import { Formik, Form } from 'formik';
import { Intent } from '@blueprintjs/core';
import { queryCache } from 'react-query';
import { useHistory } from 'react-router-dom';
-import { pick, pickBy } from 'lodash';
import { useIntl } from 'react-intl';
import classNames from 'classnames';
diff --git a/client/src/containers/Items/ItemFormBody.js b/client/src/containers/Items/ItemFormBody.js
index 12b92040c..27f23726c 100644
--- a/client/src/containers/Items/ItemFormBody.js
+++ b/client/src/containers/Items/ItemFormBody.js
@@ -2,7 +2,6 @@ import React from 'react';
import { FastField, ErrorMessage } from 'formik';
import {
FormGroup,
- Intent,
Classes,
Checkbox,
} from '@blueprintjs/core';
diff --git a/client/src/containers/Items/ItemFormFloatingActions.js b/client/src/containers/Items/ItemFormFloatingActions.js
index 7e0a7eff0..ab32bfa99 100644
--- a/client/src/containers/Items/ItemFormFloatingActions.js
+++ b/client/src/containers/Items/ItemFormFloatingActions.js
@@ -20,7 +20,7 @@ export default function ItemFormFloatingActions({ isSubmitting, itemId, onCancel
);
-}
-
-// function areEqual(prevProps, nextProps) {
-// return prevProps.isSubmitting === nextProps.isSubmitting;
-// }
-
-// export default memo(ItemFormFloatingActions, areEqual);
+}
\ No newline at end of file
diff --git a/client/src/containers/Items/ItemFormInventorySection.js b/client/src/containers/Items/ItemFormInventorySection.js
index af246f10d..42fa52166 100644
--- a/client/src/containers/Items/ItemFormInventorySection.js
+++ b/client/src/containers/Items/ItemFormInventorySection.js
@@ -1,6 +1,6 @@
import React from 'react';
-import { Field, FastField, ErrorMessage } from 'formik';
-import { FormGroup, Intent, InputGroup, Position } from '@blueprintjs/core';
+import { FastField, ErrorMessage } from 'formik';
+import { FormGroup, InputGroup, Position } from '@blueprintjs/core';
import { DateInput } from '@blueprintjs/datetime';
import { AccountsSelectList, Col, Row, Hint } from 'components';
import { CLASSES } from 'common/classes';
diff --git a/client/src/containers/Items/ItemFormPrimarySection.js b/client/src/containers/Items/ItemFormPrimarySection.js
index e63ec625d..9411779f5 100644
--- a/client/src/containers/Items/ItemFormPrimarySection.js
+++ b/client/src/containers/Items/ItemFormPrimarySection.js
@@ -1,7 +1,6 @@
import React, { useMemo } from 'react';
import {
FormGroup,
- Intent,
InputGroup,
RadioGroup,
Classes,
@@ -104,10 +103,7 @@ function ItemFormPrimarySection({
helperText={}
inline={true}
>
-
+
)}
@@ -117,16 +113,12 @@ function ItemFormPrimarySection({
{({ field, meta: { error, touched } }) => (
}
- labelInfo={}
- className={' -group--item-sku'}
+ className={'form-group--item_code'}
intent={inputIntent({ error, touched })}
helperText={}
inline={true}
>
-
+
)}