@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.
- package/.github/workflows/dependabot.yml +28 -28
- package/package.json +18 -18
- package/src/Utilities/graphQL.js +76 -76
- package/src/componentOverrideMapping.js +17 -17
- package/src/components/BecomeSeller/becomeSeller.js +335 -335
- package/src/components/BecomeSeller/becomeSeller.module.css +46 -46
- package/src/components/BecomeSellerLink/becomeSellerLink.js +52 -52
- package/src/components/BecomeSellerLink/becomeSellerLink.module.css +12 -12
- package/src/components/BecomeSellerPage/becomeSellerPage.js +45 -45
- package/src/components/BecomeSellerPage/becomeSellerPage.module.css +21 -21
- package/src/components/Filter/index.js +53 -53
- package/src/components/Header/becomeSellerLink.js +28 -28
- package/src/components/Header/becomeSellerLink.module.css +12 -12
- package/src/components/Header/websiteSwitcher.js +109 -109
- package/src/components/Pagination/index.js +49 -49
- package/src/components/PhoneTextInput/phoneTextInput.module.css +21 -21
- package/src/components/ProductItem/index.js +50 -50
- package/src/components/Search/index.js +16 -16
- package/src/components/Seller/index.js +1 -1
- package/src/components/Seller/seller.js +249 -250
- package/src/components/SellerAccountPage/sellerAccountPage.js +110 -110
- package/src/components/SellerAccountPage/sellerAccountPage.module.css +55 -55
- package/src/components/SellerCountry/sellerCountry.gql.js +11 -11
- package/src/components/SellerInformation/index.js +1 -1
- package/src/components/SellerInformation/sellerInformation.js +90 -118
- package/src/components/SellerLocation/index.js +1 -1
- package/src/components/SellerLocation/sellerLocation.js +19 -23
- package/src/components/SellerLocation/sellerLocationItem.js +27 -25
- package/src/components/SellerPage/sellerPage.js +9 -9
- package/src/components/SellerProducts/sellerProducts.js +47 -67
- package/src/components/SellerReview/index.js +1 -1
- package/src/components/SellerReview/sellerReview.js +143 -143
- package/src/components/SellerReviewItem/sellerReviewItem.js +60 -60
- package/src/components/SellerVerification/sellerVerification.js +198 -198
- package/src/components/SellerVerification/sellerVerification.module.css +47 -47
- package/src/components/SellerVerificationPage/sellerVerificationPage.js +43 -43
- package/src/components/SellerVerificationPage/sellerVerificationPage.module.css +21 -21
- package/src/components/SortBy/index.js +24 -24
- package/src/components/WebsiteSwitcher/websiteSwitcher.js +109 -109
- package/src/components/commons/Slider/index.js +13 -13
- package/src/components/commons/Tabs/index.js +64 -64
- package/src/index.js +6 -6
- package/src/intercept.js +113 -113
- package/src/moduleOverrideWebpackPlugin.js +70 -70
- package/src/overwrites/peregrine/lib/store/actions/user/asyncActions.js +96 -96
- package/src/overwrites/peregrine/lib/talons/AccountMenu/useAccountMenuItems.js +74 -74
- package/src/overwrites/peregrine/lib/talons/Adapter/useAdapter.js +208 -208
- package/src/overwrites/peregrine/lib/talons/Header/storeSwitcher.gql.js +45 -45
- package/src/overwrites/peregrine/lib/talons/Header/useStoreSwitcher.js +204 -204
- package/src/overwrites/peregrine/lib/talons/Region/useRegion.js +102 -102
- package/src/overwrites/peregrine/lib/talons/SignIn/signIn.gql.js +56 -56
- package/src/overwrites/peregrine/lib/talons/SignIn/useSignIn.js +226 -226
- package/src/overwrites/peregrine/lib/util/deriveErrorMessage.js +34 -34
- package/src/overwrites/pwa-buildpack/lib/queries/getAvailableStoresConfigData.graphql +11 -11
- package/src/overwrites/venia-ui/lib/components/Adapter/adapter.js +112 -112
- package/src/overwrites/venia-ui/lib/components/Header/header.js +130 -130
- package/src/overwrites/venia-ui/lib/components/Header/storeSwitcher.js +105 -105
- package/src/overwrites/venia-ui/lib/components/Header/switcherItem.js +47 -47
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/MegaMenu.spec.js +91 -91
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/MegaMenuItem.spec.js +123 -123
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/Submenu.spec.js +61 -61
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/SubmenuColumn.spec.js +50 -50
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/MegaMenu.spec.js.snap +114 -114
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/MegaMenuItem.spec.js.snap +71 -71
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/Submenu.spec.js.snap +59 -59
- package/src/overwrites/venia-ui/lib/components/MegaMenu/__tests__/__snapshots__/SubmenuColumn.spec.js.snap +34 -34
- package/src/overwrites/venia-ui/lib/components/MegaMenu/index.js +1 -1
- package/src/overwrites/venia-ui/lib/components/MegaMenu/megaMenu.js +90 -90
- package/src/overwrites/venia-ui/lib/components/MegaMenu/megaMenu.module.css +12 -12
- package/src/overwrites/venia-ui/lib/components/MegaMenu/megaMenuItem.js +156 -156
- package/src/overwrites/venia-ui/lib/components/MegaMenu/megaMenuItem.module.css +30 -30
- package/src/overwrites/venia-ui/lib/components/MegaMenu/submenu.js +89 -89
- package/src/overwrites/venia-ui/lib/components/MegaMenu/submenu.module.css +42 -42
- package/src/overwrites/venia-ui/lib/components/MegaMenu/submenuColumn.js +99 -99
- package/src/overwrites/venia-ui/lib/components/MegaMenu/submenuColumn.module.css +28 -28
- package/src/overwrites/venia-ui/lib/components/SearchBar/__stories__/searchBar.js +11 -11
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/searchField.spec.js.snap +72 -72
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/suggestedCategories.spec.js.snap +30 -30
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/suggestedProduct.spec.js.snap +69 -69
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/suggestedProducts.spec.js.snap +7 -7
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/__snapshots__/suggestions.spec.js.snap +12 -12
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/autocomplete.spec.js +52 -52
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/searchBar.spec.js +82 -82
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/searchField.spec.js +87 -87
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/suggestedCategories.spec.js +45 -45
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/suggestedProduct.spec.js +43 -43
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/suggestedProducts.spec.js +45 -45
- package/src/overwrites/venia-ui/lib/components/SearchBar/__tests__/suggestions.spec.js +110 -110
- package/src/overwrites/venia-ui/lib/components/SearchBar/autocomplete.js +172 -172
- package/src/overwrites/venia-ui/lib/components/SearchBar/autocomplete.module.css +62 -62
- package/src/overwrites/venia-ui/lib/components/SearchBar/index.js +1 -1
- package/src/overwrites/venia-ui/lib/components/SearchBar/searchBar.js +74 -74
- package/src/overwrites/venia-ui/lib/components/SearchBar/searchBar.module.css +49 -49
- package/src/overwrites/venia-ui/lib/components/SearchBar/searchField.js +40 -40
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedCategories.js +48 -48
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedCategories.module.css +13 -13
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedCategory.js +49 -49
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedProduct.js +97 -97
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedProduct.module.css +24 -24
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedProducts.js +43 -43
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestedProducts.module.css +13 -13
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestions.js +75 -75
- package/src/overwrites/venia-ui/lib/components/SearchBar/suggestions.module.css +6 -6
- package/src/overwrites/venia-ui/lib/components/StoreCodeRoute/storeCodeRoute.js +75 -75
- package/src/overwrites/venia-ui/lib/targets/venia-ui-intercept.js +70 -70
- package/src/queries/getAvailableWebsitesConfigData.graphql +14 -14
- package/src/queries/index.js +30 -30
- package/src/talons/BecomeSeller/becomeSeller.gql.js +45 -45
- package/src/talons/BecomeSeller/useBecomeSeller.js +145 -145
- package/src/talons/BecomeSellerLink/useBecomeSellerLink.js +11 -11
- package/src/talons/BecomeSellerPage/useBecomeSellerPage.js +76 -76
- package/src/talons/Header/useBecomeSellerLink.js +13 -13
- package/src/talons/Header/useWebsiteSwitcher.js +218 -218
- package/src/talons/Seller/seller.gql.js +139 -204
- package/src/talons/Seller/useSeller.js +66 -71
- package/src/talons/SellerAccountPage/useSellerAccountPage.js +174 -174
- package/src/talons/SellerCountry/useSellerCountry.js +25 -25
- package/src/talons/WebsiteByIp/getWebsiteByIp.gql.js +13 -13
- package/src/talons/WebsiteByIp/useWebsiteByIp.js +34 -34
- package/src/talons/WebsiteSwitcher/useWebsiteSwitcher.js +218 -218
- package/src/theme/vars.js +6 -6
- package/src/util/mapSeller.js +7 -7
- package/src/components/OperatingHours/index.js +0 -1
- package/src/components/OperatingHours/operatingHours.js +0 -32
- package/src/components/Seller/sellerAddressCard.js +0 -48
- package/src/components/SellerDetail/index.js +0 -1
- package/src/components/SellerDetail/sellerDetail.js +0 -158
- package/src/components/SellerPage/core.js +0 -10
- package/src/talons/SellerProducts/useSellerProducts.js +0 -129
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
import { useCallback, useEffect } from 'react';
|
|
2
|
-
import { BrowserPersistence } from '@magento/peregrine/lib/util';
|
|
3
|
-
|
|
4
|
-
const storage = new BrowserPersistence();
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @param {Object} props
|
|
8
|
-
* @param {Function} props.onSignOut - A function to call when sign out occurs.
|
|
9
|
-
*
|
|
10
|
-
* @returns {Object} result
|
|
11
|
-
* @returns {Function} result.handleSignOut - The function to handle sign out actions.
|
|
12
|
-
*/
|
|
13
|
-
export const useAccountMenuItems = props => {
|
|
14
|
-
const { onSignOut } = props;
|
|
15
|
-
|
|
16
|
-
const handleSignOut = useCallback(() => {
|
|
17
|
-
onSignOut();
|
|
18
|
-
}, [onSignOut]);
|
|
19
|
-
|
|
20
|
-
let MENU_ITEMS = [
|
|
21
|
-
{
|
|
22
|
-
name: 'Order History',
|
|
23
|
-
id: 'accountMenu.orderHistoryLink',
|
|
24
|
-
url: '/order-history'
|
|
25
|
-
},
|
|
26
|
-
// Hide links until features are completed
|
|
27
|
-
// {
|
|
28
|
-
// name: 'Store Credit & Gift Cards',
|
|
29
|
-
// id: 'accountMenu.storeCreditLink',
|
|
30
|
-
// url: ''
|
|
31
|
-
// },
|
|
32
|
-
{
|
|
33
|
-
name: 'Favorites Lists',
|
|
34
|
-
id: 'accountMenu.favoritesListsLink',
|
|
35
|
-
url: '/wishlist'
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
name: 'Address Book',
|
|
39
|
-
id: 'accountMenu.addressBookLink',
|
|
40
|
-
url: '/address-book'
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: 'Saved Payments',
|
|
44
|
-
id: 'accountMenu.savedPaymentsLink',
|
|
45
|
-
url: '/saved-payments'
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
name: 'Communications',
|
|
49
|
-
id: 'accountMenu.communicationsLinak',
|
|
50
|
-
url: '/communications'
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
name: 'Account Information',
|
|
54
|
-
id: 'accountMenu.accountInfoLink',
|
|
55
|
-
url: '/account-information'
|
|
56
|
-
}
|
|
57
|
-
];
|
|
58
|
-
|
|
59
|
-
if (storage && storage.getItem('is_seller')) {
|
|
60
|
-
MENU_ITEMS = [
|
|
61
|
-
...MENU_ITEMS,
|
|
62
|
-
{
|
|
63
|
-
name: 'Seller Account Information',
|
|
64
|
-
id: 'accountMenu.sellerAccountInfoLink',
|
|
65
|
-
url: '/seller-account'
|
|
66
|
-
}
|
|
67
|
-
];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
handleSignOut,
|
|
72
|
-
menuItems: MENU_ITEMS
|
|
73
|
-
};
|
|
74
|
-
};
|
|
1
|
+
import { useCallback, useEffect } from 'react';
|
|
2
|
+
import { BrowserPersistence } from '@magento/peregrine/lib/util';
|
|
3
|
+
|
|
4
|
+
const storage = new BrowserPersistence();
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {Object} props
|
|
8
|
+
* @param {Function} props.onSignOut - A function to call when sign out occurs.
|
|
9
|
+
*
|
|
10
|
+
* @returns {Object} result
|
|
11
|
+
* @returns {Function} result.handleSignOut - The function to handle sign out actions.
|
|
12
|
+
*/
|
|
13
|
+
export const useAccountMenuItems = props => {
|
|
14
|
+
const { onSignOut } = props;
|
|
15
|
+
|
|
16
|
+
const handleSignOut = useCallback(() => {
|
|
17
|
+
onSignOut();
|
|
18
|
+
}, [onSignOut]);
|
|
19
|
+
|
|
20
|
+
let MENU_ITEMS = [
|
|
21
|
+
{
|
|
22
|
+
name: 'Order History',
|
|
23
|
+
id: 'accountMenu.orderHistoryLink',
|
|
24
|
+
url: '/order-history'
|
|
25
|
+
},
|
|
26
|
+
// Hide links until features are completed
|
|
27
|
+
// {
|
|
28
|
+
// name: 'Store Credit & Gift Cards',
|
|
29
|
+
// id: 'accountMenu.storeCreditLink',
|
|
30
|
+
// url: ''
|
|
31
|
+
// },
|
|
32
|
+
{
|
|
33
|
+
name: 'Favorites Lists',
|
|
34
|
+
id: 'accountMenu.favoritesListsLink',
|
|
35
|
+
url: '/wishlist'
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'Address Book',
|
|
39
|
+
id: 'accountMenu.addressBookLink',
|
|
40
|
+
url: '/address-book'
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'Saved Payments',
|
|
44
|
+
id: 'accountMenu.savedPaymentsLink',
|
|
45
|
+
url: '/saved-payments'
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'Communications',
|
|
49
|
+
id: 'accountMenu.communicationsLinak',
|
|
50
|
+
url: '/communications'
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'Account Information',
|
|
54
|
+
id: 'accountMenu.accountInfoLink',
|
|
55
|
+
url: '/account-information'
|
|
56
|
+
}
|
|
57
|
+
];
|
|
58
|
+
|
|
59
|
+
if (storage && storage.getItem('is_seller')) {
|
|
60
|
+
MENU_ITEMS = [
|
|
61
|
+
...MENU_ITEMS,
|
|
62
|
+
{
|
|
63
|
+
name: 'Seller Account Information',
|
|
64
|
+
id: 'accountMenu.sellerAccountInfoLink',
|
|
65
|
+
url: '/seller-account'
|
|
66
|
+
}
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
handleSignOut,
|
|
72
|
+
menuItems: MENU_ITEMS
|
|
73
|
+
};
|
|
74
|
+
};
|
|
@@ -1,208 +1,208 @@
|
|
|
1
|
-
import { ApolloLink } from '@apollo/client';
|
|
2
|
-
import { InMemoryCache } from '@apollo/client/cache';
|
|
3
|
-
import { ApolloClient } from '@apollo/client/core';
|
|
4
|
-
import { CachePersistor } from 'apollo-cache-persist';
|
|
5
|
-
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
6
|
-
|
|
7
|
-
import attachClient from '@magento/peregrine/lib/Apollo/attachClientToStore';
|
|
8
|
-
import { clearCartDataFromCache } from '@magento/peregrine/lib/Apollo/clearCartDataFromCache';
|
|
9
|
-
import { clearCustomerDataFromCache } from '@magento/peregrine/lib/Apollo/clearCustomerDataFromCache';
|
|
10
|
-
import { CACHE_PERSIST_PREFIX } from '@magento/peregrine/lib/Apollo/constants';
|
|
11
|
-
import getLinks from '@magento/peregrine/lib/Apollo/links';
|
|
12
|
-
import typePolicies from '@magento/peregrine/lib/Apollo/policies';
|
|
13
|
-
import { BrowserPersistence } from '@magento/peregrine/lib/util';
|
|
14
|
-
|
|
15
|
-
const isServer = !globalThis.document;
|
|
16
|
-
const storage = new BrowserPersistence();
|
|
17
|
-
|
|
18
|
-
export const useAdapter = props => {
|
|
19
|
-
const { apiUrl, configureLinks, origin, store, styles } = props;
|
|
20
|
-
|
|
21
|
-
// Custom
|
|
22
|
-
const websiteCodes = [];
|
|
23
|
-
|
|
24
|
-
AVAILABLE_WEBSITES.forEach(store => {
|
|
25
|
-
websiteCodes.push(store.website_code);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
websiteCodes.sort((a, b) => b.length - a.length);
|
|
29
|
-
|
|
30
|
-
const { location } = globalThis;
|
|
31
|
-
const match = location && location.pathname.split("/")[1];
|
|
32
|
-
let websiteCodeInUrl = websiteCodes.find((str) => str === match);
|
|
33
|
-
|
|
34
|
-
let isBaseWebsite = false;
|
|
35
|
-
|
|
36
|
-
let websiteCode = storage.getItem('website_code');
|
|
37
|
-
|
|
38
|
-
if (!websiteCodeInUrl) {
|
|
39
|
-
isBaseWebsite = true;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
let basename = '/';
|
|
43
|
-
|
|
44
|
-
const urlHasStoreCode = isBaseWebsite ? false : true;
|
|
45
|
-
if (urlHasStoreCode) {
|
|
46
|
-
basename = `/${websiteCode}`;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const [initialized, setInitialized] = useState(false);
|
|
50
|
-
|
|
51
|
-
const apiBase = useMemo(
|
|
52
|
-
() => apiUrl || new URL('/graphql', origin).toString(),
|
|
53
|
-
[apiUrl, origin]
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
const apolloLink = useMemo(() => {
|
|
57
|
-
let links = getLinks(apiBase);
|
|
58
|
-
|
|
59
|
-
if (configureLinks) {
|
|
60
|
-
links = configureLinks(links, apiBase);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return ApolloLink.from(Array.from(links.values()));
|
|
64
|
-
}, [apiBase, configureLinks]);
|
|
65
|
-
|
|
66
|
-
const createApolloClient = useCallback((cache, link) => {
|
|
67
|
-
return new ApolloClient({
|
|
68
|
-
cache,
|
|
69
|
-
link,
|
|
70
|
-
ssrMode: isServer
|
|
71
|
-
});
|
|
72
|
-
}, []);
|
|
73
|
-
|
|
74
|
-
const createCachePersistor = useCallback((storeCode, cache) => {
|
|
75
|
-
return isServer
|
|
76
|
-
? null
|
|
77
|
-
: new CachePersistor({
|
|
78
|
-
key: `${CACHE_PERSIST_PREFIX}-${storeCode}`,
|
|
79
|
-
cache,
|
|
80
|
-
storage: globalThis.localStorage,
|
|
81
|
-
debug: process.env.NODE_ENV === 'development'
|
|
82
|
-
});
|
|
83
|
-
}, []);
|
|
84
|
-
|
|
85
|
-
const clearCacheData = useCallback(
|
|
86
|
-
async (client, cacheType) => {
|
|
87
|
-
const storeCode = storage.getItem('store_view_code') || 'default';
|
|
88
|
-
|
|
89
|
-
// Clear current store
|
|
90
|
-
if (cacheType === 'cart') {
|
|
91
|
-
await clearCartDataFromCache(client);
|
|
92
|
-
} else if (cacheType === 'customer') {
|
|
93
|
-
await clearCustomerDataFromCache(client);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Clear other stores
|
|
97
|
-
for (const store of AVAILABLE_STORE_VIEWS) {
|
|
98
|
-
if (store.store_code !== storeCode) {
|
|
99
|
-
// Get saved data directly from local storage
|
|
100
|
-
const existingStorePersistor = globalThis.localStorage.getItem(
|
|
101
|
-
`${CACHE_PERSIST_PREFIX}-${store.store_code}`
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
// Make sure we have data available
|
|
105
|
-
if (
|
|
106
|
-
existingStorePersistor &&
|
|
107
|
-
Object.keys(existingStorePersistor).length > 0
|
|
108
|
-
) {
|
|
109
|
-
const storeCache = new InMemoryCache();
|
|
110
|
-
|
|
111
|
-
// Restore available data
|
|
112
|
-
storeCache.restore(JSON.parse(existingStorePersistor));
|
|
113
|
-
|
|
114
|
-
const storeClient = createApolloClient(
|
|
115
|
-
storeCache,
|
|
116
|
-
apolloLink
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
storeClient.persistor = isServer
|
|
120
|
-
? null
|
|
121
|
-
: createCachePersistor(
|
|
122
|
-
store.store_code,
|
|
123
|
-
storeCache
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
// Clear other store
|
|
127
|
-
if (cacheType === 'cart') {
|
|
128
|
-
await clearCartDataFromCache(storeClient);
|
|
129
|
-
} else if (cacheType === 'customer') {
|
|
130
|
-
await clearCustomerDataFromCache(storeClient);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
[apolloLink, createApolloClient, createCachePersistor]
|
|
137
|
-
);
|
|
138
|
-
|
|
139
|
-
const apolloClient = useMemo(() => {
|
|
140
|
-
const storeCode = storage.getItem('store_view_code') || 'default';
|
|
141
|
-
const client = createApolloClient(preInstantiatedCache, apolloLink);
|
|
142
|
-
const persistor = isServer
|
|
143
|
-
? null
|
|
144
|
-
: createCachePersistor(storeCode, preInstantiatedCache);
|
|
145
|
-
|
|
146
|
-
client.apiBase = apiBase;
|
|
147
|
-
client.persistor = persistor;
|
|
148
|
-
client.clearCacheData = clearCacheData;
|
|
149
|
-
|
|
150
|
-
return client;
|
|
151
|
-
}, [
|
|
152
|
-
apiBase,
|
|
153
|
-
apolloLink,
|
|
154
|
-
clearCacheData,
|
|
155
|
-
createApolloClient,
|
|
156
|
-
createCachePersistor
|
|
157
|
-
]);
|
|
158
|
-
|
|
159
|
-
const getUserConfirmation = useCallback(async (message, callback) => {
|
|
160
|
-
if (typeof globalThis.handleRouteChangeConfirmation === 'function') {
|
|
161
|
-
return globalThis.handleRouteChangeConfirmation(message, callback);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return callback(globalThis.confirm(message));
|
|
165
|
-
}, []);
|
|
166
|
-
|
|
167
|
-
const apolloProps = { client: apolloClient };
|
|
168
|
-
const reduxProps = { store };
|
|
169
|
-
const routerProps = { basename, getUserConfirmation };
|
|
170
|
-
const styleProps = { initialState: styles };
|
|
171
|
-
|
|
172
|
-
// perform blocking async work here
|
|
173
|
-
useEffect(() => {
|
|
174
|
-
if (initialized) return;
|
|
175
|
-
|
|
176
|
-
// immediately invoke this async function
|
|
177
|
-
(async () => {
|
|
178
|
-
// restore persisted data to the Apollo cache
|
|
179
|
-
await apolloClient.persistor.restore();
|
|
180
|
-
|
|
181
|
-
// attach the Apollo client to the Redux store
|
|
182
|
-
await attachClient(apolloClient);
|
|
183
|
-
|
|
184
|
-
// mark this routine as complete
|
|
185
|
-
setInitialized(true);
|
|
186
|
-
})();
|
|
187
|
-
}, [apolloClient, initialized]);
|
|
188
|
-
|
|
189
|
-
return {
|
|
190
|
-
apolloProps,
|
|
191
|
-
initialized,
|
|
192
|
-
reduxProps,
|
|
193
|
-
routerProps,
|
|
194
|
-
styleProps,
|
|
195
|
-
urlHasStoreCode
|
|
196
|
-
};
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* To improve initial load time, create an apollo cache object as soon as
|
|
201
|
-
* this module is executed, since it doesn't depend on any component props.
|
|
202
|
-
* The tradeoff is that we may be creating an instance we don't end up needing.
|
|
203
|
-
*/
|
|
204
|
-
const preInstantiatedCache = new InMemoryCache({
|
|
205
|
-
// POSSIBLE_TYPES is injected into the bundle by webpack at build time.
|
|
206
|
-
possibleTypes: POSSIBLE_TYPES,
|
|
207
|
-
typePolicies
|
|
208
|
-
});
|
|
1
|
+
import { ApolloLink } from '@apollo/client';
|
|
2
|
+
import { InMemoryCache } from '@apollo/client/cache';
|
|
3
|
+
import { ApolloClient } from '@apollo/client/core';
|
|
4
|
+
import { CachePersistor } from 'apollo-cache-persist';
|
|
5
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import attachClient from '@magento/peregrine/lib/Apollo/attachClientToStore';
|
|
8
|
+
import { clearCartDataFromCache } from '@magento/peregrine/lib/Apollo/clearCartDataFromCache';
|
|
9
|
+
import { clearCustomerDataFromCache } from '@magento/peregrine/lib/Apollo/clearCustomerDataFromCache';
|
|
10
|
+
import { CACHE_PERSIST_PREFIX } from '@magento/peregrine/lib/Apollo/constants';
|
|
11
|
+
import getLinks from '@magento/peregrine/lib/Apollo/links';
|
|
12
|
+
import typePolicies from '@magento/peregrine/lib/Apollo/policies';
|
|
13
|
+
import { BrowserPersistence } from '@magento/peregrine/lib/util';
|
|
14
|
+
|
|
15
|
+
const isServer = !globalThis.document;
|
|
16
|
+
const storage = new BrowserPersistence();
|
|
17
|
+
|
|
18
|
+
export const useAdapter = props => {
|
|
19
|
+
const { apiUrl, configureLinks, origin, store, styles } = props;
|
|
20
|
+
|
|
21
|
+
// Custom
|
|
22
|
+
const websiteCodes = [];
|
|
23
|
+
|
|
24
|
+
AVAILABLE_WEBSITES.forEach(store => {
|
|
25
|
+
websiteCodes.push(store.website_code);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
websiteCodes.sort((a, b) => b.length - a.length);
|
|
29
|
+
|
|
30
|
+
const { location } = globalThis;
|
|
31
|
+
const match = location && location.pathname.split("/")[1];
|
|
32
|
+
let websiteCodeInUrl = websiteCodes.find((str) => str === match);
|
|
33
|
+
|
|
34
|
+
let isBaseWebsite = false;
|
|
35
|
+
|
|
36
|
+
let websiteCode = storage.getItem('website_code');
|
|
37
|
+
|
|
38
|
+
if (!websiteCodeInUrl) {
|
|
39
|
+
isBaseWebsite = true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let basename = '/';
|
|
43
|
+
|
|
44
|
+
const urlHasStoreCode = isBaseWebsite ? false : true;
|
|
45
|
+
if (urlHasStoreCode) {
|
|
46
|
+
basename = `/${websiteCode}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const [initialized, setInitialized] = useState(false);
|
|
50
|
+
|
|
51
|
+
const apiBase = useMemo(
|
|
52
|
+
() => apiUrl || new URL('/graphql', origin).toString(),
|
|
53
|
+
[apiUrl, origin]
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const apolloLink = useMemo(() => {
|
|
57
|
+
let links = getLinks(apiBase);
|
|
58
|
+
|
|
59
|
+
if (configureLinks) {
|
|
60
|
+
links = configureLinks(links, apiBase);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return ApolloLink.from(Array.from(links.values()));
|
|
64
|
+
}, [apiBase, configureLinks]);
|
|
65
|
+
|
|
66
|
+
const createApolloClient = useCallback((cache, link) => {
|
|
67
|
+
return new ApolloClient({
|
|
68
|
+
cache,
|
|
69
|
+
link,
|
|
70
|
+
ssrMode: isServer
|
|
71
|
+
});
|
|
72
|
+
}, []);
|
|
73
|
+
|
|
74
|
+
const createCachePersistor = useCallback((storeCode, cache) => {
|
|
75
|
+
return isServer
|
|
76
|
+
? null
|
|
77
|
+
: new CachePersistor({
|
|
78
|
+
key: `${CACHE_PERSIST_PREFIX}-${storeCode}`,
|
|
79
|
+
cache,
|
|
80
|
+
storage: globalThis.localStorage,
|
|
81
|
+
debug: process.env.NODE_ENV === 'development'
|
|
82
|
+
});
|
|
83
|
+
}, []);
|
|
84
|
+
|
|
85
|
+
const clearCacheData = useCallback(
|
|
86
|
+
async (client, cacheType) => {
|
|
87
|
+
const storeCode = storage.getItem('store_view_code') || 'default';
|
|
88
|
+
|
|
89
|
+
// Clear current store
|
|
90
|
+
if (cacheType === 'cart') {
|
|
91
|
+
await clearCartDataFromCache(client);
|
|
92
|
+
} else if (cacheType === 'customer') {
|
|
93
|
+
await clearCustomerDataFromCache(client);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Clear other stores
|
|
97
|
+
for (const store of AVAILABLE_STORE_VIEWS) {
|
|
98
|
+
if (store.store_code !== storeCode) {
|
|
99
|
+
// Get saved data directly from local storage
|
|
100
|
+
const existingStorePersistor = globalThis.localStorage.getItem(
|
|
101
|
+
`${CACHE_PERSIST_PREFIX}-${store.store_code}`
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
// Make sure we have data available
|
|
105
|
+
if (
|
|
106
|
+
existingStorePersistor &&
|
|
107
|
+
Object.keys(existingStorePersistor).length > 0
|
|
108
|
+
) {
|
|
109
|
+
const storeCache = new InMemoryCache();
|
|
110
|
+
|
|
111
|
+
// Restore available data
|
|
112
|
+
storeCache.restore(JSON.parse(existingStorePersistor));
|
|
113
|
+
|
|
114
|
+
const storeClient = createApolloClient(
|
|
115
|
+
storeCache,
|
|
116
|
+
apolloLink
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
storeClient.persistor = isServer
|
|
120
|
+
? null
|
|
121
|
+
: createCachePersistor(
|
|
122
|
+
store.store_code,
|
|
123
|
+
storeCache
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
// Clear other store
|
|
127
|
+
if (cacheType === 'cart') {
|
|
128
|
+
await clearCartDataFromCache(storeClient);
|
|
129
|
+
} else if (cacheType === 'customer') {
|
|
130
|
+
await clearCustomerDataFromCache(storeClient);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
[apolloLink, createApolloClient, createCachePersistor]
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
const apolloClient = useMemo(() => {
|
|
140
|
+
const storeCode = storage.getItem('store_view_code') || 'default';
|
|
141
|
+
const client = createApolloClient(preInstantiatedCache, apolloLink);
|
|
142
|
+
const persistor = isServer
|
|
143
|
+
? null
|
|
144
|
+
: createCachePersistor(storeCode, preInstantiatedCache);
|
|
145
|
+
|
|
146
|
+
client.apiBase = apiBase;
|
|
147
|
+
client.persistor = persistor;
|
|
148
|
+
client.clearCacheData = clearCacheData;
|
|
149
|
+
|
|
150
|
+
return client;
|
|
151
|
+
}, [
|
|
152
|
+
apiBase,
|
|
153
|
+
apolloLink,
|
|
154
|
+
clearCacheData,
|
|
155
|
+
createApolloClient,
|
|
156
|
+
createCachePersistor
|
|
157
|
+
]);
|
|
158
|
+
|
|
159
|
+
const getUserConfirmation = useCallback(async (message, callback) => {
|
|
160
|
+
if (typeof globalThis.handleRouteChangeConfirmation === 'function') {
|
|
161
|
+
return globalThis.handleRouteChangeConfirmation(message, callback);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return callback(globalThis.confirm(message));
|
|
165
|
+
}, []);
|
|
166
|
+
|
|
167
|
+
const apolloProps = { client: apolloClient };
|
|
168
|
+
const reduxProps = { store };
|
|
169
|
+
const routerProps = { basename, getUserConfirmation };
|
|
170
|
+
const styleProps = { initialState: styles };
|
|
171
|
+
|
|
172
|
+
// perform blocking async work here
|
|
173
|
+
useEffect(() => {
|
|
174
|
+
if (initialized) return;
|
|
175
|
+
|
|
176
|
+
// immediately invoke this async function
|
|
177
|
+
(async () => {
|
|
178
|
+
// restore persisted data to the Apollo cache
|
|
179
|
+
await apolloClient.persistor.restore();
|
|
180
|
+
|
|
181
|
+
// attach the Apollo client to the Redux store
|
|
182
|
+
await attachClient(apolloClient);
|
|
183
|
+
|
|
184
|
+
// mark this routine as complete
|
|
185
|
+
setInitialized(true);
|
|
186
|
+
})();
|
|
187
|
+
}, [apolloClient, initialized]);
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
apolloProps,
|
|
191
|
+
initialized,
|
|
192
|
+
reduxProps,
|
|
193
|
+
routerProps,
|
|
194
|
+
styleProps,
|
|
195
|
+
urlHasStoreCode
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* To improve initial load time, create an apollo cache object as soon as
|
|
201
|
+
* this module is executed, since it doesn't depend on any component props.
|
|
202
|
+
* The tradeoff is that we may be creating an instance we don't end up needing.
|
|
203
|
+
*/
|
|
204
|
+
const preInstantiatedCache = new InMemoryCache({
|
|
205
|
+
// POSSIBLE_TYPES is injected into the bundle by webpack at build time.
|
|
206
|
+
possibleTypes: POSSIBLE_TYPES,
|
|
207
|
+
typePolicies
|
|
208
|
+
});
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { gql } from '@apollo/client';
|
|
2
|
-
|
|
3
|
-
export const GET_STORE_CONFIG_DATA = gql`
|
|
4
|
-
query getStoreConfigData {
|
|
5
|
-
# eslint-disable-next-line @graphql-eslint/require-id-when-available
|
|
6
|
-
storeConfig {
|
|
7
|
-
store_code
|
|
8
|
-
store_name
|
|
9
|
-
store_group_name
|
|
10
|
-
website_code
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
`;
|
|
14
|
-
|
|
15
|
-
export const GET_ROUTE_DATA = gql`
|
|
16
|
-
query getRouteData($url: String!) {
|
|
17
|
-
route(url: $url) {
|
|
18
|
-
relative_url
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
`;
|
|
22
|
-
|
|
23
|
-
export const GET_AVAILABLE_STORES_DATA = gql`
|
|
24
|
-
query getAvailableStoresData {
|
|
25
|
-
# eslint-disable-next-line @graphql-eslint/require-id-when-available
|
|
26
|
-
availableStores {
|
|
27
|
-
default_display_currency_code
|
|
28
|
-
locale
|
|
29
|
-
secure_base_media_url
|
|
30
|
-
store_code
|
|
31
|
-
store_group_code
|
|
32
|
-
store_group_name
|
|
33
|
-
store_name
|
|
34
|
-
store_sort_order
|
|
35
|
-
website_code
|
|
36
|
-
is_default_store
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
`;
|
|
40
|
-
|
|
41
|
-
export default {
|
|
42
|
-
getStoreConfigData: GET_STORE_CONFIG_DATA,
|
|
43
|
-
getRouteData: GET_ROUTE_DATA,
|
|
44
|
-
getAvailableStoresData: GET_AVAILABLE_STORES_DATA
|
|
45
|
-
};
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
export const GET_STORE_CONFIG_DATA = gql`
|
|
4
|
+
query getStoreConfigData {
|
|
5
|
+
# eslint-disable-next-line @graphql-eslint/require-id-when-available
|
|
6
|
+
storeConfig {
|
|
7
|
+
store_code
|
|
8
|
+
store_name
|
|
9
|
+
store_group_name
|
|
10
|
+
website_code
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
export const GET_ROUTE_DATA = gql`
|
|
16
|
+
query getRouteData($url: String!) {
|
|
17
|
+
route(url: $url) {
|
|
18
|
+
relative_url
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
export const GET_AVAILABLE_STORES_DATA = gql`
|
|
24
|
+
query getAvailableStoresData {
|
|
25
|
+
# eslint-disable-next-line @graphql-eslint/require-id-when-available
|
|
26
|
+
availableStores {
|
|
27
|
+
default_display_currency_code
|
|
28
|
+
locale
|
|
29
|
+
secure_base_media_url
|
|
30
|
+
store_code
|
|
31
|
+
store_group_code
|
|
32
|
+
store_group_name
|
|
33
|
+
store_name
|
|
34
|
+
store_sort_order
|
|
35
|
+
website_code
|
|
36
|
+
is_default_store
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
export default {
|
|
42
|
+
getStoreConfigData: GET_STORE_CONFIG_DATA,
|
|
43
|
+
getRouteData: GET_ROUTE_DATA,
|
|
44
|
+
getAvailableStoresData: GET_AVAILABLE_STORES_DATA
|
|
45
|
+
};
|