Skip to content

Commit

Permalink
fix: update the logic to handle prefilled values if BPN is present (#244
Browse files Browse the repository at this point in the history
)
  • Loading branch information
shubhamv-ss authored Oct 21, 2024
1 parent 3f090f8 commit f5078fe
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions src/components/cax-companyData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export const CompanyDataCax = () => {
const [submitError, setSubmitError] = useState(false)
const [identifierError, setIdentifierError] = useState(false)
const [notifyError, setNotifyError] = useState(false)
const [defaultSelectedCountry, setDefaultSelectedCountry] = useState(null)

const {
data: companyDetails,
Expand Down Expand Up @@ -133,9 +134,16 @@ export const CompanyDataCax = () => {
}
}, [countryList, i18n.language])

const defaultSelectedCountry = countryArr?.filter(
(code) => code.id === country
)[0]
useEffect(() => {
if (country) {
const countryCodeValue = countryArr?.find((code) => code.id === country)
if (countryCodeValue) {
setDefaultSelectedCountry(countryCodeValue)
}
} else {
setDefaultSelectedCountry(null)
}
}, [country, countryArr])

useEffect(() => {
refetchCompanyData()
Expand All @@ -158,18 +166,20 @@ export const CompanyDataCax = () => {
}, [identifierType, identifierNumber, country])

useEffect(() => {
setBpn(companyDetails?.bpn)
setLegalEntity(companyDetails?.name)
setRegisteredName(companyDetails?.name)
setStreetHouseNumber(companyDetails?.streetName)
setRegion(companyDetails?.region)
setPostalCode(companyDetails?.zipCode)
setCity(companyDetails?.city)
setCountry(companyDetails?.countryAlpha2Code)
setUniqueIds(companyDetails?.uniqueIds)
setIdentifierNumber(companyDetails?.uniqueIds?.[0]?.value)
setIdentifierType(companyDetails?.uniqueIds?.[0]?.type)
}, [companyDetails])
if (!bpn) {
setBpn(companyDetails?.bpn)
setLegalEntity(companyDetails?.name)
setRegisteredName(companyDetails?.name)
setStreetHouseNumber(companyDetails?.streetName)
setRegion(companyDetails?.region)
setPostalCode(companyDetails?.zipCode ?? '')
setCity(companyDetails?.city)
setCountry(companyDetails?.countryAlpha2Code)
setUniqueIds(companyDetails?.uniqueIds)
setIdentifierNumber(companyDetails?.uniqueIds?.[0]?.value)
setIdentifierType(companyDetails?.uniqueIds?.[0]?.type)
}
}, [companyDetails, bpn])

useEffect(() => {
if (companyDataError ?? submitError ?? identifierError) {
Expand All @@ -190,7 +200,7 @@ export const CompanyDataCax = () => {
// @ts-expect-error keep for compatibility
setRegion(details.region)
// @ts-expect-error keep for compatibility
setPostalCode(details.zipcode)
setPostalCode(details.zipCode)
// @ts-expect-error keep for compatibility
setCity(details.city)
// @ts-expect-error keep for compatibility
Expand Down

0 comments on commit f5078fe

Please sign in to comment.