@open-tender/cloud 0.0.36 → 0.0.38
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.
|
@@ -12,7 +12,8 @@ export declare enum CustomerGroupOrdersActionType {
|
|
|
12
12
|
FetchCustomerGroupOrders = "customer/fetchCustomerGroupOrders",
|
|
13
13
|
FetchCustomerGroupOrder = "customer/fetchCustomerGroupOrder",
|
|
14
14
|
AddCustomerGroupOrder = "customer/addCustomerGroupOrder",
|
|
15
|
-
RemoveCustomerGroupOrder = "customer/removeCustomerGroupOrder"
|
|
15
|
+
RemoveCustomerGroupOrder = "customer/removeCustomerGroupOrder",
|
|
16
|
+
ReopenGroupOrder = "customer/reopenGroupOrder"
|
|
16
17
|
}
|
|
17
18
|
export declare const fetchCustomerGroupOrders: import("@reduxjs/toolkit").AsyncThunk<GroupOrders, void, {
|
|
18
19
|
state: AppState;
|
|
@@ -36,6 +37,10 @@ export declare const removeCustomerGroupOrder: import("@reduxjs/toolkit").AsyncT
|
|
|
36
37
|
state: AppState;
|
|
37
38
|
rejectValue: RequestError;
|
|
38
39
|
}>;
|
|
40
|
+
export declare const reopenGroupOrder: import("@reduxjs/toolkit").AsyncThunk<(GroupOrder | undefined)[], Partial<GroupOrder>, {
|
|
41
|
+
state: AppState;
|
|
42
|
+
rejectValue: RequestError;
|
|
43
|
+
}>;
|
|
39
44
|
export declare const resetCustomerGroupOrders: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>, resetCustomerGroupOrdersError: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>, setCustomerGroupOrders: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>;
|
|
40
45
|
export declare const selectCustomerGroupOrders: (state: AppState) => CustomerGroupOrdersState;
|
|
41
46
|
export declare const customerGroupOrdersReducer: import("redux").Reducer<CustomerGroupOrdersState, import("redux").AnyAction>;
|
|
@@ -1,13 +1,14 @@
|
|
|
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.removeCustomerGroupOrder = exports.addCustomerGroupOrder = exports.fetchCustomerGroupOrder = exports.fetchCustomerGroupOrders = exports.CustomerGroupOrdersActionType = void 0;
|
|
4
|
+
exports.customerGroupOrdersReducer = exports.selectCustomerGroupOrders = exports.setCustomerGroupOrders = exports.resetCustomerGroupOrdersError = exports.resetCustomerGroupOrders = exports.reopenGroupOrder = 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");
|
|
8
8
|
const types_2 = require("@open-tender/types");
|
|
9
9
|
const account_1 = require("./account");
|
|
10
10
|
const groupOrder_1 = require("../groupOrder");
|
|
11
|
+
const order_1 = require("../order");
|
|
11
12
|
const utils_1 = require("@open-tender/utils");
|
|
12
13
|
const notifications_1 = require("../notifications");
|
|
13
14
|
const initialState = {
|
|
@@ -22,6 +23,7 @@ var CustomerGroupOrdersActionType;
|
|
|
22
23
|
CustomerGroupOrdersActionType["FetchCustomerGroupOrder"] = "customer/fetchCustomerGroupOrder";
|
|
23
24
|
CustomerGroupOrdersActionType["AddCustomerGroupOrder"] = "customer/addCustomerGroupOrder";
|
|
24
25
|
CustomerGroupOrdersActionType["RemoveCustomerGroupOrder"] = "customer/removeCustomerGroupOrder";
|
|
26
|
+
CustomerGroupOrdersActionType["ReopenGroupOrder"] = "customer/reopenGroupOrder";
|
|
25
27
|
})(CustomerGroupOrdersActionType = exports.CustomerGroupOrdersActionType || (exports.CustomerGroupOrdersActionType = {}));
|
|
26
28
|
exports.fetchCustomerGroupOrders = (0, toolkit_1.createAsyncThunk)(CustomerGroupOrdersActionType.FetchCustomerGroupOrders, (_, { dispatch, getState, rejectWithValue }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
27
29
|
try {
|
|
@@ -111,6 +113,38 @@ exports.removeCustomerGroupOrder = (0, toolkit_1.createAsyncThunk)(CustomerGroup
|
|
|
111
113
|
return (0, account_1.checkAuth)(error, dispatch, () => rejectWithValue(error));
|
|
112
114
|
}
|
|
113
115
|
}));
|
|
116
|
+
exports.reopenGroupOrder = (0, toolkit_1.createAsyncThunk)(CustomerGroupOrdersActionType.ReopenGroupOrder, (cart, { dispatch, getState, rejectWithValue }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
117
|
+
try {
|
|
118
|
+
const api = getState().config.api;
|
|
119
|
+
const token = (0, account_1.selectToken)(getState());
|
|
120
|
+
if (!token)
|
|
121
|
+
throw new Error(types_2.MISSING_CUSTOMER);
|
|
122
|
+
const alert = { type: 'working', args: { text: 'Building your order...' } };
|
|
123
|
+
dispatch((0, order_1.setAlert)(alert));
|
|
124
|
+
const { revenue_center_id, service_type, requested_at, cart_id } = cart;
|
|
125
|
+
const revenueCenter = yield api.getLocation(revenue_center_id);
|
|
126
|
+
dispatch((0, order_1.setRevenueCenter)(revenueCenter));
|
|
127
|
+
const menuItems = yield api.getMenuItems(revenue_center_id, service_type);
|
|
128
|
+
const data = { revenue_center_id, requested_at, service_type };
|
|
129
|
+
const response = yield api.putCustomerGroupOrder(token, cart_id, data);
|
|
130
|
+
dispatch((0, order_1.setRequestedAt)(response.requested_at));
|
|
131
|
+
const customer = getState().customer.account.profile;
|
|
132
|
+
const { customer_id } = customer || {};
|
|
133
|
+
const items = response.cart.filter((i) => i.customer_id === customer_id);
|
|
134
|
+
const { cart: customerCart } = (0, utils_1.rehydrateCart)(menuItems, items);
|
|
135
|
+
dispatch((0, order_1.setCart)(customerCart));
|
|
136
|
+
const payload = Object.assign(Object.assign({}, (0, groupOrder_1.makeCartPayload)(response)), { isCartOwner: true, cartOwner: customer });
|
|
137
|
+
dispatch((0, notifications_1.showNotification)('Group order reopened!'));
|
|
138
|
+
dispatch((0, order_1.setAlert)({ type: 'groupOrder' }));
|
|
139
|
+
return payload;
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
dispatch((0, order_1.resetAlert)());
|
|
143
|
+
dispatch((0, order_1.addMessage)('Something went wrong. Please contact support.'));
|
|
144
|
+
const error = err;
|
|
145
|
+
return (0, account_1.checkAuth)(error, dispatch, () => rejectWithValue(error));
|
|
146
|
+
}
|
|
147
|
+
}));
|
|
114
148
|
const customerGroupOrdersSlice = (0, toolkit_1.createSlice)({
|
|
115
149
|
name: types_1.ReducerType.GroupOrders,
|
|
116
150
|
initialState,
|
|
@@ -174,6 +208,16 @@ const customerGroupOrdersSlice = (0, toolkit_1.createSlice)({
|
|
|
174
208
|
.addCase(exports.removeCustomerGroupOrder.rejected, (state, action) => {
|
|
175
209
|
state.error = action.payload;
|
|
176
210
|
state.loading = 'idle';
|
|
211
|
+
})
|
|
212
|
+
.addCase(exports.reopenGroupOrder.fulfilled, (state, action) => {
|
|
213
|
+
state = Object.assign(Object.assign(Object.assign({}, state), action.payload), { loading: 'idle', error: null });
|
|
214
|
+
})
|
|
215
|
+
.addCase(exports.reopenGroupOrder.pending, state => {
|
|
216
|
+
state.loading = 'pending';
|
|
217
|
+
})
|
|
218
|
+
.addCase(exports.reopenGroupOrder.rejected, (state, action) => {
|
|
219
|
+
state.error = action.payload;
|
|
220
|
+
state.loading = 'idle';
|
|
177
221
|
});
|
|
178
222
|
}
|
|
179
223
|
});
|
|
@@ -12,7 +12,8 @@ export declare enum CustomerGroupOrdersActionType {
|
|
|
12
12
|
FetchCustomerGroupOrders = "customer/fetchCustomerGroupOrders",
|
|
13
13
|
FetchCustomerGroupOrder = "customer/fetchCustomerGroupOrder",
|
|
14
14
|
AddCustomerGroupOrder = "customer/addCustomerGroupOrder",
|
|
15
|
-
RemoveCustomerGroupOrder = "customer/removeCustomerGroupOrder"
|
|
15
|
+
RemoveCustomerGroupOrder = "customer/removeCustomerGroupOrder",
|
|
16
|
+
ReopenGroupOrder = "customer/reopenGroupOrder"
|
|
16
17
|
}
|
|
17
18
|
export declare const fetchCustomerGroupOrders: import("@reduxjs/toolkit").AsyncThunk<GroupOrders, void, {
|
|
18
19
|
state: AppState;
|
|
@@ -36,6 +37,10 @@ export declare const removeCustomerGroupOrder: import("@reduxjs/toolkit").AsyncT
|
|
|
36
37
|
state: AppState;
|
|
37
38
|
rejectValue: RequestError;
|
|
38
39
|
}>;
|
|
40
|
+
export declare const reopenGroupOrder: import("@reduxjs/toolkit").AsyncThunk<(GroupOrder | undefined)[], Partial<GroupOrder>, {
|
|
41
|
+
state: AppState;
|
|
42
|
+
rejectValue: RequestError;
|
|
43
|
+
}>;
|
|
39
44
|
export declare const resetCustomerGroupOrders: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>, resetCustomerGroupOrdersError: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<string>, setCustomerGroupOrders: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, string>;
|
|
40
45
|
export declare const selectCustomerGroupOrders: (state: AppState) => CustomerGroupOrdersState;
|
|
41
46
|
export declare const customerGroupOrdersReducer: import("redux").Reducer<CustomerGroupOrdersState, import("redux").AnyAction>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
2
|
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
|
|
3
3
|
import { ReducerType } from '../types';
|
|
4
|
-
import { MISSING_CUSTOMER } from '@open-tender/types';
|
|
4
|
+
import { MISSING_CUSTOMER, } from '@open-tender/types';
|
|
5
5
|
import { checkAuth, selectToken } from './account';
|
|
6
6
|
import { makeCartPayload, resetGroupOrder } from '../groupOrder';
|
|
7
|
-
import {
|
|
7
|
+
import { addMessage, resetAlert, setAlert, setCart, setRequestedAt, setRevenueCenter } from '../order';
|
|
8
|
+
import { makeSimpleCart, rehydrateCart } from '@open-tender/utils';
|
|
8
9
|
import { showNotification } from '../notifications';
|
|
9
10
|
const initialState = {
|
|
10
11
|
entities: [],
|
|
@@ -18,6 +19,7 @@ export var CustomerGroupOrdersActionType;
|
|
|
18
19
|
CustomerGroupOrdersActionType["FetchCustomerGroupOrder"] = "customer/fetchCustomerGroupOrder";
|
|
19
20
|
CustomerGroupOrdersActionType["AddCustomerGroupOrder"] = "customer/addCustomerGroupOrder";
|
|
20
21
|
CustomerGroupOrdersActionType["RemoveCustomerGroupOrder"] = "customer/removeCustomerGroupOrder";
|
|
22
|
+
CustomerGroupOrdersActionType["ReopenGroupOrder"] = "customer/reopenGroupOrder";
|
|
21
23
|
})(CustomerGroupOrdersActionType || (CustomerGroupOrdersActionType = {}));
|
|
22
24
|
export const fetchCustomerGroupOrders = createAsyncThunk(CustomerGroupOrdersActionType.FetchCustomerGroupOrders, (_, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
25
|
try {
|
|
@@ -107,6 +109,38 @@ export const removeCustomerGroupOrder = createAsyncThunk(CustomerGroupOrdersActi
|
|
|
107
109
|
return checkAuth(error, dispatch, () => rejectWithValue(error));
|
|
108
110
|
}
|
|
109
111
|
}));
|
|
112
|
+
export const reopenGroupOrder = createAsyncThunk(CustomerGroupOrdersActionType.ReopenGroupOrder, (cart, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
|
+
try {
|
|
114
|
+
const api = getState().config.api;
|
|
115
|
+
const token = selectToken(getState());
|
|
116
|
+
if (!token)
|
|
117
|
+
throw new Error(MISSING_CUSTOMER);
|
|
118
|
+
const alert = { type: 'working', args: { text: 'Building your order...' } };
|
|
119
|
+
dispatch(setAlert(alert));
|
|
120
|
+
const { revenue_center_id, service_type, requested_at, cart_id } = cart;
|
|
121
|
+
const revenueCenter = yield api.getLocation(revenue_center_id);
|
|
122
|
+
dispatch(setRevenueCenter(revenueCenter));
|
|
123
|
+
const menuItems = yield api.getMenuItems(revenue_center_id, service_type);
|
|
124
|
+
const data = { revenue_center_id, requested_at, service_type };
|
|
125
|
+
const response = yield api.putCustomerGroupOrder(token, cart_id, data);
|
|
126
|
+
dispatch(setRequestedAt(response.requested_at));
|
|
127
|
+
const customer = getState().customer.account.profile;
|
|
128
|
+
const { customer_id } = customer || {};
|
|
129
|
+
const items = response.cart.filter((i) => i.customer_id === customer_id);
|
|
130
|
+
const { cart: customerCart } = rehydrateCart(menuItems, items);
|
|
131
|
+
dispatch(setCart(customerCart));
|
|
132
|
+
const payload = Object.assign(Object.assign({}, makeCartPayload(response)), { isCartOwner: true, cartOwner: customer });
|
|
133
|
+
dispatch(showNotification('Group order reopened!'));
|
|
134
|
+
dispatch(setAlert({ type: 'groupOrder' }));
|
|
135
|
+
return payload;
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
dispatch(resetAlert());
|
|
139
|
+
dispatch(addMessage('Something went wrong. Please contact support.'));
|
|
140
|
+
const error = err;
|
|
141
|
+
return checkAuth(error, dispatch, () => rejectWithValue(error));
|
|
142
|
+
}
|
|
143
|
+
}));
|
|
110
144
|
const customerGroupOrdersSlice = createSlice({
|
|
111
145
|
name: ReducerType.GroupOrders,
|
|
112
146
|
initialState,
|
|
@@ -170,6 +204,16 @@ const customerGroupOrdersSlice = createSlice({
|
|
|
170
204
|
.addCase(removeCustomerGroupOrder.rejected, (state, action) => {
|
|
171
205
|
state.error = action.payload;
|
|
172
206
|
state.loading = 'idle';
|
|
207
|
+
})
|
|
208
|
+
.addCase(reopenGroupOrder.fulfilled, (state, action) => {
|
|
209
|
+
state = Object.assign(Object.assign(Object.assign({}, state), action.payload), { loading: 'idle', error: null });
|
|
210
|
+
})
|
|
211
|
+
.addCase(reopenGroupOrder.pending, state => {
|
|
212
|
+
state.loading = 'pending';
|
|
213
|
+
})
|
|
214
|
+
.addCase(reopenGroupOrder.rejected, (state, action) => {
|
|
215
|
+
state.error = action.payload;
|
|
216
|
+
state.loading = 'idle';
|
|
173
217
|
});
|
|
174
218
|
}
|
|
175
219
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-tender/cloud",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.38",
|
|
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",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"react": "^18.2.0"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@open-tender/types": "^0.0.
|
|
59
|
-
"@open-tender/utils": "^0.0.
|
|
58
|
+
"@open-tender/types": "^0.0.79",
|
|
59
|
+
"@open-tender/utils": "^0.0.22"
|
|
60
60
|
}
|
|
61
61
|
}
|