@open-tender/cloud 0.0.27 → 0.0.29
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/dist/cjs/slices/customer/account.d.ts +9 -1
- package/dist/cjs/slices/customer/account.js +41 -2
- package/dist/cjs/slices/customer/groupOrders.d.ts +9 -1
- package/dist/cjs/slices/customer/groupOrders.js +36 -1
- package/dist/esm/slices/customer/account.d.ts +9 -1
- package/dist/esm/slices/customer/account.js +40 -1
- package/dist/esm/slices/customer/groupOrders.d.ts +9 -1
- package/dist/esm/slices/customer/groupOrders.js +36 -1
- package/package.json +1 -1
|
@@ -13,7 +13,8 @@ export declare enum AccountActionType {
|
|
|
13
13
|
FetchCustomer = "customer/fetchCustomer",
|
|
14
14
|
UpdateCustomer = "customer/updateCustomer",
|
|
15
15
|
VerifyCustomer = "customer/verifyCustomer",
|
|
16
|
-
LinkPosToken = "customer/linkPosToken"
|
|
16
|
+
LinkPosToken = "customer/linkPosToken",
|
|
17
|
+
DeleteCustomer = "customer/deleteCustomer"
|
|
17
18
|
}
|
|
18
19
|
export declare const checkAuth: (err: RequestError, dispatch: ThunkDispatch<AppState, unknown, AnyAction>, rejectWithValue: () => any) => Promise<any>;
|
|
19
20
|
export declare const fetchCustomer: import("@reduxjs/toolkit").AsyncThunk<Partial<Profile>, void, {
|
|
@@ -54,6 +55,13 @@ export declare const authCustomerThanx: import("@reduxjs/toolkit").AsyncThunk<Au
|
|
|
54
55
|
state: AppState;
|
|
55
56
|
rejectValue: RequestError;
|
|
56
57
|
}>;
|
|
58
|
+
export declare const deleteCustomer: import("@reduxjs/toolkit").AsyncThunk<void, {
|
|
59
|
+
data: Partial<Profile>;
|
|
60
|
+
callback?: ((data: Partial<Profile>) => void) | undefined;
|
|
61
|
+
}, {
|
|
62
|
+
state: AppState;
|
|
63
|
+
rejectValue: RequestError;
|
|
64
|
+
}>;
|
|
57
65
|
export declare const resetCustomer: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>, resetLoginError: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>, fulfillLoginCustomer: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>;
|
|
58
66
|
export declare const selectToken: (state: AppState) => string | null;
|
|
59
67
|
export declare const selectCustomer: (state: AppState) => AccountState;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.accountReducer = exports.selectCustomer = exports.selectToken = exports.fulfillLoginCustomer = exports.resetLoginError = exports.resetCustomer = exports.authCustomerThanx = exports.loginCustomerThanx = exports.sendCustomerVerificationEmail = exports.updateCustomer = exports.linkPosToken = exports.logoutCustomer = exports.loginCustomer = exports.fetchCustomer = exports.checkAuth = exports.AccountActionType = void 0;
|
|
4
|
+
exports.accountReducer = exports.selectCustomer = exports.selectToken = exports.fulfillLoginCustomer = exports.resetLoginError = exports.resetCustomer = exports.deleteCustomer = exports.authCustomerThanx = exports.loginCustomerThanx = exports.sendCustomerVerificationEmail = exports.updateCustomer = exports.linkPosToken = exports.logoutCustomer = exports.loginCustomer = exports.fetchCustomer = exports.checkAuth = exports.AccountActionType = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const toolkit_1 = require("@reduxjs/toolkit");
|
|
7
7
|
const types_1 = require("../types");
|
|
@@ -39,6 +39,7 @@ var AccountActionType;
|
|
|
39
39
|
AccountActionType["UpdateCustomer"] = "customer/updateCustomer";
|
|
40
40
|
AccountActionType["VerifyCustomer"] = "customer/verifyCustomer";
|
|
41
41
|
AccountActionType["LinkPosToken"] = "customer/linkPosToken";
|
|
42
|
+
AccountActionType["DeleteCustomer"] = "customer/deleteCustomer";
|
|
42
43
|
})(AccountActionType = exports.AccountActionType || (exports.AccountActionType = {}));
|
|
43
44
|
const checkAuth = (err, dispatch, rejectWithValue) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
44
45
|
if ((err === null || err === void 0 ? void 0 : err.status) === 401) {
|
|
@@ -204,6 +205,39 @@ exports.authCustomerThanx = (0, toolkit_1.createAsyncThunk)(AccountActionType.Lo
|
|
|
204
205
|
return rejectWithValue(err);
|
|
205
206
|
}
|
|
206
207
|
}));
|
|
208
|
+
exports.deleteCustomer = (0, toolkit_1.createAsyncThunk)(AccountActionType.DeleteCustomer, (requestData, { dispatch, getState, rejectWithValue }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
209
|
+
try {
|
|
210
|
+
const token = (0, exports.selectToken)(getState());
|
|
211
|
+
const api = getState().config.api;
|
|
212
|
+
if (!token)
|
|
213
|
+
throw new Error(types_2.MISSING_CUSTOMER);
|
|
214
|
+
yield api.deleteCustomer(token);
|
|
215
|
+
yield api.postLogout(token);
|
|
216
|
+
dispatch((0, checkout_1.updateCheckoutCustomer)(null));
|
|
217
|
+
dispatch((0, addresses_1.resetCustomerAddresses)());
|
|
218
|
+
dispatch((0, allergens_1.resetCustomerAllergens)());
|
|
219
|
+
dispatch((0, creditCards_1.resetCustomerCreditCards)());
|
|
220
|
+
dispatch((0, favorites_1.resetCustomerFavorites)());
|
|
221
|
+
dispatch((0, levelup_1.resetCustomerLevelUp)());
|
|
222
|
+
dispatch((0, giftCards_1.resetCustomerGiftCards)());
|
|
223
|
+
dispatch((0, houseAccounts_1.resetCustomerHouseAccounts)());
|
|
224
|
+
dispatch((0, loyalty_1.resetCustomerLoyalty)());
|
|
225
|
+
dispatch((0, order_1.resetCustomerOrder)());
|
|
226
|
+
dispatch((0, orders_1.resetCustomerOrders)());
|
|
227
|
+
dispatch((0, groupOrder_1.resetGroupOrder)());
|
|
228
|
+
dispatch((0, rewards_1.resetCustomerRewards)());
|
|
229
|
+
dispatch((0, communicationPreferences_1.resetCustomerCommunicationPreferences)());
|
|
230
|
+
dispatch((0, guest_1.resetGuest)());
|
|
231
|
+
dispatch((0, notifications_1.showNotification)('Account deleted!'));
|
|
232
|
+
if (requestData.callback)
|
|
233
|
+
requestData.callback(requestData.data);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
catch (err) {
|
|
237
|
+
const error = err;
|
|
238
|
+
return (0, exports.checkAuth)(error, dispatch, () => rejectWithValue(error));
|
|
239
|
+
}
|
|
240
|
+
}));
|
|
207
241
|
const accountSlice = (0, toolkit_1.createSlice)({
|
|
208
242
|
name: types_1.ReducerType.Account,
|
|
209
243
|
initialState,
|
|
@@ -279,7 +313,12 @@ const accountSlice = (0, toolkit_1.createSlice)({
|
|
|
279
313
|
})
|
|
280
314
|
.addCase(exports.linkPosToken.rejected, () => {
|
|
281
315
|
//do nothing
|
|
282
|
-
})
|
|
316
|
+
})
|
|
317
|
+
.addCase(exports.deleteCustomer.fulfilled, () => initialState)
|
|
318
|
+
.addCase(exports.deleteCustomer.pending, (state) => {
|
|
319
|
+
state.loading = 'pending';
|
|
320
|
+
})
|
|
321
|
+
.addCase(exports.deleteCustomer.rejected, () => initialState);
|
|
283
322
|
}
|
|
284
323
|
});
|
|
285
324
|
_a = accountSlice.actions, exports.resetCustomer = _a.resetCustomer, exports.resetLoginError = _a.resetLoginError, exports.fulfillLoginCustomer = _a.fulfillLoginCustomer;
|
|
@@ -11,7 +11,8 @@ export interface CustomerGroupOrdersState {
|
|
|
11
11
|
export declare enum CustomerGroupOrdersActionType {
|
|
12
12
|
FetchCustomerGroupOrders = "customer/fetchCustomerGroupOrders",
|
|
13
13
|
FetchCustomerGroupOrder = "customer/fetchCustomerGroupOrder",
|
|
14
|
-
AddCustomerGroupOrder = "customer/addCustomerGroupOrder"
|
|
14
|
+
AddCustomerGroupOrder = "customer/addCustomerGroupOrder",
|
|
15
|
+
RemoveCustomerGroupOrder = "customer/removeCustomerGroupOrder"
|
|
15
16
|
}
|
|
16
17
|
export declare const fetchCustomerGroupOrders: import("@reduxjs/toolkit").AsyncThunk<GroupOrders, void, {
|
|
17
18
|
state: AppState;
|
|
@@ -28,6 +29,13 @@ export declare const addCustomerGroupOrder: import("@reduxjs/toolkit").AsyncThun
|
|
|
28
29
|
state: AppState;
|
|
29
30
|
rejectValue: RequestError;
|
|
30
31
|
}>;
|
|
32
|
+
export declare const removeCustomerGroupOrder: import("@reduxjs/toolkit").AsyncThunk<GroupOrders, {
|
|
33
|
+
cartId: number;
|
|
34
|
+
callback?: (() => void) | undefined;
|
|
35
|
+
}, {
|
|
36
|
+
state: AppState;
|
|
37
|
+
rejectValue: RequestError;
|
|
38
|
+
}>;
|
|
31
39
|
export declare const resetCustomerGroupOrders: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>, resetCustomerGroupOrdersError: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>, setCustomerGroupOrders: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>;
|
|
32
40
|
export declare const selectCustomerGroupOrders: (state: AppState) => CustomerGroupOrdersState;
|
|
33
41
|
export declare const customerGroupOrdersReducer: import("redux").Reducer<CustomerGroupOrdersState, import("redux").AnyAction>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.customerGroupOrdersReducer = exports.selectCustomerGroupOrders = exports.setCustomerGroupOrders = exports.resetCustomerGroupOrdersError = exports.resetCustomerGroupOrders = exports.addCustomerGroupOrder = exports.fetchCustomerGroupOrder = exports.fetchCustomerGroupOrders = exports.CustomerGroupOrdersActionType = void 0;
|
|
4
|
+
exports.customerGroupOrdersReducer = exports.selectCustomerGroupOrders = exports.setCustomerGroupOrders = exports.resetCustomerGroupOrdersError = exports.resetCustomerGroupOrders = exports.removeCustomerGroupOrder = exports.addCustomerGroupOrder = exports.fetchCustomerGroupOrder = exports.fetchCustomerGroupOrders = exports.CustomerGroupOrdersActionType = void 0;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const toolkit_1 = require("@reduxjs/toolkit");
|
|
7
7
|
const types_1 = require("../types");
|
|
@@ -9,6 +9,7 @@ const types_2 = require("@open-tender/types");
|
|
|
9
9
|
const account_1 = require("./account");
|
|
10
10
|
const groupOrder_1 = require("../groupOrder");
|
|
11
11
|
const utils_1 = require("@open-tender/utils");
|
|
12
|
+
const notifications_1 = require("../notifications");
|
|
12
13
|
const initialState = {
|
|
13
14
|
entities: [],
|
|
14
15
|
lookup: {},
|
|
@@ -20,6 +21,7 @@ var CustomerGroupOrdersActionType;
|
|
|
20
21
|
CustomerGroupOrdersActionType["FetchCustomerGroupOrders"] = "customer/fetchCustomerGroupOrders";
|
|
21
22
|
CustomerGroupOrdersActionType["FetchCustomerGroupOrder"] = "customer/fetchCustomerGroupOrder";
|
|
22
23
|
CustomerGroupOrdersActionType["AddCustomerGroupOrder"] = "customer/addCustomerGroupOrder";
|
|
24
|
+
CustomerGroupOrdersActionType["RemoveCustomerGroupOrder"] = "customer/removeCustomerGroupOrder";
|
|
23
25
|
})(CustomerGroupOrdersActionType = exports.CustomerGroupOrdersActionType || (exports.CustomerGroupOrdersActionType = {}));
|
|
24
26
|
exports.fetchCustomerGroupOrders = (0, toolkit_1.createAsyncThunk)(CustomerGroupOrdersActionType.FetchCustomerGroupOrders, (_, { dispatch, getState, rejectWithValue }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
25
27
|
try {
|
|
@@ -88,6 +90,27 @@ exports.addCustomerGroupOrder = (0, toolkit_1.createAsyncThunk)(CustomerGroupOrd
|
|
|
88
90
|
return (0, account_1.checkAuth)(error, dispatch, () => rejectWithValue(error));
|
|
89
91
|
}
|
|
90
92
|
}));
|
|
93
|
+
exports.removeCustomerGroupOrder = (0, toolkit_1.createAsyncThunk)(CustomerGroupOrdersActionType.RemoveCustomerGroupOrder, (requestData, { dispatch, getState, rejectWithValue }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
94
|
+
try {
|
|
95
|
+
const api = getState().config.api;
|
|
96
|
+
const token = (0, account_1.selectToken)(getState());
|
|
97
|
+
if (!token)
|
|
98
|
+
throw new Error(types_2.MISSING_CUSTOMER);
|
|
99
|
+
yield api.deleteCustomerGroupOrder(token, requestData.cartId);
|
|
100
|
+
dispatch((0, groupOrder_1.resetGroupOrder)());
|
|
101
|
+
const orders = yield api.getCustomerGroupOrders(token);
|
|
102
|
+
dispatch((0, notifications_1.showNotification)('Group order deleted!'));
|
|
103
|
+
if (requestData.callback)
|
|
104
|
+
requestData.callback();
|
|
105
|
+
return orders;
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
dispatch((0, groupOrder_1.resetGroupOrder)());
|
|
109
|
+
dispatch((0, notifications_1.showNotification)('Group order deleted!'));
|
|
110
|
+
const error = err;
|
|
111
|
+
return (0, account_1.checkAuth)(error, dispatch, () => rejectWithValue(error));
|
|
112
|
+
}
|
|
113
|
+
}));
|
|
91
114
|
const customerGroupOrdersSlice = (0, toolkit_1.createSlice)({
|
|
92
115
|
name: types_1.ReducerType.GroupOrders,
|
|
93
116
|
initialState,
|
|
@@ -139,6 +162,18 @@ const customerGroupOrdersSlice = (0, toolkit_1.createSlice)({
|
|
|
139
162
|
.addCase(exports.addCustomerGroupOrder.rejected, (state, action) => {
|
|
140
163
|
state.error = action.payload;
|
|
141
164
|
state.loading = 'idle';
|
|
165
|
+
})
|
|
166
|
+
.addCase(exports.removeCustomerGroupOrder.fulfilled, (state, action) => {
|
|
167
|
+
state.entities = action.payload;
|
|
168
|
+
state.loading = 'idle';
|
|
169
|
+
state.error = null;
|
|
170
|
+
})
|
|
171
|
+
.addCase(exports.removeCustomerGroupOrder.pending, state => {
|
|
172
|
+
state.loading = 'pending';
|
|
173
|
+
})
|
|
174
|
+
.addCase(exports.removeCustomerGroupOrder.rejected, (state, action) => {
|
|
175
|
+
state.error = action.payload;
|
|
176
|
+
state.loading = 'idle';
|
|
142
177
|
});
|
|
143
178
|
}
|
|
144
179
|
});
|
|
@@ -13,7 +13,8 @@ export declare enum AccountActionType {
|
|
|
13
13
|
FetchCustomer = "customer/fetchCustomer",
|
|
14
14
|
UpdateCustomer = "customer/updateCustomer",
|
|
15
15
|
VerifyCustomer = "customer/verifyCustomer",
|
|
16
|
-
LinkPosToken = "customer/linkPosToken"
|
|
16
|
+
LinkPosToken = "customer/linkPosToken",
|
|
17
|
+
DeleteCustomer = "customer/deleteCustomer"
|
|
17
18
|
}
|
|
18
19
|
export declare const checkAuth: (err: RequestError, dispatch: ThunkDispatch<AppState, unknown, AnyAction>, rejectWithValue: () => any) => Promise<any>;
|
|
19
20
|
export declare const fetchCustomer: import("@reduxjs/toolkit").AsyncThunk<Partial<Profile>, void, {
|
|
@@ -54,6 +55,13 @@ export declare const authCustomerThanx: import("@reduxjs/toolkit").AsyncThunk<Au
|
|
|
54
55
|
state: AppState;
|
|
55
56
|
rejectValue: RequestError;
|
|
56
57
|
}>;
|
|
58
|
+
export declare const deleteCustomer: import("@reduxjs/toolkit").AsyncThunk<void, {
|
|
59
|
+
data: Partial<Profile>;
|
|
60
|
+
callback?: ((data: Partial<Profile>) => void) | undefined;
|
|
61
|
+
}, {
|
|
62
|
+
state: AppState;
|
|
63
|
+
rejectValue: RequestError;
|
|
64
|
+
}>;
|
|
57
65
|
export declare const resetCustomer: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>, resetLoginError: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>, fulfillLoginCustomer: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>;
|
|
58
66
|
export declare const selectToken: (state: AppState) => string | null;
|
|
59
67
|
export declare const selectCustomer: (state: AppState) => AccountState;
|
|
@@ -35,6 +35,7 @@ export var AccountActionType;
|
|
|
35
35
|
AccountActionType["UpdateCustomer"] = "customer/updateCustomer";
|
|
36
36
|
AccountActionType["VerifyCustomer"] = "customer/verifyCustomer";
|
|
37
37
|
AccountActionType["LinkPosToken"] = "customer/linkPosToken";
|
|
38
|
+
AccountActionType["DeleteCustomer"] = "customer/deleteCustomer";
|
|
38
39
|
})(AccountActionType || (AccountActionType = {}));
|
|
39
40
|
export const checkAuth = (err, dispatch, rejectWithValue) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
41
|
if ((err === null || err === void 0 ? void 0 : err.status) === 401) {
|
|
@@ -199,6 +200,39 @@ export const authCustomerThanx = createAsyncThunk(AccountActionType.LoginCustome
|
|
|
199
200
|
return rejectWithValue(err);
|
|
200
201
|
}
|
|
201
202
|
}));
|
|
203
|
+
export const deleteCustomer = createAsyncThunk(AccountActionType.DeleteCustomer, (requestData, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
204
|
+
try {
|
|
205
|
+
const token = selectToken(getState());
|
|
206
|
+
const api = getState().config.api;
|
|
207
|
+
if (!token)
|
|
208
|
+
throw new Error(MISSING_CUSTOMER);
|
|
209
|
+
yield api.deleteCustomer(token);
|
|
210
|
+
yield api.postLogout(token);
|
|
211
|
+
dispatch(updateCheckoutCustomer(null));
|
|
212
|
+
dispatch(resetCustomerAddresses());
|
|
213
|
+
dispatch(resetCustomerAllergens());
|
|
214
|
+
dispatch(resetCustomerCreditCards());
|
|
215
|
+
dispatch(resetCustomerFavorites());
|
|
216
|
+
dispatch(resetCustomerLevelUp());
|
|
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 (requestData.callback)
|
|
228
|
+
requestData.callback(requestData.data);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
catch (err) {
|
|
232
|
+
const error = err;
|
|
233
|
+
return checkAuth(error, dispatch, () => rejectWithValue(error));
|
|
234
|
+
}
|
|
235
|
+
}));
|
|
202
236
|
const accountSlice = createSlice({
|
|
203
237
|
name: ReducerType.Account,
|
|
204
238
|
initialState,
|
|
@@ -274,7 +308,12 @@ const accountSlice = createSlice({
|
|
|
274
308
|
})
|
|
275
309
|
.addCase(linkPosToken.rejected, () => {
|
|
276
310
|
//do nothing
|
|
277
|
-
})
|
|
311
|
+
})
|
|
312
|
+
.addCase(deleteCustomer.fulfilled, () => initialState)
|
|
313
|
+
.addCase(deleteCustomer.pending, (state) => {
|
|
314
|
+
state.loading = 'pending';
|
|
315
|
+
})
|
|
316
|
+
.addCase(deleteCustomer.rejected, () => initialState);
|
|
278
317
|
}
|
|
279
318
|
});
|
|
280
319
|
export const { resetCustomer, resetLoginError, fulfillLoginCustomer } = accountSlice.actions;
|
|
@@ -11,7 +11,8 @@ export interface CustomerGroupOrdersState {
|
|
|
11
11
|
export declare enum CustomerGroupOrdersActionType {
|
|
12
12
|
FetchCustomerGroupOrders = "customer/fetchCustomerGroupOrders",
|
|
13
13
|
FetchCustomerGroupOrder = "customer/fetchCustomerGroupOrder",
|
|
14
|
-
AddCustomerGroupOrder = "customer/addCustomerGroupOrder"
|
|
14
|
+
AddCustomerGroupOrder = "customer/addCustomerGroupOrder",
|
|
15
|
+
RemoveCustomerGroupOrder = "customer/removeCustomerGroupOrder"
|
|
15
16
|
}
|
|
16
17
|
export declare const fetchCustomerGroupOrders: import("@reduxjs/toolkit").AsyncThunk<GroupOrders, void, {
|
|
17
18
|
state: AppState;
|
|
@@ -28,6 +29,13 @@ export declare const addCustomerGroupOrder: import("@reduxjs/toolkit").AsyncThun
|
|
|
28
29
|
state: AppState;
|
|
29
30
|
rejectValue: RequestError;
|
|
30
31
|
}>;
|
|
32
|
+
export declare const removeCustomerGroupOrder: import("@reduxjs/toolkit").AsyncThunk<GroupOrders, {
|
|
33
|
+
cartId: number;
|
|
34
|
+
callback?: (() => void) | undefined;
|
|
35
|
+
}, {
|
|
36
|
+
state: AppState;
|
|
37
|
+
rejectValue: RequestError;
|
|
38
|
+
}>;
|
|
31
39
|
export declare const resetCustomerGroupOrders: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>, resetCustomerGroupOrdersError: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>, setCustomerGroupOrders: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>;
|
|
32
40
|
export declare const selectCustomerGroupOrders: (state: AppState) => CustomerGroupOrdersState;
|
|
33
41
|
export declare const customerGroupOrdersReducer: import("redux").Reducer<CustomerGroupOrdersState, import("redux").AnyAction>;
|
|
@@ -3,8 +3,9 @@ import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
|
|
|
3
3
|
import { ReducerType } from '../types';
|
|
4
4
|
import { MISSING_CUSTOMER } from '@open-tender/types';
|
|
5
5
|
import { checkAuth, selectToken } from './account';
|
|
6
|
-
import { makeCartPayload } from '../groupOrder';
|
|
6
|
+
import { makeCartPayload, resetGroupOrder } from '../groupOrder';
|
|
7
7
|
import { makeSimpleCart } from '@open-tender/utils';
|
|
8
|
+
import { showNotification } from '../notifications';
|
|
8
9
|
const initialState = {
|
|
9
10
|
entities: [],
|
|
10
11
|
lookup: {},
|
|
@@ -16,6 +17,7 @@ export var CustomerGroupOrdersActionType;
|
|
|
16
17
|
CustomerGroupOrdersActionType["FetchCustomerGroupOrders"] = "customer/fetchCustomerGroupOrders";
|
|
17
18
|
CustomerGroupOrdersActionType["FetchCustomerGroupOrder"] = "customer/fetchCustomerGroupOrder";
|
|
18
19
|
CustomerGroupOrdersActionType["AddCustomerGroupOrder"] = "customer/addCustomerGroupOrder";
|
|
20
|
+
CustomerGroupOrdersActionType["RemoveCustomerGroupOrder"] = "customer/removeCustomerGroupOrder";
|
|
19
21
|
})(CustomerGroupOrdersActionType || (CustomerGroupOrdersActionType = {}));
|
|
20
22
|
export const fetchCustomerGroupOrders = createAsyncThunk(CustomerGroupOrdersActionType.FetchCustomerGroupOrders, (_, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
23
|
try {
|
|
@@ -84,6 +86,27 @@ export const addCustomerGroupOrder = createAsyncThunk(CustomerGroupOrdersActionT
|
|
|
84
86
|
return checkAuth(error, dispatch, () => rejectWithValue(error));
|
|
85
87
|
}
|
|
86
88
|
}));
|
|
89
|
+
export const removeCustomerGroupOrder = createAsyncThunk(CustomerGroupOrdersActionType.RemoveCustomerGroupOrder, (requestData, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
+
try {
|
|
91
|
+
const api = getState().config.api;
|
|
92
|
+
const token = selectToken(getState());
|
|
93
|
+
if (!token)
|
|
94
|
+
throw new Error(MISSING_CUSTOMER);
|
|
95
|
+
yield api.deleteCustomerGroupOrder(token, requestData.cartId);
|
|
96
|
+
dispatch(resetGroupOrder());
|
|
97
|
+
const orders = yield api.getCustomerGroupOrders(token);
|
|
98
|
+
dispatch(showNotification('Group order deleted!'));
|
|
99
|
+
if (requestData.callback)
|
|
100
|
+
requestData.callback();
|
|
101
|
+
return orders;
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
dispatch(resetGroupOrder());
|
|
105
|
+
dispatch(showNotification('Group order deleted!'));
|
|
106
|
+
const error = err;
|
|
107
|
+
return checkAuth(error, dispatch, () => rejectWithValue(error));
|
|
108
|
+
}
|
|
109
|
+
}));
|
|
87
110
|
const customerGroupOrdersSlice = createSlice({
|
|
88
111
|
name: ReducerType.GroupOrders,
|
|
89
112
|
initialState,
|
|
@@ -135,6 +158,18 @@ const customerGroupOrdersSlice = createSlice({
|
|
|
135
158
|
.addCase(addCustomerGroupOrder.rejected, (state, action) => {
|
|
136
159
|
state.error = action.payload;
|
|
137
160
|
state.loading = 'idle';
|
|
161
|
+
})
|
|
162
|
+
.addCase(removeCustomerGroupOrder.fulfilled, (state, action) => {
|
|
163
|
+
state.entities = action.payload;
|
|
164
|
+
state.loading = 'idle';
|
|
165
|
+
state.error = null;
|
|
166
|
+
})
|
|
167
|
+
.addCase(removeCustomerGroupOrder.pending, state => {
|
|
168
|
+
state.loading = 'pending';
|
|
169
|
+
})
|
|
170
|
+
.addCase(removeCustomerGroupOrder.rejected, (state, action) => {
|
|
171
|
+
state.error = action.payload;
|
|
172
|
+
state.loading = 'idle';
|
|
138
173
|
});
|
|
139
174
|
}
|
|
140
175
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/cloud",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.29",
|
|
4
4
|
"description": "A library of hooks, reducers, utility functions, and types for use with Open Tender applications that utilize our cloud-based Order API.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|