Skip to content

Commit

Permalink
Update component UserAddress and change prop name
Browse files Browse the repository at this point in the history
  • Loading branch information
albertm805 committed Mar 24, 2022
1 parent af84e4f commit c3f9d9d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added
- New prop to `UserAddress` showIfMasked to remove entire string if asterics are present

## [3.158.0] - 2022-03-23

### Added
Expand Down
4 changes: 4 additions & 0 deletions react/UserAddress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type Props = {
showPrefix?: boolean
/** Define if component should render if address is empty */
showIfEmpty?: boolean
/** Define if component should render if ZipCode contains asterics */
showIfMasked?: boolean
/** Used to override default CSS handles */
classes?: CssHandlesTypes.CustomClasses<typeof USER_ADDRESS_CSS_HANDLES>
}
Expand All @@ -39,6 +41,7 @@ function UserAddress({
showPostalCode = false,
showPrefix = true,
showIfEmpty = false,
showIfMasked = false,
classes,
}: Props) {
const { handles, withModifiers } = useCssHandles(USER_ADDRESS_CSS_HANDLES, {
Expand Down Expand Up @@ -84,6 +87,7 @@ function UserAddress({
showPostalCode={showPostalCode}
showPrefix={showPrefix}
showIfEmpty={showIfEmpty}
showIfMasked={showIfMasked}
/>
</UserAddressCssHandlesProvider>
)
Expand Down
19 changes: 9 additions & 10 deletions react/components/UserAddress/AddressInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Props = {
showStreet: boolean
showCityAndState: boolean
showPostalCode: boolean
showIfMasked: boolean
showPrefix: boolean
showIfEmpty: boolean
}
Expand All @@ -33,6 +34,7 @@ const AddressInfo = ({
showStreet,
showCityAndState,
showPostalCode,
showIfMasked,
showPrefix,
showIfEmpty,
}: Props) => {
Expand All @@ -41,7 +43,11 @@ const AddressInfo = ({
const { handles } = useUserAddressCssHandles()
const intl = useIntl()

if (!shippingData || !shippingData.address) {
if (
!shippingData ||
!shippingData.address ||
(!showIfMasked && shippingData.address.postalCode.includes('*'))
) {
if (!showIfEmpty) {
return null
}
Expand Down Expand Up @@ -84,15 +90,8 @@ const AddressInfo = ({
)
}

const {
street,
number,
complement,
addressType,
city,
state,
postalCode,
} = shippingData.address
const { street, number, complement, addressType, city, state, postalCode } =
shippingData.address

let displayStreet = number ? `${street}, ${number}` : street

Expand Down

0 comments on commit c3f9d9d

Please sign in to comment.