Last active
April 3, 2018 17:45
-
-
Save cristianoliveira/b48dcbc1db3977d3f47823cbe9c99df7 to your computer and use it in GitHub Desktop.
Same same but different - post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is the common field set free of country specific things. | |
function GeneralInternationalAddress(props) { | |
return ( | |
<Fragment> | |
<AddressLineInput value={props.address_line} /> | |
<AddressLineInput | |
name="address_line2" | |
value={props.address_line2} | |
optional | |
/> | |
<PostCodeInput value={props.post_code} /> | |
<CityInput value={props.city} /> | |
</Fragment> | |
); | |
} | |
export default GeneralInternationalAddress; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function RegionAddress(props) { | |
return ( | |
<Fragment> | |
<AddressLineInput value={props.address_line} /> | |
<AddressLineInput | |
name="address_line2" | |
value={props.address_line2} | |
optional | |
/> | |
<PostCodeInput type="text" value={props.post_code} /> | |
<CityInput value={props.city} /> | |
<RegionSelector regions={props.regions} /> | |
</Fragment> | |
); | |
} | |
export default RegionAddress; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is one example when you can't make it generic. Sometimes the | |
// requirements are so weird it's better to have some duplication than | |
// contaminating all your components with country specific logic :/ | |
import COUNTRY_STATES from './country-states' | |
function BrazilianAddress(props) { | |
const states = Object.keys(COUNTRY_STATES).map(code => ({ | |
code, | |
name: COUNTRY_STATES[code], | |
})); | |
return ( | |
<Fragment> | |
<AddressLineInput value={props.address_line} /> | |
<WarningMessage | |
visible={props.address_line && !props.street_no} | |
text='My message' /> | |
<StreetNumberInput value={props.street_no} /> | |
<AddressLineInput | |
name="address_line2" | |
value={props.address_line2} | |
optional | |
/> | |
<PostCodeInput value={props.post_code} /> | |
<StateSelector states={states} value={props.country_state} /> | |
{props.country_state && ( | |
<div> | |
<div>Its a behavior only for brazil</div> | |
<div>Select the city of {COUNTRY_STATES[props.country_state]} </div> | |
<CityInput value={props.city} /> | |
</div> | |
)} | |
</Fragment> | |
); | |
} | |
export default BrazilianAddress; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment