@jetshop/core 5.9.0 → 5.11.2
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/ChannelHandler/ChannelHandler.d.ts +9 -13
- package/ChannelHandler/ChannelHandler.js +24 -66
- package/ChannelHandler/ChannelHandler.js.map +1 -1
- package/ChannelHandler/channelUtils.d.ts +13 -0
- package/ChannelHandler/channelUtils.js +26 -15
- package/ChannelHandler/channelUtils.js.map +1 -1
- package/ChannelHandler/redirectUtils.d.ts +3 -0
- package/ChannelHandler/redirectUtils.js +48 -0
- package/ChannelHandler/redirectUtils.js.map +1 -0
- package/ChannelHandler/redirectUtils.test.js +8 -0
- package/analytics/AnalyticsProvider.js +2 -1
- package/analytics/AnalyticsProvider.js.map +1 -1
- package/analytics/integrations/ga4.js +10 -1
- package/analytics/integrations/ga4.js.map +1 -1
- package/analytics/integrations/gtag/gtag.d.ts +0 -1
- package/analytics/integrations/gtag/gtag.js +48 -28
- package/analytics/integrations/gtag/gtag.js.map +1 -1
- package/analytics/integrations/gtm/index.d.ts +2 -2
- package/analytics/integrations/gtm/index.js +40 -27
- package/analytics/integrations/gtm/index.js.map +1 -1
- package/analytics/integrations/unslugify.d.ts +1 -0
- package/analytics/integrations/unslugify.js +16 -0
- package/analytics/integrations/unslugify.js.map +1 -0
- package/analytics/trackerRegistry.d.ts +2 -0
- package/analytics/trackerRegistry.js.map +1 -1
- package/analytics/utils/breadcrumbsWithoutProduct.d.ts +1 -0
- package/analytics/utils/breadcrumbsWithoutProduct.js +9 -0
- package/analytics/utils/breadcrumbsWithoutProduct.js.map +1 -0
- package/boot/SharedTree.js +1 -1
- package/boot/SharedTree.js.map +1 -1
- package/boot/apollo.d.ts +5 -4
- package/boot/apollo.js +18 -18
- package/boot/apollo.js.map +1 -1
- package/boot/client/startClient.js +7 -16
- package/boot/client/startClient.js.map +1 -1
- package/boot/server/createRenderer.js +8 -7
- package/boot/server/createRenderer.js.map +1 -1
- package/boot/server/index.js +2 -2
- package/boot/server/index.js.map +1 -1
- package/boot/server/persistedQueries/__tests__/getPersistedQueriesForRequest.test.js +53 -39
- package/boot/server/persistedQueries/getPersistedQueriesForRequest.js +2 -2
- package/boot/server/persistedQueries/getPersistedQueriesForRequest.js.map +1 -1
- package/cart/AddToCartFormik.d.ts +2 -2
- package/cart/AddToCartFormik.js +11 -11
- package/cart/AddToCartFormik.js.map +1 -1
- package/cart/useAddToCart.d.ts +2 -2
- package/cart/useAddToCart.js +13 -12
- package/cart/useAddToCart.js.map +1 -1
- package/components/Auth/CustomerUpdateForm.js +7 -7
- package/components/Auth/CustomerUpdateForm.js.map +1 -1
- package/components/ChannelContext/ChannelProvider.d.ts +1 -3
- package/components/ChannelContext/ChannelProvider.js +6 -13
- package/components/ChannelContext/ChannelProvider.js.map +1 -1
- package/components/ChannelContext/ChannelProvider.test.js +112 -0
- package/components/DynamicRoute/ProductRoute.d.ts +1 -0
- package/components/DynamicRoute/ProductRoute.js +16 -6
- package/components/DynamicRoute/ProductRoute.js.map +1 -1
- package/components/DynamicRoute/RouteResolver.js +1 -1
- package/components/DynamicRoute/RouteResolver.js.map +1 -1
- package/components/Head.js +4 -4
- package/components/Head.js.map +1 -1
- package/components/Mutation/AddToCart/addToCartUtils.d.ts +1 -1
- package/components/Mutation/AddToCart/addToCartUtils.js +10 -3
- package/components/Mutation/AddToCart/addToCartUtils.js.map +1 -1
- package/components/Mutation/RemoveFromCart.d.ts +1 -1
- package/components/Mutation/RemoveFromCart.js +10 -1
- package/components/Mutation/RemoveFromCart.js.map +1 -1
- package/components/Mutation/cartMutationUtils.js +7 -6
- package/components/Mutation/cartMutationUtils.js.map +1 -1
- package/components/Mutation/useDecrementQuantity.js +8 -3
- package/components/Mutation/useDecrementQuantity.js.map +1 -1
- package/components/Mutation/useIncrementQuantity.js +8 -3
- package/components/Mutation/useIncrementQuantity.js.map +1 -1
- package/components/Mutation/useRemoveFromCart.js +10 -1
- package/components/Mutation/useRemoveFromCart.js.map +1 -1
- package/components/OpenGraph/OpenGraphProductData.js +3 -3
- package/components/OpenGraph/OpenGraphProductData.js.map +1 -1
- package/components/Query/CartProvider.js +32 -22
- package/components/Query/CartProvider.js.map +1 -1
- package/components/StructuredData/StructuredBreadcrumbData.d.ts +8 -3
- package/components/StructuredData/StructuredBreadcrumbData.js +42 -23
- package/components/StructuredData/StructuredBreadcrumbData.js.map +1 -1
- package/components/StructuredData/StructuredProductData.js +2 -2
- package/components/StructuredData/StructuredProductData.js.map +1 -1
- package/data/fragments/ProductListsFragments.gql +94 -0
- package/data/fragments/RouteMetaFragment.gql +18 -0
- package/data/mutations/productListMutations.gql +18 -0
- package/data/queries/ProductLists.gql +8 -0
- package/dependencies.d.ts +10 -1
- package/helpers/isRelativeUrl.d.ts +1 -0
- package/helpers/isRelativeUrl.js +5 -0
- package/helpers/isRelativeUrl.js.map +1 -0
- package/hooks/PackageProducts/usePackageProductItem.d.ts +2 -2
- package/hooks/ProductList/ProductListContext.js +49 -14
- package/hooks/ProductList/ProductListContext.js.map +1 -1
- package/hooks/ProductList/ProductLists.gql +0 -0
- package/hooks/ProductList/action-creators.d.ts +20 -7
- package/hooks/ProductList/action-creators.js +138 -44
- package/hooks/ProductList/action-creators.js.map +1 -1
- package/hooks/ProductList/index.d.ts +34 -8
- package/hooks/ProductList/index.js +19 -0
- package/hooks/ProductList/index.js.map +1 -1
- package/hooks/ProductList/list-transforms.d.ts +3 -2
- package/hooks/ProductList/list-transforms.js +22 -22
- package/hooks/ProductList/list-transforms.js.map +1 -1
- package/hooks/ProductList/list-transforms.test.js +103 -100
- package/hooks/ProductList/product-list-reducer.d.ts +37 -14
- package/hooks/ProductList/product-list-reducer.js +106 -43
- package/hooks/ProductList/product-list-reducer.js.map +1 -1
- package/hooks/ProductList/product-list-reducer.test.js +144 -82
- package/hooks/ProductList/useProductList.d.ts +2 -2
- package/hooks/ProductList/useProductList.js +12 -5
- package/hooks/ProductList/useProductList.js.map +1 -1
- package/hooks/ProductList/useProductListItems.d.ts +1 -1
- package/hooks/ProductList/useProductListItems.js +8 -6
- package/hooks/ProductList/useProductListItems.js.map +1 -1
- package/hooks/useAddMultipleToCart.js +11 -5
- package/hooks/useAddMultipleToCart.js.map +1 -1
- package/hooks/useProductVariants/useProductVariants.d.ts +1 -2
- package/hooks/useProductVariants/useProductVariants.js +1 -1
- package/hooks/useProductVariants/useProductVariants.js.map +1 -1
- package/hooks/useRoutePreload.js +2 -2
- package/hooks/useRoutePreload.js.map +1 -1
- package/package.json +5 -5
- package/resolvers/index.d.ts +3 -0
- package/resolvers/index.js +3 -0
- package/resolvers/index.js.map +1 -1
- package/sentry/client.js +9 -4
- package/sentry/client.js.map +1 -1
- package/sentry/common.d.ts +1 -0
- package/sentry/common.js +5 -0
- package/sentry/common.js.map +1 -0
- package/sentry/server.js +11 -2
- package/sentry/server.js.map +1 -1
- package/server/tracking/types.d.ts +1 -1
- package/time.d.ts +1 -0
- package/time.js +6 -0
- package/time.js.map +1 -0
- package/types.d.ts +1 -0
|
@@ -11,28 +11,60 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import React, { useEffect, useMemo } from 'react';
|
|
13
13
|
import { useMutation, useQuery } from 'react-apollo';
|
|
14
|
+
import useWarningInDev from '@jetshop/core/hooks/useWarningInDev';
|
|
15
|
+
import productListQueries from '@jetshop/core/data/queries/ProductLists.gql';
|
|
16
|
+
import productListMutations from '@jetshop/core/data/mutations/productListMutations.gql';
|
|
17
|
+
import { emptyProductLists, productListMapToArray, PRODUCT_LISTS_KEY } from '.';
|
|
14
18
|
import useAuth from '../../components/AuthContext/useAuth';
|
|
15
19
|
import { useThunkReducer } from '../useThunkReducer';
|
|
16
|
-
import { loginAction, refreshAction } from './action-creators';
|
|
20
|
+
import { createListAction, deleteListAction, loginAction, refreshAction } from './action-creators';
|
|
17
21
|
import { normalizeServerList } from './list-transforms';
|
|
18
22
|
import { init, reducer } from './product-list-reducer';
|
|
19
23
|
export const ProductListContext = React.createContext(undefined);
|
|
20
|
-
|
|
24
|
+
function useMissingQueryWarning(property, queries) {
|
|
25
|
+
return useWarningInDev(!(property in queries), `No \`${property}\` query available in \`queries\` for \`ProductListProvider\`. ` +
|
|
26
|
+
`Check migration guide for 5.11.0 (product lists section) to remove this warning`);
|
|
27
|
+
}
|
|
21
28
|
export const ProductListProvider = function ProductListProvider(_a) {
|
|
22
29
|
var { queries, initialState = {} } = _a, rest = __rest(_a, ["queries", "initialState"]);
|
|
30
|
+
// NOTE: Warn about missing queries, should be removed in next major release.
|
|
31
|
+
useMissingQueryWarning('all', queries);
|
|
32
|
+
useMissingQueryWarning('createList', queries);
|
|
33
|
+
useMissingQueryWarning('deleteList', queries);
|
|
23
34
|
const { loggedIn } = useAuth();
|
|
24
35
|
const requestIdRef = React.useRef(null);
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
skip: !loggedIn
|
|
36
|
+
const allQuery = queries.all || productListQueries.ProductLists;
|
|
37
|
+
const { data: serverList, client } = useQuery(allQuery, {
|
|
38
|
+
skip: !loggedIn
|
|
28
39
|
});
|
|
40
|
+
const lists = serverList
|
|
41
|
+
? new Map(serverList.customerProductLists.map(
|
|
42
|
+
// The default list (name === null) must have listId null
|
|
43
|
+
(productList) => [
|
|
44
|
+
productList.name === null ? null : productList.id,
|
|
45
|
+
normalizeServerList(productList)
|
|
46
|
+
]))
|
|
47
|
+
: emptyProductLists();
|
|
29
48
|
const defaultInitialState = Object.assign({ loggedIn,
|
|
30
|
-
requestIdRef,
|
|
49
|
+
requestIdRef,
|
|
50
|
+
lists }, initialState);
|
|
31
51
|
const [state, dispatch] = useThunkReducer(reducer, defaultInitialState, (initialState) => init(initialState));
|
|
32
52
|
const usingLocalList = !state.loggedIn;
|
|
33
|
-
usePersistLocalList({
|
|
53
|
+
usePersistLocalList({ lists: state.lists });
|
|
54
|
+
// When localstorage updates, sync it to reducer state
|
|
34
55
|
useLocalStorageListener({ refresh });
|
|
56
|
+
// loginMutation is a mutation to merge product lists
|
|
35
57
|
const [loginMutation] = useMutation(queries.login);
|
|
58
|
+
// To be used to fetch all lists of user after login
|
|
59
|
+
const fetchAll = () => client.query({ query: allQuery });
|
|
60
|
+
const [createMutation] = useMutation(queries.createList || productListMutations.CreateProductList);
|
|
61
|
+
const [deleteListMutation] = useMutation(queries.deleteList || productListMutations.DeleteProductList);
|
|
62
|
+
function deleteList(listId) {
|
|
63
|
+
dispatch(deleteListAction({ listId, deleteListMutation }));
|
|
64
|
+
}
|
|
65
|
+
function createList(name) {
|
|
66
|
+
dispatch(createListAction({ name, createMutation }));
|
|
67
|
+
}
|
|
36
68
|
function refresh() {
|
|
37
69
|
dispatch(refreshAction());
|
|
38
70
|
}
|
|
@@ -40,14 +72,16 @@ export const ProductListProvider = function ProductListProvider(_a) {
|
|
|
40
72
|
if (loggedIn === state.loggedIn)
|
|
41
73
|
return;
|
|
42
74
|
loggedIn
|
|
43
|
-
? dispatch(loginAction({ loginMutation }))
|
|
44
|
-
: dispatch({ type: 'LOGOUT' });
|
|
75
|
+
? dispatch(loginAction({ loginMutation, fetchAll })) // Merge logged out lists to account
|
|
76
|
+
: dispatch({ type: 'LOGOUT' }); // Clear lists
|
|
45
77
|
}, [dispatch, loggedIn, loginMutation, state.loggedIn]);
|
|
46
78
|
const value = useMemo(() => ({
|
|
79
|
+
createList,
|
|
80
|
+
deleteList,
|
|
47
81
|
state,
|
|
48
82
|
dispatch,
|
|
49
83
|
queries,
|
|
50
|
-
usingLocalList
|
|
84
|
+
usingLocalList
|
|
51
85
|
}), [dispatch, queries, state, usingLocalList]);
|
|
52
86
|
// We spread props here so during testing we can override value
|
|
53
87
|
return React.createElement(ProductListContext.Provider, Object.assign({ value: value }, rest));
|
|
@@ -55,15 +89,16 @@ export const ProductListProvider = function ProductListProvider(_a) {
|
|
|
55
89
|
/**
|
|
56
90
|
* Persist local list to localStorage on every change
|
|
57
91
|
*/
|
|
58
|
-
function usePersistLocalList({
|
|
92
|
+
function usePersistLocalList({ lists }) {
|
|
93
|
+
const productListArray = productListMapToArray(lists);
|
|
59
94
|
useEffect(() => {
|
|
60
|
-
localStorage.setItem(
|
|
61
|
-
}, [
|
|
95
|
+
localStorage.setItem(PRODUCT_LISTS_KEY, JSON.stringify(productListArray));
|
|
96
|
+
}, [lists]);
|
|
62
97
|
}
|
|
63
98
|
function useLocalStorageListener({ refresh }) {
|
|
64
99
|
useEffect(() => {
|
|
65
100
|
const listener = (e) => {
|
|
66
|
-
if (e.storageArea === localStorage && e.key ===
|
|
101
|
+
if (e.storageArea === localStorage && e.key === PRODUCT_LISTS_KEY) {
|
|
67
102
|
refresh();
|
|
68
103
|
}
|
|
69
104
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProductListContext.js","sourceRoot":"","sources":["ProductListContext.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAW,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"ProductListContext.js","sourceRoot":"","sources":["ProductListContext.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAW,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,eAAe,MAAM,qCAAqC,CAAC;AAClE,OAAO,kBAAkB,MAAM,6CAA6C,CAAC;AAC7E,OAAO,oBAAoB,MAAM,uDAAuD,CAAC;AACzF,OAAO,EAEL,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EAKlB,MAAM,GAAG,CAAC;AACX,OAAO,OAAO,MAAM,sCAAsC,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,W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;QACb,MAAM,QAAQ,GAAG,CAAC,CAAe,EAAE,EAAE;YACnC,IAAI,CAAC,CAAC,WAAW,KAAK,YAAY,IAAI,CAAC,CAAC,GAAG,KAAK,iBAAiB,EAAE;gBACjE,OAAO,EAAE,CAAC;aACX;QACH,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAE7C,OAAO,GAAG,EAAE;YACV,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAClD,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC"}
|
|
File without changes
|
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { MutationFunction } from 'react-apollo';
|
|
3
|
-
import { AddToListMutation, ProductListItemOptions, ProductListState, RemoveFromListMutation, UpdateListInput, UpdateListOptions } from '.';
|
|
3
|
+
import { AddToListMutation, ProductListItemOptions, ProductListState, ProductListId, RemoveFromListMutation, UpdateListInput, UpdateListOptions } from '.';
|
|
4
4
|
import { Mutation } from '../../types';
|
|
5
5
|
import { Action } from './product-list-reducer';
|
|
6
|
-
export declare function loginAction({ loginMutation }: {
|
|
7
|
-
loginMutation: MutationFunction<Mutation
|
|
6
|
+
export declare function loginAction({ loginMutation, fetchAll }: {
|
|
7
|
+
loginMutation: MutationFunction<Pick<Mutation, 'addToCustomerProductList'>>;
|
|
8
|
+
fetchAll: any;
|
|
8
9
|
}): (dispatch: React.Dispatch<Action>, getState: () => ProductListState) => void;
|
|
9
10
|
export declare function refreshAction(): (dispatch: React.Dispatch<Action>) => void;
|
|
10
|
-
export declare function
|
|
11
|
+
export declare function createListAction({ createMutation, name }: {
|
|
12
|
+
createMutation: MutationFunction<Pick<Mutation, 'createCustomerProductList'>>;
|
|
13
|
+
name: string;
|
|
14
|
+
}): (dispatch: React.Dispatch<Action>) => void;
|
|
15
|
+
export declare function deleteListAction({ listId, deleteListMutation }: {
|
|
16
|
+
listId: ProductListId;
|
|
17
|
+
deleteListMutation: MutationFunction<Pick<Mutation, 'deleteCustomerProductList'>>;
|
|
18
|
+
}): (dispatch: React.Dispatch<Action>) => void;
|
|
19
|
+
export declare function updateAction({ listId, updateAPI, removeMutation, addMutation, options, articleNumber, variantToReplace, variantArticleNumber }: {
|
|
20
|
+
listId: ProductListId;
|
|
11
21
|
updateAPI: boolean;
|
|
12
22
|
removeMutation: RemoveFromListMutation;
|
|
13
23
|
addMutation: AddToListMutation;
|
|
@@ -16,16 +26,19 @@ export declare function updateAction({ updateAPI, removeMutation, addMutation, o
|
|
|
16
26
|
variantArticleNumber: string;
|
|
17
27
|
articleNumber: string;
|
|
18
28
|
}): (dispatch: React.Dispatch<Action>, getState: () => ProductListState) => void;
|
|
19
|
-
export declare function removeAction({ updateAPI, articleNumber, variantArticleNumber, removeMutation }: UpdateListInput & {
|
|
29
|
+
export declare function removeAction({ listId, updateAPI, articleNumber, variantArticleNumber, removeMutation }: UpdateListInput & {
|
|
30
|
+
listId: ProductListId;
|
|
20
31
|
removeMutation: RemoveFromListMutation;
|
|
21
32
|
updateAPI: boolean;
|
|
22
33
|
articleNumber: string;
|
|
23
34
|
}): (dispatch: React.Dispatch<Action>, getState: () => ProductListState) => void;
|
|
24
|
-
export declare function clearAction({ updateAPI, removeMutation }: {
|
|
35
|
+
export declare function clearAction({ listId, updateAPI, removeMutation }: {
|
|
36
|
+
listId: ProductListId;
|
|
25
37
|
updateAPI: boolean;
|
|
26
38
|
removeMutation: RemoveFromListMutation;
|
|
27
39
|
}): (dispatch: React.Dispatch<Action>, getState: () => ProductListState) => void;
|
|
28
|
-
export declare function addAction({ articleNumber, variantArticleNumber, addMutation, options, updateAPI }: UpdateListInput & {
|
|
40
|
+
export declare function addAction({ listId, articleNumber, variantArticleNumber, addMutation, options, updateAPI }: UpdateListInput & {
|
|
41
|
+
listId: ProductListId;
|
|
29
42
|
addMutation: AddToListMutation;
|
|
30
43
|
options: ProductListItemOptions;
|
|
31
44
|
updateAPI: boolean;
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
import { PRODUCT_LISTS_KEY, productListArrayToMap } from '.';
|
|
1
2
|
import { flattenList, normalizeServerList } from './list-transforms';
|
|
2
3
|
import uniqueId from '../../helpers/uniqueId';
|
|
3
|
-
export function loginAction({ loginMutation }) {
|
|
4
|
+
export function loginAction({ loginMutation, fetchAll }) {
|
|
4
5
|
return (dispatch, getState) => {
|
|
5
6
|
const state = getState();
|
|
7
|
+
// Merge what is in the default list onto the default list on the server
|
|
8
|
+
// for this user.
|
|
9
|
+
const list = state.lists.get(null);
|
|
6
10
|
loginMutation({
|
|
7
11
|
fetchPolicy: 'no-cache',
|
|
8
|
-
context: {
|
|
12
|
+
context: { useApolloNetworkStatus: false },
|
|
9
13
|
variables: {
|
|
10
14
|
id: null,
|
|
11
|
-
items: flattenList(
|
|
15
|
+
items: flattenList(list).map((listItem) => ({
|
|
12
16
|
articleNumber: listItem.articleNumber,
|
|
13
17
|
quantity: listItem.options.quantity,
|
|
14
18
|
description: listItem.options.description
|
|
@@ -16,8 +20,32 @@ export function loginAction({ loginMutation }) {
|
|
|
16
20
|
}
|
|
17
21
|
})
|
|
18
22
|
.then((response) => {
|
|
19
|
-
const list = normalizeServerList(response.data.addToCustomerProductList);
|
|
20
|
-
dispatch({
|
|
23
|
+
const list = normalizeServerList(response.data.addToCustomerProductList.customerProductList);
|
|
24
|
+
dispatch({
|
|
25
|
+
type: 'LOGIN',
|
|
26
|
+
payload: {
|
|
27
|
+
listId: null,
|
|
28
|
+
list
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
// Also fetch any other list that this user might have and update the state.
|
|
32
|
+
return fetchAll().then((response) => {
|
|
33
|
+
response.data.customerProductLists.forEach((serverList) => {
|
|
34
|
+
if (serverList.name === null) {
|
|
35
|
+
// The null (default) list has already been fetched and added as listId null
|
|
36
|
+
// so ignore it here.
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const list = normalizeServerList(serverList);
|
|
40
|
+
dispatch({
|
|
41
|
+
type: 'REPLACE',
|
|
42
|
+
payload: {
|
|
43
|
+
listId: serverList.id,
|
|
44
|
+
list
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
21
49
|
})
|
|
22
50
|
.catch((err) => {
|
|
23
51
|
console.error('Lists could not be merged', err);
|
|
@@ -26,18 +54,65 @@ export function loginAction({ loginMutation }) {
|
|
|
26
54
|
}
|
|
27
55
|
export function refreshAction() {
|
|
28
56
|
return (dispatch) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
57
|
+
const lists = JSON.parse(localStorage.getItem(PRODUCT_LISTS_KEY));
|
|
58
|
+
if (lists) {
|
|
59
|
+
dispatch({
|
|
60
|
+
type: 'SET_LISTS',
|
|
61
|
+
payload: {
|
|
62
|
+
lists: productListArrayToMap(lists)
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export function createListAction({ createMutation, name }) {
|
|
69
|
+
const variables = {
|
|
70
|
+
input: {
|
|
71
|
+
name
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
return (dispatch) => {
|
|
75
|
+
createMutation({ variables }).then((response) => {
|
|
76
|
+
const serverList = response.data.createCustomerProductList.customerProductList;
|
|
77
|
+
const listId = serverList.id;
|
|
78
|
+
if (response.data.createCustomerProductList.success) {
|
|
79
|
+
dispatch({
|
|
80
|
+
type: 'CREATE_LIST',
|
|
81
|
+
payload: { listId, list: normalizeServerList(serverList) }
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
console.warn(`Could not create list`);
|
|
86
|
+
}
|
|
32
87
|
});
|
|
33
88
|
};
|
|
34
89
|
}
|
|
35
|
-
export function
|
|
90
|
+
export function deleteListAction({ listId, deleteListMutation }) {
|
|
91
|
+
const variables = {
|
|
92
|
+
id: listId
|
|
93
|
+
};
|
|
94
|
+
return (dispatch) => {
|
|
95
|
+
deleteListMutation({ variables }).then((response) => {
|
|
96
|
+
const success = response.data.deleteCustomerProductList.success;
|
|
97
|
+
if (success) {
|
|
98
|
+
dispatch({
|
|
99
|
+
type: 'DELETE_LIST',
|
|
100
|
+
payload: { listId }
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
console.warn(`Could not delete product list with id ${listId}`);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
export function updateAction({ listId, updateAPI = false, removeMutation, addMutation, options, articleNumber, variantToReplace, variantArticleNumber }) {
|
|
36
110
|
return (dispatch, getState) => {
|
|
37
111
|
const { description, quantity } = options;
|
|
38
112
|
dispatch({
|
|
39
113
|
type: 'UPDATE',
|
|
40
114
|
payload: {
|
|
115
|
+
listId,
|
|
41
116
|
articleNumber,
|
|
42
117
|
options,
|
|
43
118
|
variantArticleNumber,
|
|
@@ -54,18 +129,18 @@ export function updateAction({ updateAPI = false, removeMutation, addMutation, o
|
|
|
54
129
|
remove({
|
|
55
130
|
// Don't write to the cache. This avoids re-rendering the list.
|
|
56
131
|
fetchPolicy: 'no-cache',
|
|
57
|
-
context: {
|
|
132
|
+
context: { useApolloNetworkStatus: false },
|
|
58
133
|
variables: {
|
|
59
|
-
id:
|
|
134
|
+
id: listId,
|
|
60
135
|
articleNumbers: [variantToReplace || articleNumber]
|
|
61
136
|
}
|
|
62
137
|
})
|
|
63
138
|
.then(() => {
|
|
64
139
|
add({
|
|
65
140
|
fetchPolicy: 'no-cache',
|
|
66
|
-
context: {
|
|
141
|
+
context: { useApolloNetworkStatus: false },
|
|
67
142
|
variables: {
|
|
68
|
-
id:
|
|
143
|
+
id: listId,
|
|
69
144
|
items: [
|
|
70
145
|
{
|
|
71
146
|
articleNumber: variantArticleNumber || articleNumber,
|
|
@@ -74,22 +149,26 @@ export function updateAction({ updateAPI = false, removeMutation, addMutation, o
|
|
|
74
149
|
}
|
|
75
150
|
]
|
|
76
151
|
}
|
|
77
|
-
}).then(response => {
|
|
152
|
+
}).then((response) => {
|
|
78
153
|
requestId === previousState.requestIdRef.current &&
|
|
79
|
-
syncListFromServer(dispatch, response.data.addToCustomerProductList);
|
|
154
|
+
syncListFromServer(dispatch, listId, response.data.addToCustomerProductList);
|
|
80
155
|
});
|
|
81
156
|
})
|
|
82
|
-
.catch(err => {
|
|
83
|
-
rollbackList(dispatch, previousState.list);
|
|
157
|
+
.catch((err) => {
|
|
84
158
|
console.error('List could not be updated', err);
|
|
159
|
+
const previousList = previousState.lists.get(listId);
|
|
160
|
+
if (previousList) {
|
|
161
|
+
rollbackList(dispatch, listId, previousList);
|
|
162
|
+
}
|
|
85
163
|
});
|
|
86
164
|
};
|
|
87
165
|
}
|
|
88
|
-
export function removeAction({ updateAPI = false, articleNumber, variantArticleNumber, removeMutation }) {
|
|
166
|
+
export function removeAction({ listId, updateAPI = false, articleNumber, variantArticleNumber, removeMutation }) {
|
|
89
167
|
return (dispatch, getState) => {
|
|
90
168
|
dispatch({
|
|
91
169
|
type: 'REMOVE',
|
|
92
170
|
payload: {
|
|
171
|
+
listId,
|
|
93
172
|
articleNumber,
|
|
94
173
|
variantArticleNumber
|
|
95
174
|
}
|
|
@@ -102,53 +181,61 @@ export function removeAction({ updateAPI = false, articleNumber, variantArticleN
|
|
|
102
181
|
previousState.requestIdRef.current = requestId;
|
|
103
182
|
remove({
|
|
104
183
|
fetchPolicy: 'no-cache',
|
|
105
|
-
context: {
|
|
184
|
+
context: { useApolloNetworkStatus: false },
|
|
106
185
|
variables: {
|
|
107
186
|
articleNumbers: [variantArticleNumber || articleNumber],
|
|
108
|
-
id:
|
|
187
|
+
id: listId
|
|
109
188
|
}
|
|
110
189
|
})
|
|
111
|
-
.then(response => {
|
|
190
|
+
.then((response) => {
|
|
112
191
|
requestId === previousState.requestIdRef.current &&
|
|
113
|
-
syncListFromServer(dispatch, response.data.removeFromCustomerProductList);
|
|
192
|
+
syncListFromServer(dispatch, listId, response.data.removeFromCustomerProductList);
|
|
114
193
|
})
|
|
115
|
-
.catch(err => {
|
|
194
|
+
.catch((err) => {
|
|
116
195
|
console.error('Product could not be removed from list', err);
|
|
117
|
-
|
|
196
|
+
const previousList = previousState.lists.get(listId);
|
|
197
|
+
if (previousList) {
|
|
198
|
+
rollbackList(dispatch, listId, previousList);
|
|
199
|
+
}
|
|
118
200
|
});
|
|
119
201
|
};
|
|
120
202
|
}
|
|
121
|
-
export function clearAction({ updateAPI = false, removeMutation }) {
|
|
203
|
+
export function clearAction({ listId, updateAPI = false, removeMutation }) {
|
|
122
204
|
return (dispatch, getState) => {
|
|
123
|
-
dispatch({
|
|
205
|
+
dispatch({
|
|
206
|
+
type: 'CLEAR_ITEMS',
|
|
207
|
+
payload: { listId }
|
|
208
|
+
});
|
|
124
209
|
if (!updateAPI)
|
|
125
210
|
return;
|
|
126
211
|
const [remove] = removeMutation;
|
|
127
212
|
const state = getState();
|
|
128
|
-
const
|
|
213
|
+
const list = state.lists.get(listId);
|
|
214
|
+
const articleNumbers = flattenList(list).map((listItem) => listItem.articleNumber);
|
|
129
215
|
const requestId = scopedUniqueID();
|
|
130
216
|
state.requestIdRef.current = requestId;
|
|
131
217
|
remove({
|
|
132
218
|
fetchPolicy: 'no-cache',
|
|
133
|
-
context: {
|
|
134
|
-
variables: { articleNumbers, id:
|
|
219
|
+
context: { useApolloNetworkStatus: false },
|
|
220
|
+
variables: { articleNumbers, id: listId }
|
|
135
221
|
})
|
|
136
|
-
.then(response => {
|
|
222
|
+
.then((response) => {
|
|
137
223
|
requestId === state.requestIdRef.current &&
|
|
138
|
-
syncListFromServer(dispatch, response.data.removeFromCustomerProductList);
|
|
224
|
+
syncListFromServer(dispatch, listId, response.data.removeFromCustomerProductList);
|
|
139
225
|
})
|
|
140
|
-
.catch(err => {
|
|
226
|
+
.catch((err) => {
|
|
141
227
|
console.error('List could not be cleared', err);
|
|
142
|
-
rollbackList(dispatch,
|
|
228
|
+
rollbackList(dispatch, listId, list);
|
|
143
229
|
});
|
|
144
230
|
};
|
|
145
231
|
}
|
|
146
|
-
export function addAction({ articleNumber, variantArticleNumber, addMutation, options, updateAPI = false }) {
|
|
232
|
+
export function addAction({ listId, articleNumber, variantArticleNumber, addMutation, options, updateAPI = false }) {
|
|
147
233
|
return (dispatch, getState) => {
|
|
148
234
|
const { quantity, description } = options;
|
|
149
235
|
dispatch({
|
|
150
236
|
type: 'ADD',
|
|
151
237
|
payload: {
|
|
238
|
+
listId,
|
|
152
239
|
articleNumber,
|
|
153
240
|
variantArticleNumber,
|
|
154
241
|
options: { quantity, description }
|
|
@@ -162,9 +249,10 @@ export function addAction({ articleNumber, variantArticleNumber, addMutation, op
|
|
|
162
249
|
previousState.requestIdRef.current = requestId;
|
|
163
250
|
add({
|
|
164
251
|
fetchPolicy: 'no-cache',
|
|
165
|
-
context: {
|
|
252
|
+
context: { useApolloNetworkStatus: false },
|
|
166
253
|
variables: {
|
|
167
|
-
id: null,
|
|
254
|
+
//id: null, XXX
|
|
255
|
+
id: listId,
|
|
168
256
|
items: [
|
|
169
257
|
{
|
|
170
258
|
articleNumber: variantArticleNumber || articleNumber,
|
|
@@ -176,28 +264,34 @@ export function addAction({ articleNumber, variantArticleNumber, addMutation, op
|
|
|
176
264
|
})
|
|
177
265
|
.then(({ data: { addToCustomerProductList } }) => {
|
|
178
266
|
requestId === previousState.requestIdRef.current &&
|
|
179
|
-
syncListFromServer(dispatch, addToCustomerProductList);
|
|
267
|
+
syncListFromServer(dispatch, listId, addToCustomerProductList);
|
|
180
268
|
})
|
|
181
|
-
.catch(err => {
|
|
269
|
+
.catch((err) => {
|
|
182
270
|
console.error('Product could not be added to list', err);
|
|
183
|
-
rollbackList(dispatch, previousState.
|
|
271
|
+
rollbackList(dispatch, listId, previousState.lists.get(listId));
|
|
184
272
|
});
|
|
185
273
|
};
|
|
186
274
|
}
|
|
187
275
|
function scopedUniqueID() {
|
|
188
276
|
return uniqueId('_product_list_');
|
|
189
277
|
}
|
|
190
|
-
function syncListFromServer(dispatch, productList) {
|
|
191
|
-
const
|
|
278
|
+
function syncListFromServer(dispatch, listId, productList) {
|
|
279
|
+
const list = normalizeServerList(productList.customerProductList);
|
|
192
280
|
dispatch({
|
|
193
281
|
type: 'REPLACE',
|
|
194
|
-
payload:
|
|
282
|
+
payload: {
|
|
283
|
+
listId,
|
|
284
|
+
list
|
|
285
|
+
}
|
|
195
286
|
});
|
|
196
287
|
}
|
|
197
|
-
function rollbackList(dispatch, productList) {
|
|
288
|
+
function rollbackList(dispatch, listId, productList) {
|
|
198
289
|
dispatch({
|
|
199
290
|
type: 'REPLACE',
|
|
200
|
-
payload:
|
|
291
|
+
payload: {
|
|
292
|
+
listId,
|
|
293
|
+
list: productList
|
|
294
|
+
}
|
|
201
295
|
});
|
|
202
296
|
}
|
|
203
297
|
//# sourceMappingURL=action-creators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action-creators.js","sourceRoot":"","sources":["action-creators.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"action-creators.js","sourceRoot":"","sources":["action-creators.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,iBAAiB,EAOjB,qBAAqB,EACtB,MAAM,GAAG,CAAC;AAEX,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,QAAQ,MAAM,wBAAwB,CAAC;AAE9C,MAAM,UAAU,WAAW,CAAC,EAC1B,aAAa,EACb,QAAQ,EAIT;IACC,OAAO,CACL,QAAgC,EAChC,QAAgC,EAChC,EAAE;QACF,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC;QAEzB,wEAAwE;QACxE,iBAAiB;QACjB,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACnC,aAAa,CAAC;YACZ,WAAW,EAAE,UAAU;YACvB,OAAO,EAAE,E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QAAgC,EAChC,MAAqB,EACrB,WAAsC;IAEtC,MAAM,IAAI,GAAG,mBAAmB,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC;IAElE,QAAQ,CAAC;QACP,IAAI,EAAE,SAAS;QACf,OAAO,EAAE;YACP,MAAM;YACN,IAAI;SACL;KACF,CAAC,CAAC;AACL,CAAC;AAED,SAAS,YAAY,CACnB,QAAgC,EAChC,MAAqB,EACrB,WAAkC;IAElC,QAAQ,CAAC;QACP,IAAI,EAAE,SAAS;QACf,OAAO,EAAE;YACP,MAAM;YACN,IAAI,EAAE,WAAW;SAClB;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { DocumentNode } from 'graphql';
|
|
3
3
|
import { MutationTuple, QueryResult } from 'react-apollo';
|
|
4
|
-
import { CustomerProductListResult, MutationAddToCustomerProductListArgs, MutationRemoveFromCustomerProductListArgs, MutationUpdateCustomerProductListItemArgs, Product, ProductVariant, QueryCustomerProductListArgs, QueryProductsArgs } from '../../types';
|
|
4
|
+
import { CustomerProductListResult, MutationCreateCustomerProductListArgs, MutationAddToCustomerProductListArgs, MutationRemoveFromCustomerProductListArgs, MutationUpdateCustomerProductListItemArgs, Product, ProductVariant, QueryCustomerProductListArgs, QueryProductsArgs } from '../../types';
|
|
5
5
|
import { ThunkAction } from '../useThunkReducer';
|
|
6
6
|
import { Action } from './product-list-reducer';
|
|
7
7
|
export { useProductList } from './useProductList';
|
|
@@ -17,16 +17,42 @@ export interface ProductListContextOptions {
|
|
|
17
17
|
usingLocalList: boolean;
|
|
18
18
|
queries: ProductListQueries;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* A Product list mapping is a mapping between an ID and a product list
|
|
22
|
+
*
|
|
23
|
+
* As a convenienve, an ID of null is used for the "default" product list.
|
|
24
|
+
*/
|
|
25
|
+
export declare type ProductListId = string | null;
|
|
26
|
+
export declare type ProductListMap = Map<ProductListId, NormalizedProductList>;
|
|
27
|
+
export interface NormalizedProductList {
|
|
28
|
+
name: string | null;
|
|
29
|
+
items: {
|
|
30
|
+
[articleNumber: string]: {
|
|
31
|
+
options: ProductListItemOptions;
|
|
32
|
+
variants: ProductListItemVariants | null;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export declare const PRODUCT_LISTS_KEY = "productLists";
|
|
37
|
+
export declare function emptyProductLists(): ProductListMap;
|
|
38
|
+
export declare function productListMapToArray(map: ProductListMap): [string, NormalizedProductList][];
|
|
39
|
+
export declare function productListArrayToMap(array: [ProductListId, NormalizedProductList][]): Map<string, NormalizedProductList>;
|
|
20
40
|
export interface ProductListState {
|
|
21
41
|
loggedIn: boolean;
|
|
22
|
-
|
|
42
|
+
lists: ProductListMap;
|
|
23
43
|
requestIdRef: React.MutableRefObject<string | null>;
|
|
24
44
|
}
|
|
25
45
|
export interface ProductListQueries {
|
|
26
46
|
/** Products query, used for retrieving products from localList */
|
|
27
47
|
productsQuery: DocumentNode;
|
|
48
|
+
/** The customerProductLists query */
|
|
49
|
+
all: DocumentNode;
|
|
28
50
|
/** The customerProductList query */
|
|
29
51
|
query: DocumentNode;
|
|
52
|
+
/** The createCustomerProductList mutation */
|
|
53
|
+
createList: DocumentNode;
|
|
54
|
+
/** The deleteCustomerProductList mutation */
|
|
55
|
+
deleteList: DocumentNode;
|
|
30
56
|
/** The addToCustomerProductList mutation */
|
|
31
57
|
add: DocumentNode;
|
|
32
58
|
/** An addToCustomerProductList mutation that returns the full list */
|
|
@@ -45,12 +71,6 @@ export interface ProductListDetail {
|
|
|
45
71
|
/** An array containing the product data */
|
|
46
72
|
products: ProductListProduct[];
|
|
47
73
|
}
|
|
48
|
-
export interface NormalizedProductList {
|
|
49
|
-
[articleNumber: string]: {
|
|
50
|
-
options: ProductListItemOptions;
|
|
51
|
-
variants: ProductListItemVariants | null;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
74
|
export interface FlattenedProductListItem {
|
|
55
75
|
articleNumber: string;
|
|
56
76
|
parentArticleNumber?: string;
|
|
@@ -80,12 +100,18 @@ export declare type ProductListProductValidation = {
|
|
|
80
100
|
export declare type AddToListMutation = MutationTuple<{
|
|
81
101
|
addToCustomerProductList: CustomerProductListResult;
|
|
82
102
|
}, MutationAddToCustomerProductListArgs>;
|
|
103
|
+
export declare type CreateListMutation = MutationTuple<{
|
|
104
|
+
createCustomerProductList: CustomerProductListResult;
|
|
105
|
+
}, MutationCreateCustomerProductListArgs>;
|
|
83
106
|
export declare type RemoveFromListMutation = MutationTuple<{
|
|
84
107
|
removeFromCustomerProductList: CustomerProductListResult;
|
|
85
108
|
}, MutationRemoveFromCustomerProductListArgs>;
|
|
86
109
|
export declare type UpdateListItemMutation = MutationTuple<{
|
|
87
110
|
updateCustomerProductListItem: CustomerProductListResult;
|
|
88
111
|
}, MutationUpdateCustomerProductListItemArgs>;
|
|
112
|
+
export declare type ListsProductsQuery = QueryResult<{
|
|
113
|
+
customerProductLists: CustomerProductListResult[];
|
|
114
|
+
}>;
|
|
89
115
|
export declare type ListProductsQuery = QueryResult<CustomerProductListResult, QueryCustomerProductListArgs>;
|
|
90
116
|
export declare type ProductsQuery = QueryResult<{
|
|
91
117
|
products: Product[];
|
|
@@ -1,3 +1,22 @@
|
|
|
1
1
|
export { useProductList } from './useProductList';
|
|
2
2
|
export { useProductListItems } from './useProductListItems';
|
|
3
|
+
export const PRODUCT_LISTS_KEY = 'productLists';
|
|
4
|
+
export function emptyProductLists() {
|
|
5
|
+
return new Map([
|
|
6
|
+
[
|
|
7
|
+
null,
|
|
8
|
+
{
|
|
9
|
+
items: {},
|
|
10
|
+
name: null
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
]);
|
|
14
|
+
}
|
|
15
|
+
export function productListMapToArray(map) {
|
|
16
|
+
const [...array] = map;
|
|
17
|
+
return array;
|
|
18
|
+
}
|
|
19
|
+
export function productListArrayToMap(array) {
|
|
20
|
+
return new Map(array);
|
|
21
|
+
}
|
|
3
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAgC5D,MAAM,CAAC,MAAM,iBAAiB,GAAG,cAAc,CAAC;AAEhD,MAAM,UAAU,iBAAiB;IAC/B,OAAO,IAAI,GAAG,CAAC;QACb;YACE,IAAI;YACJ;gBACE,KAAK,EAAE,EAAE;gBACT,IAAI,EAAE,IAAI;aACX;SACF;KACF,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,GAAmB;IACvD,MAAM,CAAC,GAAG,KAAK,CAAC,GAAG,GAAG,CAAC;IACvB,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,KAA+C;IAE/C,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;AACxB,CAAC"}
|