From 54400b223f08bc702804155521f0c6b65f6863ba Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Sat, 18 Oct 2025 13:27:05 +0200 Subject: [PATCH] wip --- .../src/components/Select/DisplayNameList.tsx | 96 +++--- .../src/components/Select/SalutationList.tsx | 22 +- .../CustomerForm/CustomerAddressTabs.tsx | 286 +++++++----------- .../CustomerFormAfterPrimarySection.tsx | 74 ++--- .../CustomerFormPrimarySection.tsx | 123 +++----- .../CustomerForm/CustomerNotePanel.tsx | 21 +- .../CustomerForm/CustomerTypeRadioField.tsx | 45 +-- .../Items/ItemFormPrimarySection.tsx | 39 +-- .../VendorFormAfterPrimarySection.tsx | 74 ++--- .../VendorForm/VendorFormPrimarySection.tsx | 139 +++------ 10 files changed, 339 insertions(+), 580 deletions(-) diff --git a/packages/webapp/src/components/Select/DisplayNameList.tsx b/packages/webapp/src/components/Select/DisplayNameList.tsx index 922f02884..d42da993c 100644 --- a/packages/webapp/src/components/Select/DisplayNameList.tsx +++ b/packages/webapp/src/components/Select/DisplayNameList.tsx @@ -1,50 +1,68 @@ -// @ts-nocheck -import React from 'react'; +import React, { useMemo } from 'react'; import intl from 'react-intl-universal'; -import { ListSelect } from './ListSelect'; +import { FSelect } from '../Forms'; +import { useFormikContext } from 'formik'; -export function DisplayNameList({ - salutation, - firstName, - lastName, - company, - ...restProps -}) { - const formats = [ - { - format: '{1} {2} {3}', - values: [salutation, firstName, lastName], - required: [1], +export type DisplayNameListItem = { label: string }; + +export interface DisplayNameListProps + extends Omit< + React.ComponentProps, + 'items' | 'valueAccessor' | 'textAccessor' | 'labelAccessor' + > {} + +export function DisplayNameList({ ...restProps }: DisplayNameListProps) { + const { + values: { + first_name: firstName, + last_name: lastName, + company_name: companyName, + salutation, }, - { format: '{1} {2}', values: [firstName, lastName], required: [] }, - { format: '{1}, {2}', values: [firstName, lastName], required: [1, 2] }, - { format: '{1}', values: [company], required: [1] }, - ]; + } = useFormikContext(); - const formatOptions = formats - .filter( - (format) => - !format.values.some((value, index) => { - return !value && format.required.indexOf(index + 1) !== -1; + const formats = useMemo( + () => [ + { + format: '{1} {2} {3}', + values: [salutation, firstName, lastName], + required: [1], + }, + { format: '{1} {2}', values: [firstName, lastName], required: [] }, + { format: '{1}, {2}', values: [firstName, lastName], required: [1, 2] }, + { format: '{1}', values: [companyName], required: [1] }, + ], + [firstName, lastName, companyName, salutation], + ); + + const formatOptions: DisplayNameListItem[] = useMemo( + () => + formats + .filter( + (format) => + !format.values.some((value, index) => { + return !value && format.required.indexOf(index + 1) !== -1; + }), + ) + .map((formatOption) => { + const { format, values } = formatOption; + let label = format; + + values.forEach((value, index) => { + const replaceWith = value || ''; + label = label.replace(`{${index + 1}}`, replaceWith).trim(); + }); + return { label: label.replace(/\s+/g, ' ') }; }), - ) - .map((formatOption) => { - const { format, values } = formatOption; - let label = format; - - values.forEach((value, index) => { - const replaceWith = value || ''; - label = label.replace(`{${index + 1}}`, replaceWith).trim(); - }); - return { label: label.replace(/\s+/g, ' ') }; - }); + [formats], + ); return ( - diff --git a/packages/webapp/src/components/Select/SalutationList.tsx b/packages/webapp/src/components/Select/SalutationList.tsx index 0ea7a670c..a57dd1229 100644 --- a/packages/webapp/src/components/Select/SalutationList.tsx +++ b/packages/webapp/src/components/Select/SalutationList.tsx @@ -1,10 +1,16 @@ -// @ts-nocheck import React from 'react'; import intl from 'react-intl-universal'; +import { FSelect } from '../Forms'; -import { ListSelect } from './ListSelect'; +export type SalutationItem = { key: string; label: string }; -export function SalutationList({ ...restProps }) { +export interface SalutationListProps + extends Omit< + React.ComponentProps, + 'items' | 'valueAccessor' | 'textAccessor' | 'labelAccessor' + > {} + +export function SalutationList({ ...restProps }: SalutationListProps) { const saluations = [ intl.get('mr'), intl.get('mrs'), @@ -12,17 +18,17 @@ export function SalutationList({ ...restProps }) { intl.get('miss'), intl.get('dr'), ]; - const items = saluations.map((saluation) => ({ + const items: SalutationItem[] = saluations.map((saluation) => ({ key: saluation, label: saluation, })); return ( - diff --git a/packages/webapp/src/containers/Customers/CustomerForm/CustomerAddressTabs.tsx b/packages/webapp/src/containers/Customers/CustomerForm/CustomerAddressTabs.tsx index 07b61e5d3..7005804c7 100644 --- a/packages/webapp/src/containers/Customers/CustomerForm/CustomerAddressTabs.tsx +++ b/packages/webapp/src/containers/Customers/CustomerForm/CustomerAddressTabs.tsx @@ -1,10 +1,12 @@ // @ts-nocheck import React from 'react'; -import { FormGroup, InputGroup, TextArea } from '@blueprintjs/core'; import { Row, Col } from '@/components'; -import { FormattedMessage as T } from '@/components'; -import { FastField, ErrorMessage } from 'formik'; -import { inputIntent } from '@/utils'; +import { + FormattedMessage as T, + FFormGroup, + FInputGroup, + FTextArea, +} from '@/components'; const CustomerBillingAddress = ({}) => { return ( @@ -15,105 +17,65 @@ const CustomerBillingAddress = ({}) => { {/*------------ Billing Address country -----------*/} - - {({ field, field: { value }, meta: { error, touched } }) => ( - } - label={} - > - - - )} - + } + > + + {/*------------ Billing Address 1 -----------*/} - - {({ field, field: { value }, meta: { error, touched } }) => ( - } - className={'form-group--address_line_1'} - intent={inputIntent({ error, touched })} - inline={true} - helperText={} - > -