Skip to content

Commit

Permalink
fix: account Form Fields Display Name not updating correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianJiang2021 authored and libruce committed Dec 27, 2023
1 parent 755b43b commit 8a19e20
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 66 deletions.
14 changes: 2 additions & 12 deletions apps/storefront/src/pages/accountSetting/AccountSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
updateBCAccountSettings,
} from '@/shared/service/b2b'
import { Fields, ParamProps } from '@/types/accountSetting'
import { B3SStorage, manipulateString, snackbar } from '@/utils'
import { B3SStorage, snackbar } from '@/utils'

import { getAccountFormFields } from '../registered/config'

Expand Down Expand Up @@ -288,16 +288,6 @@ function AccountSetting() {
})()
}

const convertLabel = (infos: Partial<Fields>[]) =>
infos.map((info: Partial<Fields>) => {
const { label } = info
if (label) {
info.label = manipulateString(label)
}

return info
}) || []

return (
<B3Sping isSpinning={isloadding} background={backgroundColor}>
<Box
Expand Down Expand Up @@ -325,7 +315,7 @@ function AccountSetting() {
}}
>
<B3CustomForm
formFields={convertLabel(accountInfoFormFields)}
formFields={accountInfoFormFields}
errors={errors}
control={control}
getValues={getValues}
Expand Down
11 changes: 2 additions & 9 deletions apps/storefront/src/pages/address/Address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
getB2BCountries,
getBCCustomerAddress,
} from '@/shared/service/b2b'
import { manipulateString, snackbar } from '@/utils'
import { snackbar } from '@/utils'

import B3Filter from '../../components/filter/B3Filter'
import {
Expand Down Expand Up @@ -87,14 +87,7 @@ function Address() {
!isBCPermission,
countries
)
const newAddressFields =
addressFields?.map((field) => {
const { label } = field
if (label) field.label = manipulateString(label)

return field
}) || []
setAddressFields(newAddressFields)
setAddressFields(addressFields || [])
} catch (err) {
console.log(err)
} finally {
Expand Down
8 changes: 3 additions & 5 deletions apps/storefront/src/pages/registered/RegisterComplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
sendSubscribersState,
uploadB2BFile,
} from '@/shared/service/b2b'
import { convertLabel, manipulateString, storeHash } from '@/utils'
import { storeHash } from '@/utils'

import RegisteredStepButton from './component/RegisteredStepButton'
import { RegisteredContext } from './context/RegisteredContext'
Expand Down Expand Up @@ -85,11 +85,9 @@ export default function RegisterComplete(props: RegisterCompleteProps) {
const list: RegisterCompleteList =
accountType === '1' ? contactInformation : bcContactInformation
const passwordInfo: RegisterCompleteList =
accountType === '1'
? convertLabel(passwordInformation)
: convertLabel(bcPasswordInformation)
accountType === '1' ? passwordInformation : bcPasswordInformation

const passwordName = manipulateString(passwordInfo[0]?.groupName) || ''
const passwordName = passwordInfo[0]?.groupName || ''

const additionalInfo: RegisterCompleteList =
accountType === '1' ? additionalInformation : bcAdditionalInformation
Expand Down
17 changes: 5 additions & 12 deletions apps/storefront/src/pages/registered/RegisteredAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { CustomStyleContext } from '@/shared/customStyleButtton'
import { GlobaledContext } from '@/shared/global'
import { checkUserBCEmail, checkUserEmail } from '@/shared/service/b2b'
import { themeFrameSelector } from '@/store'
import { convertLabel, manipulateString } from '@/utils'

import RegisteredStepButton from './component/RegisteredStepButton'
import { RegisteredContext } from './context/RegisteredContext'
Expand Down Expand Up @@ -79,37 +78,31 @@ export default function RegisteredAccount(props: RegisteredAccountProps) {
accountType === '1' ? 'additionalInformation' : 'bcAdditionalInformation'
const additionalInfo: any =
accountType === '1'
? convertLabel(additionalInformation || [])
: convertLabel(bcAdditionalInformation || [])
? additionalInformation || []
: bcAdditionalInformation || []

const newContactInformation = contactInformation?.map(
(info: CustomFieldItems) => {
if (info.fieldId === 'field_email' && accountType === '1') {
info.isTip = true
info.tipText = 'This email will be used to sign in to your account'
}
const { label } = info
if (label) {
info.label = manipulateString(label)
}

return info
}
)

const contactInfo: any =
accountType === '1'
? newContactInformation
: convertLabel(bcContactInformation || [])
accountType === '1' ? newContactInformation : bcContactInformation || []
const contactName =
accountType === '1' ? 'contactInformation' : 'bcContactInformationFields'

const contactInformationLabel = contactInfo.length
? manipulateString(contactInfo[0]?.groupName)
? contactInfo[0]?.groupName
: ''

const additionalInformationLabel = additionalInfo.length
? manipulateString(additionalInfo[0]?.groupName)
? additionalInfo[0]?.groupName
: ''

const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
Expand Down
27 changes: 8 additions & 19 deletions apps/storefront/src/pages/registered/RegisteredBCToB2B.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ import { getContrastColor } from '@/components/outSideComponents/utils/b3CustomS
import { useMobile } from '@/hooks'
import { CustomStyleContext } from '@/shared/customStyleButtton'
import { GlobaledContext } from '@/shared/global'
import {
convertLabel,
getCurrentCustomerInfo,
manipulateString,
storeHash,
} from '@/utils'
import { getCurrentCustomerInfo, storeHash } from '@/utils'

import {
createB2BCompanyUser,
Expand Down Expand Up @@ -595,13 +590,11 @@ export default function RegisteredBCToB2B(props: RegisteredProps) {
>
<InformationFourLabels>
{bcTob2bContactInformation?.length
? manipulateString(
bcTob2bContactInformation[0]?.groupName
)
? bcTob2bContactInformation[0]?.groupName
: ''}
</InformationFourLabels>
<B3CustomForm
formFields={convertLabel(bcTob2bContactInformation || [])}
formFields={bcTob2bContactInformation || []}
errors={errors}
control={control}
getValues={getValues}
Expand All @@ -616,15 +609,13 @@ export default function RegisteredBCToB2B(props: RegisteredProps) {
>
<InformationFourLabels>
{bcTob2bCompanyInformation?.length
? manipulateString(
bcTob2bCompanyInformation[0]?.groupName
)
? bcTob2bCompanyInformation[0]?.groupName
: ''}
</InformationFourLabels>
<B3CustomForm
formFields={[
...convertLabel(bcTob2bCompanyInformation),
...convertLabel(bcTob2bCompanyExtraFields),
...bcTob2bCompanyInformation,
...bcTob2bCompanyExtraFields,
]}
errors={errors}
control={control}
Expand All @@ -640,14 +631,12 @@ export default function RegisteredBCToB2B(props: RegisteredProps) {
>
<InformationFourLabels>
{bcTob2bAddressBasicFields?.length
? manipulateString(
bcTob2bAddressBasicFields[0]?.groupName
)
? bcTob2bAddressBasicFields[0]?.groupName
: ''}
</InformationFourLabels>

<B3CustomForm
formFields={convertLabel(bcTob2bAddressBasicFields)}
formFields={bcTob2bAddressBasicFields}
errors={errors}
control={control}
getValues={getValues}
Expand Down
13 changes: 4 additions & 9 deletions apps/storefront/src/pages/registered/RegisteredDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { B3CustomForm } from '@/components'
import { getContrastColor } from '@/components/outSideComponents/utils/b3CustomStyles'
import { CustomStyleContext } from '@/shared/customStyleButtton'
import { validateBCCompanyExtraFields } from '@/shared/service/b2b'
import { convertLabel, manipulateString } from '@/utils'

import RegisteredStepButton from './component/RegisteredStepButton'
import { RegisteredContext } from './context/RegisteredContext'
Expand Down Expand Up @@ -55,18 +54,14 @@ export default function RegisteredDetail(props: RegisteredDetailProps) {
mode: 'all',
})
const businessDetailsName =
accountType === '1'
? manipulateString(companyInformation[0]?.groupName)
: ''
accountType === '1' ? companyInformation[0]?.groupName : ''

const addressBasicName =
accountType === '1' ? 'addressBasicFields' : 'bcAddressBasicFields'
const addressBasicList =
accountType === '1'
? convertLabel(addressBasicFields)
: convertLabel(bcAddressBasicFields)
accountType === '1' ? addressBasicFields : bcAddressBasicFields

const addressName = manipulateString(addressBasicList[0]?.groupName) || ''
const addressName = addressBasicList[0]?.groupName || ''

const handleCountryChange = (countryCode: string, stateCode = '') => {
const stateList =
Expand Down Expand Up @@ -266,7 +261,7 @@ export default function RegisteredDetail(props: RegisteredDetailProps) {
<Box>
<InformationFourLabels>{businessDetailsName}</InformationFourLabels>
<B3CustomForm
formFields={[...convertLabel(companyInformation)]}
formFields={[...companyInformation]}
errors={errors}
control={control}
getValues={getValues}
Expand Down

0 comments on commit 8a19e20

Please sign in to comment.