@techstuff-dev/foundation-api-utils 1.24.0 → 1.26.0
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/@types/lib/hooks/index.d.ts +24 -16
- package/dist/@types/lib/services/cart/slice.d.ts +155 -0
- package/dist/@types/lib/services/content/content.interfaces.d.ts +59 -3
- package/dist/@types/lib/services/index.d.ts +1 -0
- package/dist/@types/lib/services/payment/index.d.ts +563 -39
- package/dist/@types/lib/store/index.d.ts +60 -40
- package/dist/@types/lib/utils/dataFormat/index.d.ts +2 -1
- package/dist/@types/lib/utils/helpers/index.d.ts +12 -0
- package/dist/index.esm.js +201 -46
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +220 -44
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -75,13 +75,23 @@ function __generator(thisArg, body) {
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
function __spreadArray(to, from, pack) {
|
|
79
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
80
|
+
if (ar || !(i in from)) {
|
|
81
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
82
|
+
ar[i] = from[i];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
86
|
+
}
|
|
87
|
+
|
|
78
88
|
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
79
89
|
var e = new Error(message);
|
|
80
90
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
81
91
|
};
|
|
82
92
|
|
|
83
|
-
var _a$
|
|
84
|
-
var initialState = {
|
|
93
|
+
var _a$2, _b$2;
|
|
94
|
+
var initialState$1 = {
|
|
85
95
|
authenticated: false,
|
|
86
96
|
verifying: false,
|
|
87
97
|
user: {
|
|
@@ -105,29 +115,13 @@ var initialState = {
|
|
|
105
115
|
email: '',
|
|
106
116
|
sub: '',
|
|
107
117
|
},
|
|
108
|
-
// creating: {
|
|
109
|
-
// details: '',
|
|
110
|
-
// payment: '',
|
|
111
|
-
// },
|
|
112
118
|
loading: false,
|
|
113
119
|
error: false,
|
|
114
120
|
session: undefined,
|
|
115
121
|
};
|
|
116
|
-
// interface AuthReducers {
|
|
117
|
-
// setCredentials: (
|
|
118
|
-
// state: AuthState,
|
|
119
|
-
// data: {
|
|
120
|
-
// payload: any;
|
|
121
|
-
// type: string;
|
|
122
|
-
// },
|
|
123
|
-
// ) => AuthState;
|
|
124
|
-
// resetCreating: (state: AuthState) => void;
|
|
125
|
-
// updateSubscription: (state: AuthState, data: any) => void;
|
|
126
|
-
// logout: () => void;
|
|
127
|
-
// }
|
|
128
122
|
var authSlice = toolkit.createSlice({
|
|
129
123
|
name: 'auth',
|
|
130
|
-
initialState: initialState,
|
|
124
|
+
initialState: initialState$1,
|
|
131
125
|
reducers: {
|
|
132
126
|
setCredentials: function (state, data) {
|
|
133
127
|
return __assign(__assign({}, state), { session: data.payload.accessToken, authenticated: true, verifying: true, user: __assign(__assign({}, state.user), data.payload) });
|
|
@@ -141,15 +135,13 @@ var authSlice = toolkit.createSlice({
|
|
|
141
135
|
updateSubscription: function (state, data) {
|
|
142
136
|
return __assign(__assign({}, state), { user: __assign(__assign({}, state.user), { details: __assign(__assign({}, state.user.details), { customerId: data.payload.customerId, subscription: data.payload.subscription, subscriptionDetails: data.payload.subscriptionDetails }) }) });
|
|
143
137
|
},
|
|
144
|
-
logout: function () { return initialState; },
|
|
138
|
+
logout: function () { return initialState$1; },
|
|
145
139
|
},
|
|
146
140
|
selectors: {
|
|
147
141
|
isAuthenticated: function (auth) { return auth.authenticated; },
|
|
148
142
|
selectAccessToken: function (auth) { return auth.user.accessToken; },
|
|
149
143
|
selectRefreshToken: function (auth) { return auth.user.refreshToken; },
|
|
150
144
|
selectCurrentUser: function (auth) { return auth.user.details; },
|
|
151
|
-
// selectUserCreating: (auth) => auth.creating,
|
|
152
|
-
// selectUserCreatingDetails: (auth) => auth.creating.details,
|
|
153
145
|
isVerifying: function (auth) { return auth.verifying; },
|
|
154
146
|
getUserSession: function (auth) { return (auth.authenticated ? auth.session : false); },
|
|
155
147
|
selectCurrentUserSub: function (auth) { return auth.user.sub; },
|
|
@@ -176,12 +168,9 @@ var authSlice = toolkit.createSlice({
|
|
|
176
168
|
},
|
|
177
169
|
});
|
|
178
170
|
// Action creators are generated for each case reducer function.
|
|
179
|
-
var setCredentials = (_a$
|
|
171
|
+
var setCredentials = (_a$2 = authSlice.actions, _a$2.setCredentials), resetCreating = _a$2.resetCreating, logout = _a$2.logout, updateSubscription = _a$2.updateSubscription;
|
|
180
172
|
// Selectors returned by `slice.selectors` take the root state as their first argument.
|
|
181
|
-
var isAuthenticated = (_b$
|
|
182
|
-
// selectUserCreating,
|
|
183
|
-
// selectUserCreatingDetails,
|
|
184
|
-
isVerifying = _b$1.isVerifying, getUserSession = _b$1.getUserSession, selectCurrentUserSub = _b$1.selectCurrentUserSub, selectCurrentUserRefreshToken = _b$1.selectCurrentUserRefreshToken, selectUserTokens = _b$1.selectUserTokens, selectUserSubscriptionStatus = _b$1.selectUserSubscriptionStatus, selectSubscription = _b$1.selectSubscription, selectSubscriptionPrice = _b$1.selectSubscriptionPrice;
|
|
173
|
+
var isAuthenticated = (_b$2 = authSlice.selectors, _b$2.isAuthenticated), selectAccessToken = _b$2.selectAccessToken, selectRefreshToken = _b$2.selectRefreshToken, selectCurrentUser = _b$2.selectCurrentUser, isVerifying = _b$2.isVerifying, getUserSession = _b$2.getUserSession, selectCurrentUserSub = _b$2.selectCurrentUserSub, selectCurrentUserRefreshToken = _b$2.selectCurrentUserRefreshToken, selectUserTokens = _b$2.selectUserTokens, selectUserSubscriptionStatus = _b$2.selectUserSubscriptionStatus, selectSubscription = _b$2.selectSubscription, selectSubscriptionPrice = _b$2.selectSubscriptionPrice;
|
|
185
174
|
authSlice.reducer;
|
|
186
175
|
|
|
187
176
|
// TODO: typing.
|
|
@@ -664,8 +653,8 @@ function formatConfig(data) {
|
|
|
664
653
|
name: (_r = (_q = item === null || item === void 0 ? void 0 : item._source) === null || _q === void 0 ? void 0 : _q.name) === null || _r === void 0 ? void 0 : _r[0],
|
|
665
654
|
price: (_t = (_s = item === null || item === void 0 ? void 0 : item._source) === null || _s === void 0 ? void 0 : _s.price) === null || _t === void 0 ? void 0 : _t[0],
|
|
666
655
|
video: (_v = (_u = item === null || item === void 0 ? void 0 : item._source) === null || _u === void 0 ? void 0 : _u.video) === null || _v === void 0 ? void 0 : _v[0],
|
|
667
|
-
|
|
668
|
-
|
|
656
|
+
imageHomepage: (_x = (_w = item === null || item === void 0 ? void 0 : item._source) === null || _w === void 0 ? void 0 : _w.image_homepage) === null || _x === void 0 ? void 0 : _x[0],
|
|
657
|
+
imageSectionBanner: (_z = (_y = item === null || item === void 0 ? void 0 : item._source) === null || _y === void 0 ? void 0 : _y.image_section_banner) === null || _z === void 0 ? void 0 : _z[0],
|
|
669
658
|
};
|
|
670
659
|
});
|
|
671
660
|
}
|
|
@@ -776,15 +765,46 @@ var formatLongform = function (data) {
|
|
|
776
765
|
};
|
|
777
766
|
});
|
|
778
767
|
};
|
|
768
|
+
var formatMediaItem = function (data) {
|
|
769
|
+
return data.map(function (item) {
|
|
770
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18;
|
|
771
|
+
return {
|
|
772
|
+
changed: (_b = (_a = item === null || item === void 0 ? void 0 : item._source) === null || _a === void 0 ? void 0 : _a.changed) === null || _b === void 0 ? void 0 : _b[0],
|
|
773
|
+
created: (_d = (_c = item === null || item === void 0 ? void 0 : item._source) === null || _c === void 0 ? void 0 : _c.created) === null || _d === void 0 ? void 0 : _d[0],
|
|
774
|
+
image: (_f = (_e = item === null || item === void 0 ? void 0 : item._source) === null || _e === void 0 ? void 0 : _e.image) === null || _f === void 0 ? void 0 : _f[0],
|
|
775
|
+
customThumbnail: (_h = (_g = item === null || item === void 0 ? void 0 : item._source) === null || _g === void 0 ? void 0 : _g.custom_thumbnail) === null || _h === void 0 ? void 0 : _h[0],
|
|
776
|
+
price: (_k = (_j = item === null || item === void 0 ? void 0 : item._source) === null || _j === void 0 ? void 0 : _j.price) === null || _k === void 0 ? void 0 : _k[0],
|
|
777
|
+
priceTwoYear: (_m = (_l = item === null || item === void 0 ? void 0 : item._source) === null || _l === void 0 ? void 0 : _l.price_2_year) === null || _m === void 0 ? void 0 : _m[0],
|
|
778
|
+
revisionTimestamp: (_p = (_o = item === null || item === void 0 ? void 0 : item._source) === null || _o === void 0 ? void 0 : _o.revision_timestamp) === null || _p === void 0 ? void 0 : _p[0],
|
|
779
|
+
sku: (_r = (_q = item === null || item === void 0 ? void 0 : item._source) === null || _q === void 0 ? void 0 : _q.sku) === null || _r === void 0 ? void 0 : _r[0],
|
|
780
|
+
status: (_t = (_s = item === null || item === void 0 ? void 0 : item._source) === null || _s === void 0 ? void 0 : _s.status) === null || _t === void 0 ? void 0 : _t[0],
|
|
781
|
+
uuid: (_v = (_u = item === null || item === void 0 ? void 0 : item._source) === null || _u === void 0 ? void 0 : _u.uuid) === null || _v === void 0 ? void 0 : _v[0],
|
|
782
|
+
description: (_x = (_w = item === null || item === void 0 ? void 0 : item._source) === null || _w === void 0 ? void 0 : _w.description) === null || _x === void 0 ? void 0 : _x[0],
|
|
783
|
+
transcript: (_z = (_y = item === null || item === void 0 ? void 0 : item._source) === null || _y === void 0 ? void 0 : _y.transcript) === null || _z === void 0 ? void 0 : _z[0],
|
|
784
|
+
entities: (_0 = item === null || item === void 0 ? void 0 : item._source) === null || _0 === void 0 ? void 0 : _0.entities,
|
|
785
|
+
phrases: (_1 = item === null || item === void 0 ? void 0 : item._source) === null || _1 === void 0 ? void 0 : _1.phrases,
|
|
786
|
+
video: (_3 = (_2 = item === null || item === void 0 ? void 0 : item._source) === null || _2 === void 0 ? void 0 : _2.video) === null || _3 === void 0 ? void 0 : _3[0],
|
|
787
|
+
title: (_5 = (_4 = item === null || item === void 0 ? void 0 : item._source) === null || _4 === void 0 ? void 0 : _4.title) === null || _5 === void 0 ? void 0 : _5[0],
|
|
788
|
+
generatedTitle: (_7 = (_6 = item === null || item === void 0 ? void 0 : item._source) === null || _6 === void 0 ? void 0 : _6.generated_title) === null || _7 === void 0 ? void 0 : _7[0],
|
|
789
|
+
projectPricing: (_9 = (_8 = item === null || item === void 0 ? void 0 : item._source) === null || _8 === void 0 ? void 0 : _8.project_pricing) === null || _9 === void 0 ? void 0 : _9[0],
|
|
790
|
+
related_items: (_10 = item === null || item === void 0 ? void 0 : item._source) === null || _10 === void 0 ? void 0 : _10.related_uuids,
|
|
791
|
+
franchises: (_11 = item === null || item === void 0 ? void 0 : item._source) === null || _11 === void 0 ? void 0 : _11.franchise_name,
|
|
792
|
+
franchisesIds: (_12 = item === null || item === void 0 ? void 0 : item._source) === null || _12 === void 0 ? void 0 : _12.franchise_tid,
|
|
793
|
+
original: (_14 = (_13 = item === null || item === void 0 ? void 0 : item._source) === null || _13 === void 0 ? void 0 : _13.original) === null || _14 === void 0 ? void 0 : _14[0],
|
|
794
|
+
script: (_16 = (_15 = item === null || item === void 0 ? void 0 : item._source) === null || _15 === void 0 ? void 0 : _15.script) === null || _16 === void 0 ? void 0 : _16[0],
|
|
795
|
+
hideThumbnailTitle: (_18 = (_17 = item === null || item === void 0 ? void 0 : item._source) === null || _17 === void 0 ? void 0 : _17.hide_thumbnail_title) === null || _18 === void 0 ? void 0 : _18[0],
|
|
796
|
+
};
|
|
797
|
+
});
|
|
798
|
+
};
|
|
779
799
|
|
|
780
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
800
|
+
var _a$1, _b$1, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
781
801
|
// Render the store based on the environment.
|
|
782
802
|
var isWeb = process.env.NEXT_PUBLIC_WEB_APP;
|
|
783
803
|
var ENV = isWeb ? process.env : require('react-native-config').default;
|
|
784
804
|
// export const ENV = process.env;
|
|
785
|
-
((_a = process.env) === null || _a === void 0 ? void 0 : _a.NEXT_PUBLIC_API_PREFIX) || ENV.API_PREFIX;
|
|
805
|
+
((_a$1 = process.env) === null || _a$1 === void 0 ? void 0 : _a$1.NEXT_PUBLIC_API_PREFIX) || ENV.API_PREFIX;
|
|
786
806
|
// Auth specific API
|
|
787
|
-
var API_AUTH_PREFIX = ((_b = process.env) === null || _b === void 0 ? void 0 : _b.NEXT_PUBLIC_API_AUTH_PREFIX) || ENV.API_AUTH_PREFIX;
|
|
807
|
+
var API_AUTH_PREFIX = ((_b$1 = process.env) === null || _b$1 === void 0 ? void 0 : _b$1.NEXT_PUBLIC_API_AUTH_PREFIX) || ENV.API_AUTH_PREFIX;
|
|
788
808
|
// Payments specific API
|
|
789
809
|
var API_PAYMENTS_PREFIX = ((_c = process.env) === null || _c === void 0 ? void 0 : _c.NEXT_PUBLIC_API_PAYMENTS_PREFIX) || ENV.API_PAYMENTS_PREFIX;
|
|
790
810
|
((_d = process.env) === null || _d === void 0 ? void 0 : _d.NEXT_PUBLIC_APP_BASE_URL) || ENV.APP_BASE_URL;
|
|
@@ -1191,7 +1211,7 @@ var paymentApi = react.createApi({
|
|
|
1191
1211
|
}); },
|
|
1192
1212
|
credentials: 'include',
|
|
1193
1213
|
}),
|
|
1194
|
-
tagTypes: ['UserSubscription', 'Plans'],
|
|
1214
|
+
tagTypes: ['UserSubscription', 'Plans', 'TaxRates', 'PromoCodes'],
|
|
1195
1215
|
// keepUnusedDataFor: 300,
|
|
1196
1216
|
endpoints: function (builder) { return ({
|
|
1197
1217
|
/**
|
|
@@ -1213,10 +1233,154 @@ var paymentApi = react.createApi({
|
|
|
1213
1233
|
query: function () { return '/payment/plans'; },
|
|
1214
1234
|
providesTags: ['Plans'],
|
|
1215
1235
|
}),
|
|
1236
|
+
getTaxRates: builder.query({
|
|
1237
|
+
query: function () { return ({
|
|
1238
|
+
url: '/payment/tax-rates',
|
|
1239
|
+
method: 'GET',
|
|
1240
|
+
}); },
|
|
1241
|
+
providesTags: ['TaxRates'],
|
|
1242
|
+
}),
|
|
1243
|
+
checkPromoCode: builder.query({
|
|
1244
|
+
query: function (promoCode) { return ({
|
|
1245
|
+
url: "/payment/coupon/".concat(promoCode),
|
|
1246
|
+
method: 'GET',
|
|
1247
|
+
}); },
|
|
1248
|
+
providesTags: ['PromoCodes'],
|
|
1249
|
+
}),
|
|
1216
1250
|
}); },
|
|
1217
1251
|
});
|
|
1218
1252
|
// Export hooks for usage in functional components.
|
|
1219
|
-
paymentApi.useCheckUserSubscriptionQuery; paymentApi.useLazyCheckUserSubscriptionQuery; paymentApi.useGetPaymentPlansQuery; paymentApi.useLazyGetPaymentPlansQuery;
|
|
1253
|
+
paymentApi.useCheckUserSubscriptionQuery; paymentApi.useLazyCheckUserSubscriptionQuery; paymentApi.useGetPaymentPlansQuery; paymentApi.useLazyGetPaymentPlansQuery; paymentApi.useGetTaxRatesQuery; paymentApi.useLazyGetTaxRatesQuery; paymentApi.useCheckPromoCodeQuery; paymentApi.useLazyCheckPromoCodeQuery;
|
|
1254
|
+
|
|
1255
|
+
function applyCoupon(coupon, netTotal) {
|
|
1256
|
+
var discountedAmount = netTotal * (Number(coupon.discount) / 100);
|
|
1257
|
+
var discountedTotal = netTotal - discountedAmount;
|
|
1258
|
+
var data = __assign(__assign({}, coupon), { discountedTotal: discountedTotal, discountedAmount: discountedAmount });
|
|
1259
|
+
return data;
|
|
1260
|
+
}
|
|
1261
|
+
function applyTax(taxRate, netTotal) {
|
|
1262
|
+
var taxAmount = netTotal * (taxRate.percentage / 100);
|
|
1263
|
+
return taxAmount;
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
var _a, _b;
|
|
1267
|
+
var initialState = {
|
|
1268
|
+
addedItems: [],
|
|
1269
|
+
netTotal: 0,
|
|
1270
|
+
taxRate: {
|
|
1271
|
+
country: 'none',
|
|
1272
|
+
percentage: 0,
|
|
1273
|
+
},
|
|
1274
|
+
taxAmount: 0,
|
|
1275
|
+
promoCode: {
|
|
1276
|
+
code: '',
|
|
1277
|
+
name: '',
|
|
1278
|
+
discount: '',
|
|
1279
|
+
discountedAmount: 0,
|
|
1280
|
+
},
|
|
1281
|
+
grossTotal: 0,
|
|
1282
|
+
loading: false,
|
|
1283
|
+
error: false,
|
|
1284
|
+
open: false,
|
|
1285
|
+
};
|
|
1286
|
+
var cartSlice = toolkit.createSlice({
|
|
1287
|
+
name: 'cart',
|
|
1288
|
+
initialState: initialState,
|
|
1289
|
+
reducers: {
|
|
1290
|
+
setTaxRate: function (state, action) {
|
|
1291
|
+
var netTotal = state.netTotal, promoCode = state.promoCode;
|
|
1292
|
+
var currentTotal = netTotal;
|
|
1293
|
+
if (promoCode === null || promoCode === void 0 ? void 0 : promoCode.code) {
|
|
1294
|
+
var data = applyCoupon(promoCode, currentTotal);
|
|
1295
|
+
currentTotal = data.discountedTotal;
|
|
1296
|
+
}
|
|
1297
|
+
var taxAmount = applyTax(action.payload, currentTotal);
|
|
1298
|
+
var grossTotal = currentTotal + taxAmount;
|
|
1299
|
+
return __assign(__assign({}, state), { taxRate: action.payload, taxAmount: taxAmount, grossTotal: grossTotal });
|
|
1300
|
+
},
|
|
1301
|
+
resetTaxRate: function (state, action) {
|
|
1302
|
+
console.log('resetTaxRate', action);
|
|
1303
|
+
return __assign(__assign({}, state), { taxRate: {
|
|
1304
|
+
country: 'none',
|
|
1305
|
+
percentage: 0,
|
|
1306
|
+
}, taxAmount: 0 });
|
|
1307
|
+
},
|
|
1308
|
+
setPromoCode: function (state, action) {
|
|
1309
|
+
var netTotal = state.netTotal, taxRate = state.taxRate;
|
|
1310
|
+
var data = applyCoupon(action.payload, netTotal);
|
|
1311
|
+
var taxAmount = applyTax(taxRate, data.discountedTotal);
|
|
1312
|
+
var grossTotal = data.discountedTotal + taxAmount;
|
|
1313
|
+
return __assign(__assign({}, state), { promoCode: {
|
|
1314
|
+
code: data.code,
|
|
1315
|
+
name: data.code,
|
|
1316
|
+
discount: data.discount,
|
|
1317
|
+
discountedAmount: data.discountedAmount,
|
|
1318
|
+
}, taxAmount: taxAmount, grossTotal: grossTotal });
|
|
1319
|
+
},
|
|
1320
|
+
removePromoCode: function (state, action) {
|
|
1321
|
+
console.log('removePromoCode', action);
|
|
1322
|
+
var netTotal = state.netTotal, taxRate = state.taxRate;
|
|
1323
|
+
var taxAmount = applyTax(taxRate, netTotal);
|
|
1324
|
+
var grossTotal = netTotal + taxAmount;
|
|
1325
|
+
return __assign(__assign({}, state), { promoCode: initialState.promoCode, taxAmount: taxAmount, grossTotal: grossTotal });
|
|
1326
|
+
},
|
|
1327
|
+
addToCart: function (state, action) {
|
|
1328
|
+
var _a = action.payload, options = _a.options, item = _a.item;
|
|
1329
|
+
var newTotal = state.netTotal + options.selectedPrice;
|
|
1330
|
+
var taxAmount = newTotal * (state.taxRate.percentage / 100);
|
|
1331
|
+
var grossTotal = newTotal + taxAmount;
|
|
1332
|
+
var addItem = item ? __assign(__assign({}, item), { options: options }) : null;
|
|
1333
|
+
if (!addItem) {
|
|
1334
|
+
return state;
|
|
1335
|
+
}
|
|
1336
|
+
var addedItems = __spreadArray(__spreadArray([], state.addedItems, true), [addItem], false);
|
|
1337
|
+
return __assign(__assign({}, state), { addedItems: addedItems, netTotal: newTotal, grossTotal: grossTotal });
|
|
1338
|
+
},
|
|
1339
|
+
updateCart: function (state, action) {
|
|
1340
|
+
var options = action.payload.options;
|
|
1341
|
+
return __assign(__assign({}, state), { addedItems: state.addedItems.map(function (item) {
|
|
1342
|
+
return item && __assign(__assign({}, item), { options: options });
|
|
1343
|
+
}) });
|
|
1344
|
+
},
|
|
1345
|
+
removeFromCart: function (state, action) {
|
|
1346
|
+
var _a = action.payload, id = _a.id, price = _a.price;
|
|
1347
|
+
var newTotal = state.netTotal - price;
|
|
1348
|
+
var taxAmount = newTotal * (state.taxRate.percentage / 100);
|
|
1349
|
+
var grossTotal = newTotal + taxAmount;
|
|
1350
|
+
return __assign(__assign({}, state), { addedItems: state.addedItems.filter(function (item) { return item && item.uuid !== id; }), netTotal: newTotal, grossTotal: grossTotal });
|
|
1351
|
+
},
|
|
1352
|
+
toggleCart: function (state, action) {
|
|
1353
|
+
return __assign(__assign({}, state), { open: action.payload });
|
|
1354
|
+
},
|
|
1355
|
+
emptyCart: function () { return initialState; },
|
|
1356
|
+
},
|
|
1357
|
+
selectors: {
|
|
1358
|
+
selectMediaInCart: function (cart) { return cart.addedItems; },
|
|
1359
|
+
selectCartTotal: function (cart) { return cart.grossTotal; },
|
|
1360
|
+
selectCartNetTotal: function (cart) { return cart.netTotal; },
|
|
1361
|
+
selectCartTaxRate: function (cart) { return cart.taxRate; },
|
|
1362
|
+
selectCartTaxAmount: function (cart) { return cart.taxAmount; },
|
|
1363
|
+
selectCartCount: function (cart) { return cart.addedItems.length; },
|
|
1364
|
+
selectCartStatus: function (cart) { return cart.open; },
|
|
1365
|
+
selectPromoCode: function (cart) { return cart.promoCode; },
|
|
1366
|
+
},
|
|
1367
|
+
});
|
|
1368
|
+
var setTaxRate = (_a = cartSlice.actions, _a.setTaxRate), resetTaxRate = _a.resetTaxRate, setPromoCode = _a.setPromoCode, removePromoCode = _a.removePromoCode, addToCart = _a.addToCart, updateCart = _a.updateCart, removeFromCart = _a.removeFromCart, emptyCart = _a.emptyCart, toggleCart = _a.toggleCart;
|
|
1369
|
+
var selectMediaInCart = (_b = cartSlice.selectors, _b.selectMediaInCart), selectCartTotal = _b.selectCartTotal, selectCartNetTotal = _b.selectCartNetTotal, selectCartTaxRate = _b.selectCartTaxRate, selectCartTaxAmount = _b.selectCartTaxAmount, selectCartCount = _b.selectCartCount, selectCartStatus = _b.selectCartStatus, selectPromoCode = _b.selectPromoCode;
|
|
1370
|
+
var selectCartItems = toolkit.createSelector([selectMediaInCart], function (items) {
|
|
1371
|
+
return items.map(function (item) {
|
|
1372
|
+
return {
|
|
1373
|
+
title: item.title || item.generatedTitle,
|
|
1374
|
+
file: "".concat(item.sku, ".mp4"),
|
|
1375
|
+
options: item.options,
|
|
1376
|
+
script: item.script,
|
|
1377
|
+
};
|
|
1378
|
+
});
|
|
1379
|
+
});
|
|
1380
|
+
var selectCartItemsIds = toolkit.createSelector([selectMediaInCart], function (items) {
|
|
1381
|
+
return items.map(function (item) { return item.uuid; });
|
|
1382
|
+
});
|
|
1383
|
+
cartSlice.reducer;
|
|
1220
1384
|
|
|
1221
1385
|
var useLoggedIn = function () {
|
|
1222
1386
|
var isLoggedIn = reactRedux.useSelector(isAuthenticated);
|
|
@@ -1249,13 +1413,7 @@ function createPersistStorage() {
|
|
|
1249
1413
|
}
|
|
1250
1414
|
|
|
1251
1415
|
// Infer the `RootState` type from the root reducer
|
|
1252
|
-
var rootReducer = toolkit.combineSlices(authSlice, authApi, contentApi, paymentApi);
|
|
1253
|
-
// export interface RootState {
|
|
1254
|
-
// [authSlice.name]: ReturnType<typeof authSlice.reducer>;
|
|
1255
|
-
// [authApi.reducerPath]: ReturnType<typeof authApi.reducer>;
|
|
1256
|
-
// [contentApi.reducerPath]: ReturnType<typeof contentApi.reducer>;
|
|
1257
|
-
// [paymentApi.reducerPath]: ReturnType<typeof paymentApi.reducer>;
|
|
1258
|
-
// }
|
|
1416
|
+
var rootReducer = toolkit.combineSlices(cartSlice, authSlice, authApi, contentApi, paymentApi);
|
|
1259
1417
|
// eg. ['auth', 'creating'], or an empty array if you don't want to whitelist any.
|
|
1260
1418
|
// const storageWhiteList: string[] = [];
|
|
1261
1419
|
var storageBlackList = [];
|
|
@@ -1313,9 +1471,6 @@ var makeNativeStore = function () {
|
|
|
1313
1471
|
};
|
|
1314
1472
|
var makeWebStore = function () {
|
|
1315
1473
|
var storage = createPersistStorage();
|
|
1316
|
-
// if (process.env.NEXT_PUBLIC_STORE_BLACKLIST) {
|
|
1317
|
-
// storageBlackList.push(process.env.NEXT_PUBLIC_STORE_BLACKLIST);
|
|
1318
|
-
// }
|
|
1319
1474
|
storageBlackList.push(paymentApi.reducerPath, authApi.reducerPath, contentApi.reducerPath);
|
|
1320
1475
|
var persistConfig = {
|
|
1321
1476
|
key: 'root',
|
|
@@ -1353,9 +1508,12 @@ var makeWebStore = function () {
|
|
|
1353
1508
|
var nativeStore = !isWeb && makeNativeStore();
|
|
1354
1509
|
var webStore = isWeb && makeWebStore();
|
|
1355
1510
|
|
|
1511
|
+
exports.addToCart = addToCart;
|
|
1356
1512
|
exports.authApi = authApi;
|
|
1357
1513
|
exports.authSlice = authSlice;
|
|
1514
|
+
exports.cartSlice = cartSlice;
|
|
1358
1515
|
exports.contentApi = contentApi;
|
|
1516
|
+
exports.emptyCart = emptyCart;
|
|
1359
1517
|
exports.formatAuthSession = formatAuthSession;
|
|
1360
1518
|
exports.formatChallengeDays = formatChallengeDays;
|
|
1361
1519
|
exports.formatChallenges = formatChallenges;
|
|
@@ -1364,6 +1522,7 @@ exports.formatFaqs = formatFaqs;
|
|
|
1364
1522
|
exports.formatFedaratedSession = formatFedaratedSession;
|
|
1365
1523
|
exports.formatGuests = formatGuests;
|
|
1366
1524
|
exports.formatLongform = formatLongform;
|
|
1525
|
+
exports.formatMediaItem = formatMediaItem;
|
|
1367
1526
|
exports.formatPages = formatPages;
|
|
1368
1527
|
exports.formatPress = formatPress;
|
|
1369
1528
|
exports.formatPromos = formatPromos;
|
|
@@ -1387,17 +1546,34 @@ exports.isVerifying = isVerifying;
|
|
|
1387
1546
|
exports.logout = logout;
|
|
1388
1547
|
exports.nativeStore = nativeStore;
|
|
1389
1548
|
exports.paymentApi = paymentApi;
|
|
1549
|
+
exports.removeFromCart = removeFromCart;
|
|
1550
|
+
exports.removePromoCode = removePromoCode;
|
|
1390
1551
|
exports.resetCreating = resetCreating;
|
|
1552
|
+
exports.resetTaxRate = resetTaxRate;
|
|
1391
1553
|
exports.selectAccessToken = selectAccessToken;
|
|
1554
|
+
exports.selectCartCount = selectCartCount;
|
|
1555
|
+
exports.selectCartItems = selectCartItems;
|
|
1556
|
+
exports.selectCartItemsIds = selectCartItemsIds;
|
|
1557
|
+
exports.selectCartNetTotal = selectCartNetTotal;
|
|
1558
|
+
exports.selectCartStatus = selectCartStatus;
|
|
1559
|
+
exports.selectCartTaxAmount = selectCartTaxAmount;
|
|
1560
|
+
exports.selectCartTaxRate = selectCartTaxRate;
|
|
1561
|
+
exports.selectCartTotal = selectCartTotal;
|
|
1392
1562
|
exports.selectCurrentUser = selectCurrentUser;
|
|
1393
1563
|
exports.selectCurrentUserRefreshToken = selectCurrentUserRefreshToken;
|
|
1394
1564
|
exports.selectCurrentUserSub = selectCurrentUserSub;
|
|
1565
|
+
exports.selectMediaInCart = selectMediaInCart;
|
|
1566
|
+
exports.selectPromoCode = selectPromoCode;
|
|
1395
1567
|
exports.selectRefreshToken = selectRefreshToken;
|
|
1396
1568
|
exports.selectSubscription = selectSubscription;
|
|
1397
1569
|
exports.selectSubscriptionPrice = selectSubscriptionPrice;
|
|
1398
1570
|
exports.selectUserSubscriptionStatus = selectUserSubscriptionStatus;
|
|
1399
1571
|
exports.selectUserTokens = selectUserTokens;
|
|
1400
1572
|
exports.setCredentials = setCredentials;
|
|
1573
|
+
exports.setPromoCode = setPromoCode;
|
|
1574
|
+
exports.setTaxRate = setTaxRate;
|
|
1575
|
+
exports.toggleCart = toggleCart;
|
|
1576
|
+
exports.updateCart = updateCart;
|
|
1401
1577
|
exports.updateSubscription = updateSubscription;
|
|
1402
1578
|
exports.useAppDispatch = useAppDispatch;
|
|
1403
1579
|
exports.useAppSelector = useAppSelector;
|