@riosst100/pwa-marketplace 1.0.6 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@riosst100/pwa-marketplace",
3
3
  "author": "riosst100@gmail.com",
4
- "version": "1.0.6",
4
+ "version": "1.0.8",
5
5
  "main": "src/index.js",
6
6
  "pwa-studio": {
7
7
  "targets": {
@@ -7,6 +7,7 @@ module.exports = componentOverrideMapping = {
7
7
  [`@magento/peregrine/lib/talons/Adapter/useAdapter.js`]: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/talons/Adapter/useAdapter.js',
8
8
  [`@magento/peregrine/lib/talons/Header/useStoreSwitcher.js`]: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/talons/Header/useStoreSwitcher.js',
9
9
  [`@magento/peregrine/lib/talons/Header/storeSwitcher.gql.js`]: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/talons/Header/storeSwitcher.gql.js',
10
+ [`@magento/peregrine/lib/talons/Region/useRegion.js`]: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/talons/Region/useRegion.js',
10
11
  [`@magento/pwa-buildpack/lib/queries/getAvailableStoresConfigData.graphql`]: '@riosst100/pwa-marketplace/src/overwrites/pwa-buildpack/lib/queries/getAvailableStoresConfigData.graphql',
11
12
  [`@magento/peregrine/lib/store/actions/user/asyncActions.js`]: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/store/actions/user/asyncActions.js',
12
13
  [`@magento/peregrine/lib/talons/SignIn/signIn.gql.js`]: '@riosst100/pwa-marketplace/src/overwrites/peregrine/lib/talons/SignIn/signIn.gql.js',
@@ -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 Country from '@magento/venia-ui/lib/components/Country';
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
- <Country
196
+ <SellerCountry
197
197
  field="seller.country_id"
198
198
  validate={isRequired}
199
199
  />
@@ -259,6 +259,7 @@ const BecomeSeller = props => {
259
259
  id: 'global.region',
260
260
  defaultMessage: 'Region'
261
261
  })}
262
+ translationId="global.region"
262
263
  countryCodeField="seller.country_id"
263
264
  validate={isRequired}
264
265
  />
@@ -17,7 +17,7 @@ const BecomeSellerLink = props => {
17
17
 
18
18
  return isSeller ? (
19
19
  <div className={classes.root} data-cy="BecomeSellerLink-root">
20
- <a href="https://seller-local.tcgcollective.co/lofmarketplace/seller/login/">
20
+ <a href={process.env.MAGENTO_BACKEND_URL + "/lofmarketplace/seller/login"}>
21
21
  {formatMessage({
22
22
  id: 'sellerDashboard.title',
23
23
  defaultMessage: 'Seller Dashboard'
@@ -70,9 +70,7 @@ const SellerAccountPage = props => {
70
70
  </span>
71
71
  </div>
72
72
  <div className={classes.editButtonContainer}>
73
- <a href="https://seller-local.tcgcollective.co/lofmarketplace/seller/login/"
74
- className={classes.editInformationButton}
75
- >
73
+ <a href={process.env.MAGENTO_BACKEND_URL + "/lofmarketplace/seller/login"} className={classes.editInformationButton}>
76
74
  <FormattedMessage
77
75
  id={'global.sellerDashboardText'}
78
76
  defaultMessage={'Seller Dashboard'}
@@ -0,0 +1 @@
1
+ export { default } from './sellerCountry';
@@ -0,0 +1,11 @@
1
+ import { gql } from '@apollo/client';
2
+
3
+ export const GET_SELLER_COUNTRIES_QUERY = gql`
4
+ query GetSellerCountries {
5
+ sellerCountries {
6
+ id
7
+ full_name_english
8
+ two_letter_abbreviation
9
+ }
10
+ }
11
+ `;
@@ -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,3 @@
1
+ .root {
2
+ grid-area: country;
3
+ }
@@ -0,0 +1,102 @@
1
+ import { useEffect, useRef } from 'react';
2
+ import { useQuery } from '@apollo/client';
3
+ import { useFieldApi } from 'informed';
4
+ import useFieldState from '@magento/peregrine/lib/hooks/hook-wrappers/useInformedFieldStateWrapper';
5
+
6
+ /**
7
+ * The useRegion talon handles logic for:
8
+ *
9
+ * * Resetting the region field value when the country changes.
10
+ * * Querying for available regions for a country and rendering them.
11
+ *
12
+ * @param {Object} props
13
+ * @param {string} props.countryCodeField
14
+ * @param {string} props.fieldInput - the reference field path for free form text input Defaults to "region".
15
+ * @param {string} props.fieldSelect - the reference field path for selectable list of regions. Defaults to "region".
16
+ * @param {string} props.optionValueKey - the key used to get the value for the field. Defaults to "code"
17
+ * @param {GraphQLAST} props.queries.getRegionsQuery - query to fetch regions for a country.
18
+ *
19
+ * @return {RegionTalonProps}
20
+ */
21
+ export const useRegion = props => {
22
+ const {
23
+ countryCodeField = 'country',
24
+ fieldInput = 'region',
25
+ fieldSelect = 'region',
26
+ optionValueKey = 'code',
27
+ queries: { getRegionsQuery }
28
+ } = props;
29
+
30
+ const hasInitialized = useRef(false);
31
+ const countryFieldState = useFieldState(countryCodeField);
32
+ const { value: country } = countryFieldState;
33
+
34
+ const regionInputFieldApi = useFieldApi(fieldInput);
35
+ const regionSelectFieldApi = useFieldApi(fieldSelect);
36
+
37
+ const { data, loading } = useQuery(getRegionsQuery, {
38
+ variables: { countryCode: country },
39
+ skip: !country
40
+ });
41
+
42
+ // Reset region value when country changes. Because of how Informed sets
43
+ // initialValues, we want to skip the first state change of the value being
44
+ // initialized.
45
+ useEffect(() => {
46
+ if (country && !loading) {
47
+ if (hasInitialized.current) {
48
+ regionInputFieldApi.exists() && regionInputFieldApi.setValue();
49
+ regionSelectFieldApi.exists() &&
50
+ regionSelectFieldApi.setValue();
51
+ } else {
52
+ hasInitialized.current = true;
53
+ }
54
+ }
55
+ }, [country, regionInputFieldApi, regionSelectFieldApi, loading]);
56
+
57
+ let formattedRegionsData = [{ label: 'Loading Regions...', value: '' }];
58
+ if (data) {
59
+ const { country } = data;
60
+ const { available_regions: availableRegions } = country;
61
+ if (availableRegions) {
62
+ formattedRegionsData = availableRegions.map(region => ({
63
+ key: region.id,
64
+ label: region.name,
65
+ value: region[optionValueKey]
66
+ }));
67
+ formattedRegionsData.unshift({
68
+ disabled: true,
69
+ hidden: true,
70
+ label: '',
71
+ value: ''
72
+ });
73
+ } else {
74
+ formattedRegionsData = [];
75
+ }
76
+ } else if (!loading) {
77
+ formattedRegionsData = [];
78
+ }
79
+
80
+ return {
81
+ loading,
82
+ regions: formattedRegionsData
83
+ };
84
+ };
85
+
86
+ /** JSDocs type definitions */
87
+
88
+ /**
89
+ * @typedef {Object} RegionTalonProps
90
+ *
91
+ * @property {boolean} loading whether the regions are loading
92
+ * @property {Array<Region>} regions array of formatted regions for the country
93
+ *
94
+ */
95
+
96
+ /**
97
+ * @typedef {Object} Region
98
+ *
99
+ * @property {number} key the id of the region
100
+ * @property {String} label the label of the region
101
+ * @property {String} value the value of the region
102
+ */
@@ -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
+ };