@open-tender/cloud 0.1.59 → 0.1.61

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.
Files changed (42) hide show
  1. package/dist/cjs/app/hooks.d.ts +0 -2
  2. package/dist/cjs/app/store.d.ts +0 -6
  3. package/dist/cjs/app/store.js +0 -1
  4. package/dist/cjs/services/api.d.ts +0 -5
  5. package/dist/cjs/services/api.js +0 -15
  6. package/dist/cjs/slices/allergens.d.ts +0 -2
  7. package/dist/cjs/slices/customer/account.d.ts +2 -2
  8. package/dist/cjs/slices/customer/account.js +13 -14
  9. package/dist/cjs/slices/customer/index.d.ts +0 -2
  10. package/dist/cjs/slices/customer/index.js +1 -4
  11. package/dist/cjs/slices/index.d.ts +0 -1
  12. package/dist/cjs/slices/index.js +0 -1
  13. package/dist/cjs/slices/order.d.ts +0 -6
  14. package/dist/cjs/slices/tags.d.ts +0 -2
  15. package/dist/cjs/slices/types.d.ts +0 -1
  16. package/dist/cjs/slices/types.js +0 -1
  17. package/dist/esm/app/hooks.d.ts +0 -2
  18. package/dist/esm/app/store.d.ts +0 -6
  19. package/dist/esm/app/store.js +1 -2
  20. package/dist/esm/services/api.d.ts +0 -5
  21. package/dist/esm/services/api.js +0 -15
  22. package/dist/esm/slices/allergens.d.ts +0 -2
  23. package/dist/esm/slices/customer/account.d.ts +2 -2
  24. package/dist/esm/slices/customer/account.js +12 -13
  25. package/dist/esm/slices/customer/index.d.ts +0 -2
  26. package/dist/esm/slices/customer/index.js +1 -4
  27. package/dist/esm/slices/index.d.ts +0 -1
  28. package/dist/esm/slices/index.js +0 -1
  29. package/dist/esm/slices/order.d.ts +0 -6
  30. package/dist/esm/slices/tags.d.ts +0 -2
  31. package/dist/esm/slices/types.d.ts +0 -1
  32. package/dist/esm/slices/types.js +0 -1
  33. package/package.json +3 -3
  34. package/dist/.DS_Store +0 -0
  35. package/dist/cjs/slices/customer/levelup.d.ts +0 -81
  36. package/dist/cjs/slices/customer/levelup.js +0 -184
  37. package/dist/cjs/slices/levelup.d.ts +0 -25
  38. package/dist/cjs/slices/levelup.js +0 -55
  39. package/dist/esm/slices/customer/levelup.d.ts +0 -81
  40. package/dist/esm/slices/customer/levelup.js +0 -177
  41. package/dist/esm/slices/levelup.d.ts +0 -25
  42. package/dist/esm/slices/levelup.js +0 -50
@@ -16,7 +16,6 @@ import { resetCustomerOrders } from './orders';
16
16
  import { resetCustomerRewards } from './rewards';
17
17
  import { resetCustomerCommunicationPreferences } from './communicationPreferences';
18
18
  import { resetCustomerGiftCards, setCustomerGiftCards } from './giftCards';
19
- import { resetCustomerLevelUp, setCustomerLevelUp } from './levelup';
20
19
  import { addMessage, resetOrder, setAlert } from '../order';
21
20
  import { resetCheckout, updateCheckoutCustomer } from '../checkout';
22
21
  import { resetGroupOrder } from '../groupOrder';
@@ -56,12 +55,11 @@ export const fetchCustomer = createAsyncThunk(AccountActionType.FetchCustomer,
56
55
  if (!token)
57
56
  throw new Error(MISSING_CUSTOMER);
58
57
  const customer = yield api.getCustomer(token);
59
- const { allergens, gift_cards, favorites, levelup } = customer;
58
+ const { allergens, gift_cards, favorites } = customer;
60
59
  dispatch(setCustomerAllergens(allergens || []));
61
60
  dispatch(setSelectedAllergens(allergens || []));
62
61
  dispatch(setCustomerGiftCards(gift_cards || []));
63
62
  dispatch(setCustomerFavorites(favorites || []));
64
- dispatch(setCustomerLevelUp(levelup || []));
65
63
  const lookup = makeFavoritesLookup(favorites);
66
64
  dispatch(setCustomerFavoritesLookup(lookup || {}));
67
65
  const profile = makeCustomerProfile(customer);
@@ -72,10 +70,13 @@ export const fetchCustomer = createAsyncThunk(AccountActionType.FetchCustomer,
72
70
  return checkAuth(error, dispatch, () => rejectWithValue(error));
73
71
  }
74
72
  }));
75
- export const loginCustomer = createAsyncThunk(AccountActionType.LoginCustomer, ({ email, password }, { getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
73
+ export const loginCustomer = createAsyncThunk(AccountActionType.LoginCustomer, ({ email, password }, { dispatch, getState, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
76
74
  try {
77
75
  const api = getState().config.api;
78
- return yield api.postLogin(email, password);
76
+ const auth = yield api.postLogin(email, password);
77
+ dispatch(setCustomerAuth(auth));
78
+ yield dispatch(fetchCustomer());
79
+ return;
79
80
  }
80
81
  catch (err) {
81
82
  return rejectWithValue(err);
@@ -98,7 +99,6 @@ export const logoutCustomer = createAsyncThunk(AccountActionType.LogoutCustomer,
98
99
  dispatch(resetCustomerAllergens());
99
100
  dispatch(resetCustomerCreditCards());
100
101
  dispatch(resetCustomerFavorites());
101
- dispatch(resetCustomerLevelUp());
102
102
  dispatch(resetCustomerGiftCards());
103
103
  dispatch(resetCustomerHouseAccounts());
104
104
  dispatch(resetCustomerLoyalty());
@@ -209,7 +209,6 @@ export const deleteCustomer = createAsyncThunk(AccountActionType.DeleteCustomer,
209
209
  dispatch(resetCustomerAllergens());
210
210
  dispatch(resetCustomerCreditCards());
211
211
  dispatch(resetCustomerFavorites());
212
- dispatch(resetCustomerLevelUp());
213
212
  dispatch(resetCustomerGiftCards());
214
213
  dispatch(resetCustomerHouseAccounts());
215
214
  dispatch(resetCustomerLoyalty());
@@ -238,16 +237,16 @@ const accountSlice = createSlice({
238
237
  state.loading = 'idle';
239
238
  state.error = null;
240
239
  },
241
- fulfillLoginCustomer: (state, action) => {
240
+ setCustomerAuth: (state, action) => {
242
241
  state.auth = action.payload;
243
- state.loading = 'idle';
244
- state.error = null;
242
+ // state.loading = 'idle'
243
+ // state.error = null
245
244
  }
246
245
  },
247
246
  extraReducers: builder => {
248
247
  builder
249
- .addCase(loginCustomer.fulfilled, (state, action) => {
250
- state.auth = action.payload;
248
+ .addCase(loginCustomer.fulfilled, state => {
249
+ // state.auth = action.payload
251
250
  state.loading = 'idle';
252
251
  state.error = null;
253
252
  })
@@ -312,7 +311,7 @@ const accountSlice = createSlice({
312
311
  .addCase(deleteCustomer.rejected, () => initialState);
313
312
  }
314
313
  });
315
- export const { resetCustomer, resetLoginError, fulfillLoginCustomer } = accountSlice.actions;
314
+ export const { resetCustomer, resetLoginError, setCustomerAuth } = accountSlice.actions;
316
315
  export const selectToken = (state) => state.customer.account.auth ? state.customer.account.auth.access_token : null;
317
316
  export const selectCustomer = (state) => state.customer.account;
318
317
  export const accountReducer = accountSlice.reducer;
@@ -15,7 +15,6 @@ export declare const customerReducer: import("redux").Reducer<import("redux").Co
15
15
  rewards: import("./rewards").CustomerRewardsState;
16
16
  qrcode: import("./qrCode").CustomerQRCodeState;
17
17
  thanx: import("./thanx").CustomerThanxState;
18
- levelup: import("./levelup").CustomerLevelUpState;
19
18
  }>, import("redux").AnyAction>;
20
19
  export * from './account';
21
20
  export * from './allergens';
@@ -33,4 +32,3 @@ export * from './thanx';
33
32
  export * from './order';
34
33
  export * from './houseAccounts';
35
34
  export * from './qrCode';
36
- export * from './levelup';
@@ -10,7 +10,6 @@ import { customerFcmTokenReducer } from './fcmToken';
10
10
  import { customerGiftCardsReducer } from './giftCards';
11
11
  import { customerGroupOrdersReducer } from './groupOrders';
12
12
  import { customerHouseAccountsReducer } from './houseAccounts';
13
- import { customerLevelUpReducer } from './levelup';
14
13
  import { customerLoyaltyReducer } from './loyalty';
15
14
  import { customerOrderReducer } from './order';
16
15
  import { customerOrdersReducer } from './orders';
@@ -33,8 +32,7 @@ export const customerReducer = combineReducers({
33
32
  [ReducerType.HouseAccounts]: customerHouseAccountsReducer,
34
33
  [ReducerType.Rewards]: customerRewardsReducer,
35
34
  [ReducerType.QRCode]: customerQRCodeReducer,
36
- [ReducerType.Thanx]: customerThanxReducer,
37
- [ReducerType.Levelup]: customerLevelUpReducer
35
+ [ReducerType.Thanx]: customerThanxReducer
38
36
  });
39
37
  export * from './account';
40
38
  export * from './allergens';
@@ -52,4 +50,3 @@ export * from './thanx';
52
50
  export * from './order';
53
51
  export * from './houseAccounts';
54
52
  export * from './qrCode';
55
- export * from './levelup';
@@ -12,7 +12,6 @@ export * from './geolocation';
12
12
  export * from './giftCards';
13
13
  export * from './groupOrder';
14
14
  export * from './guest';
15
- export * from './levelup';
16
15
  export * from './loader';
17
16
  export * from './menu';
18
17
  export * from './menuDisplay';
@@ -12,7 +12,6 @@ export * from './geolocation';
12
12
  export * from './giftCards';
13
13
  export * from './groupOrder';
14
14
  export * from './guest';
15
- export * from './levelup';
16
15
  export * from './loader';
17
16
  export * from './menu';
18
17
  export * from './menuDisplay';
@@ -140,7 +140,6 @@ export declare const selectOrderLimits: ((state: import("redux").EmptyObject & {
140
140
  rewards: import("./customer").CustomerRewardsState;
141
141
  qrcode: import("./customer").CustomerQRCodeState;
142
142
  thanx: import("./customer").CustomerThanxState;
143
- levelup: import("./customer").CustomerLevelUpState;
144
143
  }>;
145
144
  signUp: import("./signUp").SignUpState;
146
145
  revenueCenters: import("./revenueCenters").RevenueCentersState;
@@ -161,7 +160,6 @@ export declare const selectOrderLimits: ((state: import("redux").EmptyObject & {
161
160
  menuDisplay: import("./menuDisplay").MenuDisplayState;
162
161
  giftCards: import("./giftCards").GiftCardsState;
163
162
  groupOrder: import("./groupOrder").GroupOrderState;
164
- levelup: import("./levelup").LevelupState;
165
163
  config: import("./config").ConfigState;
166
164
  geolocation: import("./geolocation").GeoLocationState;
167
165
  loader: import("./loader").LoaderState;
@@ -212,7 +210,6 @@ export declare const selectCartIds: ((state: import("redux").EmptyObject & {
212
210
  rewards: import("./customer").CustomerRewardsState;
213
211
  qrcode: import("./customer").CustomerQRCodeState;
214
212
  thanx: import("./customer").CustomerThanxState;
215
- levelup: import("./customer").CustomerLevelUpState;
216
213
  }>;
217
214
  signUp: import("./signUp").SignUpState;
218
215
  revenueCenters: import("./revenueCenters").RevenueCentersState;
@@ -233,7 +230,6 @@ export declare const selectCartIds: ((state: import("redux").EmptyObject & {
233
230
  menuDisplay: import("./menuDisplay").MenuDisplayState;
234
231
  giftCards: import("./giftCards").GiftCardsState;
235
232
  groupOrder: import("./groupOrder").GroupOrderState;
236
- levelup: import("./levelup").LevelupState;
237
233
  config: import("./config").ConfigState;
238
234
  geolocation: import("./geolocation").GeoLocationState;
239
235
  loader: import("./loader").LoaderState;
@@ -279,7 +275,6 @@ export declare const selectMenuVars: ((state: import("redux").EmptyObject & {
279
275
  rewards: import("./customer").CustomerRewardsState;
280
276
  qrcode: import("./customer").CustomerQRCodeState;
281
277
  thanx: import("./customer").CustomerThanxState;
282
- levelup: import("./customer").CustomerLevelUpState;
283
278
  }>;
284
279
  signUp: import("./signUp").SignUpState;
285
280
  revenueCenters: import("./revenueCenters").RevenueCentersState;
@@ -300,7 +295,6 @@ export declare const selectMenuVars: ((state: import("redux").EmptyObject & {
300
295
  menuDisplay: import("./menuDisplay").MenuDisplayState;
301
296
  giftCards: import("./giftCards").GiftCardsState;
302
297
  groupOrder: import("./groupOrder").GroupOrderState;
303
- levelup: import("./levelup").LevelupState;
304
298
  config: import("./config").ConfigState;
305
299
  geolocation: import("./geolocation").GeoLocationState;
306
300
  loader: import("./loader").LoaderState;
@@ -49,7 +49,6 @@ export declare const selectSelectedTagNames: ((state: import("redux").EmptyObjec
49
49
  rewards: import("./customer").CustomerRewardsState;
50
50
  qrcode: import("./customer").CustomerQRCodeState;
51
51
  thanx: import("./customer").CustomerThanxState;
52
- levelup: import("./customer").CustomerLevelUpState;
53
52
  }>;
54
53
  signUp: import("./signUp").SignUpState;
55
54
  revenueCenters: import("./revenueCenters").RevenueCentersState;
@@ -70,7 +69,6 @@ export declare const selectSelectedTagNames: ((state: import("redux").EmptyObjec
70
69
  menuDisplay: import("./menuDisplay").MenuDisplayState;
71
70
  giftCards: import("./giftCards").GiftCardsState;
72
71
  groupOrder: import("./groupOrder").GroupOrderState;
73
- levelup: import("./levelup").LevelupState;
74
72
  config: import("./config").ConfigState;
75
73
  geolocation: import("./geolocation").GeoLocationState;
76
74
  loader: import("./loader").LoaderState;
@@ -22,7 +22,6 @@ export declare enum ReducerType {
22
22
  GroupOrders = "groupOrders",
23
23
  Guest = "guest",
24
24
  HouseAccounts = "houseAccounts",
25
- Levelup = "levelup",
26
25
  Loader = "loader",
27
26
  Loyalty = "loyalty",
28
27
  Menu = "menu",
@@ -23,7 +23,6 @@ export var ReducerType;
23
23
  ReducerType["GroupOrders"] = "groupOrders";
24
24
  ReducerType["Guest"] = "guest";
25
25
  ReducerType["HouseAccounts"] = "houseAccounts";
26
- ReducerType["Levelup"] = "levelup";
27
26
  ReducerType["Loader"] = "loader";
28
27
  ReducerType["Loyalty"] = "loyalty";
29
28
  ReducerType["Menu"] = "menu";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-tender/cloud",
3
- "version": "0.1.59",
3
+ "version": "0.1.61",
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",
@@ -49,8 +49,8 @@
49
49
  "typescript": "^4.8.2"
50
50
  },
51
51
  "peerDependencies": {
52
- "@open-tender/types": "^0.2.54",
53
- "@open-tender/utils": "^0.1.118",
52
+ "@open-tender/types": "^0.2.55",
53
+ "@open-tender/utils": "^0.1.123",
54
54
  "@reduxjs/toolkit": "^1.8.5",
55
55
  "react": "^18.2.0"
56
56
  },
package/dist/.DS_Store DELETED
Binary file
@@ -1,81 +0,0 @@
1
- import { AppState } from '../../app';
2
- import { LevelUp, RequestError, RequestStatus } from '@open-tender/types';
3
- export interface CustomerLevelUpState {
4
- entities: LevelUp[];
5
- error: RequestError;
6
- loading: RequestStatus;
7
- lookup: {
8
- [key: number | string]: number;
9
- };
10
- levelup?: any;
11
- }
12
- export declare enum CustomerLevelUpActionType {
13
- FetchCustomerLevelUp = "customer/fetchCustomerLevelUp",
14
- RemoveCustomerLevelUp = "customer/removeCustomerLevelUp",
15
- AddCustomerLevelUp = "customer/addCustomerLevelUp"
16
- }
17
- export declare const fetchCustomerLevelUp: import("@reduxjs/toolkit").AsyncThunk<LevelUp[], void, {
18
- state: AppState;
19
- rejectValue: RequestError;
20
- dispatch?: import("redux").Dispatch<import("redux").AnyAction> | undefined;
21
- extra?: unknown;
22
- serializedErrorType?: unknown;
23
- pendingMeta?: unknown;
24
- fulfilledMeta?: unknown;
25
- rejectedMeta?: unknown;
26
- }>;
27
- export declare const removeCustomerLevelUp: import("@reduxjs/toolkit").AsyncThunk<LevelUp[], {
28
- levelupConnectId: number;
29
- callback?: (() => void) | undefined;
30
- }, {
31
- state: AppState;
32
- rejectValue: RequestError;
33
- dispatch?: import("redux").Dispatch<import("redux").AnyAction> | undefined;
34
- extra?: unknown;
35
- serializedErrorType?: unknown;
36
- pendingMeta?: unknown;
37
- fulfilledMeta?: unknown;
38
- rejectedMeta?: unknown;
39
- }>;
40
- export declare const addCustomerLevelUp: import("@reduxjs/toolkit").AsyncThunk<LevelUp[], {
41
- data: LevelUp;
42
- callback?: (() => void) | undefined;
43
- }, {
44
- state: AppState;
45
- rejectValue: RequestError;
46
- dispatch?: import("redux").Dispatch<import("redux").AnyAction> | undefined;
47
- extra?: unknown;
48
- serializedErrorType?: unknown;
49
- pendingMeta?: unknown;
50
- fulfilledMeta?: unknown;
51
- rejectedMeta?: unknown;
52
- }>;
53
- export declare const resetCustomerLevelUp: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"levelup/resetCustomerLevelUp">, setCustomerLevelUp: import("@reduxjs/toolkit").ActionCreatorWithPayload<any, "levelup/setCustomerLevelUp">, resetCustomerLevelUpError: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"levelup/resetCustomerLevelUpError">;
54
- export declare const selectCustomerLevelUp: (state: AppState) => CustomerLevelUpState;
55
- export declare const customerLevelUpReducer: import("redux").Reducer<CustomerLevelUpState, import("redux").AnyAction>;
56
- export declare const makeLevelUpProgram: (user: any) => {
57
- name: any;
58
- description: any;
59
- progress: number;
60
- spend: any;
61
- remaining: string;
62
- threshold: any;
63
- credit: any;
64
- towards: string;
65
- rewards: never[];
66
- } | null;
67
- export declare const selectCustomerLevelUpProgram: (state: AppState) => {
68
- program: {
69
- name: any;
70
- description: any;
71
- progress: number;
72
- spend: any;
73
- remaining: string;
74
- threshold: any;
75
- credit: any;
76
- towards: string;
77
- rewards: never[];
78
- } | null;
79
- loading: RequestStatus;
80
- error: RequestError;
81
- };
@@ -1,184 +0,0 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.selectCustomerLevelUpProgram = exports.makeLevelUpProgram = exports.customerLevelUpReducer = exports.selectCustomerLevelUp = exports.resetCustomerLevelUpError = exports.setCustomerLevelUp = exports.resetCustomerLevelUp = exports.addCustomerLevelUp = exports.removeCustomerLevelUp = exports.fetchCustomerLevelUp = exports.CustomerLevelUpActionType = void 0;
5
- const tslib_1 = require("tslib");
6
- const toolkit_1 = require("@reduxjs/toolkit");
7
- const types_1 = require("../types");
8
- const types_2 = require("@open-tender/types");
9
- const account_1 = require("./account");
10
- const notifications_1 = require("../notifications");
11
- const initialState = {
12
- entities: [],
13
- lookup: {},
14
- loading: 'idle',
15
- error: null
16
- };
17
- var CustomerLevelUpActionType;
18
- (function (CustomerLevelUpActionType) {
19
- CustomerLevelUpActionType["FetchCustomerLevelUp"] = "customer/fetchCustomerLevelUp";
20
- CustomerLevelUpActionType["RemoveCustomerLevelUp"] = "customer/removeCustomerLevelUp";
21
- CustomerLevelUpActionType["AddCustomerLevelUp"] = "customer/addCustomerLevelUp";
22
- })(CustomerLevelUpActionType = exports.CustomerLevelUpActionType || (exports.CustomerLevelUpActionType = {}));
23
- exports.fetchCustomerLevelUp = (0, toolkit_1.createAsyncThunk)(CustomerLevelUpActionType.FetchCustomerLevelUp, (_, { dispatch, getState, rejectWithValue }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
24
- try {
25
- const api = getState().config.api;
26
- const token = (0, account_1.selectToken)(getState());
27
- if (!token)
28
- throw new Error(types_2.MISSING_CUSTOMER);
29
- const levelup = yield api.getCustomerLevelUp(token);
30
- return levelup;
31
- }
32
- catch (err) {
33
- const error = err;
34
- return (0, account_1.checkAuth)(error, dispatch, () => rejectWithValue(error));
35
- }
36
- }));
37
- exports.removeCustomerLevelUp = (0, toolkit_1.createAsyncThunk)(CustomerLevelUpActionType.RemoveCustomerLevelUp, (requestData, { dispatch, getState, rejectWithValue }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
38
- try {
39
- const api = getState().config.api;
40
- const token = (0, account_1.selectToken)(getState());
41
- if (!token)
42
- throw new Error(types_2.MISSING_CUSTOMER);
43
- yield api.deleteCustomerLevelUp(token, requestData.levelupConnectId);
44
- dispatch((0, notifications_1.showNotification)('LevelUp disconnected!'));
45
- if (requestData.callback)
46
- requestData.callback();
47
- return [];
48
- }
49
- catch (err) {
50
- const error = err;
51
- return (0, account_1.checkAuth)(error, dispatch, () => rejectWithValue(error));
52
- }
53
- }));
54
- exports.addCustomerLevelUp = (0, toolkit_1.createAsyncThunk)(CustomerLevelUpActionType.AddCustomerLevelUp, (requestData, { dispatch, getState, rejectWithValue }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
55
- try {
56
- const api = getState().config.api;
57
- const token = (0, account_1.selectToken)(getState());
58
- if (!token)
59
- throw new Error(types_2.MISSING_CUSTOMER);
60
- const response = yield api.postCustomerLevelUp(token, requestData.data);
61
- dispatch((0, notifications_1.showNotification)('LevelUp connected!'));
62
- if (requestData.callback)
63
- requestData.callback();
64
- return [response];
65
- }
66
- catch (err) {
67
- const error = err;
68
- return (0, account_1.checkAuth)(error, dispatch, () => rejectWithValue(error));
69
- }
70
- }));
71
- // export const fetchLevelUpCustomer = createAsyncThunk<
72
- // Array<LevelUp>,
73
- // { token: string; callback?: () => void },
74
- // { state: AppState; rejectValue: RequestError }
75
- // >(
76
- // CustomerLevelUpActionType.AddCustomerLevelUp,
77
- // async (requestData, { dispatch, getState, rejectWithValue }) => {
78
- // try {
79
- // const { api } = getState().config
80
- // if (!api) return
81
- // const auth = await api.postLevelUp({ token: requestData.token })
82
- // dispatch(fetchCustomer())
83
- // if (requestData.callback) requestData.callback()
84
- // return auth
85
- // } catch (err) {
86
- // return rejectWithValue(err as RequestError)
87
- // }
88
- // }
89
- // )
90
- const customerLevelUpSlice = (0, toolkit_1.createSlice)({
91
- name: types_1.ReducerType.Levelup,
92
- initialState,
93
- reducers: {
94
- resetCustomerLevelUp: () => initialState,
95
- setCustomerLevelUp: (state, action) => {
96
- state.entities = action.payload;
97
- state.error = null;
98
- },
99
- resetCustomerLevelUpError: state => {
100
- state.error = null;
101
- state.loading = 'idle';
102
- }
103
- },
104
- extraReducers: builder => {
105
- builder
106
- .addCase(exports.fetchCustomerLevelUp.fulfilled, (state, action) => {
107
- state.entities = action.payload;
108
- state.loading = 'idle';
109
- state.error = null;
110
- })
111
- .addCase(exports.fetchCustomerLevelUp.pending, state => {
112
- state.loading = 'pending';
113
- })
114
- .addCase(exports.fetchCustomerLevelUp.rejected, (state, action) => {
115
- state.error = action.payload;
116
- state.loading = 'idle';
117
- })
118
- .addCase(exports.removeCustomerLevelUp.fulfilled, (state, action) => {
119
- state.entities = action.payload;
120
- state.loading = 'idle';
121
- state.error = null;
122
- })
123
- .addCase(exports.removeCustomerLevelUp.pending, state => {
124
- state.loading = 'pending';
125
- })
126
- .addCase(exports.removeCustomerLevelUp.rejected, (state, action) => {
127
- state.error = action.payload;
128
- state.loading = 'idle';
129
- })
130
- .addCase(exports.addCustomerLevelUp.fulfilled, (state, action) => {
131
- state.entities = action.payload;
132
- state.loading = 'idle';
133
- state.error = null;
134
- })
135
- .addCase(exports.addCustomerLevelUp.pending, state => {
136
- state.loading = 'pending';
137
- })
138
- .addCase(exports.addCustomerLevelUp.rejected, (state, action) => {
139
- state.error = action.payload;
140
- state.loading = 'idle';
141
- });
142
- // .addCase(fetchLevelUpCustomer.fulfilled, () => initialState)
143
- // .addCase(fetchLevelUpCustomer.pending, state => {
144
- // state.loading = 'pending'
145
- // })
146
- // .addCase(fetchLevelUpCustomer.rejected, (state, action) => {
147
- // state.error = action.payload
148
- // state.loading = 'idle'
149
- // })
150
- }
151
- });
152
- _a = customerLevelUpSlice.actions, exports.resetCustomerLevelUp = _a.resetCustomerLevelUp, exports.setCustomerLevelUp = _a.setCustomerLevelUp, exports.resetCustomerLevelUpError = _a.resetCustomerLevelUpError;
153
- const selectCustomerLevelUp = (state) => state.customer.levelup;
154
- exports.selectCustomerLevelUp = selectCustomerLevelUp;
155
- exports.customerLevelUpReducer = customerLevelUpSlice.reducer;
156
- const makeLevelUpProgram = (user) => {
157
- if (!user.program)
158
- return null;
159
- let { spend, credit, threshold } = user.program;
160
- const { name, description, reward } = user.program;
161
- credit = parseFloat(credit);
162
- spend = parseFloat(spend);
163
- threshold = parseFloat(threshold);
164
- const remaining = threshold - spend;
165
- const progress = (spend / threshold) * 100;
166
- return {
167
- name,
168
- description,
169
- progress,
170
- spend: spend.toFixed(2),
171
- remaining: remaining.toFixed(2),
172
- threshold: threshold.toFixed(2),
173
- credit: credit.toFixed(2),
174
- towards: `$${reward} off your order`,
175
- rewards: []
176
- };
177
- };
178
- exports.makeLevelUpProgram = makeLevelUpProgram;
179
- const selectCustomerLevelUpProgram = (state) => {
180
- const { entities, loading, error } = state.customer.levelup;
181
- const program = entities.length ? (0, exports.makeLevelUpProgram)(entities[0]) : null;
182
- return { program, loading, error };
183
- };
184
- exports.selectCustomerLevelUpProgram = selectCustomerLevelUpProgram;
@@ -1,25 +0,0 @@
1
- import { AppState } from '../app';
2
- import { RequestError, RequestStatus } from '@open-tender/types';
3
- export interface LevelupState {
4
- loading: RequestStatus;
5
- error: RequestError;
6
- }
7
- export declare enum LevelupActionType {
8
- FetchLevelUpCustomer = "levelup/fetchLevelUpCustomer"
9
- }
10
- export declare const fetchLevelUpCustomer: import("@reduxjs/toolkit").AsyncThunk<void, {
11
- token: string;
12
- callback?: (() => void) | undefined;
13
- }, {
14
- state: AppState;
15
- rejectValue: RequestError;
16
- dispatch?: import("redux").Dispatch<import("redux").AnyAction> | undefined;
17
- extra?: unknown;
18
- serializedErrorType?: unknown;
19
- pendingMeta?: unknown;
20
- fulfilledMeta?: unknown;
21
- rejectedMeta?: unknown;
22
- }>;
23
- export declare const resetLevelup: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"levelup/resetLevelup">, resetLevelUpCustomer: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"levelup/resetLevelUpCustomer">;
24
- export declare const levelupReducer: import("redux").Reducer<LevelupState, import("redux").AnyAction>;
25
- export declare const selectLevelUp: (state: AppState) => LevelupState;
@@ -1,55 +0,0 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.selectLevelUp = exports.levelupReducer = exports.resetLevelUpCustomer = exports.resetLevelup = exports.fetchLevelUpCustomer = exports.LevelupActionType = void 0;
5
- const tslib_1 = require("tslib");
6
- const toolkit_1 = require("@reduxjs/toolkit");
7
- const types_1 = require("./types");
8
- const customer_1 = require("./customer");
9
- const initialState = {
10
- loading: 'idle',
11
- error: null
12
- };
13
- var LevelupActionType;
14
- (function (LevelupActionType) {
15
- LevelupActionType["FetchLevelUpCustomer"] = "levelup/fetchLevelUpCustomer";
16
- })(LevelupActionType = exports.LevelupActionType || (exports.LevelupActionType = {}));
17
- exports.fetchLevelUpCustomer = (0, toolkit_1.createAsyncThunk)(LevelupActionType.FetchLevelUpCustomer, (data, { dispatch, getState, rejectWithValue }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
18
- const { api } = getState().config;
19
- if (!api)
20
- return;
21
- try {
22
- const auth = yield api.postLevelUp({ token: data.token });
23
- dispatch((0, customer_1.fulfillLoginCustomer)(auth));
24
- dispatch((0, customer_1.fetchCustomer)());
25
- if (data.callback)
26
- data.callback();
27
- return;
28
- }
29
- catch (err) {
30
- return rejectWithValue(err);
31
- }
32
- }));
33
- const levelupSlice = (0, toolkit_1.createSlice)({
34
- name: types_1.ReducerType.Levelup,
35
- initialState,
36
- reducers: {
37
- resetLevelup: () => initialState,
38
- resetLevelUpCustomer: () => initialState
39
- },
40
- extraReducers: builder => {
41
- builder
42
- .addCase(exports.fetchLevelUpCustomer.fulfilled, () => initialState)
43
- .addCase(exports.fetchLevelUpCustomer.pending, state => {
44
- state.loading = 'pending';
45
- })
46
- .addCase(exports.fetchLevelUpCustomer.rejected, (state, action) => {
47
- state.loading = 'idle';
48
- state.error = action.payload;
49
- });
50
- }
51
- });
52
- _a = levelupSlice.actions, exports.resetLevelup = _a.resetLevelup, exports.resetLevelUpCustomer = _a.resetLevelUpCustomer;
53
- exports.levelupReducer = levelupSlice.reducer;
54
- const selectLevelUp = (state) => state.levelup;
55
- exports.selectLevelUp = selectLevelUp;