From 9241f8b8a53eaa4620672c93a1d4c2142fe68313 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Sun, 8 Nov 2020 21:44:20 +0200 Subject: [PATCH] feat: customer form styling. feat: customers list. --- client/src/components/DataTable.js | 2 - .../Customers/CustomerAddressTabs.js | 6 +- .../Customers/CustomerFinancialPanel.js | 2 +- .../src/containers/Customers/CustomerForm.js | 75 +++--- .../Customers/CustomerFormPrimarySection.js | 10 +- .../containers/Customers/CustomerNotePanel.js | 37 ++- .../src/containers/Customers/CustomerTable.js | 117 ++++++---- .../src/containers/Customers/CustomersList.js | 5 +- client/src/lang/en/index.js | 3 +- .../src/store/customers/customers.actions.js | 2 +- client/src/style/pages/customer.scss | 219 ++++++------------ .../src/api/controllers/Contacts/Contacts.ts | 8 +- .../src/api/controllers/Contacts/Customers.ts | 17 +- .../20200104232644_create_contacts_table.js | 11 +- server/src/interfaces/Contact.ts | 18 +- .../src/services/Contacts/ContactsService.ts | 32 ++- .../src/services/Contacts/CustomersService.ts | 23 +- 17 files changed, 305 insertions(+), 282 deletions(-) diff --git a/client/src/components/DataTable.js b/client/src/components/DataTable.js index 7a9134a27..84ae9520a 100644 --- a/client/src/components/DataTable.js +++ b/client/src/components/DataTable.js @@ -12,8 +12,6 @@ import { Checkbox, Spinner, ContextMenu, - Menu, - MenuItem, } from '@blueprintjs/core'; import classnames from 'classnames'; import { FixedSizeList } from 'react-window'; diff --git a/client/src/containers/Customers/CustomerAddressTabs.js b/client/src/containers/Customers/CustomerAddressTabs.js index a9071d816..79c2bb158 100644 --- a/client/src/containers/Customers/CustomerAddressTabs.js +++ b/client/src/containers/Customers/CustomerAddressTabs.js @@ -12,11 +12,7 @@ const CustomerBillingAddress = ({ getFieldProps, }) => { return ( -
+

diff --git a/client/src/containers/Customers/CustomerFinancialPanel.js b/client/src/containers/Customers/CustomerFinancialPanel.js index e286798ab..548165c64 100644 --- a/client/src/containers/Customers/CustomerFinancialPanel.js +++ b/client/src/containers/Customers/CustomerFinancialPanel.js @@ -28,7 +28,7 @@ export default function CustomerFinancialPanel({ ); return ( -
+
{ customer && customer.id - ? changePageTitle(formatMessage({ id: 'edit_customer_details' })) + ? changePageTitle(formatMessage({ id: 'edit_customer' })) : changePageTitle(formatMessage({ id: 'new_customer' })); }, [changePageTitle, customer, formatMessage]); + const handleFormSubmit = (values, { setSubmitting, resetForm, setErrors }) => { + const formValues = { ...values, status: payload.publish }; + if (customer && customer.id) { + requestEditCustomer(customer.id, formValues) + .then((response) => { + AppToaster.show({ + message: formatMessage({ + id: 'the_item_customer_has_been_successfully_edited', + }), + intent: Intent.SUCCESS, + }); + setSubmitting(false); + resetForm(); + saveInvokeSubmit({ action: 'update', ...payload }); + }) + .catch((errors) => { + setSubmitting(false); + }); + } else { + requestSubmitCustomer(formValues) + .then((response) => { + AppToaster.show({ + message: formatMessage({ + id: 'the_customer_has_been_successfully_created', + }), + intent: Intent.SUCCESS, + }); + setSubmitting(false); + saveInvokeSubmit({ action: 'new', ...payload }); + }) + .catch((errors) => { + setSubmitting(false); + }); + } + }; + const { setFieldValue, getFieldProps, @@ -160,42 +196,7 @@ function CustomerForm({ initialValues: { ...initialValues, }, - onSubmit: (values, { setSubmitting, resetForm, setErrors }) => { - const formValues = { ...values, status: payload.publish }; - if (customer && customer.id) { - requestEditCustomer(customer.id, formValues) - .then((response) => { - AppToaster.show({ - message: formatMessage({ - id: 'the_item_customer_has_been_successfully_edited', - }), - intent: Intent.SUCCESS, - }); - setSubmitting(false); - resetForm(); - saveInvokeSubmit({ action: 'update', ...payload }); - }) - .catch((errors) => { - setSubmitting(false); - }); - } else { - requestSubmitCustomer(formValues) - .then((response) => { - AppToaster.show({ - message: formatMessage({ - id: 'the_customer_has_been_successfully_created', - }), - intent: Intent.SUCCESS, - }); - // history.push('/customers'); - setSubmitting(false); - saveInvokeSubmit({ action: 'new', ...payload }); - }) - .catch((errors) => { - setSubmitting(false); - }); - } - }, + onSubmit: handleFormSubmit, }); diff --git a/client/src/containers/Customers/CustomerFormPrimarySection.js b/client/src/containers/Customers/CustomerFormPrimarySection.js index 611b44d73..2b8c22371 100644 --- a/client/src/containers/Customers/CustomerFormPrimarySection.js +++ b/client/src/containers/Customers/CustomerFormPrimarySection.js @@ -32,13 +32,14 @@ export default function CustomerFormPrimarySection({ ); // Handle salutation field select. - const handleSalutationSelect = (salutation) => { + const handleSalutationSelect = useCallback((salutation) => { setFieldValue('salutation', salutation.label); - }; + }, [setFieldValue]); + // Handle display name field select. - const handleDisplayNameSelect = (displayName) => { + const handleDisplayNameSelect = useCallback((displayName) => { setFieldValue('display_name', displayName.label); - }; + }, [setFieldValue]); return (
@@ -116,6 +117,7 @@ export default function CustomerFormPrimarySection({ firstName={values.first_name} lastName={values.last_name} company={values.company_name} + salutation={values.salutation} onItemSelect={handleDisplayNameSelect} popoverProps={{ minimal: true }} /> diff --git a/client/src/containers/Customers/CustomerNotePanel.js b/client/src/containers/Customers/CustomerNotePanel.js index f3806bb17..32cd1f8e7 100644 --- a/client/src/containers/Customers/CustomerNotePanel.js +++ b/client/src/containers/Customers/CustomerNotePanel.js @@ -7,28 +7,21 @@ import ErrorMessage from 'components/ErrorMessage'; export default function CustomerNotePanel({ errors, touched, getFieldProps }) { return ( -
- - - } - className={classNames('form-group--select-list', Classes.FILL)} - intent={errors.note && touched.note && Intent.DANGER} - helperText={ - - } - > -