@lodashventure/medusa-membership 0.0.6
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/.medusa/server/src/admin/index.js +2039 -0
- package/.medusa/server/src/admin/index.mjs +2038 -0
- package/.medusa/server/src/api/admin/member-tiers/[id]/route.js +40 -0
- package/.medusa/server/src/api/admin/member-tiers/route.js +49 -0
- package/.medusa/server/src/api/admin/membership/config/[store_id]/route.js +43 -0
- package/.medusa/server/src/api/admin/membership-consents/[id]/route.js +40 -0
- package/.medusa/server/src/api/admin/membership-consents/route.js +48 -0
- package/.medusa/server/src/api/admin/promotions/[id]/update-collectable/route.js +34 -0
- package/.medusa/server/src/api/middlewares/consent.js +32 -0
- package/.medusa/server/src/api/middlewares/customers.js +23 -0
- package/.medusa/server/src/api/middlewares/member-tiers.js +38 -0
- package/.medusa/server/src/api/middlewares/notifications.js +27 -0
- package/.medusa/server/src/api/middlewares/promotion-codes.js +22 -0
- package/.medusa/server/src/api/middlewares/wishlist.js +27 -0
- package/.medusa/server/src/api/middlewares.js +26 -0
- package/.medusa/server/src/api/store/customers/me/consents/[keyId]/route.js +22 -0
- package/.medusa/server/src/api/store/customers/me/consents/route.js +15 -0
- package/.medusa/server/src/api/store/customers/me/notifications/[key]/route.js +21 -0
- package/.medusa/server/src/api/store/customers/me/notifications/route.js +15 -0
- package/.medusa/server/src/api/store/customers/me/promotion-codes/route.js +20 -0
- package/.medusa/server/src/api/store/customers/me/wishlist/[variant_id]/route.js +17 -0
- package/.medusa/server/src/api/store/customers/me/wishlist/route.js +61 -0
- package/.medusa/server/src/api/store/promotion-codes/route.js +66 -0
- package/.medusa/server/src/api/utils/middlewares/checkFeatureFlag.js +18 -0
- package/.medusa/server/src/links/customer-membership.js +10 -0
- package/.medusa/server/src/links/promotion-usable-promo.js +10 -0
- package/.medusa/server/src/links/store-membership-config.js +10 -0
- package/.medusa/server/src/links/wishlisht-customer.js +15 -0
- package/.medusa/server/src/links/wishlisht-item-product-variant.js +16 -0
- package/.medusa/server/src/modules/membership/index.js +13 -0
- package/.medusa/server/src/modules/membership/migrations/Migration20250416034358.js +19 -0
- package/.medusa/server/src/modules/membership/migrations/Migration20250416231624.js +15 -0
- package/.medusa/server/src/modules/membership/migrations/Migration20250418020235.js +14 -0
- package/.medusa/server/src/modules/membership/migrations/Migration20250420014232.js +17 -0
- package/.medusa/server/src/modules/membership/migrations/Migration20250420050937.js +15 -0
- package/.medusa/server/src/modules/membership/migrations/Migration20250421010109.js +15 -0
- package/.medusa/server/src/modules/membership/migrations/Migration20250421011451.js +15 -0
- package/.medusa/server/src/modules/membership/migrations/Migration20250422230822.js +14 -0
- package/.medusa/server/src/modules/membership/migrations/Migration20250423021328.js +23 -0
- package/.medusa/server/src/modules/membership/migrations/Migration20250423021925.js +15 -0
- package/.medusa/server/src/modules/membership/migrations/Migration20250424011144.js +14 -0
- package/.medusa/server/src/modules/membership/migrations/Migration20250507013347.js +14 -0
- package/.medusa/server/src/modules/membership/models/member-tier.js +12 -0
- package/.medusa/server/src/modules/membership/models/membership-config.js +14 -0
- package/.medusa/server/src/modules/membership/models/membership-consent-keys.js +21 -0
- package/.medusa/server/src/modules/membership/models/membership-consent.js +19 -0
- package/.medusa/server/src/modules/membership/models/membership-notification.js +13 -0
- package/.medusa/server/src/modules/membership/models/membership-transaction.js +12 -0
- package/.medusa/server/src/modules/membership/models/membership.js +10 -0
- package/.medusa/server/src/modules/membership/service.js +25 -0
- package/.medusa/server/src/modules/membership/types/membership-config.js +15 -0
- package/.medusa/server/src/modules/promotion-cache/index.js +13 -0
- package/.medusa/server/src/modules/promotion-cache/service.js +126 -0
- package/.medusa/server/src/modules/usable-promo/index.js +13 -0
- package/.medusa/server/src/modules/usable-promo/migrations/Migration20250504044646.js +17 -0
- package/.medusa/server/src/modules/usable-promo/models/usable-promotion.js +10 -0
- package/.medusa/server/src/modules/usable-promo/service.js +13 -0
- package/.medusa/server/src/modules/wishlist/index.js +13 -0
- package/.medusa/server/src/modules/wishlist/migrations/Migration20250424011114.js +23 -0
- package/.medusa/server/src/modules/wishlist/models/wishlist-item.js +23 -0
- package/.medusa/server/src/modules/wishlist/models/wishlist.js +17 -0
- package/.medusa/server/src/modules/wishlist/service.js +15 -0
- package/.medusa/server/src/subscribers/customer-created.js +26 -0
- package/.medusa/server/src/subscribers/order-completed.js +27 -0
- package/.medusa/server/src/subscribers/order-placed.js +17 -0
- package/.medusa/server/src/workflows/hooks/membershipConfigInitialized.js +15 -0
- package/.medusa/server/src/workflows/hooks/promotionDeleteHook.js +26 -0
- package/.medusa/server/src/workflows/member-tier/create-member-tier.js +32 -0
- package/.medusa/server/src/workflows/member-tier/delete-member-tier.js +25 -0
- package/.medusa/server/src/workflows/member-tier/update-member-tier.js +28 -0
- package/.medusa/server/src/workflows/membership/add-membership-points.js +75 -0
- package/.medusa/server/src/workflows/membership/create-membership.js +67 -0
- package/.medusa/server/src/workflows/membership/update-membership.js +35 -0
- package/.medusa/server/src/workflows/membership-consent/create-membership-consent.js +24 -0
- package/.medusa/server/src/workflows/membership-consent/retrieve-membership-consent.js +39 -0
- package/.medusa/server/src/workflows/membership-consent/update-membership-consent.js +27 -0
- package/.medusa/server/src/workflows/membership-consent-key/create-membership-consent-key.js +22 -0
- package/.medusa/server/src/workflows/membership-consent-key/delete-membership-consent-key.js +19 -0
- package/.medusa/server/src/workflows/membership-consent-key/update-membership-consent-key.js +23 -0
- package/.medusa/server/src/workflows/membership-notification/create-membership-notification.js +23 -0
- package/.medusa/server/src/workflows/membership-notification/retrieve-membership-notification.js +33 -0
- package/.medusa/server/src/workflows/membership-notification/update-membership-notification.js +27 -0
- package/.medusa/server/src/workflows/membership_config/init-membership-config.js +61 -0
- package/.medusa/server/src/workflows/membership_config/retrieve-membership-config.js +24 -0
- package/.medusa/server/src/workflows/membership_config/update-membership-config.js +23 -0
- package/.medusa/server/src/workflows/usable-promo/invalidateUsedPromotionWorkflow.js +28 -0
- package/.medusa/server/src/workflows/usable-promo/updateCollectablePromoWorkflow.js +65 -0
- package/.medusa/server/src/workflows/wishlist/create-wishlist-items.js +45 -0
- package/.medusa/server/src/workflows/wishlist/create-wishlist.js +21 -0
- package/.medusa/server/src/workflows/wishlist/delete-wishlist-items.js +25 -0
- package/README.md +36 -0
- package/package.json +79 -0
|
@@ -0,0 +1,2038 @@
|
|
|
1
|
+
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { defineWidgetConfig, defineRouteConfig } from "@medusajs/admin-sdk";
|
|
3
|
+
import { toast, Container, Heading, Switch, Label, Text, Input, Button, createDataTableColumnHelper, usePrompt, useDataTable, DataTable, Drawer, Textarea } from "@medusajs/ui";
|
|
4
|
+
import { useQuery, useQueryClient, useMutation } from "@tanstack/react-query";
|
|
5
|
+
import Medusa from "@medusajs/js-sdk";
|
|
6
|
+
import { Users } from "@medusajs/icons";
|
|
7
|
+
import { useState, useEffect } from "react";
|
|
8
|
+
function getDefaultExportFromCjs(x) {
|
|
9
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
10
|
+
}
|
|
11
|
+
var axios$3 = { exports: {} };
|
|
12
|
+
var bind$2 = function bind(fn, thisArg) {
|
|
13
|
+
return function wrap() {
|
|
14
|
+
var args = new Array(arguments.length);
|
|
15
|
+
for (var i = 0; i < args.length; i++) {
|
|
16
|
+
args[i] = arguments[i];
|
|
17
|
+
}
|
|
18
|
+
return fn.apply(thisArg, args);
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
var bind$1 = bind$2;
|
|
22
|
+
var toString = Object.prototype.toString;
|
|
23
|
+
function isArray(val) {
|
|
24
|
+
return toString.call(val) === "[object Array]";
|
|
25
|
+
}
|
|
26
|
+
function isUndefined(val) {
|
|
27
|
+
return typeof val === "undefined";
|
|
28
|
+
}
|
|
29
|
+
function isBuffer(val) {
|
|
30
|
+
return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor) && typeof val.constructor.isBuffer === "function" && val.constructor.isBuffer(val);
|
|
31
|
+
}
|
|
32
|
+
function isArrayBuffer(val) {
|
|
33
|
+
return toString.call(val) === "[object ArrayBuffer]";
|
|
34
|
+
}
|
|
35
|
+
function isFormData(val) {
|
|
36
|
+
return typeof FormData !== "undefined" && val instanceof FormData;
|
|
37
|
+
}
|
|
38
|
+
function isArrayBufferView(val) {
|
|
39
|
+
var result;
|
|
40
|
+
if (typeof ArrayBuffer !== "undefined" && ArrayBuffer.isView) {
|
|
41
|
+
result = ArrayBuffer.isView(val);
|
|
42
|
+
} else {
|
|
43
|
+
result = val && val.buffer && val.buffer instanceof ArrayBuffer;
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
function isString(val) {
|
|
48
|
+
return typeof val === "string";
|
|
49
|
+
}
|
|
50
|
+
function isNumber(val) {
|
|
51
|
+
return typeof val === "number";
|
|
52
|
+
}
|
|
53
|
+
function isObject(val) {
|
|
54
|
+
return val !== null && typeof val === "object";
|
|
55
|
+
}
|
|
56
|
+
function isPlainObject(val) {
|
|
57
|
+
if (toString.call(val) !== "[object Object]") {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
var prototype = Object.getPrototypeOf(val);
|
|
61
|
+
return prototype === null || prototype === Object.prototype;
|
|
62
|
+
}
|
|
63
|
+
function isDate(val) {
|
|
64
|
+
return toString.call(val) === "[object Date]";
|
|
65
|
+
}
|
|
66
|
+
function isFile(val) {
|
|
67
|
+
return toString.call(val) === "[object File]";
|
|
68
|
+
}
|
|
69
|
+
function isBlob(val) {
|
|
70
|
+
return toString.call(val) === "[object Blob]";
|
|
71
|
+
}
|
|
72
|
+
function isFunction(val) {
|
|
73
|
+
return toString.call(val) === "[object Function]";
|
|
74
|
+
}
|
|
75
|
+
function isStream(val) {
|
|
76
|
+
return isObject(val) && isFunction(val.pipe);
|
|
77
|
+
}
|
|
78
|
+
function isURLSearchParams(val) {
|
|
79
|
+
return typeof URLSearchParams !== "undefined" && val instanceof URLSearchParams;
|
|
80
|
+
}
|
|
81
|
+
function trim(str) {
|
|
82
|
+
return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, "");
|
|
83
|
+
}
|
|
84
|
+
function isStandardBrowserEnv() {
|
|
85
|
+
if (typeof navigator !== "undefined" && (navigator.product === "ReactNative" || navigator.product === "NativeScript" || navigator.product === "NS")) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
89
|
+
}
|
|
90
|
+
function forEach(obj, fn) {
|
|
91
|
+
if (obj === null || typeof obj === "undefined") {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (typeof obj !== "object") {
|
|
95
|
+
obj = [obj];
|
|
96
|
+
}
|
|
97
|
+
if (isArray(obj)) {
|
|
98
|
+
for (var i = 0, l = obj.length; i < l; i++) {
|
|
99
|
+
fn.call(null, obj[i], i, obj);
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
for (var key in obj) {
|
|
103
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
104
|
+
fn.call(null, obj[key], key, obj);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function merge() {
|
|
110
|
+
var result = {};
|
|
111
|
+
function assignValue(val, key) {
|
|
112
|
+
if (isPlainObject(result[key]) && isPlainObject(val)) {
|
|
113
|
+
result[key] = merge(result[key], val);
|
|
114
|
+
} else if (isPlainObject(val)) {
|
|
115
|
+
result[key] = merge({}, val);
|
|
116
|
+
} else if (isArray(val)) {
|
|
117
|
+
result[key] = val.slice();
|
|
118
|
+
} else {
|
|
119
|
+
result[key] = val;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
for (var i = 0, l = arguments.length; i < l; i++) {
|
|
123
|
+
forEach(arguments[i], assignValue);
|
|
124
|
+
}
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
function extend(a, b, thisArg) {
|
|
128
|
+
forEach(b, function assignValue(val, key) {
|
|
129
|
+
if (thisArg && typeof val === "function") {
|
|
130
|
+
a[key] = bind$1(val, thisArg);
|
|
131
|
+
} else {
|
|
132
|
+
a[key] = val;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
return a;
|
|
136
|
+
}
|
|
137
|
+
function stripBOM(content) {
|
|
138
|
+
if (content.charCodeAt(0) === 65279) {
|
|
139
|
+
content = content.slice(1);
|
|
140
|
+
}
|
|
141
|
+
return content;
|
|
142
|
+
}
|
|
143
|
+
var utils$9 = {
|
|
144
|
+
isArray,
|
|
145
|
+
isArrayBuffer,
|
|
146
|
+
isBuffer,
|
|
147
|
+
isFormData,
|
|
148
|
+
isArrayBufferView,
|
|
149
|
+
isString,
|
|
150
|
+
isNumber,
|
|
151
|
+
isObject,
|
|
152
|
+
isPlainObject,
|
|
153
|
+
isUndefined,
|
|
154
|
+
isDate,
|
|
155
|
+
isFile,
|
|
156
|
+
isBlob,
|
|
157
|
+
isFunction,
|
|
158
|
+
isStream,
|
|
159
|
+
isURLSearchParams,
|
|
160
|
+
isStandardBrowserEnv,
|
|
161
|
+
forEach,
|
|
162
|
+
merge,
|
|
163
|
+
extend,
|
|
164
|
+
trim,
|
|
165
|
+
stripBOM
|
|
166
|
+
};
|
|
167
|
+
var utils$8 = utils$9;
|
|
168
|
+
function encode(val) {
|
|
169
|
+
return encodeURIComponent(val).replace(/%3A/gi, ":").replace(/%24/g, "$").replace(/%2C/gi, ",").replace(/%20/g, "+").replace(/%5B/gi, "[").replace(/%5D/gi, "]");
|
|
170
|
+
}
|
|
171
|
+
var buildURL$1 = function buildURL(url, params, paramsSerializer) {
|
|
172
|
+
if (!params) {
|
|
173
|
+
return url;
|
|
174
|
+
}
|
|
175
|
+
var serializedParams;
|
|
176
|
+
if (paramsSerializer) {
|
|
177
|
+
serializedParams = paramsSerializer(params);
|
|
178
|
+
} else if (utils$8.isURLSearchParams(params)) {
|
|
179
|
+
serializedParams = params.toString();
|
|
180
|
+
} else {
|
|
181
|
+
var parts = [];
|
|
182
|
+
utils$8.forEach(params, function serialize(val, key) {
|
|
183
|
+
if (val === null || typeof val === "undefined") {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (utils$8.isArray(val)) {
|
|
187
|
+
key = key + "[]";
|
|
188
|
+
} else {
|
|
189
|
+
val = [val];
|
|
190
|
+
}
|
|
191
|
+
utils$8.forEach(val, function parseValue(v) {
|
|
192
|
+
if (utils$8.isDate(v)) {
|
|
193
|
+
v = v.toISOString();
|
|
194
|
+
} else if (utils$8.isObject(v)) {
|
|
195
|
+
v = JSON.stringify(v);
|
|
196
|
+
}
|
|
197
|
+
parts.push(encode(key) + "=" + encode(v));
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
serializedParams = parts.join("&");
|
|
201
|
+
}
|
|
202
|
+
if (serializedParams) {
|
|
203
|
+
var hashmarkIndex = url.indexOf("#");
|
|
204
|
+
if (hashmarkIndex !== -1) {
|
|
205
|
+
url = url.slice(0, hashmarkIndex);
|
|
206
|
+
}
|
|
207
|
+
url += (url.indexOf("?") === -1 ? "?" : "&") + serializedParams;
|
|
208
|
+
}
|
|
209
|
+
return url;
|
|
210
|
+
};
|
|
211
|
+
var utils$7 = utils$9;
|
|
212
|
+
function InterceptorManager$1() {
|
|
213
|
+
this.handlers = [];
|
|
214
|
+
}
|
|
215
|
+
InterceptorManager$1.prototype.use = function use(fulfilled, rejected, options) {
|
|
216
|
+
this.handlers.push({
|
|
217
|
+
fulfilled,
|
|
218
|
+
rejected,
|
|
219
|
+
synchronous: options ? options.synchronous : false,
|
|
220
|
+
runWhen: options ? options.runWhen : null
|
|
221
|
+
});
|
|
222
|
+
return this.handlers.length - 1;
|
|
223
|
+
};
|
|
224
|
+
InterceptorManager$1.prototype.eject = function eject(id) {
|
|
225
|
+
if (this.handlers[id]) {
|
|
226
|
+
this.handlers[id] = null;
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
InterceptorManager$1.prototype.forEach = function forEach2(fn) {
|
|
230
|
+
utils$7.forEach(this.handlers, function forEachHandler(h) {
|
|
231
|
+
if (h !== null) {
|
|
232
|
+
fn(h);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
var InterceptorManager_1 = InterceptorManager$1;
|
|
237
|
+
var utils$6 = utils$9;
|
|
238
|
+
var normalizeHeaderName$1 = function normalizeHeaderName(headers, normalizedName) {
|
|
239
|
+
utils$6.forEach(headers, function processHeader(value, name) {
|
|
240
|
+
if (name !== normalizedName && name.toUpperCase() === normalizedName.toUpperCase()) {
|
|
241
|
+
headers[normalizedName] = value;
|
|
242
|
+
delete headers[name];
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
var enhanceError$1 = function enhanceError(error, config2, code, request2, response) {
|
|
247
|
+
error.config = config2;
|
|
248
|
+
if (code) {
|
|
249
|
+
error.code = code;
|
|
250
|
+
}
|
|
251
|
+
error.request = request2;
|
|
252
|
+
error.response = response;
|
|
253
|
+
error.isAxiosError = true;
|
|
254
|
+
error.toJSON = function toJSON() {
|
|
255
|
+
return {
|
|
256
|
+
// Standard
|
|
257
|
+
message: this.message,
|
|
258
|
+
name: this.name,
|
|
259
|
+
// Microsoft
|
|
260
|
+
description: this.description,
|
|
261
|
+
number: this.number,
|
|
262
|
+
// Mozilla
|
|
263
|
+
fileName: this.fileName,
|
|
264
|
+
lineNumber: this.lineNumber,
|
|
265
|
+
columnNumber: this.columnNumber,
|
|
266
|
+
stack: this.stack,
|
|
267
|
+
// Axios
|
|
268
|
+
config: this.config,
|
|
269
|
+
code: this.code
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
return error;
|
|
273
|
+
};
|
|
274
|
+
var createError;
|
|
275
|
+
var hasRequiredCreateError;
|
|
276
|
+
function requireCreateError() {
|
|
277
|
+
if (hasRequiredCreateError) return createError;
|
|
278
|
+
hasRequiredCreateError = 1;
|
|
279
|
+
var enhanceError3 = enhanceError$1;
|
|
280
|
+
createError = function createError2(message, config2, code, request2, response) {
|
|
281
|
+
var error = new Error(message);
|
|
282
|
+
return enhanceError3(error, config2, code, request2, response);
|
|
283
|
+
};
|
|
284
|
+
return createError;
|
|
285
|
+
}
|
|
286
|
+
var settle;
|
|
287
|
+
var hasRequiredSettle;
|
|
288
|
+
function requireSettle() {
|
|
289
|
+
if (hasRequiredSettle) return settle;
|
|
290
|
+
hasRequiredSettle = 1;
|
|
291
|
+
var createError2 = requireCreateError();
|
|
292
|
+
settle = function settle2(resolve, reject, response) {
|
|
293
|
+
var validateStatus2 = response.config.validateStatus;
|
|
294
|
+
if (!response.status || !validateStatus2 || validateStatus2(response.status)) {
|
|
295
|
+
resolve(response);
|
|
296
|
+
} else {
|
|
297
|
+
reject(createError2(
|
|
298
|
+
"Request failed with status code " + response.status,
|
|
299
|
+
response.config,
|
|
300
|
+
null,
|
|
301
|
+
response.request,
|
|
302
|
+
response
|
|
303
|
+
));
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
return settle;
|
|
307
|
+
}
|
|
308
|
+
var cookies;
|
|
309
|
+
var hasRequiredCookies;
|
|
310
|
+
function requireCookies() {
|
|
311
|
+
if (hasRequiredCookies) return cookies;
|
|
312
|
+
hasRequiredCookies = 1;
|
|
313
|
+
var utils2 = utils$9;
|
|
314
|
+
cookies = utils2.isStandardBrowserEnv() ? (
|
|
315
|
+
// Standard browser envs support document.cookie
|
|
316
|
+
/* @__PURE__ */ function standardBrowserEnv() {
|
|
317
|
+
return {
|
|
318
|
+
write: function write(name, value, expires, path, domain, secure) {
|
|
319
|
+
var cookie = [];
|
|
320
|
+
cookie.push(name + "=" + encodeURIComponent(value));
|
|
321
|
+
if (utils2.isNumber(expires)) {
|
|
322
|
+
cookie.push("expires=" + new Date(expires).toGMTString());
|
|
323
|
+
}
|
|
324
|
+
if (utils2.isString(path)) {
|
|
325
|
+
cookie.push("path=" + path);
|
|
326
|
+
}
|
|
327
|
+
if (utils2.isString(domain)) {
|
|
328
|
+
cookie.push("domain=" + domain);
|
|
329
|
+
}
|
|
330
|
+
if (secure === true) {
|
|
331
|
+
cookie.push("secure");
|
|
332
|
+
}
|
|
333
|
+
document.cookie = cookie.join("; ");
|
|
334
|
+
},
|
|
335
|
+
read: function read(name) {
|
|
336
|
+
var match = document.cookie.match(new RegExp("(^|;\\s*)(" + name + ")=([^;]*)"));
|
|
337
|
+
return match ? decodeURIComponent(match[3]) : null;
|
|
338
|
+
},
|
|
339
|
+
remove: function remove(name) {
|
|
340
|
+
this.write(name, "", Date.now() - 864e5);
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
}()
|
|
344
|
+
) : (
|
|
345
|
+
// Non standard browser env (web workers, react-native) lack needed support.
|
|
346
|
+
/* @__PURE__ */ function nonStandardBrowserEnv() {
|
|
347
|
+
return {
|
|
348
|
+
write: function write() {
|
|
349
|
+
},
|
|
350
|
+
read: function read() {
|
|
351
|
+
return null;
|
|
352
|
+
},
|
|
353
|
+
remove: function remove() {
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
}()
|
|
357
|
+
);
|
|
358
|
+
return cookies;
|
|
359
|
+
}
|
|
360
|
+
var isAbsoluteURL;
|
|
361
|
+
var hasRequiredIsAbsoluteURL;
|
|
362
|
+
function requireIsAbsoluteURL() {
|
|
363
|
+
if (hasRequiredIsAbsoluteURL) return isAbsoluteURL;
|
|
364
|
+
hasRequiredIsAbsoluteURL = 1;
|
|
365
|
+
isAbsoluteURL = function isAbsoluteURL2(url) {
|
|
366
|
+
return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
|
|
367
|
+
};
|
|
368
|
+
return isAbsoluteURL;
|
|
369
|
+
}
|
|
370
|
+
var combineURLs;
|
|
371
|
+
var hasRequiredCombineURLs;
|
|
372
|
+
function requireCombineURLs() {
|
|
373
|
+
if (hasRequiredCombineURLs) return combineURLs;
|
|
374
|
+
hasRequiredCombineURLs = 1;
|
|
375
|
+
combineURLs = function combineURLs2(baseURL, relativeURL) {
|
|
376
|
+
return relativeURL ? baseURL.replace(/\/+$/, "") + "/" + relativeURL.replace(/^\/+/, "") : baseURL;
|
|
377
|
+
};
|
|
378
|
+
return combineURLs;
|
|
379
|
+
}
|
|
380
|
+
var buildFullPath;
|
|
381
|
+
var hasRequiredBuildFullPath;
|
|
382
|
+
function requireBuildFullPath() {
|
|
383
|
+
if (hasRequiredBuildFullPath) return buildFullPath;
|
|
384
|
+
hasRequiredBuildFullPath = 1;
|
|
385
|
+
var isAbsoluteURL2 = requireIsAbsoluteURL();
|
|
386
|
+
var combineURLs2 = requireCombineURLs();
|
|
387
|
+
buildFullPath = function buildFullPath2(baseURL, requestedURL) {
|
|
388
|
+
if (baseURL && !isAbsoluteURL2(requestedURL)) {
|
|
389
|
+
return combineURLs2(baseURL, requestedURL);
|
|
390
|
+
}
|
|
391
|
+
return requestedURL;
|
|
392
|
+
};
|
|
393
|
+
return buildFullPath;
|
|
394
|
+
}
|
|
395
|
+
var parseHeaders;
|
|
396
|
+
var hasRequiredParseHeaders;
|
|
397
|
+
function requireParseHeaders() {
|
|
398
|
+
if (hasRequiredParseHeaders) return parseHeaders;
|
|
399
|
+
hasRequiredParseHeaders = 1;
|
|
400
|
+
var utils2 = utils$9;
|
|
401
|
+
var ignoreDuplicateOf = [
|
|
402
|
+
"age",
|
|
403
|
+
"authorization",
|
|
404
|
+
"content-length",
|
|
405
|
+
"content-type",
|
|
406
|
+
"etag",
|
|
407
|
+
"expires",
|
|
408
|
+
"from",
|
|
409
|
+
"host",
|
|
410
|
+
"if-modified-since",
|
|
411
|
+
"if-unmodified-since",
|
|
412
|
+
"last-modified",
|
|
413
|
+
"location",
|
|
414
|
+
"max-forwards",
|
|
415
|
+
"proxy-authorization",
|
|
416
|
+
"referer",
|
|
417
|
+
"retry-after",
|
|
418
|
+
"user-agent"
|
|
419
|
+
];
|
|
420
|
+
parseHeaders = function parseHeaders2(headers) {
|
|
421
|
+
var parsed = {};
|
|
422
|
+
var key;
|
|
423
|
+
var val;
|
|
424
|
+
var i;
|
|
425
|
+
if (!headers) {
|
|
426
|
+
return parsed;
|
|
427
|
+
}
|
|
428
|
+
utils2.forEach(headers.split("\n"), function parser(line) {
|
|
429
|
+
i = line.indexOf(":");
|
|
430
|
+
key = utils2.trim(line.substr(0, i)).toLowerCase();
|
|
431
|
+
val = utils2.trim(line.substr(i + 1));
|
|
432
|
+
if (key) {
|
|
433
|
+
if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) {
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
if (key === "set-cookie") {
|
|
437
|
+
parsed[key] = (parsed[key] ? parsed[key] : []).concat([val]);
|
|
438
|
+
} else {
|
|
439
|
+
parsed[key] = parsed[key] ? parsed[key] + ", " + val : val;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
return parsed;
|
|
444
|
+
};
|
|
445
|
+
return parseHeaders;
|
|
446
|
+
}
|
|
447
|
+
var isURLSameOrigin;
|
|
448
|
+
var hasRequiredIsURLSameOrigin;
|
|
449
|
+
function requireIsURLSameOrigin() {
|
|
450
|
+
if (hasRequiredIsURLSameOrigin) return isURLSameOrigin;
|
|
451
|
+
hasRequiredIsURLSameOrigin = 1;
|
|
452
|
+
var utils2 = utils$9;
|
|
453
|
+
isURLSameOrigin = utils2.isStandardBrowserEnv() ? (
|
|
454
|
+
// Standard browser envs have full support of the APIs needed to test
|
|
455
|
+
// whether the request URL is of the same origin as current location.
|
|
456
|
+
function standardBrowserEnv() {
|
|
457
|
+
var msie = /(msie|trident)/i.test(navigator.userAgent);
|
|
458
|
+
var urlParsingNode = document.createElement("a");
|
|
459
|
+
var originURL;
|
|
460
|
+
function resolveURL(url) {
|
|
461
|
+
var href = url;
|
|
462
|
+
if (msie) {
|
|
463
|
+
urlParsingNode.setAttribute("href", href);
|
|
464
|
+
href = urlParsingNode.href;
|
|
465
|
+
}
|
|
466
|
+
urlParsingNode.setAttribute("href", href);
|
|
467
|
+
return {
|
|
468
|
+
href: urlParsingNode.href,
|
|
469
|
+
protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, "") : "",
|
|
470
|
+
host: urlParsingNode.host,
|
|
471
|
+
search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, "") : "",
|
|
472
|
+
hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, "") : "",
|
|
473
|
+
hostname: urlParsingNode.hostname,
|
|
474
|
+
port: urlParsingNode.port,
|
|
475
|
+
pathname: urlParsingNode.pathname.charAt(0) === "/" ? urlParsingNode.pathname : "/" + urlParsingNode.pathname
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
originURL = resolveURL(window.location.href);
|
|
479
|
+
return function isURLSameOrigin2(requestURL) {
|
|
480
|
+
var parsed = utils2.isString(requestURL) ? resolveURL(requestURL) : requestURL;
|
|
481
|
+
return parsed.protocol === originURL.protocol && parsed.host === originURL.host;
|
|
482
|
+
};
|
|
483
|
+
}()
|
|
484
|
+
) : (
|
|
485
|
+
// Non standard browser envs (web workers, react-native) lack needed support.
|
|
486
|
+
/* @__PURE__ */ function nonStandardBrowserEnv() {
|
|
487
|
+
return function isURLSameOrigin2() {
|
|
488
|
+
return true;
|
|
489
|
+
};
|
|
490
|
+
}()
|
|
491
|
+
);
|
|
492
|
+
return isURLSameOrigin;
|
|
493
|
+
}
|
|
494
|
+
var xhr;
|
|
495
|
+
var hasRequiredXhr;
|
|
496
|
+
function requireXhr() {
|
|
497
|
+
if (hasRequiredXhr) return xhr;
|
|
498
|
+
hasRequiredXhr = 1;
|
|
499
|
+
var utils2 = utils$9;
|
|
500
|
+
var settle2 = requireSettle();
|
|
501
|
+
var cookies2 = requireCookies();
|
|
502
|
+
var buildURL3 = buildURL$1;
|
|
503
|
+
var buildFullPath2 = requireBuildFullPath();
|
|
504
|
+
var parseHeaders2 = requireParseHeaders();
|
|
505
|
+
var isURLSameOrigin2 = requireIsURLSameOrigin();
|
|
506
|
+
var createError2 = requireCreateError();
|
|
507
|
+
xhr = function xhrAdapter(config2) {
|
|
508
|
+
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
|
509
|
+
var requestData = config2.data;
|
|
510
|
+
var requestHeaders = config2.headers;
|
|
511
|
+
var responseType = config2.responseType;
|
|
512
|
+
if (utils2.isFormData(requestData)) {
|
|
513
|
+
delete requestHeaders["Content-Type"];
|
|
514
|
+
}
|
|
515
|
+
var request2 = new XMLHttpRequest();
|
|
516
|
+
if (config2.auth) {
|
|
517
|
+
var username = config2.auth.username || "";
|
|
518
|
+
var password = config2.auth.password ? unescape(encodeURIComponent(config2.auth.password)) : "";
|
|
519
|
+
requestHeaders.Authorization = "Basic " + btoa(username + ":" + password);
|
|
520
|
+
}
|
|
521
|
+
var fullPath = buildFullPath2(config2.baseURL, config2.url);
|
|
522
|
+
request2.open(config2.method.toUpperCase(), buildURL3(fullPath, config2.params, config2.paramsSerializer), true);
|
|
523
|
+
request2.timeout = config2.timeout;
|
|
524
|
+
function onloadend() {
|
|
525
|
+
if (!request2) {
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
var responseHeaders = "getAllResponseHeaders" in request2 ? parseHeaders2(request2.getAllResponseHeaders()) : null;
|
|
529
|
+
var responseData = !responseType || responseType === "text" || responseType === "json" ? request2.responseText : request2.response;
|
|
530
|
+
var response = {
|
|
531
|
+
data: responseData,
|
|
532
|
+
status: request2.status,
|
|
533
|
+
statusText: request2.statusText,
|
|
534
|
+
headers: responseHeaders,
|
|
535
|
+
config: config2,
|
|
536
|
+
request: request2
|
|
537
|
+
};
|
|
538
|
+
settle2(resolve, reject, response);
|
|
539
|
+
request2 = null;
|
|
540
|
+
}
|
|
541
|
+
if ("onloadend" in request2) {
|
|
542
|
+
request2.onloadend = onloadend;
|
|
543
|
+
} else {
|
|
544
|
+
request2.onreadystatechange = function handleLoad() {
|
|
545
|
+
if (!request2 || request2.readyState !== 4) {
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
if (request2.status === 0 && !(request2.responseURL && request2.responseURL.indexOf("file:") === 0)) {
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
setTimeout(onloadend);
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
request2.onabort = function handleAbort() {
|
|
555
|
+
if (!request2) {
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
reject(createError2("Request aborted", config2, "ECONNABORTED", request2));
|
|
559
|
+
request2 = null;
|
|
560
|
+
};
|
|
561
|
+
request2.onerror = function handleError() {
|
|
562
|
+
reject(createError2("Network Error", config2, null, request2));
|
|
563
|
+
request2 = null;
|
|
564
|
+
};
|
|
565
|
+
request2.ontimeout = function handleTimeout() {
|
|
566
|
+
var timeoutErrorMessage = "timeout of " + config2.timeout + "ms exceeded";
|
|
567
|
+
if (config2.timeoutErrorMessage) {
|
|
568
|
+
timeoutErrorMessage = config2.timeoutErrorMessage;
|
|
569
|
+
}
|
|
570
|
+
reject(createError2(
|
|
571
|
+
timeoutErrorMessage,
|
|
572
|
+
config2,
|
|
573
|
+
config2.transitional && config2.transitional.clarifyTimeoutError ? "ETIMEDOUT" : "ECONNABORTED",
|
|
574
|
+
request2
|
|
575
|
+
));
|
|
576
|
+
request2 = null;
|
|
577
|
+
};
|
|
578
|
+
if (utils2.isStandardBrowserEnv()) {
|
|
579
|
+
var xsrfValue = (config2.withCredentials || isURLSameOrigin2(fullPath)) && config2.xsrfCookieName ? cookies2.read(config2.xsrfCookieName) : void 0;
|
|
580
|
+
if (xsrfValue) {
|
|
581
|
+
requestHeaders[config2.xsrfHeaderName] = xsrfValue;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
if ("setRequestHeader" in request2) {
|
|
585
|
+
utils2.forEach(requestHeaders, function setRequestHeader(val, key) {
|
|
586
|
+
if (typeof requestData === "undefined" && key.toLowerCase() === "content-type") {
|
|
587
|
+
delete requestHeaders[key];
|
|
588
|
+
} else {
|
|
589
|
+
request2.setRequestHeader(key, val);
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
if (!utils2.isUndefined(config2.withCredentials)) {
|
|
594
|
+
request2.withCredentials = !!config2.withCredentials;
|
|
595
|
+
}
|
|
596
|
+
if (responseType && responseType !== "json") {
|
|
597
|
+
request2.responseType = config2.responseType;
|
|
598
|
+
}
|
|
599
|
+
if (typeof config2.onDownloadProgress === "function") {
|
|
600
|
+
request2.addEventListener("progress", config2.onDownloadProgress);
|
|
601
|
+
}
|
|
602
|
+
if (typeof config2.onUploadProgress === "function" && request2.upload) {
|
|
603
|
+
request2.upload.addEventListener("progress", config2.onUploadProgress);
|
|
604
|
+
}
|
|
605
|
+
if (config2.cancelToken) {
|
|
606
|
+
config2.cancelToken.promise.then(function onCanceled(cancel) {
|
|
607
|
+
if (!request2) {
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
request2.abort();
|
|
611
|
+
reject(cancel);
|
|
612
|
+
request2 = null;
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
if (!requestData) {
|
|
616
|
+
requestData = null;
|
|
617
|
+
}
|
|
618
|
+
request2.send(requestData);
|
|
619
|
+
});
|
|
620
|
+
};
|
|
621
|
+
return xhr;
|
|
622
|
+
}
|
|
623
|
+
var utils$5 = utils$9;
|
|
624
|
+
var normalizeHeaderName2 = normalizeHeaderName$1;
|
|
625
|
+
var enhanceError2 = enhanceError$1;
|
|
626
|
+
var DEFAULT_CONTENT_TYPE = {
|
|
627
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
628
|
+
};
|
|
629
|
+
function setContentTypeIfUnset(headers, value) {
|
|
630
|
+
if (!utils$5.isUndefined(headers) && utils$5.isUndefined(headers["Content-Type"])) {
|
|
631
|
+
headers["Content-Type"] = value;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
function getDefaultAdapter() {
|
|
635
|
+
var adapter;
|
|
636
|
+
if (typeof XMLHttpRequest !== "undefined") {
|
|
637
|
+
adapter = requireXhr();
|
|
638
|
+
} else if (typeof process !== "undefined" && Object.prototype.toString.call(process) === "[object process]") {
|
|
639
|
+
adapter = requireXhr();
|
|
640
|
+
}
|
|
641
|
+
return adapter;
|
|
642
|
+
}
|
|
643
|
+
function stringifySafely(rawValue, parser, encoder) {
|
|
644
|
+
if (utils$5.isString(rawValue)) {
|
|
645
|
+
try {
|
|
646
|
+
(parser || JSON.parse)(rawValue);
|
|
647
|
+
return utils$5.trim(rawValue);
|
|
648
|
+
} catch (e) {
|
|
649
|
+
if (e.name !== "SyntaxError") {
|
|
650
|
+
throw e;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
return (encoder || JSON.stringify)(rawValue);
|
|
655
|
+
}
|
|
656
|
+
var defaults$3 = {
|
|
657
|
+
transitional: {
|
|
658
|
+
silentJSONParsing: true,
|
|
659
|
+
forcedJSONParsing: true,
|
|
660
|
+
clarifyTimeoutError: false
|
|
661
|
+
},
|
|
662
|
+
adapter: getDefaultAdapter(),
|
|
663
|
+
transformRequest: [function transformRequest(data, headers) {
|
|
664
|
+
normalizeHeaderName2(headers, "Accept");
|
|
665
|
+
normalizeHeaderName2(headers, "Content-Type");
|
|
666
|
+
if (utils$5.isFormData(data) || utils$5.isArrayBuffer(data) || utils$5.isBuffer(data) || utils$5.isStream(data) || utils$5.isFile(data) || utils$5.isBlob(data)) {
|
|
667
|
+
return data;
|
|
668
|
+
}
|
|
669
|
+
if (utils$5.isArrayBufferView(data)) {
|
|
670
|
+
return data.buffer;
|
|
671
|
+
}
|
|
672
|
+
if (utils$5.isURLSearchParams(data)) {
|
|
673
|
+
setContentTypeIfUnset(headers, "application/x-www-form-urlencoded;charset=utf-8");
|
|
674
|
+
return data.toString();
|
|
675
|
+
}
|
|
676
|
+
if (utils$5.isObject(data) || headers && headers["Content-Type"] === "application/json") {
|
|
677
|
+
setContentTypeIfUnset(headers, "application/json");
|
|
678
|
+
return stringifySafely(data);
|
|
679
|
+
}
|
|
680
|
+
return data;
|
|
681
|
+
}],
|
|
682
|
+
transformResponse: [function transformResponse(data) {
|
|
683
|
+
var transitional2 = this.transitional;
|
|
684
|
+
var silentJSONParsing = transitional2 && transitional2.silentJSONParsing;
|
|
685
|
+
var forcedJSONParsing = transitional2 && transitional2.forcedJSONParsing;
|
|
686
|
+
var strictJSONParsing = !silentJSONParsing && this.responseType === "json";
|
|
687
|
+
if (strictJSONParsing || forcedJSONParsing && utils$5.isString(data) && data.length) {
|
|
688
|
+
try {
|
|
689
|
+
return JSON.parse(data);
|
|
690
|
+
} catch (e) {
|
|
691
|
+
if (strictJSONParsing) {
|
|
692
|
+
if (e.name === "SyntaxError") {
|
|
693
|
+
throw enhanceError2(e, this, "E_JSON_PARSE");
|
|
694
|
+
}
|
|
695
|
+
throw e;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
return data;
|
|
700
|
+
}],
|
|
701
|
+
/**
|
|
702
|
+
* A timeout in milliseconds to abort a request. If set to 0 (default) a
|
|
703
|
+
* timeout is not created.
|
|
704
|
+
*/
|
|
705
|
+
timeout: 0,
|
|
706
|
+
xsrfCookieName: "XSRF-TOKEN",
|
|
707
|
+
xsrfHeaderName: "X-XSRF-TOKEN",
|
|
708
|
+
maxContentLength: -1,
|
|
709
|
+
maxBodyLength: -1,
|
|
710
|
+
validateStatus: function validateStatus(status) {
|
|
711
|
+
return status >= 200 && status < 300;
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
defaults$3.headers = {
|
|
715
|
+
common: {
|
|
716
|
+
"Accept": "application/json, text/plain, */*"
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
utils$5.forEach(["delete", "get", "head"], function forEachMethodNoData(method) {
|
|
720
|
+
defaults$3.headers[method] = {};
|
|
721
|
+
});
|
|
722
|
+
utils$5.forEach(["post", "put", "patch"], function forEachMethodWithData(method) {
|
|
723
|
+
defaults$3.headers[method] = utils$5.merge(DEFAULT_CONTENT_TYPE);
|
|
724
|
+
});
|
|
725
|
+
var defaults_1 = defaults$3;
|
|
726
|
+
var utils$4 = utils$9;
|
|
727
|
+
var defaults$2 = defaults_1;
|
|
728
|
+
var transformData$1 = function transformData(data, headers, fns) {
|
|
729
|
+
var context = this || defaults$2;
|
|
730
|
+
utils$4.forEach(fns, function transform(fn) {
|
|
731
|
+
data = fn.call(context, data, headers);
|
|
732
|
+
});
|
|
733
|
+
return data;
|
|
734
|
+
};
|
|
735
|
+
var isCancel$1;
|
|
736
|
+
var hasRequiredIsCancel;
|
|
737
|
+
function requireIsCancel() {
|
|
738
|
+
if (hasRequiredIsCancel) return isCancel$1;
|
|
739
|
+
hasRequiredIsCancel = 1;
|
|
740
|
+
isCancel$1 = function isCancel2(value) {
|
|
741
|
+
return !!(value && value.__CANCEL__);
|
|
742
|
+
};
|
|
743
|
+
return isCancel$1;
|
|
744
|
+
}
|
|
745
|
+
var utils$3 = utils$9;
|
|
746
|
+
var transformData2 = transformData$1;
|
|
747
|
+
var isCancel = requireIsCancel();
|
|
748
|
+
var defaults$1 = defaults_1;
|
|
749
|
+
function throwIfCancellationRequested(config2) {
|
|
750
|
+
if (config2.cancelToken) {
|
|
751
|
+
config2.cancelToken.throwIfRequested();
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
var dispatchRequest$1 = function dispatchRequest(config2) {
|
|
755
|
+
throwIfCancellationRequested(config2);
|
|
756
|
+
config2.headers = config2.headers || {};
|
|
757
|
+
config2.data = transformData2.call(
|
|
758
|
+
config2,
|
|
759
|
+
config2.data,
|
|
760
|
+
config2.headers,
|
|
761
|
+
config2.transformRequest
|
|
762
|
+
);
|
|
763
|
+
config2.headers = utils$3.merge(
|
|
764
|
+
config2.headers.common || {},
|
|
765
|
+
config2.headers[config2.method] || {},
|
|
766
|
+
config2.headers
|
|
767
|
+
);
|
|
768
|
+
utils$3.forEach(
|
|
769
|
+
["delete", "get", "head", "post", "put", "patch", "common"],
|
|
770
|
+
function cleanHeaderConfig(method) {
|
|
771
|
+
delete config2.headers[method];
|
|
772
|
+
}
|
|
773
|
+
);
|
|
774
|
+
var adapter = config2.adapter || defaults$1.adapter;
|
|
775
|
+
return adapter(config2).then(function onAdapterResolution(response) {
|
|
776
|
+
throwIfCancellationRequested(config2);
|
|
777
|
+
response.data = transformData2.call(
|
|
778
|
+
config2,
|
|
779
|
+
response.data,
|
|
780
|
+
response.headers,
|
|
781
|
+
config2.transformResponse
|
|
782
|
+
);
|
|
783
|
+
return response;
|
|
784
|
+
}, function onAdapterRejection(reason) {
|
|
785
|
+
if (!isCancel(reason)) {
|
|
786
|
+
throwIfCancellationRequested(config2);
|
|
787
|
+
if (reason && reason.response) {
|
|
788
|
+
reason.response.data = transformData2.call(
|
|
789
|
+
config2,
|
|
790
|
+
reason.response.data,
|
|
791
|
+
reason.response.headers,
|
|
792
|
+
config2.transformResponse
|
|
793
|
+
);
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
return Promise.reject(reason);
|
|
797
|
+
});
|
|
798
|
+
};
|
|
799
|
+
var utils$2 = utils$9;
|
|
800
|
+
var mergeConfig$2 = function mergeConfig(config1, config2) {
|
|
801
|
+
config2 = config2 || {};
|
|
802
|
+
var config3 = {};
|
|
803
|
+
var valueFromConfig2Keys = ["url", "method", "data"];
|
|
804
|
+
var mergeDeepPropertiesKeys = ["headers", "auth", "proxy", "params"];
|
|
805
|
+
var defaultToConfig2Keys = [
|
|
806
|
+
"baseURL",
|
|
807
|
+
"transformRequest",
|
|
808
|
+
"transformResponse",
|
|
809
|
+
"paramsSerializer",
|
|
810
|
+
"timeout",
|
|
811
|
+
"timeoutMessage",
|
|
812
|
+
"withCredentials",
|
|
813
|
+
"adapter",
|
|
814
|
+
"responseType",
|
|
815
|
+
"xsrfCookieName",
|
|
816
|
+
"xsrfHeaderName",
|
|
817
|
+
"onUploadProgress",
|
|
818
|
+
"onDownloadProgress",
|
|
819
|
+
"decompress",
|
|
820
|
+
"maxContentLength",
|
|
821
|
+
"maxBodyLength",
|
|
822
|
+
"maxRedirects",
|
|
823
|
+
"transport",
|
|
824
|
+
"httpAgent",
|
|
825
|
+
"httpsAgent",
|
|
826
|
+
"cancelToken",
|
|
827
|
+
"socketPath",
|
|
828
|
+
"responseEncoding"
|
|
829
|
+
];
|
|
830
|
+
var directMergeKeys = ["validateStatus"];
|
|
831
|
+
function getMergedValue(target, source) {
|
|
832
|
+
if (utils$2.isPlainObject(target) && utils$2.isPlainObject(source)) {
|
|
833
|
+
return utils$2.merge(target, source);
|
|
834
|
+
} else if (utils$2.isPlainObject(source)) {
|
|
835
|
+
return utils$2.merge({}, source);
|
|
836
|
+
} else if (utils$2.isArray(source)) {
|
|
837
|
+
return source.slice();
|
|
838
|
+
}
|
|
839
|
+
return source;
|
|
840
|
+
}
|
|
841
|
+
function mergeDeepProperties(prop) {
|
|
842
|
+
if (!utils$2.isUndefined(config2[prop])) {
|
|
843
|
+
config3[prop] = getMergedValue(config1[prop], config2[prop]);
|
|
844
|
+
} else if (!utils$2.isUndefined(config1[prop])) {
|
|
845
|
+
config3[prop] = getMergedValue(void 0, config1[prop]);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
utils$2.forEach(valueFromConfig2Keys, function valueFromConfig2(prop) {
|
|
849
|
+
if (!utils$2.isUndefined(config2[prop])) {
|
|
850
|
+
config3[prop] = getMergedValue(void 0, config2[prop]);
|
|
851
|
+
}
|
|
852
|
+
});
|
|
853
|
+
utils$2.forEach(mergeDeepPropertiesKeys, mergeDeepProperties);
|
|
854
|
+
utils$2.forEach(defaultToConfig2Keys, function defaultToConfig2(prop) {
|
|
855
|
+
if (!utils$2.isUndefined(config2[prop])) {
|
|
856
|
+
config3[prop] = getMergedValue(void 0, config2[prop]);
|
|
857
|
+
} else if (!utils$2.isUndefined(config1[prop])) {
|
|
858
|
+
config3[prop] = getMergedValue(void 0, config1[prop]);
|
|
859
|
+
}
|
|
860
|
+
});
|
|
861
|
+
utils$2.forEach(directMergeKeys, function merge2(prop) {
|
|
862
|
+
if (prop in config2) {
|
|
863
|
+
config3[prop] = getMergedValue(config1[prop], config2[prop]);
|
|
864
|
+
} else if (prop in config1) {
|
|
865
|
+
config3[prop] = getMergedValue(void 0, config1[prop]);
|
|
866
|
+
}
|
|
867
|
+
});
|
|
868
|
+
var axiosKeys = valueFromConfig2Keys.concat(mergeDeepPropertiesKeys).concat(defaultToConfig2Keys).concat(directMergeKeys);
|
|
869
|
+
var otherKeys = Object.keys(config1).concat(Object.keys(config2)).filter(function filterAxiosKeys(key) {
|
|
870
|
+
return axiosKeys.indexOf(key) === -1;
|
|
871
|
+
});
|
|
872
|
+
utils$2.forEach(otherKeys, mergeDeepProperties);
|
|
873
|
+
return config3;
|
|
874
|
+
};
|
|
875
|
+
const version = "0.21.4";
|
|
876
|
+
const require$$0 = {
|
|
877
|
+
version
|
|
878
|
+
};
|
|
879
|
+
var pkg = require$$0;
|
|
880
|
+
var validators$1 = {};
|
|
881
|
+
["object", "boolean", "number", "function", "string", "symbol"].forEach(function(type, i) {
|
|
882
|
+
validators$1[type] = function validator2(thing) {
|
|
883
|
+
return typeof thing === type || "a" + (i < 1 ? "n " : " ") + type;
|
|
884
|
+
};
|
|
885
|
+
});
|
|
886
|
+
var deprecatedWarnings = {};
|
|
887
|
+
var currentVerArr = pkg.version.split(".");
|
|
888
|
+
function isOlderVersion(version2, thanVersion) {
|
|
889
|
+
var pkgVersionArr = thanVersion ? thanVersion.split(".") : currentVerArr;
|
|
890
|
+
var destVer = version2.split(".");
|
|
891
|
+
for (var i = 0; i < 3; i++) {
|
|
892
|
+
if (pkgVersionArr[i] > destVer[i]) {
|
|
893
|
+
return true;
|
|
894
|
+
} else if (pkgVersionArr[i] < destVer[i]) {
|
|
895
|
+
return false;
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
return false;
|
|
899
|
+
}
|
|
900
|
+
validators$1.transitional = function transitional(validator2, version2, message) {
|
|
901
|
+
var isDeprecated = version2 && isOlderVersion(version2);
|
|
902
|
+
function formatMessage(opt, desc) {
|
|
903
|
+
return "[Axios v" + pkg.version + "] Transitional option '" + opt + "'" + desc + (message ? ". " + message : "");
|
|
904
|
+
}
|
|
905
|
+
return function(value, opt, opts) {
|
|
906
|
+
if (validator2 === false) {
|
|
907
|
+
throw new Error(formatMessage(opt, " has been removed in " + version2));
|
|
908
|
+
}
|
|
909
|
+
if (isDeprecated && !deprecatedWarnings[opt]) {
|
|
910
|
+
deprecatedWarnings[opt] = true;
|
|
911
|
+
console.warn(
|
|
912
|
+
formatMessage(
|
|
913
|
+
opt,
|
|
914
|
+
" has been deprecated since v" + version2 + " and will be removed in the near future"
|
|
915
|
+
)
|
|
916
|
+
);
|
|
917
|
+
}
|
|
918
|
+
return validator2 ? validator2(value, opt, opts) : true;
|
|
919
|
+
};
|
|
920
|
+
};
|
|
921
|
+
function assertOptions(options, schema, allowUnknown) {
|
|
922
|
+
if (typeof options !== "object") {
|
|
923
|
+
throw new TypeError("options must be an object");
|
|
924
|
+
}
|
|
925
|
+
var keys = Object.keys(options);
|
|
926
|
+
var i = keys.length;
|
|
927
|
+
while (i-- > 0) {
|
|
928
|
+
var opt = keys[i];
|
|
929
|
+
var validator2 = schema[opt];
|
|
930
|
+
if (validator2) {
|
|
931
|
+
var value = options[opt];
|
|
932
|
+
var result = value === void 0 || validator2(value, opt, options);
|
|
933
|
+
if (result !== true) {
|
|
934
|
+
throw new TypeError("option " + opt + " must be " + result);
|
|
935
|
+
}
|
|
936
|
+
continue;
|
|
937
|
+
}
|
|
938
|
+
if (allowUnknown !== true) {
|
|
939
|
+
throw Error("Unknown option " + opt);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
var validator$1 = {
|
|
944
|
+
isOlderVersion,
|
|
945
|
+
assertOptions,
|
|
946
|
+
validators: validators$1
|
|
947
|
+
};
|
|
948
|
+
var utils$1 = utils$9;
|
|
949
|
+
var buildURL2 = buildURL$1;
|
|
950
|
+
var InterceptorManager = InterceptorManager_1;
|
|
951
|
+
var dispatchRequest2 = dispatchRequest$1;
|
|
952
|
+
var mergeConfig$1 = mergeConfig$2;
|
|
953
|
+
var validator = validator$1;
|
|
954
|
+
var validators = validator.validators;
|
|
955
|
+
function Axios$1(instanceConfig) {
|
|
956
|
+
this.defaults = instanceConfig;
|
|
957
|
+
this.interceptors = {
|
|
958
|
+
request: new InterceptorManager(),
|
|
959
|
+
response: new InterceptorManager()
|
|
960
|
+
};
|
|
961
|
+
}
|
|
962
|
+
Axios$1.prototype.request = function request(config2) {
|
|
963
|
+
if (typeof config2 === "string") {
|
|
964
|
+
config2 = arguments[1] || {};
|
|
965
|
+
config2.url = arguments[0];
|
|
966
|
+
} else {
|
|
967
|
+
config2 = config2 || {};
|
|
968
|
+
}
|
|
969
|
+
config2 = mergeConfig$1(this.defaults, config2);
|
|
970
|
+
if (config2.method) {
|
|
971
|
+
config2.method = config2.method.toLowerCase();
|
|
972
|
+
} else if (this.defaults.method) {
|
|
973
|
+
config2.method = this.defaults.method.toLowerCase();
|
|
974
|
+
} else {
|
|
975
|
+
config2.method = "get";
|
|
976
|
+
}
|
|
977
|
+
var transitional2 = config2.transitional;
|
|
978
|
+
if (transitional2 !== void 0) {
|
|
979
|
+
validator.assertOptions(transitional2, {
|
|
980
|
+
silentJSONParsing: validators.transitional(validators.boolean, "1.0.0"),
|
|
981
|
+
forcedJSONParsing: validators.transitional(validators.boolean, "1.0.0"),
|
|
982
|
+
clarifyTimeoutError: validators.transitional(validators.boolean, "1.0.0")
|
|
983
|
+
}, false);
|
|
984
|
+
}
|
|
985
|
+
var requestInterceptorChain = [];
|
|
986
|
+
var synchronousRequestInterceptors = true;
|
|
987
|
+
this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
|
|
988
|
+
if (typeof interceptor.runWhen === "function" && interceptor.runWhen(config2) === false) {
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
synchronousRequestInterceptors = synchronousRequestInterceptors && interceptor.synchronous;
|
|
992
|
+
requestInterceptorChain.unshift(interceptor.fulfilled, interceptor.rejected);
|
|
993
|
+
});
|
|
994
|
+
var responseInterceptorChain = [];
|
|
995
|
+
this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
|
|
996
|
+
responseInterceptorChain.push(interceptor.fulfilled, interceptor.rejected);
|
|
997
|
+
});
|
|
998
|
+
var promise;
|
|
999
|
+
if (!synchronousRequestInterceptors) {
|
|
1000
|
+
var chain = [dispatchRequest2, void 0];
|
|
1001
|
+
Array.prototype.unshift.apply(chain, requestInterceptorChain);
|
|
1002
|
+
chain = chain.concat(responseInterceptorChain);
|
|
1003
|
+
promise = Promise.resolve(config2);
|
|
1004
|
+
while (chain.length) {
|
|
1005
|
+
promise = promise.then(chain.shift(), chain.shift());
|
|
1006
|
+
}
|
|
1007
|
+
return promise;
|
|
1008
|
+
}
|
|
1009
|
+
var newConfig = config2;
|
|
1010
|
+
while (requestInterceptorChain.length) {
|
|
1011
|
+
var onFulfilled = requestInterceptorChain.shift();
|
|
1012
|
+
var onRejected = requestInterceptorChain.shift();
|
|
1013
|
+
try {
|
|
1014
|
+
newConfig = onFulfilled(newConfig);
|
|
1015
|
+
} catch (error) {
|
|
1016
|
+
onRejected(error);
|
|
1017
|
+
break;
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
try {
|
|
1021
|
+
promise = dispatchRequest2(newConfig);
|
|
1022
|
+
} catch (error) {
|
|
1023
|
+
return Promise.reject(error);
|
|
1024
|
+
}
|
|
1025
|
+
while (responseInterceptorChain.length) {
|
|
1026
|
+
promise = promise.then(responseInterceptorChain.shift(), responseInterceptorChain.shift());
|
|
1027
|
+
}
|
|
1028
|
+
return promise;
|
|
1029
|
+
};
|
|
1030
|
+
Axios$1.prototype.getUri = function getUri(config2) {
|
|
1031
|
+
config2 = mergeConfig$1(this.defaults, config2);
|
|
1032
|
+
return buildURL2(config2.url, config2.params, config2.paramsSerializer).replace(/^\?/, "");
|
|
1033
|
+
};
|
|
1034
|
+
utils$1.forEach(["delete", "get", "head", "options"], function forEachMethodNoData2(method) {
|
|
1035
|
+
Axios$1.prototype[method] = function(url, config2) {
|
|
1036
|
+
return this.request(mergeConfig$1(config2 || {}, {
|
|
1037
|
+
method,
|
|
1038
|
+
url,
|
|
1039
|
+
data: (config2 || {}).data
|
|
1040
|
+
}));
|
|
1041
|
+
};
|
|
1042
|
+
});
|
|
1043
|
+
utils$1.forEach(["post", "put", "patch"], function forEachMethodWithData2(method) {
|
|
1044
|
+
Axios$1.prototype[method] = function(url, data, config2) {
|
|
1045
|
+
return this.request(mergeConfig$1(config2 || {}, {
|
|
1046
|
+
method,
|
|
1047
|
+
url,
|
|
1048
|
+
data
|
|
1049
|
+
}));
|
|
1050
|
+
};
|
|
1051
|
+
});
|
|
1052
|
+
var Axios_1 = Axios$1;
|
|
1053
|
+
var Cancel_1;
|
|
1054
|
+
var hasRequiredCancel;
|
|
1055
|
+
function requireCancel() {
|
|
1056
|
+
if (hasRequiredCancel) return Cancel_1;
|
|
1057
|
+
hasRequiredCancel = 1;
|
|
1058
|
+
function Cancel(message) {
|
|
1059
|
+
this.message = message;
|
|
1060
|
+
}
|
|
1061
|
+
Cancel.prototype.toString = function toString2() {
|
|
1062
|
+
return "Cancel" + (this.message ? ": " + this.message : "");
|
|
1063
|
+
};
|
|
1064
|
+
Cancel.prototype.__CANCEL__ = true;
|
|
1065
|
+
Cancel_1 = Cancel;
|
|
1066
|
+
return Cancel_1;
|
|
1067
|
+
}
|
|
1068
|
+
var CancelToken_1;
|
|
1069
|
+
var hasRequiredCancelToken;
|
|
1070
|
+
function requireCancelToken() {
|
|
1071
|
+
if (hasRequiredCancelToken) return CancelToken_1;
|
|
1072
|
+
hasRequiredCancelToken = 1;
|
|
1073
|
+
var Cancel = requireCancel();
|
|
1074
|
+
function CancelToken(executor) {
|
|
1075
|
+
if (typeof executor !== "function") {
|
|
1076
|
+
throw new TypeError("executor must be a function.");
|
|
1077
|
+
}
|
|
1078
|
+
var resolvePromise;
|
|
1079
|
+
this.promise = new Promise(function promiseExecutor(resolve) {
|
|
1080
|
+
resolvePromise = resolve;
|
|
1081
|
+
});
|
|
1082
|
+
var token = this;
|
|
1083
|
+
executor(function cancel(message) {
|
|
1084
|
+
if (token.reason) {
|
|
1085
|
+
return;
|
|
1086
|
+
}
|
|
1087
|
+
token.reason = new Cancel(message);
|
|
1088
|
+
resolvePromise(token.reason);
|
|
1089
|
+
});
|
|
1090
|
+
}
|
|
1091
|
+
CancelToken.prototype.throwIfRequested = function throwIfRequested() {
|
|
1092
|
+
if (this.reason) {
|
|
1093
|
+
throw this.reason;
|
|
1094
|
+
}
|
|
1095
|
+
};
|
|
1096
|
+
CancelToken.source = function source() {
|
|
1097
|
+
var cancel;
|
|
1098
|
+
var token = new CancelToken(function executor(c) {
|
|
1099
|
+
cancel = c;
|
|
1100
|
+
});
|
|
1101
|
+
return {
|
|
1102
|
+
token,
|
|
1103
|
+
cancel
|
|
1104
|
+
};
|
|
1105
|
+
};
|
|
1106
|
+
CancelToken_1 = CancelToken;
|
|
1107
|
+
return CancelToken_1;
|
|
1108
|
+
}
|
|
1109
|
+
var spread;
|
|
1110
|
+
var hasRequiredSpread;
|
|
1111
|
+
function requireSpread() {
|
|
1112
|
+
if (hasRequiredSpread) return spread;
|
|
1113
|
+
hasRequiredSpread = 1;
|
|
1114
|
+
spread = function spread2(callback) {
|
|
1115
|
+
return function wrap(arr) {
|
|
1116
|
+
return callback.apply(null, arr);
|
|
1117
|
+
};
|
|
1118
|
+
};
|
|
1119
|
+
return spread;
|
|
1120
|
+
}
|
|
1121
|
+
var isAxiosError;
|
|
1122
|
+
var hasRequiredIsAxiosError;
|
|
1123
|
+
function requireIsAxiosError() {
|
|
1124
|
+
if (hasRequiredIsAxiosError) return isAxiosError;
|
|
1125
|
+
hasRequiredIsAxiosError = 1;
|
|
1126
|
+
isAxiosError = function isAxiosError2(payload) {
|
|
1127
|
+
return typeof payload === "object" && payload.isAxiosError === true;
|
|
1128
|
+
};
|
|
1129
|
+
return isAxiosError;
|
|
1130
|
+
}
|
|
1131
|
+
var utils = utils$9;
|
|
1132
|
+
var bind2 = bind$2;
|
|
1133
|
+
var Axios = Axios_1;
|
|
1134
|
+
var mergeConfig2 = mergeConfig$2;
|
|
1135
|
+
var defaults = defaults_1;
|
|
1136
|
+
function createInstance(defaultConfig) {
|
|
1137
|
+
var context = new Axios(defaultConfig);
|
|
1138
|
+
var instance = bind2(Axios.prototype.request, context);
|
|
1139
|
+
utils.extend(instance, Axios.prototype, context);
|
|
1140
|
+
utils.extend(instance, context);
|
|
1141
|
+
return instance;
|
|
1142
|
+
}
|
|
1143
|
+
var axios$2 = createInstance(defaults);
|
|
1144
|
+
axios$2.Axios = Axios;
|
|
1145
|
+
axios$2.create = function create(instanceConfig) {
|
|
1146
|
+
return createInstance(mergeConfig2(axios$2.defaults, instanceConfig));
|
|
1147
|
+
};
|
|
1148
|
+
axios$2.Cancel = requireCancel();
|
|
1149
|
+
axios$2.CancelToken = requireCancelToken();
|
|
1150
|
+
axios$2.isCancel = requireIsCancel();
|
|
1151
|
+
axios$2.all = function all(promises) {
|
|
1152
|
+
return Promise.all(promises);
|
|
1153
|
+
};
|
|
1154
|
+
axios$2.spread = requireSpread();
|
|
1155
|
+
axios$2.isAxiosError = requireIsAxiosError();
|
|
1156
|
+
axios$3.exports = axios$2;
|
|
1157
|
+
axios$3.exports.default = axios$2;
|
|
1158
|
+
var axiosExports = axios$3.exports;
|
|
1159
|
+
var axios = axiosExports;
|
|
1160
|
+
const axios$1 = /* @__PURE__ */ getDefaultExportFromCjs(axios);
|
|
1161
|
+
const useMembershipConfig = (storeId, options) => {
|
|
1162
|
+
return useQuery({
|
|
1163
|
+
...options,
|
|
1164
|
+
queryKey: ["membership-config", storeId],
|
|
1165
|
+
queryFn: async () => {
|
|
1166
|
+
if (!storeId) {
|
|
1167
|
+
throw new Error("No store id found");
|
|
1168
|
+
}
|
|
1169
|
+
const { data: config2 } = await axios$1.get(
|
|
1170
|
+
`/admin/membership/config/${storeId}`
|
|
1171
|
+
);
|
|
1172
|
+
return config2;
|
|
1173
|
+
}
|
|
1174
|
+
});
|
|
1175
|
+
};
|
|
1176
|
+
const sdk = new Medusa({
|
|
1177
|
+
baseUrl: "/",
|
|
1178
|
+
debug: false,
|
|
1179
|
+
auth: {
|
|
1180
|
+
type: "session"
|
|
1181
|
+
}
|
|
1182
|
+
});
|
|
1183
|
+
const useStore = () => {
|
|
1184
|
+
return useQuery({
|
|
1185
|
+
queryFn: async () => {
|
|
1186
|
+
var _a;
|
|
1187
|
+
const response = await sdk.admin.store.list();
|
|
1188
|
+
const activeStore = (_a = response.stores) == null ? void 0 : _a[0];
|
|
1189
|
+
if (!activeStore) {
|
|
1190
|
+
throw new Error("No active store found");
|
|
1191
|
+
}
|
|
1192
|
+
return activeStore;
|
|
1193
|
+
},
|
|
1194
|
+
queryKey: ["store"]
|
|
1195
|
+
});
|
|
1196
|
+
};
|
|
1197
|
+
const usePromotionCollectable = (id) => {
|
|
1198
|
+
return useQuery({
|
|
1199
|
+
queryKey: ["promotion-collectable", id],
|
|
1200
|
+
queryFn: () => axios$1.get(`/admin/promotions/${id}/update-collectable`)
|
|
1201
|
+
});
|
|
1202
|
+
};
|
|
1203
|
+
const useUpdatePromotionCollectable = (id) => {
|
|
1204
|
+
const queryClient = useQueryClient();
|
|
1205
|
+
return useMutation({
|
|
1206
|
+
mutationFn: (data) => axios$1.patch(`/admin/promotions/${id}/update-collectable`, data),
|
|
1207
|
+
onSuccess: () => {
|
|
1208
|
+
queryClient.invalidateQueries({
|
|
1209
|
+
queryKey: ["promotion-collectable", id]
|
|
1210
|
+
});
|
|
1211
|
+
toast.success("Coupon collection updated successfully", {
|
|
1212
|
+
dismissable: true,
|
|
1213
|
+
duration: 2500
|
|
1214
|
+
});
|
|
1215
|
+
},
|
|
1216
|
+
onError: () => {
|
|
1217
|
+
toast.error("Failed to update coupon collection", {
|
|
1218
|
+
dismissable: true,
|
|
1219
|
+
duration: 2500
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
});
|
|
1223
|
+
};
|
|
1224
|
+
const PromotionWidget = ({ data }) => {
|
|
1225
|
+
const { id } = data;
|
|
1226
|
+
const { data: collectable } = usePromotionCollectable(id);
|
|
1227
|
+
const { data: store } = useStore();
|
|
1228
|
+
const { data: config2 } = useMembershipConfig(store == null ? void 0 : store.id);
|
|
1229
|
+
const { mutate: updateCollectable } = useUpdatePromotionCollectable(id);
|
|
1230
|
+
const handleToggleCollectable = async (checked) => {
|
|
1231
|
+
try {
|
|
1232
|
+
updateCollectable({
|
|
1233
|
+
enabled: checked
|
|
1234
|
+
});
|
|
1235
|
+
toast.success("Coupon collection updated successfully", {
|
|
1236
|
+
dismissable: true,
|
|
1237
|
+
duration: 2500
|
|
1238
|
+
});
|
|
1239
|
+
} catch (error) {
|
|
1240
|
+
toast.error("Failed to update coupon collection", {
|
|
1241
|
+
dismissable: true,
|
|
1242
|
+
duration: 2500
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
};
|
|
1246
|
+
if (!(config2 == null ? void 0 : config2.enable_promotion_collection)) {
|
|
1247
|
+
return null;
|
|
1248
|
+
}
|
|
1249
|
+
if (data.is_automatic) {
|
|
1250
|
+
return null;
|
|
1251
|
+
}
|
|
1252
|
+
return /* @__PURE__ */ jsxs(Container, { className: "divide-y p-6 gap-4", children: [
|
|
1253
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-center justify-between", children: /* @__PURE__ */ jsx(Heading, { level: "h2", children: "Coupon Collection" }) }),
|
|
1254
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 py-2", children: [
|
|
1255
|
+
/* @__PURE__ */ jsx(
|
|
1256
|
+
Switch,
|
|
1257
|
+
{
|
|
1258
|
+
checked: collectable == null ? void 0 : collectable.data.enabled,
|
|
1259
|
+
onCheckedChange: handleToggleCollectable
|
|
1260
|
+
}
|
|
1261
|
+
),
|
|
1262
|
+
/* @__PURE__ */ jsx(Label, { children: "Can be collected by customer" })
|
|
1263
|
+
] })
|
|
1264
|
+
] });
|
|
1265
|
+
};
|
|
1266
|
+
defineWidgetConfig({
|
|
1267
|
+
zone: "promotion.details.side.after"
|
|
1268
|
+
});
|
|
1269
|
+
const useUpdateMembershipConfig = () => {
|
|
1270
|
+
const queryClient = useQueryClient();
|
|
1271
|
+
return useMutation({
|
|
1272
|
+
mutationFn: async ({ storeId, config: config2 }) => {
|
|
1273
|
+
if (!storeId) {
|
|
1274
|
+
throw new Error("No store id found");
|
|
1275
|
+
}
|
|
1276
|
+
const response = await axios$1.patch(
|
|
1277
|
+
`/admin/membership/config/${storeId}`,
|
|
1278
|
+
config2
|
|
1279
|
+
);
|
|
1280
|
+
return response.data;
|
|
1281
|
+
},
|
|
1282
|
+
onSuccess: (data) => {
|
|
1283
|
+
queryClient.invalidateQueries({
|
|
1284
|
+
queryKey: ["membership-config", data.membershipConfig.store_id]
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
1287
|
+
});
|
|
1288
|
+
};
|
|
1289
|
+
const MembershipPage = () => {
|
|
1290
|
+
const { data: store } = useStore();
|
|
1291
|
+
const [config2, setConfig] = useState({
|
|
1292
|
+
enable_membership: false,
|
|
1293
|
+
membership_points_multiplier: 1,
|
|
1294
|
+
enable_membership_notification: false,
|
|
1295
|
+
enable_wishlist: true,
|
|
1296
|
+
enable_promotion_collection: true
|
|
1297
|
+
});
|
|
1298
|
+
const { data: curConfig, error, refetch } = useMembershipConfig(store == null ? void 0 : store.id);
|
|
1299
|
+
const { mutate: saveConfig, isPending } = useUpdateMembershipConfig();
|
|
1300
|
+
const [spendingAmount, setSpendingAmount] = useState(
|
|
1301
|
+
1 / config2.membership_points_multiplier
|
|
1302
|
+
);
|
|
1303
|
+
useEffect(() => {
|
|
1304
|
+
if (curConfig) {
|
|
1305
|
+
setConfig(curConfig);
|
|
1306
|
+
setSpendingAmount(1 / curConfig.membership_points_multiplier);
|
|
1307
|
+
}
|
|
1308
|
+
}, [curConfig]);
|
|
1309
|
+
const handleSave = async () => {
|
|
1310
|
+
var _a, _b;
|
|
1311
|
+
try {
|
|
1312
|
+
await saveConfig({
|
|
1313
|
+
storeId: store == null ? void 0 : store.id,
|
|
1314
|
+
config: config2
|
|
1315
|
+
});
|
|
1316
|
+
toast.success("Settings saved successfully", {
|
|
1317
|
+
dismissable: true,
|
|
1318
|
+
duration: 2500
|
|
1319
|
+
});
|
|
1320
|
+
await refetch();
|
|
1321
|
+
} catch (error2) {
|
|
1322
|
+
if (axios$1.isAxiosError(error2)) {
|
|
1323
|
+
toast.error("Error saving settings", {
|
|
1324
|
+
description: (_b = (_a = error2.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message,
|
|
1325
|
+
dismissable: true,
|
|
1326
|
+
duration: 2500
|
|
1327
|
+
});
|
|
1328
|
+
} else {
|
|
1329
|
+
toast.error("Error saving settings", {
|
|
1330
|
+
dismissable: true,
|
|
1331
|
+
duration: 2500
|
|
1332
|
+
});
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
};
|
|
1336
|
+
if (error || !config2) {
|
|
1337
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
1338
|
+
"Error: ",
|
|
1339
|
+
error == null ? void 0 : error.message
|
|
1340
|
+
] });
|
|
1341
|
+
}
|
|
1342
|
+
return /* @__PURE__ */ jsxs(Container, { className: "p-8 rounded-lg", children: [
|
|
1343
|
+
/* @__PURE__ */ jsx("h1", { className: "text-xl font-semibold mb-4", children: "Membership Settings" }),
|
|
1344
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4", children: [
|
|
1345
|
+
/* @__PURE__ */ jsx(
|
|
1346
|
+
Switch,
|
|
1347
|
+
{
|
|
1348
|
+
checked: config2.enable_membership,
|
|
1349
|
+
onCheckedChange: (checked) => setConfig((prev) => ({ ...prev, enable_membership: checked }))
|
|
1350
|
+
}
|
|
1351
|
+
),
|
|
1352
|
+
"Enable Membership points"
|
|
1353
|
+
] }),
|
|
1354
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4 mt-4", children: [
|
|
1355
|
+
/* @__PURE__ */ jsx(Text, { children: "Spending" }),
|
|
1356
|
+
/* @__PURE__ */ jsx(
|
|
1357
|
+
Input,
|
|
1358
|
+
{
|
|
1359
|
+
className: "w-32",
|
|
1360
|
+
type: "number",
|
|
1361
|
+
value: spendingAmount,
|
|
1362
|
+
onChange: (e) => {
|
|
1363
|
+
const value = Number(e.target.value) || 0;
|
|
1364
|
+
const ratio = 1 / value;
|
|
1365
|
+
setConfig((prev) => ({
|
|
1366
|
+
...prev,
|
|
1367
|
+
membership_points_multiplier: ratio
|
|
1368
|
+
}));
|
|
1369
|
+
setSpendingAmount(value);
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
),
|
|
1373
|
+
/* @__PURE__ */ jsx(Text, { children: "To get 1 point" })
|
|
1374
|
+
] }),
|
|
1375
|
+
/* @__PURE__ */ jsx("hr", { className: "my-4" }),
|
|
1376
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4 my-2", children: [
|
|
1377
|
+
/* @__PURE__ */ jsx(
|
|
1378
|
+
Switch,
|
|
1379
|
+
{
|
|
1380
|
+
checked: config2.enable_membership_notification,
|
|
1381
|
+
onCheckedChange: (checked) => setConfig((prev) => ({
|
|
1382
|
+
...prev,
|
|
1383
|
+
enable_membership_notification: checked
|
|
1384
|
+
}))
|
|
1385
|
+
}
|
|
1386
|
+
),
|
|
1387
|
+
"Enable Membership Notification"
|
|
1388
|
+
] }),
|
|
1389
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4 my-2", children: [
|
|
1390
|
+
/* @__PURE__ */ jsx(
|
|
1391
|
+
Switch,
|
|
1392
|
+
{
|
|
1393
|
+
checked: config2.enable_wishlist,
|
|
1394
|
+
onCheckedChange: (checked) => setConfig((prev) => ({
|
|
1395
|
+
...prev,
|
|
1396
|
+
enable_wishlist: checked
|
|
1397
|
+
}))
|
|
1398
|
+
}
|
|
1399
|
+
),
|
|
1400
|
+
"Enable Membership Wishlist"
|
|
1401
|
+
] }),
|
|
1402
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4 my-2", children: [
|
|
1403
|
+
/* @__PURE__ */ jsx(
|
|
1404
|
+
Switch,
|
|
1405
|
+
{
|
|
1406
|
+
checked: config2.enable_promotion_collection,
|
|
1407
|
+
onCheckedChange: (checked) => setConfig((prev) => ({
|
|
1408
|
+
...prev,
|
|
1409
|
+
enable_promotion_collection: checked
|
|
1410
|
+
}))
|
|
1411
|
+
}
|
|
1412
|
+
),
|
|
1413
|
+
"Enable Promotion Collection"
|
|
1414
|
+
] }),
|
|
1415
|
+
/* @__PURE__ */ jsx(Button, { onClick: handleSave, disabled: isPending, className: "mt-5", children: isPending ? "Saving..." : "Save Settings" })
|
|
1416
|
+
] });
|
|
1417
|
+
};
|
|
1418
|
+
const BannerUpload = () => {
|
|
1419
|
+
return /* @__PURE__ */ jsx(MembershipPage, {});
|
|
1420
|
+
};
|
|
1421
|
+
const config$2 = defineRouteConfig({
|
|
1422
|
+
label: "Membership",
|
|
1423
|
+
icon: Users
|
|
1424
|
+
});
|
|
1425
|
+
const useCreateMembershipConsent = () => {
|
|
1426
|
+
const queryClient = useQueryClient();
|
|
1427
|
+
return useMutation({
|
|
1428
|
+
mutationFn: async (data) => {
|
|
1429
|
+
const response = await axios$1.post("/admin/membership-consents", data);
|
|
1430
|
+
return response.data;
|
|
1431
|
+
},
|
|
1432
|
+
onSuccess: () => {
|
|
1433
|
+
queryClient.invalidateQueries({ queryKey: ["membership-consents"] });
|
|
1434
|
+
}
|
|
1435
|
+
});
|
|
1436
|
+
};
|
|
1437
|
+
const useDeleteMembershipConsent = () => {
|
|
1438
|
+
const queryClient = useQueryClient();
|
|
1439
|
+
return useMutation({
|
|
1440
|
+
mutationFn: async (id) => {
|
|
1441
|
+
await axios$1.delete(`/admin/membership-consents/${id}`);
|
|
1442
|
+
},
|
|
1443
|
+
onSuccess: () => {
|
|
1444
|
+
queryClient.invalidateQueries({ queryKey: ["membership-consents"] });
|
|
1445
|
+
}
|
|
1446
|
+
});
|
|
1447
|
+
};
|
|
1448
|
+
const MEMBERSHIP_TIERS_QUERY_KEY$1 = ["membership-consents"];
|
|
1449
|
+
const useMembershipConsents = () => {
|
|
1450
|
+
return useQuery({
|
|
1451
|
+
queryKey: [...MEMBERSHIP_TIERS_QUERY_KEY$1],
|
|
1452
|
+
queryFn: async () => {
|
|
1453
|
+
const response = await axios$1.get("/admin/membership-consents");
|
|
1454
|
+
return response.data;
|
|
1455
|
+
}
|
|
1456
|
+
});
|
|
1457
|
+
};
|
|
1458
|
+
const useUpdateMembershipConsent = () => {
|
|
1459
|
+
const queryClient = useQueryClient();
|
|
1460
|
+
return useMutation({
|
|
1461
|
+
mutationFn: async (consentKey) => {
|
|
1462
|
+
const response = await axios$1.patch(
|
|
1463
|
+
`/admin/membership-consents/${consentKey.id}`,
|
|
1464
|
+
{
|
|
1465
|
+
name: consentKey.name,
|
|
1466
|
+
description: consentKey.description
|
|
1467
|
+
}
|
|
1468
|
+
);
|
|
1469
|
+
return response.data;
|
|
1470
|
+
},
|
|
1471
|
+
onSuccess: () => {
|
|
1472
|
+
queryClient.invalidateQueries({ queryKey: ["membership-consents"] });
|
|
1473
|
+
}
|
|
1474
|
+
});
|
|
1475
|
+
};
|
|
1476
|
+
const columnHelper$1 = createDataTableColumnHelper();
|
|
1477
|
+
const columns$1 = [
|
|
1478
|
+
columnHelper$1.accessor("name", {
|
|
1479
|
+
header: "Name"
|
|
1480
|
+
}),
|
|
1481
|
+
columnHelper$1.accessor("description", {
|
|
1482
|
+
header: "Description",
|
|
1483
|
+
maxSize: 250
|
|
1484
|
+
})
|
|
1485
|
+
];
|
|
1486
|
+
const MembershipConsentsRenderer = () => {
|
|
1487
|
+
const dialog = usePrompt();
|
|
1488
|
+
const [pagination, setPagination] = useState({
|
|
1489
|
+
pageSize: 1e3,
|
|
1490
|
+
pageIndex: 0
|
|
1491
|
+
});
|
|
1492
|
+
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
|
|
1493
|
+
const [editingConsent, setEditingConsent] = useState(null);
|
|
1494
|
+
const [formData, setFormData] = useState({
|
|
1495
|
+
name: "",
|
|
1496
|
+
description: ""
|
|
1497
|
+
});
|
|
1498
|
+
const { data, isLoading, refetch } = useMembershipConsents();
|
|
1499
|
+
const createConsent = useCreateMembershipConsent();
|
|
1500
|
+
const updateConsent = useUpdateMembershipConsent();
|
|
1501
|
+
const deleteConsent = useDeleteMembershipConsent();
|
|
1502
|
+
const table = useDataTable({
|
|
1503
|
+
columns: columns$1,
|
|
1504
|
+
data: (data == null ? void 0 : data.consent_keys) || [],
|
|
1505
|
+
getRowId: (consent) => consent.id,
|
|
1506
|
+
rowCount: (data == null ? void 0 : data.count) || 0,
|
|
1507
|
+
isLoading,
|
|
1508
|
+
pagination: {
|
|
1509
|
+
state: pagination,
|
|
1510
|
+
onPaginationChange: setPagination
|
|
1511
|
+
},
|
|
1512
|
+
onRowClick: (_, row) => {
|
|
1513
|
+
openDrawer(row.original);
|
|
1514
|
+
}
|
|
1515
|
+
});
|
|
1516
|
+
const handleInputChange = (e) => {
|
|
1517
|
+
const { name, value } = e.target;
|
|
1518
|
+
setFormData((prev) => ({
|
|
1519
|
+
...prev,
|
|
1520
|
+
[name]: name === "min_points" ? Number(value) : value
|
|
1521
|
+
}));
|
|
1522
|
+
};
|
|
1523
|
+
const handleTextAreaChange = (e) => {
|
|
1524
|
+
const { name, value } = e.target;
|
|
1525
|
+
setFormData((prev) => ({
|
|
1526
|
+
...prev,
|
|
1527
|
+
[name]: value
|
|
1528
|
+
}));
|
|
1529
|
+
};
|
|
1530
|
+
const handleReset = () => {
|
|
1531
|
+
setFormData({
|
|
1532
|
+
name: "",
|
|
1533
|
+
description: ""
|
|
1534
|
+
});
|
|
1535
|
+
};
|
|
1536
|
+
const openDrawer = (consentKey) => {
|
|
1537
|
+
if (consentKey) {
|
|
1538
|
+
setEditingConsent(consentKey);
|
|
1539
|
+
setFormData({
|
|
1540
|
+
name: consentKey.name,
|
|
1541
|
+
description: consentKey.description
|
|
1542
|
+
});
|
|
1543
|
+
} else {
|
|
1544
|
+
setEditingConsent(null);
|
|
1545
|
+
handleReset();
|
|
1546
|
+
}
|
|
1547
|
+
setIsDrawerOpen(true);
|
|
1548
|
+
};
|
|
1549
|
+
const closeDrawer = () => {
|
|
1550
|
+
setIsDrawerOpen(false);
|
|
1551
|
+
setEditingConsent(null);
|
|
1552
|
+
handleReset();
|
|
1553
|
+
refetch();
|
|
1554
|
+
};
|
|
1555
|
+
const handleSubmit = async () => {
|
|
1556
|
+
var _a, _b;
|
|
1557
|
+
try {
|
|
1558
|
+
if (!formData.name) {
|
|
1559
|
+
toast.error("Name is required", { dismissable: true, duration: 2500 });
|
|
1560
|
+
return;
|
|
1561
|
+
}
|
|
1562
|
+
if (editingConsent) {
|
|
1563
|
+
await updateConsent.mutateAsync({ id: editingConsent.id, ...formData });
|
|
1564
|
+
toast.success("Consent updated successfully", {
|
|
1565
|
+
dismissable: true,
|
|
1566
|
+
duration: 2500
|
|
1567
|
+
});
|
|
1568
|
+
} else {
|
|
1569
|
+
await createConsent.mutateAsync(formData);
|
|
1570
|
+
toast.success("Consent created successfully", {
|
|
1571
|
+
dismissable: true,
|
|
1572
|
+
duration: 2500
|
|
1573
|
+
});
|
|
1574
|
+
}
|
|
1575
|
+
closeDrawer();
|
|
1576
|
+
} catch (error) {
|
|
1577
|
+
if (axios$1.isAxiosError(error)) {
|
|
1578
|
+
toast.error("Error saving consent", {
|
|
1579
|
+
description: (_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message,
|
|
1580
|
+
dismissable: true,
|
|
1581
|
+
duration: 2500
|
|
1582
|
+
});
|
|
1583
|
+
} else {
|
|
1584
|
+
toast.error("Error saving consent", {
|
|
1585
|
+
dismissable: true,
|
|
1586
|
+
duration: 2500
|
|
1587
|
+
});
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
};
|
|
1591
|
+
const handleDelete = async (id) => {
|
|
1592
|
+
var _a, _b;
|
|
1593
|
+
try {
|
|
1594
|
+
const confirmed = await dialog({
|
|
1595
|
+
title: "Delete Membership Consent",
|
|
1596
|
+
description: `Are you sure you want to delete the \`${editingConsent == null ? void 0 : editingConsent.name}\` consent?`
|
|
1597
|
+
});
|
|
1598
|
+
if (!confirmed) {
|
|
1599
|
+
return;
|
|
1600
|
+
}
|
|
1601
|
+
await deleteConsent.mutateAsync(id);
|
|
1602
|
+
toast.success("Consent deleted successfully", {
|
|
1603
|
+
dismissable: true,
|
|
1604
|
+
duration: 2500
|
|
1605
|
+
});
|
|
1606
|
+
closeDrawer();
|
|
1607
|
+
} catch (error) {
|
|
1608
|
+
if (axios$1.isAxiosError(error)) {
|
|
1609
|
+
toast.error("Error deleting consent", {
|
|
1610
|
+
description: (_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message,
|
|
1611
|
+
dismissable: true,
|
|
1612
|
+
duration: 2500
|
|
1613
|
+
});
|
|
1614
|
+
} else {
|
|
1615
|
+
toast.error("Error deleting consent", {
|
|
1616
|
+
dismissable: true,
|
|
1617
|
+
duration: 2500
|
|
1618
|
+
});
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
};
|
|
1622
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1623
|
+
/* @__PURE__ */ jsx(Container, { className: "flex flex-col p-0 overflow-hidden", children: /* @__PURE__ */ jsxs(DataTable, { instance: table, children: [
|
|
1624
|
+
/* @__PURE__ */ jsxs(DataTable.Toolbar, { className: "flex flex-col items-start justify-between gap-2 md:flex-row md:items-center", children: [
|
|
1625
|
+
/* @__PURE__ */ jsx(Heading, { children: "Membership Consents" }),
|
|
1626
|
+
/* @__PURE__ */ jsx(Button, { onClick: () => openDrawer(), children: "Add Consent" })
|
|
1627
|
+
] }),
|
|
1628
|
+
/* @__PURE__ */ jsx(DataTable.Table, {})
|
|
1629
|
+
] }) }),
|
|
1630
|
+
/* @__PURE__ */ jsx(Drawer, { open: isDrawerOpen, onOpenChange: setIsDrawerOpen, children: /* @__PURE__ */ jsxs(Drawer.Content, { children: [
|
|
1631
|
+
/* @__PURE__ */ jsx(Drawer.Header, { children: /* @__PURE__ */ jsx(Drawer.Title, { children: editingConsent ? "Edit Consent" : "Add Consent" }) }),
|
|
1632
|
+
/* @__PURE__ */ jsxs(Drawer.Body, { "aria-description": "Membership Consent Form", children: [
|
|
1633
|
+
/* @__PURE__ */ jsxs(
|
|
1634
|
+
"div",
|
|
1635
|
+
{
|
|
1636
|
+
className: "space-y-4",
|
|
1637
|
+
"aria-description": "Membership Consent Form",
|
|
1638
|
+
children: [
|
|
1639
|
+
/* @__PURE__ */ jsx(Text, { children: "Name" }),
|
|
1640
|
+
/* @__PURE__ */ jsx(
|
|
1641
|
+
Input,
|
|
1642
|
+
{
|
|
1643
|
+
name: "name",
|
|
1644
|
+
value: formData.name,
|
|
1645
|
+
onChange: handleInputChange
|
|
1646
|
+
}
|
|
1647
|
+
),
|
|
1648
|
+
/* @__PURE__ */ jsx(Text, { children: "Description" }),
|
|
1649
|
+
/* @__PURE__ */ jsx(
|
|
1650
|
+
Textarea,
|
|
1651
|
+
{
|
|
1652
|
+
className: "truncate",
|
|
1653
|
+
name: "description",
|
|
1654
|
+
value: formData.description,
|
|
1655
|
+
onChange: handleTextAreaChange
|
|
1656
|
+
}
|
|
1657
|
+
)
|
|
1658
|
+
]
|
|
1659
|
+
}
|
|
1660
|
+
),
|
|
1661
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2 mt-6", children: [
|
|
1662
|
+
/* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: closeDrawer, children: "Cancel" }),
|
|
1663
|
+
/* @__PURE__ */ jsx(Button, { onClick: handleSubmit, children: editingConsent ? "Update" : "Create" })
|
|
1664
|
+
] })
|
|
1665
|
+
] }),
|
|
1666
|
+
/* @__PURE__ */ jsx(Drawer.Footer, { className: "flex justify-start", children: editingConsent && /* @__PURE__ */ jsx(
|
|
1667
|
+
Button,
|
|
1668
|
+
{
|
|
1669
|
+
variant: "danger",
|
|
1670
|
+
onClick: () => {
|
|
1671
|
+
handleDelete(editingConsent.id);
|
|
1672
|
+
},
|
|
1673
|
+
children: "Delete"
|
|
1674
|
+
}
|
|
1675
|
+
) })
|
|
1676
|
+
] }) })
|
|
1677
|
+
] });
|
|
1678
|
+
};
|
|
1679
|
+
const MembershipConsentPage = () => {
|
|
1680
|
+
return /* @__PURE__ */ jsx(MembershipConsentsRenderer, {});
|
|
1681
|
+
};
|
|
1682
|
+
const config$1 = defineRouteConfig({
|
|
1683
|
+
label: "Membership Consents"
|
|
1684
|
+
});
|
|
1685
|
+
const useCreateMembershipTier = () => {
|
|
1686
|
+
const queryClient = useQueryClient();
|
|
1687
|
+
return useMutation({
|
|
1688
|
+
mutationFn: async (data) => {
|
|
1689
|
+
const response = await axios$1.post("/admin/member-tiers", data);
|
|
1690
|
+
return response.data;
|
|
1691
|
+
},
|
|
1692
|
+
onSuccess: () => {
|
|
1693
|
+
queryClient.invalidateQueries({ queryKey: ["membership-tiers"] });
|
|
1694
|
+
}
|
|
1695
|
+
});
|
|
1696
|
+
};
|
|
1697
|
+
const useDeleteMembershipTier = () => {
|
|
1698
|
+
const queryClient = useQueryClient();
|
|
1699
|
+
return useMutation({
|
|
1700
|
+
mutationFn: async (id) => {
|
|
1701
|
+
await axios$1.delete(`/admin/member-tiers/${id}`);
|
|
1702
|
+
},
|
|
1703
|
+
onSuccess: () => {
|
|
1704
|
+
queryClient.invalidateQueries({ queryKey: ["member-tiers"] });
|
|
1705
|
+
}
|
|
1706
|
+
});
|
|
1707
|
+
};
|
|
1708
|
+
const MEMBERSHIP_TIERS_QUERY_KEY = ["membership-tiers"];
|
|
1709
|
+
const useMembershipTiers = (params = {
|
|
1710
|
+
limit: 15,
|
|
1711
|
+
offset: 0,
|
|
1712
|
+
order: {
|
|
1713
|
+
min_points: "ASC"
|
|
1714
|
+
}
|
|
1715
|
+
}) => {
|
|
1716
|
+
return useQuery({
|
|
1717
|
+
queryKey: [...MEMBERSHIP_TIERS_QUERY_KEY, params],
|
|
1718
|
+
queryFn: async () => {
|
|
1719
|
+
const response = await axios$1.get("/admin/member-tiers", {
|
|
1720
|
+
params
|
|
1721
|
+
});
|
|
1722
|
+
return response.data;
|
|
1723
|
+
}
|
|
1724
|
+
});
|
|
1725
|
+
};
|
|
1726
|
+
const useUpdateMembershipTier = () => {
|
|
1727
|
+
const queryClient = useQueryClient();
|
|
1728
|
+
return useMutation({
|
|
1729
|
+
mutationFn: async (tier) => {
|
|
1730
|
+
const response = await axios$1.patch(`/admin/member-tiers/${tier.id}`, {
|
|
1731
|
+
name: tier.name,
|
|
1732
|
+
description: tier.description,
|
|
1733
|
+
privilege_description: tier.privilege_description,
|
|
1734
|
+
min_points: tier.min_points
|
|
1735
|
+
});
|
|
1736
|
+
return response.data;
|
|
1737
|
+
},
|
|
1738
|
+
onSuccess: () => {
|
|
1739
|
+
queryClient.invalidateQueries({ queryKey: ["member-tiers"] });
|
|
1740
|
+
}
|
|
1741
|
+
});
|
|
1742
|
+
};
|
|
1743
|
+
const columnHelper = createDataTableColumnHelper();
|
|
1744
|
+
const columns = [
|
|
1745
|
+
columnHelper.accessor("min_points", {
|
|
1746
|
+
header: "Min Points"
|
|
1747
|
+
}),
|
|
1748
|
+
columnHelper.accessor("name", {
|
|
1749
|
+
header: "Name"
|
|
1750
|
+
}),
|
|
1751
|
+
columnHelper.accessor("description", {
|
|
1752
|
+
header: "Description",
|
|
1753
|
+
maxSize: 250
|
|
1754
|
+
}),
|
|
1755
|
+
columnHelper.accessor("privilege_description", {
|
|
1756
|
+
header: "Privilege Description",
|
|
1757
|
+
maxSize: 250
|
|
1758
|
+
})
|
|
1759
|
+
];
|
|
1760
|
+
const MembershipTierRenderer = () => {
|
|
1761
|
+
const dialog = usePrompt();
|
|
1762
|
+
const [pagination, setPagination] = useState({
|
|
1763
|
+
pageSize: 1e3,
|
|
1764
|
+
pageIndex: 0
|
|
1765
|
+
});
|
|
1766
|
+
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
|
|
1767
|
+
const [editingTier, setEditingTier] = useState(null);
|
|
1768
|
+
const [formData, setFormData] = useState({
|
|
1769
|
+
name: "",
|
|
1770
|
+
description: "",
|
|
1771
|
+
privilege_description: "",
|
|
1772
|
+
min_points: 0
|
|
1773
|
+
});
|
|
1774
|
+
const { data, isLoading, refetch } = useMembershipTiers({
|
|
1775
|
+
limit: pagination.pageSize,
|
|
1776
|
+
offset: pagination.pageIndex * pagination.pageSize
|
|
1777
|
+
});
|
|
1778
|
+
const createTier = useCreateMembershipTier();
|
|
1779
|
+
const updateTier = useUpdateMembershipTier();
|
|
1780
|
+
const deleteTier = useDeleteMembershipTier();
|
|
1781
|
+
const table = useDataTable({
|
|
1782
|
+
columns,
|
|
1783
|
+
data: (data == null ? void 0 : data.tiers) || [],
|
|
1784
|
+
getRowId: (tier) => tier.id,
|
|
1785
|
+
rowCount: (data == null ? void 0 : data.count) || 0,
|
|
1786
|
+
isLoading,
|
|
1787
|
+
pagination: {
|
|
1788
|
+
state: pagination,
|
|
1789
|
+
onPaginationChange: setPagination
|
|
1790
|
+
},
|
|
1791
|
+
onRowClick: (_, row) => {
|
|
1792
|
+
openDrawer(row.original);
|
|
1793
|
+
}
|
|
1794
|
+
});
|
|
1795
|
+
const handleInputChange = (e) => {
|
|
1796
|
+
const { name, value } = e.target;
|
|
1797
|
+
setFormData((prev) => ({
|
|
1798
|
+
...prev,
|
|
1799
|
+
[name]: name === "min_points" ? Number(value) : value
|
|
1800
|
+
}));
|
|
1801
|
+
};
|
|
1802
|
+
const handleTextAreaChange = (e) => {
|
|
1803
|
+
const { name, value } = e.target;
|
|
1804
|
+
setFormData((prev) => ({
|
|
1805
|
+
...prev,
|
|
1806
|
+
[name]: value
|
|
1807
|
+
}));
|
|
1808
|
+
};
|
|
1809
|
+
const handleReset = () => {
|
|
1810
|
+
setFormData({
|
|
1811
|
+
name: "",
|
|
1812
|
+
description: "",
|
|
1813
|
+
privilege_description: "",
|
|
1814
|
+
min_points: 0
|
|
1815
|
+
});
|
|
1816
|
+
};
|
|
1817
|
+
const openDrawer = (tier) => {
|
|
1818
|
+
if (tier) {
|
|
1819
|
+
setEditingTier(tier);
|
|
1820
|
+
setFormData({
|
|
1821
|
+
name: tier.name,
|
|
1822
|
+
description: tier.description,
|
|
1823
|
+
privilege_description: tier.privilege_description,
|
|
1824
|
+
min_points: tier.min_points
|
|
1825
|
+
});
|
|
1826
|
+
} else {
|
|
1827
|
+
setEditingTier(null);
|
|
1828
|
+
handleReset();
|
|
1829
|
+
}
|
|
1830
|
+
setIsDrawerOpen(true);
|
|
1831
|
+
};
|
|
1832
|
+
const closeDrawer = () => {
|
|
1833
|
+
setIsDrawerOpen(false);
|
|
1834
|
+
setEditingTier(null);
|
|
1835
|
+
handleReset();
|
|
1836
|
+
refetch();
|
|
1837
|
+
};
|
|
1838
|
+
const handleSubmit = async () => {
|
|
1839
|
+
var _a, _b;
|
|
1840
|
+
try {
|
|
1841
|
+
if (!formData.name) {
|
|
1842
|
+
toast.error("Name is required", { dismissable: true, duration: 2500 });
|
|
1843
|
+
return;
|
|
1844
|
+
}
|
|
1845
|
+
if (editingTier) {
|
|
1846
|
+
await updateTier.mutateAsync({ id: editingTier.id, ...formData });
|
|
1847
|
+
toast.success("Tier updated successfully", {
|
|
1848
|
+
dismissable: true,
|
|
1849
|
+
duration: 2500
|
|
1850
|
+
});
|
|
1851
|
+
} else {
|
|
1852
|
+
await createTier.mutateAsync(formData);
|
|
1853
|
+
toast.success("Tier created successfully", {
|
|
1854
|
+
dismissable: true,
|
|
1855
|
+
duration: 2500
|
|
1856
|
+
});
|
|
1857
|
+
}
|
|
1858
|
+
closeDrawer();
|
|
1859
|
+
} catch (error) {
|
|
1860
|
+
if (axios$1.isAxiosError(error)) {
|
|
1861
|
+
toast.error("Error saving tier", {
|
|
1862
|
+
description: (_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message,
|
|
1863
|
+
dismissable: true,
|
|
1864
|
+
duration: 2500
|
|
1865
|
+
});
|
|
1866
|
+
} else {
|
|
1867
|
+
toast.error("Error saving tier", {
|
|
1868
|
+
dismissable: true,
|
|
1869
|
+
duration: 2500
|
|
1870
|
+
});
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
};
|
|
1874
|
+
const handleDelete = async (id) => {
|
|
1875
|
+
var _a, _b;
|
|
1876
|
+
try {
|
|
1877
|
+
const confirmed = await dialog({
|
|
1878
|
+
title: "Delete Membership Tier",
|
|
1879
|
+
description: `Are you sure you want to delete the \`${editingTier == null ? void 0 : editingTier.name}\` tier?`
|
|
1880
|
+
});
|
|
1881
|
+
if (!confirmed) {
|
|
1882
|
+
return;
|
|
1883
|
+
}
|
|
1884
|
+
await deleteTier.mutateAsync(id);
|
|
1885
|
+
toast.success("Tier deleted successfully", {
|
|
1886
|
+
dismissable: true,
|
|
1887
|
+
duration: 2500
|
|
1888
|
+
});
|
|
1889
|
+
closeDrawer();
|
|
1890
|
+
} catch (error) {
|
|
1891
|
+
if (axios$1.isAxiosError(error)) {
|
|
1892
|
+
toast.error("Error deleting tier", {
|
|
1893
|
+
description: (_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message,
|
|
1894
|
+
dismissable: true,
|
|
1895
|
+
duration: 2500
|
|
1896
|
+
});
|
|
1897
|
+
} else {
|
|
1898
|
+
toast.error("Error deleting tier", {
|
|
1899
|
+
dismissable: true,
|
|
1900
|
+
duration: 2500
|
|
1901
|
+
});
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
};
|
|
1905
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1906
|
+
/* @__PURE__ */ jsx(Container, { className: "flex flex-col p-0 overflow-hidden", children: /* @__PURE__ */ jsxs(DataTable, { instance: table, children: [
|
|
1907
|
+
/* @__PURE__ */ jsxs(DataTable.Toolbar, { className: "flex flex-col items-start justify-between gap-2 md:flex-row md:items-center", children: [
|
|
1908
|
+
/* @__PURE__ */ jsx(Heading, { children: "Membership Tiers" }),
|
|
1909
|
+
/* @__PURE__ */ jsx(Button, { onClick: () => openDrawer(), children: "Add Tier" })
|
|
1910
|
+
] }),
|
|
1911
|
+
/* @__PURE__ */ jsx(DataTable.Table, {})
|
|
1912
|
+
] }) }),
|
|
1913
|
+
/* @__PURE__ */ jsx(Drawer, { open: isDrawerOpen, onOpenChange: setIsDrawerOpen, children: /* @__PURE__ */ jsxs(Drawer.Content, { children: [
|
|
1914
|
+
/* @__PURE__ */ jsx(Drawer.Header, { children: /* @__PURE__ */ jsx(Drawer.Title, { children: editingTier ? "Edit Tier" : "Add Tier" }) }),
|
|
1915
|
+
/* @__PURE__ */ jsxs(Drawer.Body, { "aria-description": "Membership Tier Form", children: [
|
|
1916
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-4", "aria-description": "Membership Tier Form", children: [
|
|
1917
|
+
/* @__PURE__ */ jsx(Text, { children: "Name" }),
|
|
1918
|
+
/* @__PURE__ */ jsx(
|
|
1919
|
+
Input,
|
|
1920
|
+
{
|
|
1921
|
+
name: "name",
|
|
1922
|
+
value: formData.name,
|
|
1923
|
+
onChange: handleInputChange
|
|
1924
|
+
}
|
|
1925
|
+
),
|
|
1926
|
+
/* @__PURE__ */ jsx(Text, { children: "Description" }),
|
|
1927
|
+
/* @__PURE__ */ jsx(
|
|
1928
|
+
Textarea,
|
|
1929
|
+
{
|
|
1930
|
+
className: "truncate",
|
|
1931
|
+
name: "description",
|
|
1932
|
+
value: formData.description,
|
|
1933
|
+
onChange: handleTextAreaChange
|
|
1934
|
+
}
|
|
1935
|
+
),
|
|
1936
|
+
/* @__PURE__ */ jsx(Text, { children: "Privilege Description" }),
|
|
1937
|
+
/* @__PURE__ */ jsx(
|
|
1938
|
+
Textarea,
|
|
1939
|
+
{
|
|
1940
|
+
className: "truncate",
|
|
1941
|
+
name: "privilege_description",
|
|
1942
|
+
value: formData.privilege_description,
|
|
1943
|
+
onChange: handleTextAreaChange
|
|
1944
|
+
}
|
|
1945
|
+
),
|
|
1946
|
+
/* @__PURE__ */ jsx(Text, { children: "Points" }),
|
|
1947
|
+
/* @__PURE__ */ jsx(
|
|
1948
|
+
Input,
|
|
1949
|
+
{
|
|
1950
|
+
name: "min_points",
|
|
1951
|
+
type: "number",
|
|
1952
|
+
value: formData.min_points,
|
|
1953
|
+
onChange: handleInputChange
|
|
1954
|
+
}
|
|
1955
|
+
)
|
|
1956
|
+
] }),
|
|
1957
|
+
/* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2 mt-6", children: [
|
|
1958
|
+
/* @__PURE__ */ jsx(Button, { variant: "secondary", onClick: closeDrawer, children: "Cancel" }),
|
|
1959
|
+
/* @__PURE__ */ jsx(Button, { onClick: handleSubmit, children: editingTier ? "Update" : "Create" })
|
|
1960
|
+
] })
|
|
1961
|
+
] }),
|
|
1962
|
+
/* @__PURE__ */ jsx(Drawer.Footer, { className: "flex justify-start", children: editingTier && /* @__PURE__ */ jsx(
|
|
1963
|
+
Button,
|
|
1964
|
+
{
|
|
1965
|
+
variant: "danger",
|
|
1966
|
+
onClick: () => {
|
|
1967
|
+
handleDelete(editingTier.id);
|
|
1968
|
+
},
|
|
1969
|
+
children: "Delete"
|
|
1970
|
+
}
|
|
1971
|
+
) })
|
|
1972
|
+
] }) })
|
|
1973
|
+
] });
|
|
1974
|
+
};
|
|
1975
|
+
const MembershipTierPage = () => {
|
|
1976
|
+
return /* @__PURE__ */ jsx(MembershipTierRenderer, {});
|
|
1977
|
+
};
|
|
1978
|
+
const config = defineRouteConfig({
|
|
1979
|
+
label: "Membership Tiers"
|
|
1980
|
+
});
|
|
1981
|
+
const widgetModule = { widgets: [
|
|
1982
|
+
{
|
|
1983
|
+
Component: PromotionWidget,
|
|
1984
|
+
zone: ["promotion.details.side.after"]
|
|
1985
|
+
}
|
|
1986
|
+
] };
|
|
1987
|
+
const routeModule = {
|
|
1988
|
+
routes: [
|
|
1989
|
+
{
|
|
1990
|
+
Component: BannerUpload,
|
|
1991
|
+
path: "/membership"
|
|
1992
|
+
},
|
|
1993
|
+
{
|
|
1994
|
+
Component: MembershipConsentPage,
|
|
1995
|
+
path: "/membership/member-consents"
|
|
1996
|
+
},
|
|
1997
|
+
{
|
|
1998
|
+
Component: MembershipTierPage,
|
|
1999
|
+
path: "/membership/membertier"
|
|
2000
|
+
}
|
|
2001
|
+
]
|
|
2002
|
+
};
|
|
2003
|
+
const menuItemModule = {
|
|
2004
|
+
menuItems: [
|
|
2005
|
+
{
|
|
2006
|
+
label: config$2.label,
|
|
2007
|
+
icon: config$2.icon,
|
|
2008
|
+
path: "/membership",
|
|
2009
|
+
nested: void 0
|
|
2010
|
+
},
|
|
2011
|
+
{
|
|
2012
|
+
label: config$1.label,
|
|
2013
|
+
icon: void 0,
|
|
2014
|
+
path: "/membership/member-consents",
|
|
2015
|
+
nested: void 0
|
|
2016
|
+
},
|
|
2017
|
+
{
|
|
2018
|
+
label: config.label,
|
|
2019
|
+
icon: void 0,
|
|
2020
|
+
path: "/membership/membertier",
|
|
2021
|
+
nested: void 0
|
|
2022
|
+
}
|
|
2023
|
+
]
|
|
2024
|
+
};
|
|
2025
|
+
const formModule = { customFields: {} };
|
|
2026
|
+
const displayModule = {
|
|
2027
|
+
displays: {}
|
|
2028
|
+
};
|
|
2029
|
+
const plugin = {
|
|
2030
|
+
widgetModule,
|
|
2031
|
+
routeModule,
|
|
2032
|
+
menuItemModule,
|
|
2033
|
+
formModule,
|
|
2034
|
+
displayModule
|
|
2035
|
+
};
|
|
2036
|
+
export {
|
|
2037
|
+
plugin as default
|
|
2038
|
+
};
|