@riosst100/pwa-marketplace 1.2.5 → 1.2.7

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.
Files changed (129) hide show
  1. package/.github/workflows/dependabot.yml +28 -28
  2. package/package.json +18 -18
  3. package/src/Utilities/graphQL.js +76 -76
  4. package/src/componentOverrideMapping.js +17 -17
  5. package/src/components/BecomeSeller/becomeSeller.js +335 -335
  6. package/src/components/BecomeSeller/becomeSeller.module.css +46 -46
  7. package/src/components/BecomeSellerLink/becomeSellerLink.js +52 -52
  8. package/src/components/BecomeSellerLink/becomeSellerLink.module.css +12 -12
  9. package/src/components/BecomeSellerPage/becomeSellerPage.js +45 -45
  10. package/src/components/BecomeSellerPage/becomeSellerPage.module.css +21 -21
  11. package/src/components/Filter/index.js +53 -53
  12. package/src/components/Header/becomeSellerLink.js +28 -28
  13. package/src/components/Header/becomeSellerLink.module.css +12 -12
  14. package/src/components/Header/websiteSwitcher.js +109 -109
  15. package/src/components/Pagination/index.js +49 -49
  16. package/src/components/PhoneTextInput/phoneTextInput.module.css +21 -21
  17. package/src/components/ProductItem/index.js +50 -50
  18. package/src/components/Search/index.js +16 -16
  19. package/src/components/Seller/index.js +1 -1
  20. package/src/components/Seller/seller.js +249 -250
  21. package/src/components/SellerAccountPage/sellerAccountPage.js +110 -110
  22. package/src/components/SellerAccountPage/sellerAccountPage.module.css +55 -55
  23. package/src/components/SellerCountry/sellerCountry.gql.js +11 -11
  24. package/src/components/SellerInformation/index.js +1 -1
  25. package/src/components/SellerInformation/sellerInformation.js +90 -118
  26. package/src/components/SellerLocation/index.js +1 -1
  27. package/src/components/SellerLocation/sellerLocation.js +19 -23
  28. package/src/components/SellerLocation/sellerLocationItem.js +27 -25
  29. package/src/components/SellerPage/sellerPage.js +9 -9
  30. package/src/components/SellerProducts/sellerProducts.js +47 -67
  31. package/src/components/SellerReview/index.js +1 -1
  32. package/src/components/SellerReview/sellerReview.js +143 -143
  33. package/src/components/SellerReviewItem/sellerReviewItem.js +60 -60
  34. package/src/components/SellerVerification/sellerVerification.js +198 -198
  35. package/src/components/SellerVerification/sellerVerification.module.css +47 -47
  36. package/src/components/SellerVerificationPage/sellerVerificationPage.js +43 -43
  37. package/src/components/SellerVerificationPage/sellerVerificationPage.module.css +21 -21
  38. package/src/components/SortBy/index.js +24 -24
  39. package/src/components/WebsiteSwitcher/websiteSwitcher.js +109 -109
  40. package/src/components/commons/Slider/index.js +13 -13
  41. package/src/components/commons/Tabs/index.js +64 -64
  42. package/src/index.js +6 -6
  43. package/src/intercept.js +113 -113
  44. package/src/moduleOverrideWebpackPlugin.js +70 -70
  45. package/src/overwrites/peregrine/lib/store/actions/user/asyncActions.js +96 -96
  46. package/src/overwrites/peregrine/lib/talons/AccountMenu/useAccountMenuItems.js +74 -74
  47. package/src/overwrites/peregrine/lib/talons/Adapter/useAdapter.js +208 -208
  48. package/src/overwrites/peregrine/lib/talons/Header/storeSwitcher.gql.js +45 -45
  49. package/src/overwrites/peregrine/lib/talons/Header/useStoreSwitcher.js +204 -204
  50. package/src/overwrites/peregrine/lib/talons/Region/useRegion.js +102 -102
  51. package/src/overwrites/peregrine/lib/talons/SignIn/signIn.gql.js +56 -56
  52. package/src/overwrites/peregrine/lib/talons/SignIn/useSignIn.js +226 -226
  53. package/src/overwrites/peregrine/lib/util/deriveErrorMessage.js +34 -34
  54. package/src/overwrites/pwa-buildpack/lib/queries/getAvailableStoresConfigData.graphql +11 -11
  55. package/src/overwrites/venia-ui/lib/components/Adapter/adapter.js +112 -112
  56. package/src/overwrites/venia-ui/lib/components/Header/header.js +130 -130
  57. package/src/overwrites/venia-ui/lib/components/Header/storeSwitcher.js +105 -105
  58. package/src/overwrites/venia-ui/lib/components/Header/switcherItem.js +47 -47
  59. package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/MegaMenu.spec.js +91 -91
  60. package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/MegaMenuItem.spec.js +123 -123
  61. package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/Submenu.spec.js +61 -61
  62. package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/SubmenuColumn.spec.js +50 -50
  63. package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/MegaMenu.spec.js.snap +114 -114
  64. package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/MegaMenuItem.spec.js.snap +71 -71
  65. package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/Submenu.spec.js.snap +59 -59
  66. package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/SubmenuColumn.spec.js.snap +34 -34
  67. package/src/overwrites/venia-ui/lib/components/MegaMenu/index.js +1 -1
  68. package/src/overwrites/venia-ui/lib/components/MegaMenu/megaMenu.js +90 -90
  69. package/src/overwrites/venia-ui/lib/components/MegaMenu/megaMenu.module.css +12 -12
  70. package/src/overwrites/venia-ui/lib/components/MegaMenu/megaMenuItem.js +156 -156
  71. package/src/overwrites/venia-ui/lib/components/MegaMenu/megaMenuItem.module.css +30 -30
  72. package/src/overwrites/venia-ui/lib/components/MegaMenu/submenu.js +89 -89
  73. package/src/overwrites/venia-ui/lib/components/MegaMenu/submenu.module.css +42 -42
  74. package/src/overwrites/venia-ui/lib/components/MegaMenu/submenuColumn.js +99 -99
  75. package/src/overwrites/venia-ui/lib/components/MegaMenu/submenuColumn.module.css +28 -28
  76. package/src/overwrites/venia-ui/lib/components/SearchBar/__stories__/searchBar.js +11 -11
  77. package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/searchField.spec.js.snap +72 -72
  78. package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/suggestedCategories.spec.js.snap +30 -30
  79. package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/suggestedProduct.spec.js.snap +69 -69
  80. package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/suggestedProducts.spec.js.snap +7 -7
  81. package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/suggestions.spec.js.snap +12 -12
  82. package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/autocomplete.spec.js +52 -52
  83. package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/searchBar.spec.js +82 -82
  84. package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/searchField.spec.js +87 -87
  85. package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/suggestedCategories.spec.js +45 -45
  86. package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/suggestedProduct.spec.js +43 -43
  87. package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/suggestedProducts.spec.js +45 -45
  88. package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/suggestions.spec.js +110 -110
  89. package/src/overwrites/venia-ui/lib/components/SearchBar/autocomplete.js +172 -172
  90. package/src/overwrites/venia-ui/lib/components/SearchBar/autocomplete.module.css +62 -62
  91. package/src/overwrites/venia-ui/lib/components/SearchBar/index.js +1 -1
  92. package/src/overwrites/venia-ui/lib/components/SearchBar/searchBar.js +74 -74
  93. package/src/overwrites/venia-ui/lib/components/SearchBar/searchBar.module.css +49 -49
  94. package/src/overwrites/venia-ui/lib/components/SearchBar/searchField.js +40 -40
  95. package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedCategories.js +48 -48
  96. package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedCategories.module.css +13 -13
  97. package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedCategory.js +49 -49
  98. package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedProduct.js +97 -97
  99. package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedProduct.module.css +24 -24
  100. package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedProducts.js +43 -43
  101. package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedProducts.module.css +13 -13
  102. package/src/overwrites/venia-ui/lib/components/SearchBar/suggestions.js +75 -75
  103. package/src/overwrites/venia-ui/lib/components/SearchBar/suggestions.module.css +6 -6
  104. package/src/overwrites/venia-ui/lib/components/StoreCodeRoute/storeCodeRoute.js +75 -75
  105. package/src/overwrites/venia-ui/lib/targets/venia-ui-intercept.js +70 -70
  106. package/src/queries/getAvailableWebsitesConfigData.graphql +14 -14
  107. package/src/queries/index.js +30 -30
  108. package/src/talons/BecomeSeller/becomeSeller.gql.js +45 -45
  109. package/src/talons/BecomeSeller/useBecomeSeller.js +145 -145
  110. package/src/talons/BecomeSellerLink/useBecomeSellerLink.js +11 -11
  111. package/src/talons/BecomeSellerPage/useBecomeSellerPage.js +76 -76
  112. package/src/talons/Header/useBecomeSellerLink.js +13 -13
  113. package/src/talons/Header/useWebsiteSwitcher.js +218 -218
  114. package/src/talons/Seller/seller.gql.js +139 -204
  115. package/src/talons/Seller/useSeller.js +66 -71
  116. package/src/talons/SellerAccountPage/useSellerAccountPage.js +174 -174
  117. package/src/talons/SellerCountry/useSellerCountry.js +25 -25
  118. package/src/talons/WebsiteByIp/getWebsiteByIp.gql.js +13 -13
  119. package/src/talons/WebsiteByIp/useWebsiteByIp.js +34 -34
  120. package/src/talons/WebsiteSwitcher/useWebsiteSwitcher.js +218 -218
  121. package/src/theme/vars.js +6 -6
  122. package/src/util/mapSeller.js +7 -7
  123. package/src/components/OperatingHours/index.js +0 -1
  124. package/src/components/OperatingHours/operatingHours.js +0 -32
  125. package/src/components/Seller/sellerAddressCard.js +0 -48
  126. package/src/components/SellerDetail/index.js +0 -1
  127. package/src/components/SellerDetail/sellerDetail.js +0 -158
  128. package/src/components/SellerPage/core.js +0 -10
  129. package/src/talons/SellerProducts/useSellerProducts.js +0 -129
@@ -1,174 +1,174 @@
1
- import { useCallback, useMemo, useState } from 'react';
2
- import { useMutation, useQuery } from '@apollo/client';
3
- import { useUserContext } from '@magento/peregrine/lib/context/user';
4
- import { useGoogleReCaptcha } from '@magento/peregrine/lib/hooks/useGoogleReCaptcha';
5
- import { useEventingContext } from '@magento/peregrine/lib/context/eventing';
6
-
7
- export const useSellerAccountPage = props => {
8
- const {
9
- mutations: {
10
- setCustomerInformationMutation,
11
- changeCustomerPasswordMutation
12
- },
13
- queries: { getCustomerInformationQuery }
14
- } = props;
15
-
16
- const [{ isSignedIn }] = useUserContext();
17
- const [shouldShowNewPassword, setShouldShowNewPassword] = useState(false);
18
-
19
- const [isUpdateMode, setIsUpdateMode] = useState(false);
20
-
21
- const [, { dispatch }] = useEventingContext();
22
-
23
- // Use local state to determine whether to display errors or not.
24
- // Could be replaced by a "reset mutation" function from apollo client.
25
- // https://github.com/apollographql/apollo-feature-requests/issues/170
26
- const [displayError, setDisplayError] = useState(false);
27
-
28
- const { data: accountInformationData, error: loadDataError } = useQuery(
29
- getCustomerInformationQuery,
30
- {
31
- skip: !isSignedIn,
32
- fetchPolicy: 'cache-and-network',
33
- nextFetchPolicy: 'cache-first'
34
- }
35
- );
36
-
37
- const [
38
- setCustomerInformation,
39
- {
40
- error: customerInformationUpdateError,
41
- loading: isUpdatingCustomerInformation
42
- }
43
- ] = useMutation(setCustomerInformationMutation);
44
-
45
- const [
46
- changeCustomerPassword,
47
- {
48
- error: customerPasswordChangeError,
49
- loading: isChangingCustomerPassword
50
- }
51
- ] = useMutation(changeCustomerPasswordMutation);
52
-
53
- const {
54
- generateReCaptchaData,
55
- recaptchaLoading,
56
- recaptchaWidgetProps
57
- } = useGoogleReCaptcha({
58
- currentForm: 'CUSTOMER_EDIT',
59
- formAction: 'editCustomer'
60
- });
61
-
62
- const initialValues = useMemo(() => {
63
- if (accountInformationData) {
64
- return { customer: accountInformationData.customer };
65
- }
66
- }, [accountInformationData]);
67
-
68
- const handleChangePassword = useCallback(() => {
69
- setShouldShowNewPassword(true);
70
- }, [setShouldShowNewPassword]);
71
-
72
- const handleCancel = useCallback(() => {
73
- setIsUpdateMode(false);
74
- setShouldShowNewPassword(false);
75
- }, [setIsUpdateMode]);
76
-
77
- const showUpdateMode = useCallback(() => {
78
- setIsUpdateMode(true);
79
-
80
- // If there were errors from removing/updating info, hide them
81
- // when we open the modal.
82
- setDisplayError(false);
83
- }, [setIsUpdateMode]);
84
-
85
- const handleSubmit = useCallback(
86
- async ({ email, firstname, lastname, password, newPassword }) => {
87
- try {
88
- email = email.trim();
89
- firstname = firstname.trim();
90
- lastname = lastname.trim();
91
- password = password.trim();
92
- newPassword = newPassword ? newPassword.trim() : newPassword;
93
-
94
- if (
95
- initialValues.customer.email !== email ||
96
- initialValues.customer.firstname !== firstname ||
97
- initialValues.customer.lastname !== lastname
98
- ) {
99
- await setCustomerInformation({
100
- variables: {
101
- customerInput: {
102
- email,
103
- firstname,
104
- lastname,
105
- // You must send password because it is required
106
- // when changing email.
107
- password
108
- }
109
- }
110
- });
111
- }
112
- if (password && newPassword) {
113
- const recaptchaDataForChangeCustomerPassword = await generateReCaptchaData();
114
- await changeCustomerPassword({
115
- variables: {
116
- currentPassword: password,
117
- newPassword: newPassword
118
- },
119
- ...recaptchaDataForChangeCustomerPassword
120
- });
121
- }
122
-
123
- dispatch({
124
- type: 'USER_ACCOUNT_UPDATE',
125
- payload: {
126
- email,
127
- firstName: firstname,
128
- lastName: lastname
129
- }
130
- });
131
-
132
- // After submission, close the form if there were no errors.
133
- handleCancel(false);
134
- } catch {
135
- // Make sure any errors from the mutation are displayed.
136
- setDisplayError(true);
137
-
138
- // we have an onError link that logs errors, and FormError
139
- // already renders this error, so just return to avoid
140
- // triggering the success callback
141
- return;
142
- }
143
- },
144
- [
145
- initialValues,
146
- handleCancel,
147
- setCustomerInformation,
148
- generateReCaptchaData,
149
- changeCustomerPassword,
150
- dispatch
151
- ]
152
- );
153
-
154
- const errors = displayError
155
- ? [customerInformationUpdateError, customerPasswordChangeError]
156
- : [];
157
-
158
- return {
159
- handleCancel,
160
- formErrors: errors,
161
- handleSubmit,
162
- handleChangePassword,
163
- initialValues,
164
- isDisabled:
165
- isUpdatingCustomerInformation ||
166
- isChangingCustomerPassword ||
167
- recaptchaLoading,
168
- isUpdateMode,
169
- loadDataError,
170
- shouldShowNewPassword,
171
- showUpdateMode,
172
- recaptchaWidgetProps
173
- };
174
- };
1
+ import { useCallback, useMemo, useState } from 'react';
2
+ import { useMutation, useQuery } from '@apollo/client';
3
+ import { useUserContext } from '@magento/peregrine/lib/context/user';
4
+ import { useGoogleReCaptcha } from '@magento/peregrine/lib/hooks/useGoogleReCaptcha';
5
+ import { useEventingContext } from '@magento/peregrine/lib/context/eventing';
6
+
7
+ export const useSellerAccountPage = props => {
8
+ const {
9
+ mutations: {
10
+ setCustomerInformationMutation,
11
+ changeCustomerPasswordMutation
12
+ },
13
+ queries: { getCustomerInformationQuery }
14
+ } = props;
15
+
16
+ const [{ isSignedIn }] = useUserContext();
17
+ const [shouldShowNewPassword, setShouldShowNewPassword] = useState(false);
18
+
19
+ const [isUpdateMode, setIsUpdateMode] = useState(false);
20
+
21
+ const [, { dispatch }] = useEventingContext();
22
+
23
+ // Use local state to determine whether to display errors or not.
24
+ // Could be replaced by a "reset mutation" function from apollo client.
25
+ // https://github.com/apollographql/apollo-feature-requests/issues/170
26
+ const [displayError, setDisplayError] = useState(false);
27
+
28
+ const { data: accountInformationData, error: loadDataError } = useQuery(
29
+ getCustomerInformationQuery,
30
+ {
31
+ skip: !isSignedIn,
32
+ fetchPolicy: 'cache-and-network',
33
+ nextFetchPolicy: 'cache-first'
34
+ }
35
+ );
36
+
37
+ const [
38
+ setCustomerInformation,
39
+ {
40
+ error: customerInformationUpdateError,
41
+ loading: isUpdatingCustomerInformation
42
+ }
43
+ ] = useMutation(setCustomerInformationMutation);
44
+
45
+ const [
46
+ changeCustomerPassword,
47
+ {
48
+ error: customerPasswordChangeError,
49
+ loading: isChangingCustomerPassword
50
+ }
51
+ ] = useMutation(changeCustomerPasswordMutation);
52
+
53
+ const {
54
+ generateReCaptchaData,
55
+ recaptchaLoading,
56
+ recaptchaWidgetProps
57
+ } = useGoogleReCaptcha({
58
+ currentForm: 'CUSTOMER_EDIT',
59
+ formAction: 'editCustomer'
60
+ });
61
+
62
+ const initialValues = useMemo(() => {
63
+ if (accountInformationData) {
64
+ return { customer: accountInformationData.customer };
65
+ }
66
+ }, [accountInformationData]);
67
+
68
+ const handleChangePassword = useCallback(() => {
69
+ setShouldShowNewPassword(true);
70
+ }, [setShouldShowNewPassword]);
71
+
72
+ const handleCancel = useCallback(() => {
73
+ setIsUpdateMode(false);
74
+ setShouldShowNewPassword(false);
75
+ }, [setIsUpdateMode]);
76
+
77
+ const showUpdateMode = useCallback(() => {
78
+ setIsUpdateMode(true);
79
+
80
+ // If there were errors from removing/updating info, hide them
81
+ // when we open the modal.
82
+ setDisplayError(false);
83
+ }, [setIsUpdateMode]);
84
+
85
+ const handleSubmit = useCallback(
86
+ async ({ email, firstname, lastname, password, newPassword }) => {
87
+ try {
88
+ email = email.trim();
89
+ firstname = firstname.trim();
90
+ lastname = lastname.trim();
91
+ password = password.trim();
92
+ newPassword = newPassword ? newPassword.trim() : newPassword;
93
+
94
+ if (
95
+ initialValues.customer.email !== email ||
96
+ initialValues.customer.firstname !== firstname ||
97
+ initialValues.customer.lastname !== lastname
98
+ ) {
99
+ await setCustomerInformation({
100
+ variables: {
101
+ customerInput: {
102
+ email,
103
+ firstname,
104
+ lastname,
105
+ // You must send password because it is required
106
+ // when changing email.
107
+ password
108
+ }
109
+ }
110
+ });
111
+ }
112
+ if (password && newPassword) {
113
+ const recaptchaDataForChangeCustomerPassword = await generateReCaptchaData();
114
+ await changeCustomerPassword({
115
+ variables: {
116
+ currentPassword: password,
117
+ newPassword: newPassword
118
+ },
119
+ ...recaptchaDataForChangeCustomerPassword
120
+ });
121
+ }
122
+
123
+ dispatch({
124
+ type: 'USER_ACCOUNT_UPDATE',
125
+ payload: {
126
+ email,
127
+ firstName: firstname,
128
+ lastName: lastname
129
+ }
130
+ });
131
+
132
+ // After submission, close the form if there were no errors.
133
+ handleCancel(false);
134
+ } catch {
135
+ // Make sure any errors from the mutation are displayed.
136
+ setDisplayError(true);
137
+
138
+ // we have an onError link that logs errors, and FormError
139
+ // already renders this error, so just return to avoid
140
+ // triggering the success callback
141
+ return;
142
+ }
143
+ },
144
+ [
145
+ initialValues,
146
+ handleCancel,
147
+ setCustomerInformation,
148
+ generateReCaptchaData,
149
+ changeCustomerPassword,
150
+ dispatch
151
+ ]
152
+ );
153
+
154
+ const errors = displayError
155
+ ? [customerInformationUpdateError, customerPasswordChangeError]
156
+ : [];
157
+
158
+ return {
159
+ handleCancel,
160
+ formErrors: errors,
161
+ handleSubmit,
162
+ handleChangePassword,
163
+ initialValues,
164
+ isDisabled:
165
+ isUpdatingCustomerInformation ||
166
+ isChangingCustomerPassword ||
167
+ recaptchaLoading,
168
+ isUpdateMode,
169
+ loadDataError,
170
+ shouldShowNewPassword,
171
+ showUpdateMode,
172
+ recaptchaWidgetProps
173
+ };
174
+ };
@@ -1,25 +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
- };
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
+ };
@@ -1,14 +1,14 @@
1
- import gql from 'graphql-tag';
2
-
3
- export const GET_WEBSITE_BY_IP = gql`
4
- query getWebsiteByUserIp (
5
- $ip_address: String
6
- ) {
7
- getWebsiteByUserIp(ip_address: $ip_address) {
8
- store_code
9
- website_code
10
- website_name
11
- is_suggested
12
- }
13
- }
1
+ import gql from 'graphql-tag';
2
+
3
+ export const GET_WEBSITE_BY_IP = gql`
4
+ query getWebsiteByUserIp (
5
+ $ip_address: String
6
+ ) {
7
+ getWebsiteByUserIp(ip_address: $ip_address) {
8
+ store_code
9
+ website_code
10
+ website_name
11
+ is_suggested
12
+ }
13
+ }
14
14
  `;
@@ -1,34 +1,34 @@
1
- import { useState, useMemo, useEffect } from 'react';
2
- import axios from 'axios';
3
-
4
- export const useWebsiteByIp = websiteCodeInUrl => {
5
- const [websiteByUserIpData, setWebsiteByUserIpData] = useState(null);
6
-
7
- useEffect(() => {
8
- if (!websiteCodeInUrl) {
9
- const fetchData = async () => {
10
- axios.get('https://extreme-ip-lookup.com/json/?key=NqwiAPsYZXoA3jwsnP7B').then((response) => {
11
- let data = response.data;
12
- if (data) {
13
- setWebsiteByUserIpData(data)
14
- }
15
- }).catch((error) => {
16
- });
17
- };
18
-
19
- fetchData();
20
- }
21
- }, [websiteCodeInUrl]);
22
-
23
- const getWebsiteByUserIp = useMemo(() => {
24
- if (websiteByUserIpData) {
25
- return websiteByUserIpData;
26
- } else {
27
- return null;
28
- }
29
- }, [websiteByUserIpData]);
30
-
31
- return {
32
- getWebsiteByUserIp
33
- };
34
- };
1
+ import { useState, useMemo, useEffect } from 'react';
2
+ import axios from 'axios';
3
+
4
+ export const useWebsiteByIp = websiteCodeInUrl => {
5
+ const [websiteByUserIpData, setWebsiteByUserIpData] = useState(null);
6
+
7
+ useEffect(() => {
8
+ if (!websiteCodeInUrl) {
9
+ const fetchData = async () => {
10
+ axios.get('https://extreme-ip-lookup.com/json/?key=NqwiAPsYZXoA3jwsnP7B').then((response) => {
11
+ let data = response.data;
12
+ if (data) {
13
+ setWebsiteByUserIpData(data)
14
+ }
15
+ }).catch((error) => {
16
+ });
17
+ };
18
+
19
+ fetchData();
20
+ }
21
+ }, [websiteCodeInUrl]);
22
+
23
+ const getWebsiteByUserIp = useMemo(() => {
24
+ if (websiteByUserIpData) {
25
+ return websiteByUserIpData;
26
+ } else {
27
+ return null;
28
+ }
29
+ }, [websiteByUserIpData]);
30
+
31
+ return {
32
+ getWebsiteByUserIp
33
+ };
34
+ };