-
Notifications
You must be signed in to change notification settings - Fork 1
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
Convert AddressForm From Angular to React #969
Open
reldredge71
wants to merge
16
commits into
master
Choose a base branch
from
payment-methods-react
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
db24bf2
remove ts-loader
reldredge71 f72807a
Translate AddressForm Select Components to React
reldredge71 710f548
Create TextInput Component
reldredge71 474b173
Create AddressForm in React
reldredge71 b8750e6
Add Select and Text Inputs to AddressForm
reldredge71 aea7f50
Insert AddressForm into CreditCardForm
reldredge71 0f64054
Install Formik
reldredge71 72d2e73
Update AddressForm Components to Work With Formik
reldredge71 92b865d
For now, replace translation handling with hardcoded text
reldredge71 4945084
Expose address updates to parent view
reldredge71 2fba43c
Introduce Yup
reldredge71 1bf6987
Fix jest.config.js
reldredge71 a07a0e2
Call refreshRegions on selecting country
reldredge71 5cb7503
Make addressDisabled and canRetry optional
reldredge71 aa10dea
Start working on tests
reldredge71 bbabb3c
Adjustments to SelectInput and textInput to be more customizable
reldredge71 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React, { ChangeEvent, FocusEvent } from 'react'; | ||
import SelectInput, { Option } from '../../form/selectInput'; | ||
|
||
interface CountrySelectProps { | ||
addressDisabled: boolean, | ||
countries: Option[], | ||
onChange: (event: ChangeEvent<HTMLSelectElement>) => void, | ||
onBlur: (event: FocusEvent<HTMLSelectElement>) => void, | ||
onSelectCountry: (country?: string, initial?: boolean) => void, | ||
refreshCountries: () => void, | ||
value: string, | ||
error?: string, | ||
canRetry: boolean, | ||
} | ||
|
||
const CountrySelect = ({ | ||
addressDisabled, | ||
countries, | ||
onChange, | ||
onBlur, | ||
onSelectCountry, | ||
refreshCountries, | ||
value, | ||
error, | ||
canRetry, | ||
}: CountrySelectProps) => { | ||
|
||
const handleChange = (event: ChangeEvent<HTMLSelectElement>) => { | ||
onChange(event); | ||
onSelectCountry(event.target.value); | ||
}; | ||
|
||
const handleRetry = () => { | ||
refreshCountries(); | ||
}; | ||
|
||
return ( | ||
<SelectInput | ||
title="Country" | ||
name="country" | ||
required={true} | ||
disabled={addressDisabled} | ||
options={countries} | ||
onChange={handleChange} | ||
onBlur={onBlur} | ||
value={value} | ||
error={error} | ||
retry={error && canRetry ? handleRetry : undefined} | ||
/> | ||
); | ||
}; | ||
|
||
export default CountrySelect; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React, { ChangeEvent, FocusEvent } from 'react'; | ||
import SelectInput, { Option } from '../../form/SelectInput'; | ||
|
||
interface RegionSelectProps { | ||
addressDisabled: boolean, | ||
regions: Option[], | ||
onChange: (event: ChangeEvent<HTMLSelectElement>) => void, | ||
onBlur: (event: FocusEvent<HTMLSelectElement>) => void, | ||
refreshRegions: () => void, | ||
value: string, | ||
error?: string, | ||
canRetry: boolean, | ||
} | ||
|
||
const RegionSelect = ({ | ||
addressDisabled, | ||
regions, | ||
onChange, | ||
onBlur, | ||
refreshRegions, | ||
value, | ||
error, | ||
canRetry, | ||
}: RegionSelectProps) => { | ||
|
||
const handleChange = (event: ChangeEvent<HTMLSelectElement>) => { | ||
onChange(event); | ||
}; | ||
|
||
const handleRetry = () => { | ||
refreshRegions(); | ||
}; | ||
|
||
return ( | ||
<SelectInput | ||
title="State" | ||
name="region" | ||
required={true} | ||
disabled={addressDisabled} | ||
options={regions} | ||
onChange={handleChange} | ||
onBlur={onBlur} | ||
value={value} | ||
error={error} | ||
retry={error && canRetry ? handleRetry : undefined} | ||
/> | ||
); | ||
}; | ||
|
||
export default RegionSelect; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React, { ChangeEvent, FocusEvent } from 'react'; | ||
|
||
interface SelectInputProps { | ||
title?: string, | ||
name: string, | ||
required?: boolean, | ||
disabled?: boolean, | ||
options: Option[], | ||
onChange: (value: ChangeEvent<HTMLSelectElement>) => void, | ||
onBlur: (value: FocusEvent<HTMLSelectElement>) => void, | ||
value: string, | ||
error?: string, | ||
retry?: () => void, | ||
} | ||
|
||
export interface Option { | ||
name: string, | ||
displayName: string | ||
} | ||
|
||
const SelectInput = ({ | ||
title, | ||
name, | ||
required, | ||
disabled, | ||
options, | ||
onChange, | ||
onBlur, | ||
value, | ||
error, | ||
retry | ||
}: SelectInputProps) => { | ||
const optionRow = ({ name, displayName }: Option) => ( | ||
<option value={name} label={displayName} /> | ||
); | ||
|
||
return ( | ||
<div className={`form-group${required && ' is-required' || ''}${error && ' has-error' || ''}`}> | ||
{ title && <label>{title}</label> } | ||
<div className="form-group"> | ||
<select | ||
className="form-control form-control-subtle" | ||
name={name} | ||
required={required} | ||
disabled={disabled} | ||
onChange={onChange} | ||
onBlur={onBlur} | ||
value={value} | ||
> | ||
{ options.map(optionRow) } | ||
</select> | ||
{ error && ( | ||
<div role="alert"> | ||
<div className="help-block"> | ||
<span>{error}</span> | ||
{ retry && ( | ||
<button | ||
id="retryButton" | ||
type="button" | ||
className="btn btn-default btn-sm" | ||
onClick={retry} | ||
> | ||
{'Retry'} | ||
</button> | ||
)} | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default SelectInput; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this work when there are multiples on the same page? Won't the ids clash? This might need to be overwrite-able.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, this might have to be more dynamic to account for multiple instances.