@open-tender/cloud 0.5.9 → 0.5.11
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/LICENSE.md +21 -21
- package/README.md +3 -3
- package/dist/cjs/app/hooks.d.ts +67 -67
- package/dist/cjs/app/hooks.js +8 -8
- package/dist/cjs/app/index.d.ts +2 -2
- package/dist/cjs/app/index.js +5 -5
- package/dist/cjs/app/store.d.ts +197 -197
- package/dist/cjs/app/store.js +65 -65
- package/dist/cjs/index.d.ts +5 -5
- package/dist/cjs/index.js +11 -11
- package/dist/cjs/services/api.d.ts +173 -173
- package/dist/cjs/services/api.js +741 -741
- package/dist/cjs/services/errors.d.ts +50 -50
- package/dist/cjs/services/errors.js +53 -53
- package/dist/cjs/services/index.d.ts +3 -3
- package/dist/cjs/services/index.js +7 -7
- package/dist/cjs/slices/alerts.d.ts +5 -5
- package/dist/cjs/slices/alerts.js +29 -29
- package/dist/cjs/slices/allergens.d.ts +101 -101
- package/dist/cjs/slices/allergens.js +83 -83
- package/dist/cjs/slices/announcements.d.ts +180 -180
- package/dist/cjs/slices/announcements.js +81 -81
- package/dist/cjs/slices/checkout.d.ts +69 -69
- package/dist/cjs/slices/checkout.js +326 -326
- package/dist/cjs/slices/completedOrders.d.ts +31 -31
- package/dist/cjs/slices/completedOrders.js +61 -61
- package/dist/cjs/slices/config.d.ts +317 -317
- package/dist/cjs/slices/config.js +195 -195
- package/dist/cjs/slices/confirmation.d.ts +8 -8
- package/dist/cjs/slices/confirmation.js +23 -23
- package/dist/cjs/slices/customer/account.d.ts +128 -128
- package/dist/cjs/slices/customer/account.js +351 -351
- package/dist/cjs/slices/customer/addresses.d.ts +55 -55
- package/dist/cjs/slices/customer/addresses.js +132 -132
- package/dist/cjs/slices/customer/allergens.d.ts +37 -37
- package/dist/cjs/slices/customer/allergens.js +94 -94
- package/dist/cjs/slices/customer/communicationPreferences.d.ts +69 -69
- package/dist/cjs/slices/customer/communicationPreferences.js +164 -164
- package/dist/cjs/slices/customer/creditCards.d.ts +137 -137
- package/dist/cjs/slices/customer/creditCards.js +170 -170
- package/dist/cjs/slices/customer/favorites.d.ts +68 -68
- package/dist/cjs/slices/customer/favorites.js +173 -173
- package/dist/cjs/slices/customer/fcmToken.d.ts +49 -49
- package/dist/cjs/slices/customer/fcmToken.js +110 -110
- package/dist/cjs/slices/customer/giftCards.d.ts +98 -98
- package/dist/cjs/slices/customer/giftCards.js +222 -222
- package/dist/cjs/slices/customer/groupOrders.d.ts +118 -118
- package/dist/cjs/slices/customer/groupOrders.js +262 -262
- package/dist/cjs/slices/customer/history.d.ts +23 -23
- package/dist/cjs/slices/customer/history.js +57 -57
- package/dist/cjs/slices/customer/houseAccounts.d.ts +26 -26
- package/dist/cjs/slices/customer/houseAccounts.js +67 -67
- package/dist/cjs/slices/customer/index.d.ts +42 -42
- package/dist/cjs/slices/customer/index.js +68 -68
- package/dist/cjs/slices/customer/loyalty.d.ts +251 -251
- package/dist/cjs/slices/customer/loyalty.js +110 -110
- package/dist/cjs/slices/customer/order.d.ts +116 -116
- package/dist/cjs/slices/customer/order.js +98 -98
- package/dist/cjs/slices/customer/orders.d.ts +27 -27
- package/dist/cjs/slices/customer/orders.js +69 -69
- package/dist/cjs/slices/customer/pointsShop.d.ts +35 -35
- package/dist/cjs/slices/customer/pointsShop.js +86 -86
- package/dist/cjs/slices/customer/qrCode.d.ts +23 -23
- package/dist/cjs/slices/customer/qrCode.js +57 -57
- package/dist/cjs/slices/customer/rewards.d.ts +26 -26
- package/dist/cjs/slices/customer/rewards.js +67 -67
- package/dist/cjs/slices/customer/thanx.d.ts +23 -23
- package/dist/cjs/slices/customer/thanx.js +56 -56
- package/dist/cjs/slices/customer/tpls.d.ts +238 -238
- package/dist/cjs/slices/customer/tpls.js +102 -102
- package/dist/cjs/slices/customer/tplsPointsShop.d.ts +38 -38
- package/dist/cjs/slices/customer/tplsPointsShop.js +88 -88
- package/dist/cjs/slices/deals.d.ts +25 -25
- package/dist/cjs/slices/deals.js +96 -96
- package/dist/cjs/slices/donations.d.ts +27 -27
- package/dist/cjs/slices/donations.js +57 -57
- package/dist/cjs/slices/geolocation.d.ts +11 -11
- package/dist/cjs/slices/geolocation.js +36 -36
- package/dist/cjs/slices/giftCards.d.ts +27 -27
- package/dist/cjs/slices/giftCards.js +58 -58
- package/dist/cjs/slices/groupOrder.d.ts +418 -418
- package/dist/cjs/slices/groupOrder.js +266 -266
- package/dist/cjs/slices/guest.d.ts +51 -51
- package/dist/cjs/slices/guest.js +91 -91
- package/dist/cjs/slices/index.d.ts +41 -41
- package/dist/cjs/slices/index.js +44 -44
- package/dist/cjs/slices/loader.d.ts +9 -9
- package/dist/cjs/slices/loader.js +25 -25
- package/dist/cjs/slices/menu.d.ts +31 -31
- package/dist/cjs/slices/menu.js +97 -97
- package/dist/cjs/slices/menuDisplay.d.ts +32 -32
- package/dist/cjs/slices/menuDisplay.js +59 -59
- package/dist/cjs/slices/menuItems.d.ts +26 -26
- package/dist/cjs/slices/menuItems.js +57 -57
- package/dist/cjs/slices/misc.d.ts +17 -17
- package/dist/cjs/slices/misc.js +51 -51
- package/dist/cjs/slices/modal.d.ts +5 -5
- package/dist/cjs/slices/modal.js +30 -30
- package/dist/cjs/slices/nav.d.ts +7 -7
- package/dist/cjs/slices/nav.js +23 -23
- package/dist/cjs/slices/navSite.d.ts +7 -7
- package/dist/cjs/slices/navSite.js +23 -23
- package/dist/cjs/slices/notifications.d.ts +5 -5
- package/dist/cjs/slices/notifications.js +27 -27
- package/dist/cjs/slices/oneTimePasscode.d.ts +40 -40
- package/dist/cjs/slices/oneTimePasscode.js +91 -91
- package/dist/cjs/slices/order.d.ts +372 -372
- package/dist/cjs/slices/order.js +528 -528
- package/dist/cjs/slices/orderFulfillment.d.ts +37 -37
- package/dist/cjs/slices/orderFulfillment.js +77 -77
- package/dist/cjs/slices/orderRating.d.ts +52 -52
- package/dist/cjs/slices/orderRating.js +105 -105
- package/dist/cjs/slices/posts.d.ts +24 -24
- package/dist/cjs/slices/posts.js +55 -55
- package/dist/cjs/slices/pushNotifications.d.ts +9 -9
- package/dist/cjs/slices/pushNotifications.js +29 -29
- package/dist/cjs/slices/qr.d.ts +11 -11
- package/dist/cjs/slices/qr.js +34 -34
- package/dist/cjs/slices/quote.d.ts +102 -102
- package/dist/cjs/slices/quote.js +65 -65
- package/dist/cjs/slices/resetPassword.d.ts +41 -41
- package/dist/cjs/slices/resetPassword.js +80 -80
- package/dist/cjs/slices/revenueCenters.d.ts +35 -35
- package/dist/cjs/slices/revenueCenters.js +95 -95
- package/dist/cjs/slices/sidebar.d.ts +7 -7
- package/dist/cjs/slices/sidebar.js +23 -23
- package/dist/cjs/slices/sidebarModal.d.ts +7 -7
- package/dist/cjs/slices/sidebarModal.js +23 -23
- package/dist/cjs/slices/signUp.d.ts +25 -25
- package/dist/cjs/slices/signUp.js +60 -60
- package/dist/cjs/slices/tags.d.ts +101 -101
- package/dist/cjs/slices/tags.js +90 -90
- package/dist/cjs/slices/terms.d.ts +20 -20
- package/dist/cjs/slices/terms.js +51 -51
- package/dist/cjs/slices/types.d.ts +62 -62
- package/dist/cjs/slices/types.js +66 -66
- package/dist/cjs/slices/unsubscribe.d.ts +39 -39
- package/dist/cjs/slices/unsubscribe.js +78 -78
- package/dist/cjs/slices/validTimes.d.ts +23 -23
- package/dist/cjs/slices/validTimes.js +57 -57
- package/dist/cjs/slices/verifyAccount.d.ts +23 -23
- package/dist/cjs/slices/verifyAccount.js +54 -54
- package/dist/esm/app/hooks.d.ts +67 -67
- package/dist/esm/app/hooks.js +4 -4
- package/dist/esm/app/index.d.ts +2 -2
- package/dist/esm/app/index.js +2 -2
- package/dist/esm/app/store.d.ts +197 -197
- package/dist/esm/app/store.js +62 -62
- package/dist/esm/index.d.ts +5 -5
- package/dist/esm/index.js +5 -5
- package/dist/esm/services/api.d.ts +173 -173
- package/dist/esm/services/api.js +739 -739
- package/dist/esm/services/errors.d.ts +50 -50
- package/dist/esm/services/errors.js +50 -50
- package/dist/esm/services/index.d.ts +3 -3
- package/dist/esm/services/index.js +3 -3
- package/dist/esm/slices/alerts.d.ts +5 -5
- package/dist/esm/slices/alerts.js +24 -24
- package/dist/esm/slices/allergens.d.ts +101 -101
- package/dist/esm/slices/allergens.js +77 -77
- package/dist/esm/slices/announcements.d.ts +180 -180
- package/dist/esm/slices/announcements.js +75 -75
- package/dist/esm/slices/checkout.d.ts +69 -69
- package/dist/esm/slices/checkout.js +318 -318
- package/dist/esm/slices/completedOrders.d.ts +31 -31
- package/dist/esm/slices/completedOrders.js +57 -57
- package/dist/esm/slices/config.d.ts +317 -317
- package/dist/esm/slices/config.js +168 -168
- package/dist/esm/slices/confirmation.d.ts +8 -8
- package/dist/esm/slices/confirmation.js +18 -18
- package/dist/esm/slices/customer/account.d.ts +128 -128
- package/dist/esm/slices/customer/account.js +344 -344
- package/dist/esm/slices/customer/addresses.d.ts +55 -55
- package/dist/esm/slices/customer/addresses.js +127 -127
- package/dist/esm/slices/customer/allergens.d.ts +37 -37
- package/dist/esm/slices/customer/allergens.js +89 -89
- package/dist/esm/slices/customer/communicationPreferences.d.ts +69 -69
- package/dist/esm/slices/customer/communicationPreferences.js +159 -159
- package/dist/esm/slices/customer/creditCards.d.ts +137 -137
- package/dist/esm/slices/customer/creditCards.js +165 -165
- package/dist/esm/slices/customer/favorites.d.ts +68 -68
- package/dist/esm/slices/customer/favorites.js +168 -168
- package/dist/esm/slices/customer/fcmToken.d.ts +49 -49
- package/dist/esm/slices/customer/fcmToken.js +106 -106
- package/dist/esm/slices/customer/giftCards.d.ts +98 -98
- package/dist/esm/slices/customer/giftCards.js +217 -217
- package/dist/esm/slices/customer/groupOrders.d.ts +118 -118
- package/dist/esm/slices/customer/groupOrders.js +256 -256
- package/dist/esm/slices/customer/history.d.ts +23 -23
- package/dist/esm/slices/customer/history.js +53 -53
- package/dist/esm/slices/customer/houseAccounts.d.ts +26 -26
- package/dist/esm/slices/customer/houseAccounts.js +62 -62
- package/dist/esm/slices/customer/index.d.ts +42 -42
- package/dist/esm/slices/customer/index.js +64 -64
- package/dist/esm/slices/customer/loyalty.d.ts +251 -251
- package/dist/esm/slices/customer/loyalty.js +102 -102
- package/dist/esm/slices/customer/order.d.ts +116 -116
- package/dist/esm/slices/customer/order.js +94 -94
- package/dist/esm/slices/customer/orders.d.ts +27 -27
- package/dist/esm/slices/customer/orders.js +63 -63
- package/dist/esm/slices/customer/pointsShop.d.ts +35 -35
- package/dist/esm/slices/customer/pointsShop.js +82 -82
- package/dist/esm/slices/customer/qrCode.d.ts +23 -23
- package/dist/esm/slices/customer/qrCode.js +53 -53
- package/dist/esm/slices/customer/rewards.d.ts +26 -26
- package/dist/esm/slices/customer/rewards.js +62 -62
- package/dist/esm/slices/customer/thanx.d.ts +23 -23
- package/dist/esm/slices/customer/thanx.js +52 -52
- package/dist/esm/slices/customer/tpls.d.ts +238 -238
- package/dist/esm/slices/customer/tpls.js +98 -98
- package/dist/esm/slices/customer/tplsPointsShop.d.ts +38 -38
- package/dist/esm/slices/customer/tplsPointsShop.js +84 -84
- package/dist/esm/slices/deals.d.ts +25 -25
- package/dist/esm/slices/deals.js +90 -90
- package/dist/esm/slices/donations.d.ts +27 -27
- package/dist/esm/slices/donations.js +53 -53
- package/dist/esm/slices/geolocation.d.ts +11 -11
- package/dist/esm/slices/geolocation.js +30 -30
- package/dist/esm/slices/giftCards.d.ts +27 -27
- package/dist/esm/slices/giftCards.js +54 -54
- package/dist/esm/slices/groupOrder.d.ts +418 -418
- package/dist/esm/slices/groupOrder.js +259 -259
- package/dist/esm/slices/guest.d.ts +51 -51
- package/dist/esm/slices/guest.js +86 -86
- package/dist/esm/slices/index.d.ts +41 -41
- package/dist/esm/slices/index.js +41 -41
- package/dist/esm/slices/loader.d.ts +9 -9
- package/dist/esm/slices/loader.js +21 -21
- package/dist/esm/slices/menu.d.ts +31 -31
- package/dist/esm/slices/menu.js +90 -90
- package/dist/esm/slices/menuDisplay.d.ts +32 -32
- package/dist/esm/slices/menuDisplay.js +55 -55
- package/dist/esm/slices/menuItems.d.ts +26 -26
- package/dist/esm/slices/menuItems.js +52 -52
- package/dist/esm/slices/misc.d.ts +17 -17
- package/dist/esm/slices/misc.js +41 -41
- package/dist/esm/slices/modal.d.ts +5 -5
- package/dist/esm/slices/modal.js +25 -25
- package/dist/esm/slices/nav.d.ts +7 -7
- package/dist/esm/slices/nav.js +19 -19
- package/dist/esm/slices/navSite.d.ts +7 -7
- package/dist/esm/slices/navSite.js +19 -19
- package/dist/esm/slices/notifications.d.ts +5 -5
- package/dist/esm/slices/notifications.js +22 -22
- package/dist/esm/slices/oneTimePasscode.d.ts +40 -40
- package/dist/esm/slices/oneTimePasscode.js +86 -86
- package/dist/esm/slices/order.d.ts +372 -372
- package/dist/esm/slices/order.js +508 -508
- package/dist/esm/slices/orderFulfillment.d.ts +37 -37
- package/dist/esm/slices/orderFulfillment.js +73 -73
- package/dist/esm/slices/orderRating.d.ts +52 -52
- package/dist/esm/slices/orderRating.js +101 -101
- package/dist/esm/slices/posts.d.ts +24 -24
- package/dist/esm/slices/posts.js +51 -51
- package/dist/esm/slices/pushNotifications.d.ts +9 -9
- package/dist/esm/slices/pushNotifications.js +23 -23
- package/dist/esm/slices/qr.d.ts +11 -11
- package/dist/esm/slices/qr.js +29 -29
- package/dist/esm/slices/quote.d.ts +102 -102
- package/dist/esm/slices/quote.js +61 -61
- package/dist/esm/slices/resetPassword.d.ts +41 -41
- package/dist/esm/slices/resetPassword.js +76 -76
- package/dist/esm/slices/revenueCenters.d.ts +35 -35
- package/dist/esm/slices/revenueCenters.js +89 -89
- package/dist/esm/slices/sidebar.d.ts +7 -7
- package/dist/esm/slices/sidebar.js +19 -19
- package/dist/esm/slices/sidebarModal.d.ts +7 -7
- package/dist/esm/slices/sidebarModal.js +19 -19
- package/dist/esm/slices/signUp.d.ts +25 -25
- package/dist/esm/slices/signUp.js +56 -56
- package/dist/esm/slices/tags.d.ts +101 -101
- package/dist/esm/slices/tags.js +84 -84
- package/dist/esm/slices/terms.d.ts +20 -20
- package/dist/esm/slices/terms.js +47 -47
- package/dist/esm/slices/types.d.ts +62 -62
- package/dist/esm/slices/types.js +63 -63
- package/dist/esm/slices/unsubscribe.d.ts +39 -39
- package/dist/esm/slices/unsubscribe.js +74 -74
- package/dist/esm/slices/validTimes.d.ts +23 -23
- package/dist/esm/slices/validTimes.js +52 -52
- package/dist/esm/slices/verifyAccount.d.ts +23 -23
- package/dist/esm/slices/verifyAccount.js +50 -50
- package/package.json +61 -61
|
@@ -1,344 +1,344 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
2
|
-
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
|
|
3
|
-
import { ReducerType } from '../types';
|
|
4
|
-
import { MISSING_CUSTOMER, MISSING_CUSTOMER_TOKEN } from '@open-tender/types';
|
|
5
|
-
import { makeCustomerProfile, makeFavoritesLookup } from '@open-tender/utils';
|
|
6
|
-
import { showNotification } from '../notifications';
|
|
7
|
-
import { resetCustomerAllergens, setCustomerAllergens } from './allergens';
|
|
8
|
-
import { setSelectedAllergens } from '../allergens';
|
|
9
|
-
import { resetCustomerFavorites, setCustomerFavorites, setCustomerFavoritesLookup } from './favorites';
|
|
10
|
-
import { resetCustomerCreditCards } from './creditCards';
|
|
11
|
-
import { resetCustomerAddresses } from './addresses';
|
|
12
|
-
import { resetCustomerHouseAccounts } from './houseAccounts';
|
|
13
|
-
import { resetCustomerLoyalty } from './loyalty';
|
|
14
|
-
import { resetCustomerOrder } from './order';
|
|
15
|
-
import { resetCustomerOrders } from './orders';
|
|
16
|
-
import { resetCustomerRewards } from './rewards';
|
|
17
|
-
import { resetCustomerCommunicationPreferences } from './communicationPreferences';
|
|
18
|
-
import { resetCustomerGiftCards, setCustomerGiftCards } from './giftCards';
|
|
19
|
-
import { addMessage, resetOrder, setAlert } from '../order';
|
|
20
|
-
import { resetCheckout, updateCheckoutCustomer } from '../checkout';
|
|
21
|
-
import { resetGroupOrder } from '../groupOrder';
|
|
22
|
-
import { resetGuest } from '../guest';
|
|
23
|
-
import { resetCustomerTpls } from './tpls';
|
|
24
|
-
const initialState = {
|
|
25
|
-
auth: null,
|
|
26
|
-
profile: null,
|
|
27
|
-
loading: 'idle',
|
|
28
|
-
error: null
|
|
29
|
-
};
|
|
30
|
-
export var AccountActionType;
|
|
31
|
-
(function (AccountActionType) {
|
|
32
|
-
AccountActionType["LoginCustomer"] = "customer/loginCustomer";
|
|
33
|
-
AccountActionType["LogoutCustomer"] = "customer/logoutCustomer";
|
|
34
|
-
AccountActionType["FetchCustomer"] = "customer/fetchCustomer";
|
|
35
|
-
AccountActionType["UpdateCustomer"] = "customer/updateCustomer";
|
|
36
|
-
AccountActionType["VerifyCustomer"] = "customer/verifyCustomer";
|
|
37
|
-
AccountActionType["LinkPosToken"] = "customer/linkPosToken";
|
|
38
|
-
AccountActionType["DeleteCustomer"] = "customer/deleteCustomer";
|
|
39
|
-
AccountActionType["LoginCustomerThanx"] = "customer/loginCustomerThanx";
|
|
40
|
-
AccountActionType["AuthCustomerThanx"] = "customer/authCustomerThanx";
|
|
41
|
-
})(AccountActionType || (AccountActionType = {}));
|
|
42
|
-
export const checkAuth = (err, dispatch, rejectWithValue) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
-
if ((err === null || err === void 0 ? void 0 : err.status) === 401) {
|
|
44
|
-
yield dispatch(logoutCustomer());
|
|
45
|
-
dispatch(addMessage('Please login to reauthenticate your account'));
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
return rejectWithValue();
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
export const fetchCustomer = createAsyncThunk(AccountActionType.FetchCustomer,
|
|
53
|
-
// eslint-disable-next-line no-unused-vars
|
|
54
|
-
(_, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
-
try {
|
|
56
|
-
const api = getState().config.api;
|
|
57
|
-
const token = selectToken(getState());
|
|
58
|
-
if (!token)
|
|
59
|
-
throw new Error(MISSING_CUSTOMER);
|
|
60
|
-
const customer = yield api.getCustomer(token);
|
|
61
|
-
const { allergens, gift_cards, favorites } = customer;
|
|
62
|
-
dispatch(setCustomerAllergens(allergens || []));
|
|
63
|
-
dispatch(setSelectedAllergens(allergens || []));
|
|
64
|
-
dispatch(setCustomerGiftCards(gift_cards || []));
|
|
65
|
-
dispatch(setCustomerFavorites(favorites || []));
|
|
66
|
-
const lookup = makeFavoritesLookup(favorites);
|
|
67
|
-
dispatch(setCustomerFavoritesLookup(lookup || {}));
|
|
68
|
-
const profile = makeCustomerProfile(customer);
|
|
69
|
-
return profile;
|
|
70
|
-
}
|
|
71
|
-
catch (err) {
|
|
72
|
-
const error = err;
|
|
73
|
-
return checkAuth(error, dispatch, () => rejectWithValue(error));
|
|
74
|
-
}
|
|
75
|
-
}));
|
|
76
|
-
export const loginCustomer = createAsyncThunk(AccountActionType.LoginCustomer, ({ email, password }, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
|
-
try {
|
|
78
|
-
const api = getState().config.api;
|
|
79
|
-
const auth = yield api.postLogin(email, password);
|
|
80
|
-
dispatch(setCustomerAuth(auth));
|
|
81
|
-
yield dispatch(fetchCustomer());
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
catch (err) {
|
|
85
|
-
return rejectWithValue(err);
|
|
86
|
-
}
|
|
87
|
-
}));
|
|
88
|
-
export const logoutCustomer = createAsyncThunk(AccountActionType.LogoutCustomer, (isReset, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
-
try {
|
|
90
|
-
const { api } = getState().config;
|
|
91
|
-
const token = selectToken(getState());
|
|
92
|
-
if (!token)
|
|
93
|
-
throw new Error(undefined);
|
|
94
|
-
if (isReset) {
|
|
95
|
-
dispatch(resetOrder());
|
|
96
|
-
dispatch(resetCheckout());
|
|
97
|
-
dispatch(setSelectedAllergens(null));
|
|
98
|
-
}
|
|
99
|
-
yield api.postLogout(token);
|
|
100
|
-
dispatch(updateCheckoutCustomer(null));
|
|
101
|
-
dispatch(resetCustomerAddresses());
|
|
102
|
-
dispatch(resetCustomerAllergens());
|
|
103
|
-
dispatch(resetCustomerCreditCards());
|
|
104
|
-
dispatch(resetCustomerFavorites());
|
|
105
|
-
dispatch(resetCustomerGiftCards());
|
|
106
|
-
dispatch(resetCustomerHouseAccounts());
|
|
107
|
-
dispatch(resetCustomerLoyalty());
|
|
108
|
-
dispatch(resetCustomerOrder());
|
|
109
|
-
dispatch(resetCustomerOrders());
|
|
110
|
-
dispatch(resetGroupOrder());
|
|
111
|
-
dispatch(resetCustomerRewards());
|
|
112
|
-
dispatch(resetCustomerCommunicationPreferences());
|
|
113
|
-
dispatch(resetGuest());
|
|
114
|
-
dispatch(resetCustomerTpls());
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
catch (err) {
|
|
118
|
-
return rejectWithValue(err);
|
|
119
|
-
}
|
|
120
|
-
}));
|
|
121
|
-
export const linkPosToken = createAsyncThunk(AccountActionType.LinkPosToken, (posToken, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
122
|
-
try {
|
|
123
|
-
const api = getState().config.api;
|
|
124
|
-
const token = selectToken(getState());
|
|
125
|
-
if (!token)
|
|
126
|
-
throw new Error(MISSING_CUSTOMER);
|
|
127
|
-
yield api.postCustomerPosToken(token, posToken);
|
|
128
|
-
dispatch(showNotification('Order successfully linked!'));
|
|
129
|
-
dispatch(fetchCustomer());
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
catch (err) {
|
|
133
|
-
const error = err;
|
|
134
|
-
dispatch(addMessage((error === null || error === void 0 ? void 0 : error.detail) || (error === null || error === void 0 ? void 0 : error.message)));
|
|
135
|
-
return rejectWithValue(error);
|
|
136
|
-
}
|
|
137
|
-
}));
|
|
138
|
-
export const updateCustomer = createAsyncThunk(AccountActionType.UpdateCustomer, ({ data, callback }, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
139
|
-
try {
|
|
140
|
-
const token = selectToken(getState());
|
|
141
|
-
const api = getState().config.api;
|
|
142
|
-
if (!token)
|
|
143
|
-
throw new Error(MISSING_CUSTOMER);
|
|
144
|
-
const customer = yield api.putCustomer(token, data);
|
|
145
|
-
const profile = makeCustomerProfile(customer);
|
|
146
|
-
dispatch(showNotification('Account updated!'));
|
|
147
|
-
if (callback)
|
|
148
|
-
callback(data);
|
|
149
|
-
return profile;
|
|
150
|
-
}
|
|
151
|
-
catch (err) {
|
|
152
|
-
const error = err;
|
|
153
|
-
return checkAuth(error, dispatch, () => rejectWithValue(error));
|
|
154
|
-
}
|
|
155
|
-
}));
|
|
156
|
-
export const sendCustomerVerificationEmail = createAsyncThunk(AccountActionType.VerifyCustomer, (linkUrl, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
157
|
-
try {
|
|
158
|
-
const api = getState().config.api;
|
|
159
|
-
const token = selectToken(getState());
|
|
160
|
-
if (!token) {
|
|
161
|
-
dispatch(addMessage('Missing customer token'));
|
|
162
|
-
throw new Error(MISSING_CUSTOMER_TOKEN);
|
|
163
|
-
}
|
|
164
|
-
yield api.postSendVerificationEmail(token, linkUrl);
|
|
165
|
-
dispatch(showNotification('Verification email sent!'));
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
catch (err) {
|
|
169
|
-
dispatch(addMessage(err.detail || err.message));
|
|
170
|
-
return rejectWithValue(err);
|
|
171
|
-
}
|
|
172
|
-
}));
|
|
173
|
-
export const loginCustomerThanx = createAsyncThunk(AccountActionType.LoginCustomerThanx, ({ email, origin }, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
174
|
-
try {
|
|
175
|
-
const api = getState().config.api;
|
|
176
|
-
yield api.postThanxLogin(email, origin);
|
|
177
|
-
dispatch(setAlert({ type: 'close' }));
|
|
178
|
-
dispatch(addMessage('Thanks! Please check your email on this device.'));
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
catch (err) {
|
|
182
|
-
const errr = err;
|
|
183
|
-
if (errr) {
|
|
184
|
-
const error = (errr === null || errr === void 0 ? void 0 : errr.params) ? errr.params['$.email'] : null;
|
|
185
|
-
if (error && error.includes("'email'")) {
|
|
186
|
-
errr.detail = 'Please enter a valid email address';
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return rejectWithValue(errr);
|
|
190
|
-
}
|
|
191
|
-
}));
|
|
192
|
-
export const authCustomerThanx = createAsyncThunk(AccountActionType.AuthCustomerThanx, (data, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
193
|
-
try {
|
|
194
|
-
const api = getState().config.api;
|
|
195
|
-
const auth = yield api.postThanxAuth(data.code, data.path, data.origin);
|
|
196
|
-
dispatch(setCustomerAuth(auth));
|
|
197
|
-
yield dispatch(fetchCustomer());
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
catch (err) {
|
|
201
|
-
return rejectWithValue(err);
|
|
202
|
-
}
|
|
203
|
-
}));
|
|
204
|
-
export const deleteCustomer = createAsyncThunk(AccountActionType.DeleteCustomer, ({ data, callback }, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
205
|
-
try {
|
|
206
|
-
const token = selectToken(getState());
|
|
207
|
-
const api = getState().config.api;
|
|
208
|
-
if (!token)
|
|
209
|
-
throw new Error(MISSING_CUSTOMER);
|
|
210
|
-
yield api.deleteCustomer(token);
|
|
211
|
-
yield api.postLogout(token);
|
|
212
|
-
dispatch(updateCheckoutCustomer(null));
|
|
213
|
-
dispatch(resetCustomerAddresses());
|
|
214
|
-
dispatch(resetCustomerAllergens());
|
|
215
|
-
dispatch(resetCustomerCreditCards());
|
|
216
|
-
dispatch(resetCustomerFavorites());
|
|
217
|
-
dispatch(resetCustomerGiftCards());
|
|
218
|
-
dispatch(resetCustomerHouseAccounts());
|
|
219
|
-
dispatch(resetCustomerLoyalty());
|
|
220
|
-
dispatch(resetCustomerOrder());
|
|
221
|
-
dispatch(resetCustomerOrders());
|
|
222
|
-
dispatch(resetGroupOrder());
|
|
223
|
-
dispatch(resetCustomerRewards());
|
|
224
|
-
dispatch(resetCustomerCommunicationPreferences());
|
|
225
|
-
dispatch(resetGuest());
|
|
226
|
-
dispatch(showNotification('Account deleted!'));
|
|
227
|
-
if (callback)
|
|
228
|
-
callback(data);
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
catch (err) {
|
|
232
|
-
const error = err;
|
|
233
|
-
return checkAuth(error, dispatch, () => rejectWithValue(error));
|
|
234
|
-
}
|
|
235
|
-
}));
|
|
236
|
-
const accountSlice = createSlice({
|
|
237
|
-
name: ReducerType.Account,
|
|
238
|
-
initialState,
|
|
239
|
-
reducers: {
|
|
240
|
-
resetCustomer: () => initialState,
|
|
241
|
-
resetLoginError: state => {
|
|
242
|
-
state.loading = 'idle';
|
|
243
|
-
state.error = null;
|
|
244
|
-
},
|
|
245
|
-
setCustomerAuth: (state, action) => {
|
|
246
|
-
state.auth = action.payload;
|
|
247
|
-
// state.loading = 'idle'
|
|
248
|
-
// state.error = null
|
|
249
|
-
}
|
|
250
|
-
},
|
|
251
|
-
extraReducers: builder => {
|
|
252
|
-
builder
|
|
253
|
-
.addCase(loginCustomer.fulfilled, state => {
|
|
254
|
-
// state.auth = action.payload
|
|
255
|
-
state.loading = 'idle';
|
|
256
|
-
state.error = null;
|
|
257
|
-
})
|
|
258
|
-
.addCase(loginCustomer.pending, state => {
|
|
259
|
-
state.loading = 'pending';
|
|
260
|
-
})
|
|
261
|
-
.addCase(loginCustomer.rejected, (state, action) => {
|
|
262
|
-
state.loading = 'idle';
|
|
263
|
-
state.error = action.payload;
|
|
264
|
-
})
|
|
265
|
-
.addCase(fetchCustomer.fulfilled, (state, action) => {
|
|
266
|
-
state.profile = action.payload;
|
|
267
|
-
state.loading = 'idle';
|
|
268
|
-
state.error = null;
|
|
269
|
-
})
|
|
270
|
-
.addCase(fetchCustomer.pending, state => {
|
|
271
|
-
state.loading = 'pending';
|
|
272
|
-
})
|
|
273
|
-
.addCase(fetchCustomer.rejected, (state, action) => {
|
|
274
|
-
state.loading = 'idle';
|
|
275
|
-
state.error = action.payload;
|
|
276
|
-
})
|
|
277
|
-
.addCase(updateCustomer.fulfilled, (state, action) => {
|
|
278
|
-
state.profile = action.payload;
|
|
279
|
-
state.loading = 'idle';
|
|
280
|
-
state.error = null;
|
|
281
|
-
})
|
|
282
|
-
.addCase(updateCustomer.pending, state => {
|
|
283
|
-
state.loading = 'pending';
|
|
284
|
-
})
|
|
285
|
-
.addCase(updateCustomer.rejected, (state, action) => {
|
|
286
|
-
state.loading = 'idle';
|
|
287
|
-
state.error = action.payload;
|
|
288
|
-
})
|
|
289
|
-
.addCase(logoutCustomer.fulfilled, () => initialState)
|
|
290
|
-
.addCase(logoutCustomer.pending, state => {
|
|
291
|
-
state.loading = 'pending';
|
|
292
|
-
})
|
|
293
|
-
.addCase(logoutCustomer.rejected, () => initialState)
|
|
294
|
-
.addCase(sendCustomerVerificationEmail.fulfilled, state => {
|
|
295
|
-
state.loading = 'idle';
|
|
296
|
-
})
|
|
297
|
-
.addCase(sendCustomerVerificationEmail.pending, state => {
|
|
298
|
-
state.loading = 'pending';
|
|
299
|
-
})
|
|
300
|
-
.addCase(sendCustomerVerificationEmail.rejected, state => {
|
|
301
|
-
state.loading = 'idle';
|
|
302
|
-
})
|
|
303
|
-
.addCase(linkPosToken.fulfilled, () => {
|
|
304
|
-
//do nothing
|
|
305
|
-
})
|
|
306
|
-
.addCase(linkPosToken.pending, () => {
|
|
307
|
-
//do nothing
|
|
308
|
-
})
|
|
309
|
-
.addCase(linkPosToken.rejected, () => {
|
|
310
|
-
//do nothing
|
|
311
|
-
})
|
|
312
|
-
.addCase(deleteCustomer.fulfilled, () => initialState)
|
|
313
|
-
.addCase(deleteCustomer.pending, state => {
|
|
314
|
-
state.loading = 'pending';
|
|
315
|
-
})
|
|
316
|
-
.addCase(deleteCustomer.rejected, () => initialState)
|
|
317
|
-
.addCase(loginCustomerThanx.fulfilled, state => {
|
|
318
|
-
state.loading = 'idle';
|
|
319
|
-
state.error = null;
|
|
320
|
-
})
|
|
321
|
-
.addCase(loginCustomerThanx.pending, state => {
|
|
322
|
-
state.loading = 'pending';
|
|
323
|
-
})
|
|
324
|
-
.addCase(loginCustomerThanx.rejected, (state, action) => {
|
|
325
|
-
state.loading = 'idle';
|
|
326
|
-
state.error = action.payload;
|
|
327
|
-
})
|
|
328
|
-
.addCase(authCustomerThanx.fulfilled, state => {
|
|
329
|
-
state.loading = 'idle';
|
|
330
|
-
state.error = null;
|
|
331
|
-
})
|
|
332
|
-
.addCase(authCustomerThanx.pending, state => {
|
|
333
|
-
state.loading = 'pending';
|
|
334
|
-
})
|
|
335
|
-
.addCase(authCustomerThanx.rejected, (state, action) => {
|
|
336
|
-
state.loading = 'idle';
|
|
337
|
-
state.error = action.payload;
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
});
|
|
341
|
-
export const { resetCustomer, resetLoginError, setCustomerAuth } = accountSlice.actions;
|
|
342
|
-
export const selectToken = (state) => state.customer.account.auth ? state.customer.account.auth.access_token : null;
|
|
343
|
-
export const selectCustomer = (state) => state.customer.account;
|
|
344
|
-
export const accountReducer = accountSlice.reducer;
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
|
|
3
|
+
import { ReducerType } from '../types';
|
|
4
|
+
import { MISSING_CUSTOMER, MISSING_CUSTOMER_TOKEN } from '@open-tender/types';
|
|
5
|
+
import { makeCustomerProfile, makeFavoritesLookup } from '@open-tender/utils';
|
|
6
|
+
import { showNotification } from '../notifications';
|
|
7
|
+
import { resetCustomerAllergens, setCustomerAllergens } from './allergens';
|
|
8
|
+
import { setSelectedAllergens } from '../allergens';
|
|
9
|
+
import { resetCustomerFavorites, setCustomerFavorites, setCustomerFavoritesLookup } from './favorites';
|
|
10
|
+
import { resetCustomerCreditCards } from './creditCards';
|
|
11
|
+
import { resetCustomerAddresses } from './addresses';
|
|
12
|
+
import { resetCustomerHouseAccounts } from './houseAccounts';
|
|
13
|
+
import { resetCustomerLoyalty } from './loyalty';
|
|
14
|
+
import { resetCustomerOrder } from './order';
|
|
15
|
+
import { resetCustomerOrders } from './orders';
|
|
16
|
+
import { resetCustomerRewards } from './rewards';
|
|
17
|
+
import { resetCustomerCommunicationPreferences } from './communicationPreferences';
|
|
18
|
+
import { resetCustomerGiftCards, setCustomerGiftCards } from './giftCards';
|
|
19
|
+
import { addMessage, resetOrder, setAlert } from '../order';
|
|
20
|
+
import { resetCheckout, updateCheckoutCustomer } from '../checkout';
|
|
21
|
+
import { resetGroupOrder } from '../groupOrder';
|
|
22
|
+
import { resetGuest } from '../guest';
|
|
23
|
+
import { resetCustomerTpls } from './tpls';
|
|
24
|
+
const initialState = {
|
|
25
|
+
auth: null,
|
|
26
|
+
profile: null,
|
|
27
|
+
loading: 'idle',
|
|
28
|
+
error: null
|
|
29
|
+
};
|
|
30
|
+
export var AccountActionType;
|
|
31
|
+
(function (AccountActionType) {
|
|
32
|
+
AccountActionType["LoginCustomer"] = "customer/loginCustomer";
|
|
33
|
+
AccountActionType["LogoutCustomer"] = "customer/logoutCustomer";
|
|
34
|
+
AccountActionType["FetchCustomer"] = "customer/fetchCustomer";
|
|
35
|
+
AccountActionType["UpdateCustomer"] = "customer/updateCustomer";
|
|
36
|
+
AccountActionType["VerifyCustomer"] = "customer/verifyCustomer";
|
|
37
|
+
AccountActionType["LinkPosToken"] = "customer/linkPosToken";
|
|
38
|
+
AccountActionType["DeleteCustomer"] = "customer/deleteCustomer";
|
|
39
|
+
AccountActionType["LoginCustomerThanx"] = "customer/loginCustomerThanx";
|
|
40
|
+
AccountActionType["AuthCustomerThanx"] = "customer/authCustomerThanx";
|
|
41
|
+
})(AccountActionType || (AccountActionType = {}));
|
|
42
|
+
export const checkAuth = (err, dispatch, rejectWithValue) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
if ((err === null || err === void 0 ? void 0 : err.status) === 401) {
|
|
44
|
+
yield dispatch(logoutCustomer());
|
|
45
|
+
dispatch(addMessage('Please login to reauthenticate your account'));
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return rejectWithValue();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
export const fetchCustomer = createAsyncThunk(AccountActionType.FetchCustomer,
|
|
53
|
+
// eslint-disable-next-line no-unused-vars
|
|
54
|
+
(_, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
try {
|
|
56
|
+
const api = getState().config.api;
|
|
57
|
+
const token = selectToken(getState());
|
|
58
|
+
if (!token)
|
|
59
|
+
throw new Error(MISSING_CUSTOMER);
|
|
60
|
+
const customer = yield api.getCustomer(token);
|
|
61
|
+
const { allergens, gift_cards, favorites } = customer;
|
|
62
|
+
dispatch(setCustomerAllergens(allergens || []));
|
|
63
|
+
dispatch(setSelectedAllergens(allergens || []));
|
|
64
|
+
dispatch(setCustomerGiftCards(gift_cards || []));
|
|
65
|
+
dispatch(setCustomerFavorites(favorites || []));
|
|
66
|
+
const lookup = makeFavoritesLookup(favorites);
|
|
67
|
+
dispatch(setCustomerFavoritesLookup(lookup || {}));
|
|
68
|
+
const profile = makeCustomerProfile(customer);
|
|
69
|
+
return profile;
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
const error = err;
|
|
73
|
+
return checkAuth(error, dispatch, () => rejectWithValue(error));
|
|
74
|
+
}
|
|
75
|
+
}));
|
|
76
|
+
export const loginCustomer = createAsyncThunk(AccountActionType.LoginCustomer, ({ email, password }, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
|
+
try {
|
|
78
|
+
const api = getState().config.api;
|
|
79
|
+
const auth = yield api.postLogin(email, password);
|
|
80
|
+
dispatch(setCustomerAuth(auth));
|
|
81
|
+
yield dispatch(fetchCustomer());
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
return rejectWithValue(err);
|
|
86
|
+
}
|
|
87
|
+
}));
|
|
88
|
+
export const logoutCustomer = createAsyncThunk(AccountActionType.LogoutCustomer, (isReset, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
+
try {
|
|
90
|
+
const { api } = getState().config;
|
|
91
|
+
const token = selectToken(getState());
|
|
92
|
+
if (!token)
|
|
93
|
+
throw new Error(undefined);
|
|
94
|
+
if (isReset) {
|
|
95
|
+
dispatch(resetOrder());
|
|
96
|
+
dispatch(resetCheckout());
|
|
97
|
+
dispatch(setSelectedAllergens(null));
|
|
98
|
+
}
|
|
99
|
+
yield api.postLogout(token);
|
|
100
|
+
dispatch(updateCheckoutCustomer(null));
|
|
101
|
+
dispatch(resetCustomerAddresses());
|
|
102
|
+
dispatch(resetCustomerAllergens());
|
|
103
|
+
dispatch(resetCustomerCreditCards());
|
|
104
|
+
dispatch(resetCustomerFavorites());
|
|
105
|
+
dispatch(resetCustomerGiftCards());
|
|
106
|
+
dispatch(resetCustomerHouseAccounts());
|
|
107
|
+
dispatch(resetCustomerLoyalty());
|
|
108
|
+
dispatch(resetCustomerOrder());
|
|
109
|
+
dispatch(resetCustomerOrders());
|
|
110
|
+
dispatch(resetGroupOrder());
|
|
111
|
+
dispatch(resetCustomerRewards());
|
|
112
|
+
dispatch(resetCustomerCommunicationPreferences());
|
|
113
|
+
dispatch(resetGuest());
|
|
114
|
+
dispatch(resetCustomerTpls());
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
catch (err) {
|
|
118
|
+
return rejectWithValue(err);
|
|
119
|
+
}
|
|
120
|
+
}));
|
|
121
|
+
export const linkPosToken = createAsyncThunk(AccountActionType.LinkPosToken, (posToken, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
122
|
+
try {
|
|
123
|
+
const api = getState().config.api;
|
|
124
|
+
const token = selectToken(getState());
|
|
125
|
+
if (!token)
|
|
126
|
+
throw new Error(MISSING_CUSTOMER);
|
|
127
|
+
yield api.postCustomerPosToken(token, posToken);
|
|
128
|
+
dispatch(showNotification('Order successfully linked!'));
|
|
129
|
+
dispatch(fetchCustomer());
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
catch (err) {
|
|
133
|
+
const error = err;
|
|
134
|
+
dispatch(addMessage((error === null || error === void 0 ? void 0 : error.detail) || (error === null || error === void 0 ? void 0 : error.message)));
|
|
135
|
+
return rejectWithValue(error);
|
|
136
|
+
}
|
|
137
|
+
}));
|
|
138
|
+
export const updateCustomer = createAsyncThunk(AccountActionType.UpdateCustomer, ({ data, callback }, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
139
|
+
try {
|
|
140
|
+
const token = selectToken(getState());
|
|
141
|
+
const api = getState().config.api;
|
|
142
|
+
if (!token)
|
|
143
|
+
throw new Error(MISSING_CUSTOMER);
|
|
144
|
+
const customer = yield api.putCustomer(token, data);
|
|
145
|
+
const profile = makeCustomerProfile(customer);
|
|
146
|
+
dispatch(showNotification('Account updated!'));
|
|
147
|
+
if (callback)
|
|
148
|
+
callback(data);
|
|
149
|
+
return profile;
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
152
|
+
const error = err;
|
|
153
|
+
return checkAuth(error, dispatch, () => rejectWithValue(error));
|
|
154
|
+
}
|
|
155
|
+
}));
|
|
156
|
+
export const sendCustomerVerificationEmail = createAsyncThunk(AccountActionType.VerifyCustomer, (linkUrl, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
157
|
+
try {
|
|
158
|
+
const api = getState().config.api;
|
|
159
|
+
const token = selectToken(getState());
|
|
160
|
+
if (!token) {
|
|
161
|
+
dispatch(addMessage('Missing customer token'));
|
|
162
|
+
throw new Error(MISSING_CUSTOMER_TOKEN);
|
|
163
|
+
}
|
|
164
|
+
yield api.postSendVerificationEmail(token, linkUrl);
|
|
165
|
+
dispatch(showNotification('Verification email sent!'));
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
catch (err) {
|
|
169
|
+
dispatch(addMessage(err.detail || err.message));
|
|
170
|
+
return rejectWithValue(err);
|
|
171
|
+
}
|
|
172
|
+
}));
|
|
173
|
+
export const loginCustomerThanx = createAsyncThunk(AccountActionType.LoginCustomerThanx, ({ email, origin }, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
174
|
+
try {
|
|
175
|
+
const api = getState().config.api;
|
|
176
|
+
yield api.postThanxLogin(email, origin);
|
|
177
|
+
dispatch(setAlert({ type: 'close' }));
|
|
178
|
+
dispatch(addMessage('Thanks! Please check your email on this device.'));
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
catch (err) {
|
|
182
|
+
const errr = err;
|
|
183
|
+
if (errr) {
|
|
184
|
+
const error = (errr === null || errr === void 0 ? void 0 : errr.params) ? errr.params['$.email'] : null;
|
|
185
|
+
if (error && error.includes("'email'")) {
|
|
186
|
+
errr.detail = 'Please enter a valid email address';
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return rejectWithValue(errr);
|
|
190
|
+
}
|
|
191
|
+
}));
|
|
192
|
+
export const authCustomerThanx = createAsyncThunk(AccountActionType.AuthCustomerThanx, (data, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
193
|
+
try {
|
|
194
|
+
const api = getState().config.api;
|
|
195
|
+
const auth = yield api.postThanxAuth(data.code, data.path, data.origin);
|
|
196
|
+
dispatch(setCustomerAuth(auth));
|
|
197
|
+
yield dispatch(fetchCustomer());
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
catch (err) {
|
|
201
|
+
return rejectWithValue(err);
|
|
202
|
+
}
|
|
203
|
+
}));
|
|
204
|
+
export const deleteCustomer = createAsyncThunk(AccountActionType.DeleteCustomer, ({ data, callback }, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
205
|
+
try {
|
|
206
|
+
const token = selectToken(getState());
|
|
207
|
+
const api = getState().config.api;
|
|
208
|
+
if (!token)
|
|
209
|
+
throw new Error(MISSING_CUSTOMER);
|
|
210
|
+
yield api.deleteCustomer(token);
|
|
211
|
+
yield api.postLogout(token);
|
|
212
|
+
dispatch(updateCheckoutCustomer(null));
|
|
213
|
+
dispatch(resetCustomerAddresses());
|
|
214
|
+
dispatch(resetCustomerAllergens());
|
|
215
|
+
dispatch(resetCustomerCreditCards());
|
|
216
|
+
dispatch(resetCustomerFavorites());
|
|
217
|
+
dispatch(resetCustomerGiftCards());
|
|
218
|
+
dispatch(resetCustomerHouseAccounts());
|
|
219
|
+
dispatch(resetCustomerLoyalty());
|
|
220
|
+
dispatch(resetCustomerOrder());
|
|
221
|
+
dispatch(resetCustomerOrders());
|
|
222
|
+
dispatch(resetGroupOrder());
|
|
223
|
+
dispatch(resetCustomerRewards());
|
|
224
|
+
dispatch(resetCustomerCommunicationPreferences());
|
|
225
|
+
dispatch(resetGuest());
|
|
226
|
+
dispatch(showNotification('Account deleted!'));
|
|
227
|
+
if (callback)
|
|
228
|
+
callback(data);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
catch (err) {
|
|
232
|
+
const error = err;
|
|
233
|
+
return checkAuth(error, dispatch, () => rejectWithValue(error));
|
|
234
|
+
}
|
|
235
|
+
}));
|
|
236
|
+
const accountSlice = createSlice({
|
|
237
|
+
name: ReducerType.Account,
|
|
238
|
+
initialState,
|
|
239
|
+
reducers: {
|
|
240
|
+
resetCustomer: () => initialState,
|
|
241
|
+
resetLoginError: state => {
|
|
242
|
+
state.loading = 'idle';
|
|
243
|
+
state.error = null;
|
|
244
|
+
},
|
|
245
|
+
setCustomerAuth: (state, action) => {
|
|
246
|
+
state.auth = action.payload;
|
|
247
|
+
// state.loading = 'idle'
|
|
248
|
+
// state.error = null
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
extraReducers: builder => {
|
|
252
|
+
builder
|
|
253
|
+
.addCase(loginCustomer.fulfilled, state => {
|
|
254
|
+
// state.auth = action.payload
|
|
255
|
+
state.loading = 'idle';
|
|
256
|
+
state.error = null;
|
|
257
|
+
})
|
|
258
|
+
.addCase(loginCustomer.pending, state => {
|
|
259
|
+
state.loading = 'pending';
|
|
260
|
+
})
|
|
261
|
+
.addCase(loginCustomer.rejected, (state, action) => {
|
|
262
|
+
state.loading = 'idle';
|
|
263
|
+
state.error = action.payload;
|
|
264
|
+
})
|
|
265
|
+
.addCase(fetchCustomer.fulfilled, (state, action) => {
|
|
266
|
+
state.profile = action.payload;
|
|
267
|
+
state.loading = 'idle';
|
|
268
|
+
state.error = null;
|
|
269
|
+
})
|
|
270
|
+
.addCase(fetchCustomer.pending, state => {
|
|
271
|
+
state.loading = 'pending';
|
|
272
|
+
})
|
|
273
|
+
.addCase(fetchCustomer.rejected, (state, action) => {
|
|
274
|
+
state.loading = 'idle';
|
|
275
|
+
state.error = action.payload;
|
|
276
|
+
})
|
|
277
|
+
.addCase(updateCustomer.fulfilled, (state, action) => {
|
|
278
|
+
state.profile = action.payload;
|
|
279
|
+
state.loading = 'idle';
|
|
280
|
+
state.error = null;
|
|
281
|
+
})
|
|
282
|
+
.addCase(updateCustomer.pending, state => {
|
|
283
|
+
state.loading = 'pending';
|
|
284
|
+
})
|
|
285
|
+
.addCase(updateCustomer.rejected, (state, action) => {
|
|
286
|
+
state.loading = 'idle';
|
|
287
|
+
state.error = action.payload;
|
|
288
|
+
})
|
|
289
|
+
.addCase(logoutCustomer.fulfilled, () => initialState)
|
|
290
|
+
.addCase(logoutCustomer.pending, state => {
|
|
291
|
+
state.loading = 'pending';
|
|
292
|
+
})
|
|
293
|
+
.addCase(logoutCustomer.rejected, () => initialState)
|
|
294
|
+
.addCase(sendCustomerVerificationEmail.fulfilled, state => {
|
|
295
|
+
state.loading = 'idle';
|
|
296
|
+
})
|
|
297
|
+
.addCase(sendCustomerVerificationEmail.pending, state => {
|
|
298
|
+
state.loading = 'pending';
|
|
299
|
+
})
|
|
300
|
+
.addCase(sendCustomerVerificationEmail.rejected, state => {
|
|
301
|
+
state.loading = 'idle';
|
|
302
|
+
})
|
|
303
|
+
.addCase(linkPosToken.fulfilled, () => {
|
|
304
|
+
//do nothing
|
|
305
|
+
})
|
|
306
|
+
.addCase(linkPosToken.pending, () => {
|
|
307
|
+
//do nothing
|
|
308
|
+
})
|
|
309
|
+
.addCase(linkPosToken.rejected, () => {
|
|
310
|
+
//do nothing
|
|
311
|
+
})
|
|
312
|
+
.addCase(deleteCustomer.fulfilled, () => initialState)
|
|
313
|
+
.addCase(deleteCustomer.pending, state => {
|
|
314
|
+
state.loading = 'pending';
|
|
315
|
+
})
|
|
316
|
+
.addCase(deleteCustomer.rejected, () => initialState)
|
|
317
|
+
.addCase(loginCustomerThanx.fulfilled, state => {
|
|
318
|
+
state.loading = 'idle';
|
|
319
|
+
state.error = null;
|
|
320
|
+
})
|
|
321
|
+
.addCase(loginCustomerThanx.pending, state => {
|
|
322
|
+
state.loading = 'pending';
|
|
323
|
+
})
|
|
324
|
+
.addCase(loginCustomerThanx.rejected, (state, action) => {
|
|
325
|
+
state.loading = 'idle';
|
|
326
|
+
state.error = action.payload;
|
|
327
|
+
})
|
|
328
|
+
.addCase(authCustomerThanx.fulfilled, state => {
|
|
329
|
+
state.loading = 'idle';
|
|
330
|
+
state.error = null;
|
|
331
|
+
})
|
|
332
|
+
.addCase(authCustomerThanx.pending, state => {
|
|
333
|
+
state.loading = 'pending';
|
|
334
|
+
})
|
|
335
|
+
.addCase(authCustomerThanx.rejected, (state, action) => {
|
|
336
|
+
state.loading = 'idle';
|
|
337
|
+
state.error = action.payload;
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
export const { resetCustomer, resetLoginError, setCustomerAuth } = accountSlice.actions;
|
|
342
|
+
export const selectToken = (state) => state.customer.account.auth ? state.customer.account.auth.access_token : null;
|
|
343
|
+
export const selectCustomer = (state) => state.customer.account;
|
|
344
|
+
export const accountReducer = accountSlice.reducer;
|