Skip to content

Commit fcab2fb

Browse files
authored
Merge pull request #191 from dimaportenko/fix/country-region-modal-prefill-issue
Fix/country region modal prefill issue
2 parents 1ebbb92 + 5e34313 commit fcab2fb

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

src/components/account/AddAccountAddress.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class AddAccountAddress extends Component {
122122

123123
renderRegions = () => {
124124
const theme = this.context;
125-
const { countryId, countries } = this.props;
125+
const { countryId, countries, region } = this.props;
126126
if (countryId && countryId.length && countries && countries.length) {
127127
const country = countries.find(item => item.id === countryId);
128128
if (country && country.available_regions) {
@@ -131,11 +131,16 @@ class AddAccountAddress extends Component {
131131
key: value.id,
132132
}));
133133

134+
const label = region?.region
135+
? region?.region
136+
: translate('common.region');
137+
134138
return (
135139
<ModalSelect
140+
withLabel={false}
136141
disabled={data.length === 0}
137142
key="regions"
138-
label={translate('common.region')}
143+
label={label}
139144
attribute="Region"
140145
value="Region"
141146
data={data}
@@ -187,6 +192,7 @@ class AddAccountAddress extends Component {
187192

188193
return (
189194
<ModalSelect
195+
withLabel={false}
190196
disabled={data.length === 0}
191197
key="countries"
192198
label={label}

src/components/checkout/CheckoutCustomerAccount.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class CheckoutCustomerAccount extends Component {
184184
}
185185

186186
renderRegions() {
187-
const { countryId, countries } = this.props;
187+
const { countryId, countries, region } = this.props;
188188
if (countryId && countryId.length && countries && countries.length) {
189189
const country = countries.find(item => item.id === countryId);
190190
if (country && country.available_regions) {
@@ -193,11 +193,16 @@ class CheckoutCustomerAccount extends Component {
193193
key: value.id,
194194
}));
195195

196+
const label = region?.region
197+
? region?.region
198+
: translate('common.region');
199+
196200
return (
197201
<ModalSelect
202+
withLabel={false}
198203
disabled={data.length === 0}
199204
key="regions"
200-
label={translate('common.region')}
205+
label={label}
201206
attribute={translate('common.region')}
202207
value={translate('common.region')}
203208
data={data}
@@ -240,11 +245,17 @@ class CheckoutCustomerAccount extends Component {
240245
key: value.id,
241246
}));
242247

248+
const country = countries.find(item => item.id === countryId);
249+
const label = country
250+
? country.full_name_locale
251+
: translate('common.country');
252+
243253
return (
244254
<ModalSelect
255+
withLabel={false}
245256
disabled={data.length === 0}
246257
key="countries"
247-
label={translate('common.country')}
258+
label={label}
248259
attribute={translate('common.country')}
249260
value={translate('common.country')}
250261
data={data}

src/components/common/ModalSelect.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@ import ModalSelector from 'react-native-modal-selector';
44
import PropTypes from 'prop-types';
55
import { Input } from './Input';
66

7-
const ModalSelect = ({ data, disabled, label, onChange, attribute, style }) => {
7+
const ModalSelect = ({
8+
data,
9+
disabled,
10+
label,
11+
onChange,
12+
attribute,
13+
style,
14+
withLabel = true,
15+
}) => {
816
const [value, setValue] = useState('');
917

1018
const _onChange = option => {
11-
setValue(
12-
attribute === 'CurrencyCode'
13-
? option.label
14-
: `${label} : ${option.label}`,
15-
);
19+
setValue(!withLabel ? option.label : `${label} : ${option.label}`);
1620

1721
if (onChange) {
1822
onChange(attribute, option.key);

src/components/home/CurrencyPicker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const CurrencyPicker = ({
3434
disabled={data.length === 0}
3535
label={selectedCurrencyCode}
3636
attribute="CurrencyCode"
37+
withLabel={false}
3738
data={data}
3839
onChange={onChange}
3940
style={styles.currencyContainer}

0 commit comments

Comments
 (0)