Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add address composite form field #9022

Merged
merged 3 commits into from
Dec 11, 2024
Merged

Conversation

thomtrp
Copy link
Contributor

@thomtrp thomtrp commented Dec 11, 2024

  • Create FormCountrySelectInput using the existing FormSelectFieldInput
  • Create AddressFormFieldInput component
  • Fix FormSelectFieldInput dropdown + add leftIcon
Capture d’écran 2024-12-11 à 15 56 32

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR adds comprehensive address form field functionality with country selection support. Here's a concise summary of the key changes:

  • Created new FormAddressFieldInput component with fields for street address, city, state, postal code and country
  • Added FormCountrySelectInput with flag icons and country selection dropdown
  • Modified FormSelectFieldInput to support icons and transparent backgrounds for country selection
  • Updated Tag and MenuItemSelectTag components to handle country flag icons and transparent backgrounds
  • Potential issue: Using countryName instead of countryCode in FormCountrySelectInput could cause internationalization problems

The implementation appears solid overall but should consider using countryCode as the value identifier for better data consistency and internationalization support.

14 file(s) reviewed, 16 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines 28 to 30
icon: (props: IconComponentProps) =>
Flag({ width: props.size, height: props.size }), // TODO : improve this ?
}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Flag component is being recreated on every render. Consider memoizing the icon function or moving it outside the map.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, I would create a wrapper component outside of the FormCountrySelectInput. Here, we'll recreate the React component on every render unecessarily.

const FlagIcon = (props: IconComponentProps) => {
  return Flag({ width: props.size, height: props.size })
}

// ...

icon: FlagIcon,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flag comes from useCountries. It cannot be extracted. I cannot memoize either because this is inside a function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understandable. I didn't see where the Flag function was coming from!

@Devessier Devessier self-requested a review December 11, 2024 15:10
Copy link
Contributor

@Devessier Devessier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Works well. We can merge.

Comment on lines +64 to +65
options={field.metadata.options}
clearLabel={field.label}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dissociating the field definition from the input is excellent. I'm unsure if it will "scale" well as the other fields make extensive use of the useNumberField-like functions and get access to the field definition that way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's see. If it becomes too complex we will still be able to come back to full field!

Comment on lines 28 to 30
icon: (props: IconComponentProps) =>
Flag({ width: props.size, height: props.size }), // TODO : improve this ?
}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, I would create a wrapper component outside of the FormCountrySelectInput. Here, we'll recreate the React component on every render unecessarily.

const FlagIcon = (props: IconComponentProps) => {
  return Flag({ width: props.size, height: props.size })
}

// ...

icon: FlagIcon,

}

if (countryCode === null) {
onPersist('');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know much about addresses, but are we sure we want to store an empty string vs. null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep default values have to be string

@thomtrp thomtrp enabled auto-merge (squash) December 11, 2024 16:45
@thomtrp thomtrp merged commit 4d9facb into main Dec 11, 2024
19 checks passed
@thomtrp thomtrp deleted the tt-add-form-address-composite-field branch December 11, 2024 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants