@shopgate/pwa-common 7.30.0-alpha.6 → 7.30.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/App.js +48 -6
- package/action-creators/app/index.js +75 -12
- package/action-creators/app/spec.js +96 -1
- package/action-creators/client/index.js +27 -5
- package/action-creators/client/spec.js +44 -1
- package/action-creators/error/index.js +15 -3
- package/action-creators/index.js +9 -1
- package/action-creators/menu/index.js +23 -4
- package/action-creators/menu/spec.js +37 -1
- package/action-creators/modal/index.js +15 -3
- package/action-creators/modal/spec.js +26 -1
- package/action-creators/page/index.js +24 -4
- package/action-creators/page/spec.js +38 -1
- package/action-creators/router/index.js +48 -7
- package/action-creators/url/index.js +24 -4
- package/action-creators/url/spec.js +45 -1
- package/action-creators/user/index.js +90 -13
- package/action-creators/user/spec.js +186 -2
- package/actions/app/handleDeepLink.js +11 -2
- package/actions/app/handleLink.js +62 -6
- package/actions/app/handlePushNotification.js +32 -4
- package/actions/app/handleUniversalLink.js +11 -2
- package/actions/app/registerLinkEvents.js +24 -3
- package/actions/client/fetchClientInformation.js +26 -2
- package/actions/menu/fetchMenu.js +23 -2
- package/actions/modal/closeModal.js +18 -2
- package/actions/modal/promiseMap.js +3 -1
- package/actions/modal/showModal.js +54 -8
- package/actions/page/fetchPageConfig.js +69 -2
- package/actions/page/getPageConfig.js +6 -2
- package/actions/page/index.js +1 -1
- package/actions/router/historyPop.js +12 -2
- package/actions/router/historyPopToRoute.js +27 -2
- package/actions/router/historyPush.js +12 -2
- package/actions/router/historyRedirect.js +21 -2
- package/actions/router/historyReplace.js +20 -3
- package/actions/router/historyReset.js +11 -2
- package/actions/router/historyResetTo.js +12 -2
- package/actions/router/index.js +17 -1
- package/actions/router/routeDidPop.js +11 -2
- package/actions/router/routeDidPush.js +13 -2
- package/actions/router/routeDidReplace.js +11 -2
- package/actions/router/routeDidReset.js +11 -2
- package/actions/router/routeDidUpdate.js +10 -2
- package/actions/router/routeWillPop.js +11 -2
- package/actions/router/routeWillPush.js +13 -2
- package/actions/router/routeWillReplace.js +11 -2
- package/actions/router/routeWillReset.js +11 -2
- package/actions/router/windowOpenOverride.js +10 -2
- package/actions/user/fetchRegisterUrl.js +36 -2
- package/actions/user/fetchUser.js +29 -3
- package/actions/user/getUser.js +6 -2
- package/actions/user/index.js +1 -1
- package/actions/user/login.js +76 -9
- package/actions/user/logout.js +30 -2
- package/collections/AuthRoutes.js +73 -14
- package/collections/Configuration.js +54 -7
- package/collections/EmbeddedMedia.js +84 -11
- package/collections/PersistedReducers.js +41 -6
- package/collections/Redirects.js +103 -17
- package/collections/index.js +5 -1
- package/collections/media-providers/MediaProvider.js +151 -26
- package/collections/media-providers/Vimeo.js +113 -19
- package/collections/media-providers/YouTube.js +74 -14
- package/collections/media-providers/index.js +3 -1
- package/collections/media-providers/style.js +52 -2
- package/components/Backdrop/index.js +95 -6
- package/components/Backdrop/spec.js +23 -1
- package/components/Backdrop/style.js +11 -2
- package/components/Button/index.js +47 -5
- package/components/Button/spec.js +36 -1
- package/components/Button/style.js +6 -1
- package/components/Checkbox/index.js +126 -32
- package/components/Checkbox/spec.js +94 -3
- package/components/Consume/helpers/buildParams.js +13 -2
- package/components/Consume/index.js +14 -2
- package/components/CountdownTimer/index.js +115 -17
- package/components/CountdownTimer/spec.js +126 -12
- package/components/Drawer/index.js +131 -16
- package/components/Drawer/spec.js +76 -1
- package/components/Drawer/style.js +37 -1
- package/components/Dropdown/index.js +65 -6
- package/components/Dropdown/style.js +4 -1
- package/components/Dropdown/transitions.js +34 -1
- package/components/Ellipsis/index.js +16 -2
- package/components/Ellipsis/spec.js +13 -1
- package/components/EmbeddedMedia/index.js +56 -6
- package/components/EmbeddedMedia/spec.js +52 -3
- package/components/ErrorBoundary/connector.js +9 -2
- package/components/ErrorBoundary/index.js +43 -7
- package/components/Grid/components/Item/index.js +40 -4
- package/components/Grid/components/Item/spec.js +23 -1
- package/components/Grid/components/Item/style.js +17 -3
- package/components/Grid/index.js +36 -4
- package/components/Grid/spec.js +23 -1
- package/components/Grid/style.js +11 -2
- package/components/HtmlSanitizer/connector.js +24 -3
- package/components/HtmlSanitizer/index.js +104 -12
- package/components/HtmlSanitizer/spec.js +207 -6
- package/components/I18n/components/FormatDate/index.js +26 -2
- package/components/I18n/components/FormatDate/spec.js +46 -1
- package/components/I18n/components/FormatNumber/index.js +34 -2
- package/components/I18n/components/FormatNumber/spec.js +41 -2
- package/components/I18n/components/FormatPrice/index.js +32 -2
- package/components/I18n/components/FormatPrice/spec.js +46 -1
- package/components/I18n/components/FormatTime/index.js +26 -2
- package/components/I18n/components/FormatTime/spec.js +43 -2
- package/components/I18n/components/I18nProvider/index.js +52 -9
- package/components/I18n/components/I18nProvider/spec.js +39 -1
- package/components/I18n/components/Placeholder/index.js +8 -2
- package/components/I18n/components/Placeholder/spec.js +30 -1
- package/components/I18n/components/Translate/index.js +68 -7
- package/components/I18n/components/Translate/spec.js +30 -1
- package/components/I18n/index.js +16 -1
- package/components/Icon/index.js +25 -2
- package/components/Icon/style.js +6 -1
- package/components/Image/Image.js +176 -19
- package/components/Image/ImageInner.js +48 -2
- package/components/Image/index.js +1 -1
- package/components/Image/style.js +29 -2
- package/components/InfiniteContainer/index.js +381 -49
- package/components/InfiniteContainer/spec.js +199 -10
- package/components/Input/components/DateInput.js +262 -6
- package/components/Input/components/MultiLineInput.js +98 -12
- package/components/Input/components/SimpleInput.js +207 -31
- package/components/Input/index.js +32 -3
- package/components/Input/spec.js +122 -1
- package/components/KeyboardConsumer/index.js +48 -7
- package/components/Link/connector.js +7 -1
- package/components/Link/index.js +96 -11
- package/components/Link/spec.js +56 -1
- package/components/Link/style.js +10 -1
- package/components/List/components/Item/index.js +35 -3
- package/components/List/components/Item/style.js +16 -1
- package/components/List/index.js +20 -2
- package/components/List/spec.js +31 -1
- package/components/Loading/index.js +6 -2
- package/components/Modal/index.js +38 -3
- package/components/Modal/style.js +36 -1
- package/components/ModalContainer/connector.js +17 -3
- package/components/ModalContainer/index.js +36 -3
- package/components/ModalContainer/spec.js +105 -5
- package/components/Picker/components/Button/index.js +34 -2
- package/components/Picker/components/Button/style.js +19 -1
- package/components/Picker/components/List/index.js +33 -2
- package/components/Picker/components/List/style.js +17 -1
- package/components/Picker/components/Modal/index.js +60 -7
- package/components/Picker/components/Modal/style.js +78 -1
- package/components/Picker/index.js +167 -21
- package/components/Picker/spec.js +83 -2
- package/components/Portal/index.js +130 -19
- package/components/ProductCharacteristics/connector.js +33 -4
- package/components/ProductCharacteristics/context.js +2 -1
- package/components/ProductCharacteristics/helpers/index.js +135 -21
- package/components/ProductCharacteristics/index.js +266 -31
- package/components/RangeSlider/components/Handle/index.js +25 -2
- package/components/RangeSlider/components/Handle/style.js +14 -1
- package/components/RangeSlider/helper.js +43 -8
- package/components/RangeSlider/index.js +228 -38
- package/components/RangeSlider/style.js +14 -1
- package/components/Route/RouteNotFound.js +46 -3
- package/components/Route/index.js +78 -10
- package/components/Router/connector.js +9 -2
- package/components/Router/index.js +237 -31
- package/components/ScannerContainer/connector.js +9 -2
- package/components/ScannerContainer/index.js +42 -6
- package/components/Select/components/Item/index.js +20 -4
- package/components/Select/components/Item/style.js +4 -1
- package/components/Select/index.js +149 -28
- package/components/Select/spec.js +86 -2
- package/components/Select/style.js +17 -1
- package/components/SelectBox/components/Item/index.js +47 -5
- package/components/SelectBox/components/Item/style.js +7 -1
- package/components/SelectBox/index.js +173 -17
- package/components/SelectBox/spec.js +59 -3
- package/components/SelectBox/style.js +18 -1
- package/components/Slider/index.js +6 -2
- package/components/SurroundPortals/index.js +26 -2
- package/components/Swiper/components/SwiperItem/index.js +28 -4
- package/components/Swiper/components/SwiperItem/spec.js +17 -1
- package/components/Swiper/components/SwiperItem/styles.js +5 -1
- package/components/Swiper/index.js +210 -18
- package/components/Swiper/styles.js +75 -7
- package/components/Toaster/index.js +10 -2
- package/components/Transition/index.js +89 -13
- package/components/Widgets/components/Widget/index.js +52 -4
- package/components/Widgets/components/Widget/spec.js +68 -3
- package/components/Widgets/components/Widget/style.js +21 -3
- package/components/Widgets/components/WidgetGrid/index.js +52 -7
- package/components/Widgets/components/WidgetGrid/spec.js +46 -2
- package/components/Widgets/components/WidgetGrid/style.js +8 -1
- package/components/Widgets/helpers/shouldShowWidget.js +44 -7
- package/components/Widgets/index.js +127 -15
- package/components/Widgets/spec.js +213 -6
- package/components/index.js +9 -1
- package/constants/ActionTypes.js +97 -19
- package/constants/Configuration.js +12 -2
- package/constants/Device.js +29 -2
- package/constants/DisplayOptions.js +8 -1
- package/constants/MenuIDs.js +2 -1
- package/constants/ModalTypes.js +1 -1
- package/constants/PageIDs.js +1 -1
- package/constants/Pipelines.js +7 -1
- package/constants/Portals.js +136 -3
- package/constants/Registration.js +3 -1
- package/constants/RoutePaths.js +13 -2
- package/constants/Tracking.js +3 -1
- package/constants/client.js +6 -1
- package/constants/ui.js +2 -1
- package/constants/user.js +6 -2
- package/context/index.js +33 -3
- package/helpers/config/index.js +139 -21
- package/helpers/config/mock.js +200 -8
- package/helpers/config/theme.js +50 -4
- package/helpers/data/index.js +204 -29
- package/helpers/data/spec.js +187 -7
- package/helpers/date/index.js +58 -6
- package/helpers/date/spec.js +92 -1
- package/helpers/dom/index.js +48 -11
- package/helpers/environment/index.js +14 -2
- package/helpers/html/decodeHTML.js +7 -1
- package/helpers/html/handleDOM.js +172 -21
- package/helpers/html/parseHTML.js +67 -12
- package/helpers/i18n/getDateFormatter.js +23 -4
- package/helpers/i18n/getNumberFormatter.js +32 -4
- package/helpers/i18n/getPriceFormatter.js +38 -4
- package/helpers/i18n/getTimeFormatter.js +23 -4
- package/helpers/i18n/getTranslator.js +62 -8
- package/helpers/i18n/index.js +5 -1
- package/helpers/i18n/mergeTranslations.js +36 -9
- package/helpers/i18n/messageCache.js +3 -1
- package/helpers/legacy/index.js +47 -9
- package/helpers/modal/withShowModal.js +13 -2
- package/helpers/portals/portalCollection.js +28 -6
- package/helpers/portals/routePortals.js +12 -1
- package/helpers/redux/compareObjects.js +7 -2
- package/helpers/redux/generateResultHash.js +36 -3
- package/helpers/redux/generateSortedHash.js +7 -2
- package/helpers/redux/hasExpired.js +10 -2
- package/helpers/redux/index.js +7 -1
- package/helpers/redux/mutable.js +143 -24
- package/helpers/redux/shouldFetchData.js +46 -10
- package/helpers/redux/shouldFetchFilters.js +17 -4
- package/helpers/router/index.js +49 -5
- package/helpers/style/index.js +43 -4
- package/helpers/style/spec.js +108 -2
- package/helpers/tracking/index.js +52 -9
- package/helpers/validation/index.js +39 -12
- package/helpers/validation/spec.js +10 -1
- package/package.json +3 -3
- package/providers/index.js +4 -1
- package/providers/loading/context.js +2 -1
- package/providers/loading/index.js +137 -22
- package/providers/toast/context.js +2 -1
- package/providers/toast/index.js +105 -11
- package/reducers/client/connectivity.js +22 -2
- package/reducers/client/index.js +7 -1
- package/reducers/client/info.js +27 -2
- package/reducers/index.js +23 -4
- package/reducers/menu/index.js +5 -1
- package/reducers/menu/menusById.js +41 -2
- package/reducers/modal/index.js +14 -2
- package/reducers/page/index.js +68 -5
- package/reducers/router/index.js +48 -2
- package/reducers/url/index.js +42 -3
- package/reducers/user/data.js +27 -2
- package/reducers/user/index.js +7 -1
- package/reducers/user/login.js +65 -2
- package/selectors/client.js +138 -21
- package/selectors/history.js +49 -11
- package/selectors/menu.js +34 -6
- package/selectors/modal.js +15 -4
- package/selectors/page.js +25 -4
- package/selectors/router.js +154 -30
- package/selectors/url.js +25 -4
- package/selectors/user.js +90 -13
- package/store/index.js +60 -6
- package/store/middelwares/logger.js +7 -1
- package/store/middelwares/streams.js +19 -2
- package/streams/app.js +60 -8
- package/streams/client.js +8 -2
- package/streams/error.js +14 -3
- package/streams/index.js +6 -1
- package/streams/interval.js +6 -2
- package/streams/main.js +27 -2
- package/streams/router.js +45 -8
- package/streams/user.js +89 -15
- package/streams/view.js +97 -25
- package/styles/reset/form.js +57 -5
- package/styles/reset/index.js +6 -1
- package/styles/reset/media.js +22 -1
- package/styles/reset/root.js +33 -1
- package/styles/reset/table.js +10 -1
- package/styles/reset/typography.js +26 -1
- package/subscriptions/app.js +148 -17
- package/subscriptions/error.js +292 -13
- package/subscriptions/helpers/buildRegisterUrl.js +25 -6
- package/subscriptions/helpers/clearUpInAppBrowser.js +14 -3
- package/subscriptions/helpers/handleLinks.js +267 -25
- package/subscriptions/helpers/pipeline.js +12 -1
- package/subscriptions/history.js +34 -6
- package/subscriptions/index.js +25 -4
- package/subscriptions/menu.js +22 -5
- package/subscriptions/mock.js +39 -7
- package/subscriptions/router.js +336 -23
- package/subscriptions/user.js +93 -3
package/reducers/page/index.js
CHANGED
|
@@ -1,12 +1,75 @@
|
|
|
1
|
-
|
|
1
|
+
import "core-js/modules/es.array.reduce.js";
|
|
2
|
+
import { ENOTFOUND } from '@shopgate/pwa-core/constants/Pipeline';
|
|
3
|
+
import { REQUEST_PAGE_CONFIG, RECEIVE_PAGE_CONFIG, ERROR_PAGE_CONFIG, APP_WILL_START } from "../../constants/ActionTypes";
|
|
4
|
+
|
|
5
|
+
/**
|
|
2
6
|
* Enrich the widget data.
|
|
3
7
|
* @param {Object} action The action that was received.
|
|
4
8
|
* @return {Object} An enriched set of widgets.
|
|
5
|
-
*/
|
|
9
|
+
*/
|
|
10
|
+
const enrichWidgets = action => action.config.widgets.map((widget, index) => ({
|
|
11
|
+
...widget,
|
|
12
|
+
id: `${action.pageId}-${index}-${widget.type}`
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
/**
|
|
6
16
|
* The page config reducer.
|
|
7
17
|
* @param {Object} [state={}] The current application state.
|
|
8
18
|
* @param {Object} action The action object.
|
|
9
19
|
* @return {Object} The store data.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
|
|
20
|
+
*/
|
|
21
|
+
export default function pageReducer(state = {}, action) {
|
|
22
|
+
switch (action.type) {
|
|
23
|
+
case REQUEST_PAGE_CONFIG:
|
|
24
|
+
return {
|
|
25
|
+
...state,
|
|
26
|
+
[action.pageId]: {
|
|
27
|
+
...state[action.pageId],
|
|
28
|
+
isFetching: true,
|
|
29
|
+
expires: 0
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
case RECEIVE_PAGE_CONFIG:
|
|
33
|
+
{
|
|
34
|
+
return {
|
|
35
|
+
...state,
|
|
36
|
+
[action.pageId]: {
|
|
37
|
+
title: action.config.title,
|
|
38
|
+
widgets: enrichWidgets(action),
|
|
39
|
+
isFetching: false,
|
|
40
|
+
expires: Date.now() + 3600000 // One hour
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
case ERROR_PAGE_CONFIG:
|
|
45
|
+
{
|
|
46
|
+
if (action.errorCode === ENOTFOUND) {
|
|
47
|
+
// Remove the temporary page entry from the state when noting was found for the pageId.
|
|
48
|
+
const {
|
|
49
|
+
[action.pageId]: ignore,
|
|
50
|
+
...rest
|
|
51
|
+
} = state;
|
|
52
|
+
return rest;
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
...state,
|
|
56
|
+
[action.pageId]: {
|
|
57
|
+
...state[action.pageId],
|
|
58
|
+
isFetching: false,
|
|
59
|
+
expires: 0
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
case APP_WILL_START:
|
|
64
|
+
{
|
|
65
|
+
return Object.keys(state).reduce((acc, pageId) => {
|
|
66
|
+
acc[pageId].expires = 0;
|
|
67
|
+
return acc;
|
|
68
|
+
}, {
|
|
69
|
+
...state
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
default:
|
|
73
|
+
return state;
|
|
74
|
+
}
|
|
75
|
+
}
|
package/reducers/router/index.js
CHANGED
|
@@ -1,5 +1,51 @@
|
|
|
1
|
-
|
|
1
|
+
import cloneDeep from 'lodash/cloneDeep';
|
|
2
|
+
import { stack } from '@virtuous/conductor';
|
|
3
|
+
import { ROUTE_WILL_ENTER, ROUTE_DID_LEAVE, ROUTE_WILL_LEAVE, ROUTE_DID_UPDATE, ROUTE_DID_ENTER } from "../../constants/ActionTypes";
|
|
4
|
+
const defaultState = {
|
|
5
|
+
currentRoute: null,
|
|
6
|
+
stack: []
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
2
10
|
* @param {Object} state The current state.
|
|
3
11
|
* @param {Object} action The action object.
|
|
4
12
|
* @returns {Object}
|
|
5
|
-
*/
|
|
13
|
+
*/
|
|
14
|
+
export default function router(state = defaultState, action) {
|
|
15
|
+
switch (action.type) {
|
|
16
|
+
case ROUTE_WILL_LEAVE:
|
|
17
|
+
case ROUTE_DID_LEAVE:
|
|
18
|
+
{
|
|
19
|
+
return {
|
|
20
|
+
...state,
|
|
21
|
+
stack: Array.from(stack.getAll().values())
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
case ROUTE_WILL_ENTER:
|
|
25
|
+
case ROUTE_DID_ENTER:
|
|
26
|
+
return {
|
|
27
|
+
...state,
|
|
28
|
+
stack: Array.from(stack.getAll().values()),
|
|
29
|
+
currentRoute: cloneDeep(action.route)
|
|
30
|
+
};
|
|
31
|
+
case ROUTE_DID_UPDATE:
|
|
32
|
+
{
|
|
33
|
+
const {
|
|
34
|
+
id: currentId
|
|
35
|
+
} = state.currentRoute || {};
|
|
36
|
+
const {
|
|
37
|
+
id: updatedId
|
|
38
|
+
} = action.route;
|
|
39
|
+
if (currentId === updatedId) {
|
|
40
|
+
return {
|
|
41
|
+
...state,
|
|
42
|
+
stack: Array.from(stack.getAll().values()),
|
|
43
|
+
currentRoute: cloneDeep(action.route)
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return state;
|
|
47
|
+
}
|
|
48
|
+
default:
|
|
49
|
+
return state;
|
|
50
|
+
}
|
|
51
|
+
}
|
package/reducers/url/index.js
CHANGED
|
@@ -1,8 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { REQUEST_URL, RECEIVE_URL, ERROR_URL } from "../../constants/ActionTypes";
|
|
2
|
+
const URL_LIFETIME = 300000; // 5 minutes in milliseconds
|
|
3
|
+
const defaultState = {};
|
|
4
|
+
|
|
5
|
+
/**
|
|
3
6
|
* Stores the requested urls
|
|
4
7
|
* This part of the store is stored in the localStorage!
|
|
5
8
|
* @param {Object} [state] The current state.
|
|
6
9
|
* @param {Object} action The action object.
|
|
7
10
|
* @return {Object} The new state.
|
|
8
|
-
*/
|
|
11
|
+
*/
|
|
12
|
+
export default function urlReducer(state = defaultState, action) {
|
|
13
|
+
switch (action.type) {
|
|
14
|
+
case REQUEST_URL:
|
|
15
|
+
return {
|
|
16
|
+
...state,
|
|
17
|
+
[action.urlType]: {
|
|
18
|
+
...state[action.urlType],
|
|
19
|
+
url: null,
|
|
20
|
+
isFetching: true,
|
|
21
|
+
expires: 0
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
case RECEIVE_URL:
|
|
25
|
+
return {
|
|
26
|
+
...state,
|
|
27
|
+
[action.urlType]: {
|
|
28
|
+
...state[action.urlType],
|
|
29
|
+
url: action.url,
|
|
30
|
+
isFetching: false,
|
|
31
|
+
expires: action.expires ? Date.parse(action.expires) : Date.now() + URL_LIFETIME
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
case ERROR_URL:
|
|
35
|
+
return {
|
|
36
|
+
...state,
|
|
37
|
+
[action.urlType]: {
|
|
38
|
+
...state[action.urlType],
|
|
39
|
+
url: null,
|
|
40
|
+
isFetching: false,
|
|
41
|
+
expires: 0
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
default:
|
|
45
|
+
return state;
|
|
46
|
+
}
|
|
47
|
+
}
|
package/reducers/user/data.js
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
import { REQUEST_USER, RECEIVE_USER, ERROR_USER, SUCCESS_LOGOUT } from "../../constants/ActionTypes";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Stores the user data state
|
|
3
5
|
* @param {Object} [state] The current state.
|
|
4
6
|
* @param {Object} action The action object.
|
|
5
7
|
* @return {Object} The new state.
|
|
6
|
-
*/
|
|
8
|
+
*/
|
|
9
|
+
export default function userDataReducer(state = {}, action) {
|
|
10
|
+
switch (action.type) {
|
|
11
|
+
case REQUEST_USER:
|
|
12
|
+
return {
|
|
13
|
+
...state,
|
|
14
|
+
isFetching: true
|
|
15
|
+
};
|
|
16
|
+
case RECEIVE_USER:
|
|
17
|
+
return {
|
|
18
|
+
...state,
|
|
19
|
+
...action.user,
|
|
20
|
+
isFetching: false
|
|
21
|
+
};
|
|
22
|
+
case ERROR_USER:
|
|
23
|
+
return {
|
|
24
|
+
isFetching: false
|
|
25
|
+
};
|
|
26
|
+
case SUCCESS_LOGOUT:
|
|
27
|
+
return {};
|
|
28
|
+
default:
|
|
29
|
+
return state;
|
|
30
|
+
}
|
|
31
|
+
}
|
package/reducers/user/index.js
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
import{combineReducers}from'redux';
|
|
1
|
+
import { combineReducers } from 'redux';
|
|
2
|
+
import login from "./login";
|
|
3
|
+
import data from "./data";
|
|
4
|
+
export default combineReducers({
|
|
5
|
+
login,
|
|
6
|
+
data
|
|
7
|
+
});
|
package/reducers/user/login.js
CHANGED
|
@@ -1,6 +1,69 @@
|
|
|
1
|
-
|
|
1
|
+
import { APP_DID_START, REQUEST_LOGIN, SUCCESS_LOGIN, TOGGLE_LOGGED_IN, ERROR_LOGIN, SUCCESS_LOGOUT, DISABLE_LOGIN } from "../../constants/ActionTypes";
|
|
2
|
+
const defaultState = {
|
|
3
|
+
isFetching: false,
|
|
4
|
+
disabled: false,
|
|
5
|
+
isLoggedIn: false,
|
|
6
|
+
errors: null,
|
|
7
|
+
strategy: null,
|
|
8
|
+
expires: null
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
2
12
|
* Stores the login state
|
|
3
13
|
* @param {Object} [state] The current state.
|
|
4
14
|
* @param {Object} action The action object.
|
|
5
15
|
* @return {Object} The new state.
|
|
6
|
-
*/
|
|
16
|
+
*/
|
|
17
|
+
export default function userLoginReducer(state = defaultState, action) {
|
|
18
|
+
switch (action.type) {
|
|
19
|
+
case APP_DID_START:
|
|
20
|
+
return {
|
|
21
|
+
...state,
|
|
22
|
+
disabled: false
|
|
23
|
+
};
|
|
24
|
+
case DISABLE_LOGIN:
|
|
25
|
+
return {
|
|
26
|
+
...state,
|
|
27
|
+
disabled: action.value
|
|
28
|
+
};
|
|
29
|
+
case REQUEST_LOGIN:
|
|
30
|
+
return {
|
|
31
|
+
...state,
|
|
32
|
+
strategy: action.strategy,
|
|
33
|
+
isFetching: true
|
|
34
|
+
};
|
|
35
|
+
case SUCCESS_LOGIN:
|
|
36
|
+
return {
|
|
37
|
+
...state,
|
|
38
|
+
isLoggedIn: true,
|
|
39
|
+
errors: null,
|
|
40
|
+
isFetching: false,
|
|
41
|
+
strategy: action.strategy,
|
|
42
|
+
...(typeof action.sessionLifetimeInSeconds === 'number' ? {
|
|
43
|
+
expires: new Date().getTime() + action.sessionLifetimeInSeconds * 1000
|
|
44
|
+
} : {
|
|
45
|
+
expires: null
|
|
46
|
+
})
|
|
47
|
+
};
|
|
48
|
+
case ERROR_LOGIN:
|
|
49
|
+
return {
|
|
50
|
+
...state,
|
|
51
|
+
errors: action.messages,
|
|
52
|
+
isLoggedIn: false,
|
|
53
|
+
isFetching: false
|
|
54
|
+
};
|
|
55
|
+
case TOGGLE_LOGGED_IN:
|
|
56
|
+
return {
|
|
57
|
+
...state,
|
|
58
|
+
isLoggedIn: action.value,
|
|
59
|
+
strategy: null,
|
|
60
|
+
...(action.value === false ? {
|
|
61
|
+
expires: null
|
|
62
|
+
} : null)
|
|
63
|
+
};
|
|
64
|
+
case SUCCESS_LOGOUT:
|
|
65
|
+
return defaultState;
|
|
66
|
+
default:
|
|
67
|
+
return state;
|
|
68
|
+
}
|
|
69
|
+
}
|
package/selectors/client.js
CHANGED
|
@@ -1,69 +1,186 @@
|
|
|
1
|
-
import{createSelector}from'reselect';
|
|
1
|
+
import { createSelector } from 'reselect';
|
|
2
|
+
import MobileDetect from 'mobile-detect';
|
|
3
|
+
import { hasSGJavaScriptBridge } from '@shopgate/pwa-core/helpers';
|
|
4
|
+
import { isVersionAtLeast } from '@shopgate/pwa-core/helpers/version';
|
|
5
|
+
import { SCANNER_MIN_APP_LIB_VERSION } from '@shopgate/pwa-core/constants/Scanner';
|
|
6
|
+
import { hasWebBridge } from '@shopgate/engage/core/helpers/bridge';
|
|
7
|
+
import { getAreSimulatedInsetsInjected } from '@shopgate/engage/development/selectors';
|
|
8
|
+
import { OS_ANDROID, OS_IOS, MODEL_NAMES_IPHONE_X, PAGE_INSETS_ANDROID, PAGE_INSETS_IOS, PAGE_INSETS_IPHONE_X, TYPE_TABLET } from "../constants/Device";
|
|
9
|
+
const md = new MobileDetect(navigator.userAgent);
|
|
10
|
+
|
|
11
|
+
/**
|
|
2
12
|
* Returns the client state (state.client)
|
|
3
13
|
* @param {Object} state The application state.
|
|
4
14
|
* @returns {Object}
|
|
5
|
-
*/
|
|
15
|
+
*/
|
|
16
|
+
export const getClientState = state => state.client;
|
|
17
|
+
|
|
18
|
+
/**
|
|
6
19
|
* Returns the client info state (state.client.info)
|
|
7
20
|
* @param {Object} state The application state.
|
|
8
21
|
* @returns {Object}
|
|
9
|
-
*/
|
|
22
|
+
*/
|
|
23
|
+
export const getClientInformation = createSelector(getClientState, state => state.info);
|
|
24
|
+
|
|
25
|
+
/**
|
|
10
26
|
* Returns the client connectivity state (state.client.connectivity)
|
|
11
27
|
* @param {Object} state The application state.
|
|
12
28
|
* @returns {Object}
|
|
13
|
-
*/
|
|
29
|
+
*/
|
|
30
|
+
export const getClientConnectivity = createSelector(getClientState, state => state.connectivity);
|
|
31
|
+
|
|
32
|
+
/**
|
|
14
33
|
* Returns the device information.
|
|
15
34
|
* @param {Object} state The application state.
|
|
16
35
|
* @return {Object|null}
|
|
17
|
-
*/
|
|
36
|
+
*/
|
|
37
|
+
export const getDeviceInformation = createSelector(getClientInformation, clientInformation => {
|
|
38
|
+
const {
|
|
39
|
+
device
|
|
40
|
+
} = clientInformation;
|
|
41
|
+
return device || null;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
/**
|
|
18
45
|
* Creates the `getSupportedIdentityServices()` selector.
|
|
19
46
|
* @returns {Function}
|
|
20
|
-
*/
|
|
47
|
+
*/
|
|
48
|
+
export function makeGetSupportedIdentityServices() {
|
|
49
|
+
return createSelector(getClientInformation, info => info.supportedIdentityServices || []);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
21
53
|
* Creates the `supportsIdentityService()` selector.
|
|
22
54
|
* @param {string} service The identity service to check.
|
|
23
55
|
* @returns {Function}
|
|
24
|
-
*/
|
|
56
|
+
*/
|
|
57
|
+
export function makeSupportsIdentityService(service) {
|
|
58
|
+
const getSupportedIdentityServices = makeGetSupportedIdentityServices();
|
|
59
|
+
return createSelector(getSupportedIdentityServices, services => services.includes(service));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
25
63
|
* Returns the device platform.
|
|
26
64
|
* @param {Object} state The application state.
|
|
27
65
|
* @return {string|null}
|
|
28
|
-
*/
|
|
66
|
+
*/
|
|
67
|
+
export const getPlatform = createSelector(getDeviceInformation, deviceInformation => {
|
|
68
|
+
const {
|
|
69
|
+
os: {
|
|
70
|
+
platform = null
|
|
71
|
+
} = {}
|
|
72
|
+
} = deviceInformation || {};
|
|
73
|
+
return platform;
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
/**
|
|
29
77
|
* Returns the os version.
|
|
30
78
|
* @return {string|null}
|
|
31
|
-
*/
|
|
79
|
+
*/
|
|
80
|
+
export const getOSVersion = createSelector(getDeviceInformation, deviceInformation => {
|
|
81
|
+
const {
|
|
82
|
+
os: {
|
|
83
|
+
ver = null
|
|
84
|
+
} = {}
|
|
85
|
+
} = deviceInformation || {};
|
|
86
|
+
return ver;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
/**
|
|
32
90
|
* Returns the device model.
|
|
33
91
|
* @param {Object} state The application state.
|
|
34
92
|
* @return {string|null}
|
|
35
|
-
*/
|
|
93
|
+
*/
|
|
94
|
+
export const getDeviceModel = createSelector(getDeviceInformation, deviceInformation => {
|
|
95
|
+
const {
|
|
96
|
+
model = null
|
|
97
|
+
} = deviceInformation || {};
|
|
98
|
+
return model;
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
/**
|
|
36
102
|
* Check if the platform is Android.
|
|
37
103
|
* @param {Object} state The application state.
|
|
38
104
|
* @return {boolean}
|
|
39
|
-
*/
|
|
105
|
+
*/
|
|
106
|
+
export const isAndroid = createSelector(getPlatform, platform => {
|
|
107
|
+
if (hasWebBridge()) {
|
|
108
|
+
return md.os() === 'AndroidOS';
|
|
109
|
+
}
|
|
110
|
+
return platform === OS_ANDROID;
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
/**
|
|
40
114
|
* Check if the platform is iOS.
|
|
41
115
|
* @param {Object} state The application state.
|
|
42
116
|
* @return {boolean}
|
|
43
|
-
*/
|
|
117
|
+
*/
|
|
118
|
+
export const isIos = createSelector(getPlatform, platform => platform === OS_IOS);
|
|
119
|
+
|
|
120
|
+
/**
|
|
44
121
|
* Checks if the currently stored lib version is one that supports the scanner.
|
|
45
122
|
* @param {Object} state The application state.
|
|
46
123
|
* @returns {boolean}
|
|
47
|
-
*/
|
|
48
|
-
|
|
49
|
-
|
|
124
|
+
*/
|
|
125
|
+
export const hasScannerSupport = createSelector(getClientInformation, getDeviceInformation, isIos, (clientInformation, deviceInformation, deviceIsIos) => {
|
|
126
|
+
const {
|
|
127
|
+
type
|
|
128
|
+
} = deviceInformation || {};
|
|
129
|
+
const isIpad = type === TYPE_TABLET && deviceIsIos;
|
|
130
|
+
if (isVersionAtLeast('11.0.0', clientInformation.appVersion)) {
|
|
131
|
+
// scanner is supported on all apps based on the react-native based apps
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// scanner is not supported on iPads with the not react-native based app
|
|
136
|
+
return isVersionAtLeast(SCANNER_MIN_APP_LIB_VERSION, clientInformation.libVersion) && !isIpad;
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
/**
|
|
50
140
|
* Determines page insets for the current device. Used as a fallback for the native insets.
|
|
51
141
|
* @param {Object} state The application state.
|
|
52
142
|
* @returns {Object}
|
|
53
|
-
*/
|
|
54
|
-
|
|
143
|
+
*/
|
|
144
|
+
export const getPageInsets = createSelector(getDeviceModel, isIos, getAreSimulatedInsetsInjected, (model, iOS, injectSimulatedInsets) => {
|
|
145
|
+
if (injectSimulatedInsets) {
|
|
146
|
+
// Simulate safe area insets in development when user agent is set to iOS device
|
|
147
|
+
return PAGE_INSETS_IPHONE_X;
|
|
148
|
+
}
|
|
149
|
+
if (iOS) {
|
|
150
|
+
if (!hasSGJavaScriptBridge()) {
|
|
151
|
+
return PAGE_INSETS_ANDROID;
|
|
152
|
+
}
|
|
153
|
+
if (MODEL_NAMES_IPHONE_X.includes(model)) {
|
|
154
|
+
return PAGE_INSETS_IPHONE_X;
|
|
155
|
+
}
|
|
156
|
+
return PAGE_INSETS_IOS;
|
|
157
|
+
}
|
|
158
|
+
return PAGE_INSETS_ANDROID;
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
/**
|
|
55
162
|
* Determines what os version handles the insets differently compared to other os versions.
|
|
56
163
|
* @returns {boolean}
|
|
57
|
-
*/
|
|
164
|
+
*/
|
|
165
|
+
export const considerNativeInset = createSelector(isIos, getOSVersion, (ios, ver) => ios && ver && ver.indexOf('10.') === 0);
|
|
166
|
+
|
|
167
|
+
/**
|
|
58
168
|
* Checks if the client is connected.
|
|
59
169
|
* @param {Object} state The application state.
|
|
60
170
|
* @returns {boolean}
|
|
61
|
-
*/
|
|
171
|
+
*/
|
|
172
|
+
export const getIsConnected = createSelector(getClientConnectivity, connectivity => connectivity.connected);
|
|
173
|
+
|
|
174
|
+
/**
|
|
62
175
|
* Determines the network type of the client connection e.g. LTE or UMTS.
|
|
63
176
|
* @param {Object} state The application state.
|
|
64
177
|
* @returns {string}
|
|
65
|
-
*/
|
|
178
|
+
*/
|
|
179
|
+
export const getClientConnectivityNetwork = createSelector(getClientConnectivity, connectivity => connectivity.network);
|
|
180
|
+
|
|
181
|
+
/**
|
|
66
182
|
* Determines the type of the client connection e.g. WIFI or 4G.
|
|
67
183
|
* @param {Object} state The application state.
|
|
68
184
|
* @returns {string}
|
|
69
|
-
*/
|
|
185
|
+
*/
|
|
186
|
+
export const getClientConnectivityType = createSelector(getClientConnectivity, connectivity => connectivity.type);
|
package/selectors/history.js
CHANGED
|
@@ -1,43 +1,81 @@
|
|
|
1
|
-
import{createSelector}from'reselect';
|
|
1
|
+
import { createSelector } from 'reselect';
|
|
2
|
+
import { makeGetDefaultSortOrder } from '@shopgate/engage/filter/selectors';
|
|
3
|
+
import { getCurrentPathname, getCurrentQuery, getRouterStack } from "./router";
|
|
4
|
+
import { parseObjectToQueryString } from "../helpers/router";
|
|
5
|
+
|
|
6
|
+
/**
|
|
2
7
|
* @deprecated
|
|
3
|
-
*/
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
4
11
|
* Selects the history state.
|
|
5
12
|
* @param {Object} state The global state.
|
|
6
13
|
* @deprecated
|
|
7
14
|
* @return {Object}
|
|
8
|
-
*/
|
|
15
|
+
*/
|
|
16
|
+
export const getHistoryState = state => state.history;
|
|
17
|
+
|
|
18
|
+
/**
|
|
9
19
|
* Retrieves a single url parameter from the query parameters object.
|
|
10
20
|
* @param {Object} state The global state.
|
|
11
21
|
* @param {string} param The dedicated url parameter.
|
|
12
22
|
* @return {*} The URL parameter value.
|
|
13
|
-
*/
|
|
23
|
+
*/
|
|
24
|
+
export const getQueryParam = createSelector(getCurrentQuery, (state, props, param) => param, (params, param) => {
|
|
25
|
+
if (!params || !params[param]) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
return params[param];
|
|
29
|
+
});
|
|
30
|
+
const getDefaultSortOrder = makeGetDefaultSortOrder();
|
|
31
|
+
|
|
32
|
+
/**
|
|
14
33
|
* Retrieves the sort order from the URL query parameters.
|
|
15
34
|
* @param {Object} state The global state.
|
|
16
35
|
* @returns {string} The current sort order.
|
|
17
|
-
*/
|
|
36
|
+
*/
|
|
37
|
+
export const getSortOrder = createSelector((state, props) => getQueryParam(state, props, 'sort'), getDefaultSortOrder, (sortParam, defaultSort) => sortParam || defaultSort);
|
|
38
|
+
|
|
39
|
+
/**
|
|
18
40
|
* Retrieves the search phrase from the URL query parameters.
|
|
19
41
|
* @param {Object} state The global state.
|
|
20
42
|
* @returns {string|null} The current search phrase.
|
|
21
|
-
*/
|
|
43
|
+
*/
|
|
44
|
+
export const getSearchPhrase = createSelector((state, props) => getQueryParam(state, props, 's'), param => param ? param.trim() : null);
|
|
45
|
+
|
|
46
|
+
/**
|
|
22
47
|
* Gets the current history pathname.
|
|
23
48
|
* @deprecated
|
|
24
49
|
* @param {Object} state The current application state.
|
|
25
50
|
* @returns {string}
|
|
26
|
-
*/
|
|
51
|
+
*/
|
|
52
|
+
export const getHistoryPathname = getCurrentPathname;
|
|
53
|
+
|
|
54
|
+
/**
|
|
27
55
|
* Gets the length of the current history stack.
|
|
28
56
|
* @param {Object} state The current application state.
|
|
29
57
|
* @return {number}
|
|
30
|
-
*/
|
|
58
|
+
*/
|
|
59
|
+
export const getHistoryLength = createSelector(getRouterStack, stack => stack.length);
|
|
60
|
+
|
|
61
|
+
/**
|
|
31
62
|
* Gets the current query params from history state as a preformatted string.
|
|
32
63
|
* @param {Object} state The global state.
|
|
33
64
|
* @return {string}
|
|
34
|
-
*/
|
|
65
|
+
*/
|
|
66
|
+
export const getQueryParamsAsString = createSelector(getCurrentQuery, queryParams => parseObjectToQueryString(queryParams));
|
|
67
|
+
|
|
68
|
+
/**
|
|
35
69
|
* Gets the current history location from the history state.
|
|
36
70
|
* @param {Object} state The current application state.
|
|
37
71
|
* @return {string|null}
|
|
38
|
-
*/
|
|
72
|
+
*/
|
|
73
|
+
export const getHistoryLocation = createSelector(getHistoryPathname, getQueryParamsAsString, (pathname, params) => `${pathname}${params}`);
|
|
74
|
+
|
|
75
|
+
/**
|
|
39
76
|
* Gets the current redirectLocation from the history state.
|
|
40
77
|
* @param {Object} state The current application state.
|
|
41
78
|
* @deprecated
|
|
42
79
|
* @return {string|null}
|
|
43
|
-
*/
|
|
80
|
+
*/
|
|
81
|
+
export const getRedirectLocation = createSelector(getHistoryState, historyState => historyState.redirectLocation || null);
|