@open-tender/cloud 0.0.27 → 0.0.28

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.
@@ -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
  });
@@ -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.27",
3
+ "version": "0.0.28",
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",