@riosst100/pwa-marketplace 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/BecomeSeller/becomeSeller.js +2 -2
- package/src/components/SellerCountry/index.js +1 -0
- package/src/components/SellerCountry/sellerCountry.gql.js +11 -0
- package/src/components/SellerCountry/sellerCountry.js +65 -0
- package/src/components/SellerCountry/sellerCountry.module.css +3 -0
- package/src/talons/SellerCountry/useSellerCountry.js +25 -0
package/package.json
CHANGED
|
@@ -19,7 +19,7 @@ import TextInput from '@magento/venia-ui/lib/components/TextInput';
|
|
|
19
19
|
import defaultClasses from './becomeSeller.module.css';
|
|
20
20
|
import FormError from '@magento/venia-ui/lib/components/FormError';
|
|
21
21
|
import GoogleRecaptcha from '@magento/venia-ui/lib/components/GoogleReCaptcha';
|
|
22
|
-
import
|
|
22
|
+
import SellerCountry from '@riosst100/pwa-marketplace/src/components/SellerCountry';
|
|
23
23
|
import Region from '@magento/venia-ui/lib/components/Region';
|
|
24
24
|
import Postcode from '@magento/venia-ui/lib/components/Postcode';
|
|
25
25
|
import resourceUrl from '@magento/peregrine/lib/util/makeUrl';
|
|
@@ -193,7 +193,7 @@ const BecomeSeller = props => {
|
|
|
193
193
|
})}
|
|
194
194
|
/>
|
|
195
195
|
</Field>
|
|
196
|
-
<
|
|
196
|
+
<SellerCountry
|
|
197
197
|
field="seller.country_id"
|
|
198
198
|
validate={isRequired}
|
|
199
199
|
/>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './sellerCountry';
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useIntl } from 'react-intl';
|
|
3
|
+
import { func, shape, string } from 'prop-types';
|
|
4
|
+
import { useSellerCountry } from '@riosst100/pwa-marketplace/src/talons/SellerCountry/useSellerCountry';
|
|
5
|
+
|
|
6
|
+
import { useStyle } from '@magento/venia-ui/lib/classify';
|
|
7
|
+
import Field from '@magento/venia-ui/lib/components/Field';
|
|
8
|
+
import Select from '@magento/venia-ui/lib/components/Select';
|
|
9
|
+
import defaultClasses from './sellerCountry.module.css';
|
|
10
|
+
import { GET_SELLER_COUNTRIES_QUERY } from './sellerCountry.gql';
|
|
11
|
+
|
|
12
|
+
const SellerCountry = props => {
|
|
13
|
+
const talonProps = useSellerCountry({
|
|
14
|
+
queries: {
|
|
15
|
+
getSellerCountriesQuery: GET_SELLER_COUNTRIES_QUERY
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const { countries, loading } = talonProps;
|
|
19
|
+
const {
|
|
20
|
+
classes: propClasses,
|
|
21
|
+
field,
|
|
22
|
+
label,
|
|
23
|
+
translationId,
|
|
24
|
+
...inputProps
|
|
25
|
+
} = props;
|
|
26
|
+
const { formatMessage } = useIntl();
|
|
27
|
+
|
|
28
|
+
const classes = useStyle(defaultClasses, propClasses);
|
|
29
|
+
const selectProps = {
|
|
30
|
+
classes,
|
|
31
|
+
disabled: loading,
|
|
32
|
+
field,
|
|
33
|
+
items: countries,
|
|
34
|
+
...inputProps
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<Field
|
|
39
|
+
id={classes.root}
|
|
40
|
+
label={formatMessage({ id: translationId, defaultMessage: label })}
|
|
41
|
+
classes={{ root: classes.root }}
|
|
42
|
+
>
|
|
43
|
+
<Select {...selectProps} id={classes.root} />
|
|
44
|
+
</Field>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export default SellerCountry;
|
|
49
|
+
|
|
50
|
+
SellerCountry.defaultProps = {
|
|
51
|
+
field: 'country',
|
|
52
|
+
label: 'Country',
|
|
53
|
+
translationId: 'country.label'
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
SellerCountry.propTypes = {
|
|
57
|
+
classes: shape({
|
|
58
|
+
root: string
|
|
59
|
+
}),
|
|
60
|
+
field: string,
|
|
61
|
+
label: string,
|
|
62
|
+
translationId: string,
|
|
63
|
+
validate: func,
|
|
64
|
+
initialValue: string
|
|
65
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useQuery } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
export const useSellerCountry = props => {
|
|
4
|
+
const {
|
|
5
|
+
queries: { getSellerCountriesQuery }
|
|
6
|
+
} = props;
|
|
7
|
+
|
|
8
|
+
const { data, error, loading } = useQuery(getSellerCountriesQuery);
|
|
9
|
+
|
|
10
|
+
let formattedCountriesData = [{ label: 'Loading Countries...', value: '' }];
|
|
11
|
+
if (!loading && !error) {
|
|
12
|
+
const { sellerCountries } = data;
|
|
13
|
+
formattedCountriesData = sellerCountries.map(country => ({
|
|
14
|
+
// If a country is missing the full english name just show the abbreviation.
|
|
15
|
+
label: country.full_name_english || country.two_letter_abbreviation,
|
|
16
|
+
value: country.two_letter_abbreviation
|
|
17
|
+
}));
|
|
18
|
+
formattedCountriesData.sort((a, b) => (a.label < b.label ? -1 : 1));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
countries: formattedCountriesData,
|
|
23
|
+
loading
|
|
24
|
+
};
|
|
25
|
+
};
|