How to utilize the AddressAutocomplete component from the @carta/identity team
Important note: this component is not maintained by the ink team. If you have any questions, please reach out to the identity team in the #team-eng-profile Slack channel.
Establishing a new pattern for address forms at Carta
The AddressAutocomplete component uses the Google Maps API and the Carta address service to create a full-stack address component which includes autocomplete functionality. All new address forms being added to the Carta platform should utilize this component, rather than building a form from scratch.
General guidelines
Make sure the address service is running locally or is accessible at http://localhost:8053 for local development.
Three letter country code is used to determine which component to be displayed, so for existing addresses it is important to pass in either the country name in country or three letter country code in countryCode field.
By default component is rendered as non stacked but if stacked version is preferred please set isFull and isStacked optional props.
Integration guide
Host autocomplete app within a Frontend Platform monorepo app
To use the AddressAutocomplete component in a FEP monorepo app, use the Frontend Platform team's FARSComponent to host the remote app within the monorepo app.
The snippet above is hosting the remote app from a test environment. Right now the baseUrl is hardcoded to get the app that is deployed on test environment. This can be changed to baseUrl={window.AWS_CLOUDFRONT_FEDERATED_BUNDLES_BASE}.
You can add devServer proxy in the webpack.config.ext.js file of the host monorepo app to route traffic to locally running address-service.
devServer:{
proxy:{
'/api/address-service/v1':{
target:'http://localhost:8053',
pathRewrite:{'^/api/address-service/v1':'/v1/'},
},
},
}
Host autocomplete app within carta-web
To use the AddressAutocomplete component on carta-web, utilize useState to instantiate address information in the following format:
const[fields, setFields]=
useState <
AddressFields>
{
streetAddress1:"",
streetAddress2:"",
streetAddress3:"",
city:"",
postalCode:"",
province:"",
countryCode:"",
country:"",
provinceCode:"",
vettedBy:VettedBy.NO_ONE.toString(),
isValid:false,
locationId:"",
}
Then, render the autocomplete app using FARSComponent and pass in the address object to the component:
The AddressAutocomplete component accepts the following props:
export type AddressFields={
/** Address field 1 */
streetAddress1: string,
/** Address field 2 */
streetAddress2: string,
/** Address field 3 */
streetAddress3: string,
/** City */
city: string,
/** Subdivision name eg: Alberta */
province: string,
/** Postalcode/ zip code */
postalCode: string,
/** Country long name eg: United States, Canada */
country: string,
/** Subdivision two letter iso code. eg: AB */
provinceCode: string,
/** Country three-letter iso code eg: USA, CAN */
countryCode: string,
/** Country two-letter iso code eg: US, CA */
countryCodeAlpha2?: string,
/** Random hash value returned from Address Service */
locationId?: string |null,
/** Flag determining if address is validate */
isValid?: boolean,
/** Value holder determining who validated the address */
vettedBy?: string,
}
/** Unique identifier \*/
id: string;
/** Address fields that will be set by the component. Create a use state hook of type AddressFields and pass it down to the component. _/
addressFields: AddressFields;
/\*\* callback of type React dispatch. This will be used to assign the values to AddressFields. Create a usestate hook of type AddressFields and assign the setter to this prop. _/
Forms are text interfaces. Writing good questions, help text, and actionable error messages is the single most important thing you can do to create great forms.