Skip to content

Commit

Permalink
feat: add address extrafields
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianJiang2021 authored and kris-liu-smile committed Jun 27, 2023
1 parent 0ba0496 commit ec51f0e
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 4 deletions.
22 changes: 21 additions & 1 deletion apps/storefront/src/pages/registered/Registered.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { loginCheckout, LoginConfig } from '../login/config'

import { RegisteredContext } from './context/RegisteredContext'
import {
AccountFormFieldsItems,
b2bAddressRequiredFields,
companyAttachmentsFields,
getAccountFormFields,
RegisterFields,
Expand Down Expand Up @@ -105,11 +107,25 @@ function Registered(props: RegisteredProps) {

const accountFormFields = await Promise.all(accountFormAllFields)

const newB2bAccountFormFields: AccountFormFieldsItems[] = (
accountFormFields[1]?.accountFormFields || []
).map((fields: AccountFormFieldsItems) => {
if (
b2bAddressRequiredFields.includes(fields?.fieldId || '') &&
fields.groupId === 4
) {
fields.isRequired = true
fields.visible = true
}

return fields
})

const bcAccountFormFields = getAccountFormFields(
accountFormFields[0]?.accountFormFields || []
)
const b2bAccountFormFields = getAccountFormFields(
accountFormFields[1]?.accountFormFields || []
newB2bAccountFormFields || []
)

const { countries } = await getB2BCountries()
Expand All @@ -121,6 +137,10 @@ function Registered(props: RegisteredProps) {
): Partial<RegisterFieldsItems> => {
if (addressFields.name === 'country') {
addressFields.options = countries
addressFields.replaceOptions = {
label: 'countryName',
value: 'countryName',
}
}
return addressFields
}
Expand Down
26 changes: 24 additions & 2 deletions apps/storefront/src/pages/registered/RegisteredBCToB2B.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import {

import { RegisteredContext } from './context/RegisteredContext'
import {
AccountFormFieldsItems,
b2bAddressRequiredFields,
Country,
deCodeField,
getAccountFormFields,
Expand Down Expand Up @@ -130,8 +132,22 @@ export default function RegisteredBCToB2B(props: RegisteredProps) {

const accountFormAllFields = await getB2BAccountFormFields(3)

const bcToB2BAccountFormFields = getAccountFormFields(
const newAccountFormFields: AccountFormFieldsItems[] = (
accountFormAllFields?.accountFormFields || []
).map((fields: AccountFormFieldsItems) => {
if (
b2bAddressRequiredFields.includes(fields?.fieldId || '') &&
fields.groupId === 4
) {
fields.isRequired = true
fields.visible = true
}

return fields
})

const bcToB2BAccountFormFields = getAccountFormFields(
newAccountFormFields || []
)
const { countries } = await getB2BCountries()

Expand All @@ -142,6 +158,10 @@ export default function RegisteredBCToB2B(props: RegisteredProps) {
): Partial<RegisterFieldsItems> => {
if (addressFields.name === 'country') {
addressFields.options = countries
addressFields.replaceOptions = {
label: 'countryName',
value: 'countryName',
}
}
return addressFields
}
Expand Down Expand Up @@ -206,7 +226,9 @@ export default function RegisteredBCToB2B(props: RegisteredProps) {
const handleCountryChange = (countryCode: string, stateCode = '') => {
const stateList =
countryList.find(
(country: Country) => country.countryCode === countryCode
(country: Country) =>
country.countryCode === countryCode ||
country.countryName === countryCode
)?.states || []
const stateFields = bcTob2bAddressBasicFields.find(
(formFields: RegisterFields) => formFields.name === 'state'
Expand Down
4 changes: 3 additions & 1 deletion apps/storefront/src/pages/registered/RegisteredDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ export default function RegisteredDetail(props: RegisteredDetailProps) {
const handleCountryChange = (countryCode: string, stateCode = '') => {
const stateList =
countryList.find(
(country: Country) => country.countryCode === countryCode
(country: Country) =>
country.countryCode === countryCode ||
country.countryName === countryCode
)?.states || []
const stateFields = addressBasicList.find(
(formFields: RegisterFields) => formFields.name === 'state'
Expand Down
13 changes: 13 additions & 0 deletions apps/storefront/src/pages/registered/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ export interface AccountFormFieldsItems {

type AccountFormFieldsList = Array<[]> | Array<AccountFormFieldsItems>

interface ReplaceOptionsProps {
label: string
value: string
}

export interface RegisterFieldsItems {
id?: string | number
name: string
Expand All @@ -77,6 +82,7 @@ export interface RegisterFieldsItems {
groupName: string
options?: any
disabled: boolean
replaceOptions?: ReplaceOptionsProps
}

export const steps = [
Expand Down Expand Up @@ -183,6 +189,13 @@ const classificationType = (item: CustomFieldItems) => {
}

const noEncryptFieldList = ['country', 'state', 'email']
export const b2bAddressRequiredFields = [
'field_country',
'field_address_1',
'field_city',
'field_state',
'field_zip_code',
]

const groupItems = {
1: 'contactInformation',
Expand Down
7 changes: 7 additions & 0 deletions apps/storefront/src/shared/service/b2b/graphql/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ const createCompanyUser = (data: any) => `mutation{
}
fileList: ${convertArrayToGraphql(data.fileList)}
channelId: ${data.channelId || 1}
${
data?.addressExtraFields
? `addressExtraFields: ${convertArrayToGraphql(
data.addressExtraFields
)}`
: ''
}
}) {
company {
id,
Expand Down

0 comments on commit ec51f0e

Please sign in to comment.