@wtree/payload-ecommerce-coupon 3.78.4 → 3.78.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/README.md +5 -5
- package/dist/browser.d.ts +2 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +2133 -0
- package/dist/browser.js.map +1 -0
- package/dist/browser.mjs +864 -0
- package/dist/browser.mjs.map +1 -0
- package/dist/collections/createReferralProgramsCollection.d.ts.map +1 -1
- package/dist/index.js +60 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -18
- package/dist/index.mjs.map +1 -1
- package/dist/utilities/calculateValues.d.ts.map +1 -1
- package/package.json +18 -2
package/dist/browser.mjs
ADDED
|
@@ -0,0 +1,864 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region node_modules/react/cjs/react.production.js
|
|
25
|
+
/**
|
|
26
|
+
* @license React
|
|
27
|
+
* react.production.js
|
|
28
|
+
*
|
|
29
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
30
|
+
*
|
|
31
|
+
* This source code is licensed under the MIT license found in the
|
|
32
|
+
* LICENSE file in the root directory of this source tree.
|
|
33
|
+
*/
|
|
34
|
+
var require_react_production = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
35
|
+
Symbol.iterator;
|
|
36
|
+
var ReactNoopUpdateQueue = {
|
|
37
|
+
isMounted: function() {
|
|
38
|
+
return !1;
|
|
39
|
+
},
|
|
40
|
+
enqueueForceUpdate: function() {},
|
|
41
|
+
enqueueReplaceState: function() {},
|
|
42
|
+
enqueueSetState: function() {}
|
|
43
|
+
}, assign = Object.assign, emptyObject = {};
|
|
44
|
+
function Component(props, context, updater) {
|
|
45
|
+
this.props = props;
|
|
46
|
+
this.context = context;
|
|
47
|
+
this.refs = emptyObject;
|
|
48
|
+
this.updater = updater || ReactNoopUpdateQueue;
|
|
49
|
+
}
|
|
50
|
+
Component.prototype.isReactComponent = {};
|
|
51
|
+
Component.prototype.setState = function(partialState, callback) {
|
|
52
|
+
if ("object" !== typeof partialState && "function" !== typeof partialState && null != partialState) throw Error("takes an object of state variables to update or a function which returns an object of state variables.");
|
|
53
|
+
this.updater.enqueueSetState(this, partialState, callback, "setState");
|
|
54
|
+
};
|
|
55
|
+
Component.prototype.forceUpdate = function(callback) {
|
|
56
|
+
this.updater.enqueueForceUpdate(this, callback, "forceUpdate");
|
|
57
|
+
};
|
|
58
|
+
function ComponentDummy() {}
|
|
59
|
+
ComponentDummy.prototype = Component.prototype;
|
|
60
|
+
function PureComponent(props, context, updater) {
|
|
61
|
+
this.props = props;
|
|
62
|
+
this.context = context;
|
|
63
|
+
this.refs = emptyObject;
|
|
64
|
+
this.updater = updater || ReactNoopUpdateQueue;
|
|
65
|
+
}
|
|
66
|
+
var pureComponentPrototype = PureComponent.prototype = new ComponentDummy();
|
|
67
|
+
pureComponentPrototype.constructor = PureComponent;
|
|
68
|
+
assign(pureComponentPrototype, Component.prototype);
|
|
69
|
+
pureComponentPrototype.isPureReactComponent = !0;
|
|
70
|
+
Array.isArray;
|
|
71
|
+
var ReactSharedInternals = {
|
|
72
|
+
H: null,
|
|
73
|
+
A: null,
|
|
74
|
+
T: null,
|
|
75
|
+
S: null
|
|
76
|
+
};
|
|
77
|
+
Object.prototype.hasOwnProperty;
|
|
78
|
+
exports.useEffect = function(create, deps) {
|
|
79
|
+
return ReactSharedInternals.H.useEffect(create, deps);
|
|
80
|
+
};
|
|
81
|
+
exports.useState = function(initialState) {
|
|
82
|
+
return ReactSharedInternals.H.useState(initialState);
|
|
83
|
+
};
|
|
84
|
+
}));
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region node_modules/react/index.js
|
|
87
|
+
var require_react = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
88
|
+
module.exports = require_react_production();
|
|
89
|
+
}));
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region node_modules/react/cjs/react-jsx-runtime.production.js
|
|
92
|
+
/**
|
|
93
|
+
* @license React
|
|
94
|
+
* react-jsx-runtime.production.js
|
|
95
|
+
*
|
|
96
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
97
|
+
*
|
|
98
|
+
* This source code is licensed under the MIT license found in the
|
|
99
|
+
* LICENSE file in the root directory of this source tree.
|
|
100
|
+
*/
|
|
101
|
+
var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
102
|
+
var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element");
|
|
103
|
+
function jsxProd(type, config, maybeKey) {
|
|
104
|
+
var key = null;
|
|
105
|
+
void 0 !== maybeKey && (key = "" + maybeKey);
|
|
106
|
+
void 0 !== config.key && (key = "" + config.key);
|
|
107
|
+
if ("key" in config) {
|
|
108
|
+
maybeKey = {};
|
|
109
|
+
for (var propName in config) "key" !== propName && (maybeKey[propName] = config[propName]);
|
|
110
|
+
} else maybeKey = config;
|
|
111
|
+
config = maybeKey.ref;
|
|
112
|
+
return {
|
|
113
|
+
$$typeof: REACT_ELEMENT_TYPE,
|
|
114
|
+
type,
|
|
115
|
+
key,
|
|
116
|
+
ref: void 0 !== config ? config : null,
|
|
117
|
+
props: maybeKey
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
exports.jsx = jsxProd;
|
|
121
|
+
exports.jsxs = jsxProd;
|
|
122
|
+
}));
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region node_modules/react/jsx-runtime.js
|
|
125
|
+
var require_jsx_runtime = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
126
|
+
module.exports = require_react_jsx_runtime_production();
|
|
127
|
+
}));
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/components/PartnerDashboard/EarningsSummary.tsx
|
|
130
|
+
var import_react = /* @__PURE__ */ __toESM(require_react());
|
|
131
|
+
var import_jsx_runtime = require_jsx_runtime();
|
|
132
|
+
const formatCurrency$3 = (amount, currency) => {
|
|
133
|
+
return new Intl.NumberFormat("en-US", {
|
|
134
|
+
style: "currency",
|
|
135
|
+
currency,
|
|
136
|
+
minimumFractionDigits: 2
|
|
137
|
+
}).format(amount);
|
|
138
|
+
};
|
|
139
|
+
const EarningsSummary = ({ stats, currency }) => {
|
|
140
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
141
|
+
className: "partner-widget partner-widget--earnings",
|
|
142
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", {
|
|
143
|
+
className: "partner-widget__title",
|
|
144
|
+
children: "Earnings Summary"
|
|
145
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
146
|
+
className: "partner-widget__content",
|
|
147
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
148
|
+
className: "earnings-grid",
|
|
149
|
+
children: [
|
|
150
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
151
|
+
className: "earnings-card earnings-card--total",
|
|
152
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
153
|
+
className: "earnings-card__label",
|
|
154
|
+
children: "Total Earnings"
|
|
155
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
156
|
+
className: "earnings-card__value",
|
|
157
|
+
children: formatCurrency$3(stats.totalEarnings, currency)
|
|
158
|
+
})]
|
|
159
|
+
}),
|
|
160
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
161
|
+
className: "earnings-card earnings-card--pending",
|
|
162
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
163
|
+
className: "earnings-card__label",
|
|
164
|
+
children: "Pending"
|
|
165
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
166
|
+
className: "earnings-card__value",
|
|
167
|
+
children: formatCurrency$3(stats.pendingEarnings, currency)
|
|
168
|
+
})]
|
|
169
|
+
}),
|
|
170
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
171
|
+
className: "earnings-card earnings-card--paid",
|
|
172
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
173
|
+
className: "earnings-card__label",
|
|
174
|
+
children: "Paid Out"
|
|
175
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
176
|
+
className: "earnings-card__value",
|
|
177
|
+
children: formatCurrency$3(stats.paidEarnings, currency)
|
|
178
|
+
})]
|
|
179
|
+
})
|
|
180
|
+
]
|
|
181
|
+
})
|
|
182
|
+
})]
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region src/components/PartnerDashboard/ReferralPerformance.tsx
|
|
187
|
+
const ReferralPerformance = ({ stats }) => {
|
|
188
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
189
|
+
className: "partner-widget partner-widget--performance",
|
|
190
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", {
|
|
191
|
+
className: "partner-widget__title",
|
|
192
|
+
children: "Referral Performance"
|
|
193
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
194
|
+
className: "partner-widget__content",
|
|
195
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
196
|
+
className: "performance-grid",
|
|
197
|
+
children: [
|
|
198
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
199
|
+
className: "performance-stat",
|
|
200
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
201
|
+
className: "performance-stat__value",
|
|
202
|
+
children: stats.totalReferrals
|
|
203
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
204
|
+
className: "performance-stat__label",
|
|
205
|
+
children: "Total Referrals"
|
|
206
|
+
})]
|
|
207
|
+
}),
|
|
208
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
209
|
+
className: "performance-stat",
|
|
210
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
211
|
+
className: "performance-stat__value",
|
|
212
|
+
children: stats.successfulReferrals
|
|
213
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
214
|
+
className: "performance-stat__label",
|
|
215
|
+
children: "Successful"
|
|
216
|
+
})]
|
|
217
|
+
}),
|
|
218
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
219
|
+
className: "performance-stat",
|
|
220
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
221
|
+
className: "performance-stat__value",
|
|
222
|
+
children: [stats.conversionRate.toFixed(1), "%"]
|
|
223
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
224
|
+
className: "performance-stat__label",
|
|
225
|
+
children: "Conversion Rate"
|
|
226
|
+
})]
|
|
227
|
+
})
|
|
228
|
+
]
|
|
229
|
+
}), stats.monthlyEarnings.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
230
|
+
className: "performance-chart",
|
|
231
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", {
|
|
232
|
+
className: "performance-chart__title",
|
|
233
|
+
children: "Monthly Trend"
|
|
234
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
235
|
+
className: "performance-chart__bars",
|
|
236
|
+
children: stats.monthlyEarnings.map((month, index) => {
|
|
237
|
+
const maxEarnings = Math.max(...stats.monthlyEarnings.map((m) => m.earnings), 1);
|
|
238
|
+
const heightPercent = month.earnings / maxEarnings * 100;
|
|
239
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
240
|
+
className: "performance-chart__bar-container",
|
|
241
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
242
|
+
className: "performance-chart__bar",
|
|
243
|
+
style: { height: `${Math.max(heightPercent, 5)}%` },
|
|
244
|
+
title: `${month.month}: ${month.referrals} referrals`
|
|
245
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
246
|
+
className: "performance-chart__label",
|
|
247
|
+
children: month.month.split(" ")[0]
|
|
248
|
+
})]
|
|
249
|
+
}, index);
|
|
250
|
+
})
|
|
251
|
+
})]
|
|
252
|
+
})]
|
|
253
|
+
})]
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
//#endregion
|
|
257
|
+
//#region src/components/PartnerDashboard/RecentReferrals.tsx
|
|
258
|
+
const formatCurrency$2 = (amount, currency) => {
|
|
259
|
+
return new Intl.NumberFormat("en-US", {
|
|
260
|
+
style: "currency",
|
|
261
|
+
currency,
|
|
262
|
+
minimumFractionDigits: 2
|
|
263
|
+
}).format(amount);
|
|
264
|
+
};
|
|
265
|
+
const formatDate = (dateString) => {
|
|
266
|
+
return new Date(dateString).toLocaleDateString("en-US", {
|
|
267
|
+
month: "short",
|
|
268
|
+
day: "numeric",
|
|
269
|
+
year: "numeric"
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
const RecentReferrals = ({ referrals, currency }) => {
|
|
273
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
274
|
+
className: "partner-widget partner-widget--recent",
|
|
275
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", {
|
|
276
|
+
className: "partner-widget__title",
|
|
277
|
+
children: "Recent Referrals"
|
|
278
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
279
|
+
className: "partner-widget__content",
|
|
280
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
281
|
+
className: "referrals-table",
|
|
282
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
283
|
+
className: "referrals-table__header",
|
|
284
|
+
children: [
|
|
285
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Code" }),
|
|
286
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Order Value" }),
|
|
287
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Commission" }),
|
|
288
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Date" }),
|
|
289
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "Status" })
|
|
290
|
+
]
|
|
291
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
292
|
+
className: "referrals-table__body",
|
|
293
|
+
children: referrals.map((referral) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
294
|
+
className: "referrals-table__row",
|
|
295
|
+
children: [
|
|
296
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
297
|
+
className: "referrals-table__code",
|
|
298
|
+
children: referral.code
|
|
299
|
+
}),
|
|
300
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
301
|
+
className: "referrals-table__value",
|
|
302
|
+
children: formatCurrency$2(referral.orderValue, currency)
|
|
303
|
+
}),
|
|
304
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
305
|
+
className: "referrals-table__commission",
|
|
306
|
+
children: formatCurrency$2(referral.commission, currency)
|
|
307
|
+
}),
|
|
308
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
309
|
+
className: "referrals-table__date",
|
|
310
|
+
children: formatDate(referral.date)
|
|
311
|
+
}),
|
|
312
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
313
|
+
className: `referrals-table__status referrals-table__status--${referral.status}`,
|
|
314
|
+
children: referral.status
|
|
315
|
+
})
|
|
316
|
+
]
|
|
317
|
+
}, referral.id))
|
|
318
|
+
})]
|
|
319
|
+
})
|
|
320
|
+
})]
|
|
321
|
+
});
|
|
322
|
+
};
|
|
323
|
+
//#endregion
|
|
324
|
+
//#region src/components/PartnerDashboard/ReferralCodes.tsx
|
|
325
|
+
const formatCurrency$1 = (amount, currency) => {
|
|
326
|
+
return new Intl.NumberFormat("en-US", {
|
|
327
|
+
style: "currency",
|
|
328
|
+
currency,
|
|
329
|
+
minimumFractionDigits: 2
|
|
330
|
+
}).format(amount);
|
|
331
|
+
};
|
|
332
|
+
const ReferralCodes = ({ codes, currency }) => {
|
|
333
|
+
const [copiedCode, setCopiedCode] = (0, import_react.useState)(null);
|
|
334
|
+
const copyToClipboard = async (code) => {
|
|
335
|
+
try {
|
|
336
|
+
await navigator.clipboard.writeText(code);
|
|
337
|
+
setCopiedCode(code);
|
|
338
|
+
setTimeout(() => setCopiedCode(null), 2e3);
|
|
339
|
+
} catch {
|
|
340
|
+
const textArea = document.createElement("textarea");
|
|
341
|
+
textArea.value = code;
|
|
342
|
+
document.body.appendChild(textArea);
|
|
343
|
+
textArea.select();
|
|
344
|
+
document.execCommand("copy");
|
|
345
|
+
document.body.removeChild(textArea);
|
|
346
|
+
setCopiedCode(code);
|
|
347
|
+
setTimeout(() => setCopiedCode(null), 2e3);
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
351
|
+
className: "partner-widget partner-widget--codes",
|
|
352
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", {
|
|
353
|
+
className: "partner-widget__title",
|
|
354
|
+
children: "Your Referral Codes"
|
|
355
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
356
|
+
className: "partner-widget__content",
|
|
357
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
358
|
+
className: "codes-list",
|
|
359
|
+
children: codes.map((codeData) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
360
|
+
className: `code-card ${!codeData.isActive ? "code-card--inactive" : ""}`,
|
|
361
|
+
children: [
|
|
362
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
363
|
+
className: "code-card__header",
|
|
364
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
365
|
+
className: "code-card__code",
|
|
366
|
+
children: codeData.code
|
|
367
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
368
|
+
type: "button",
|
|
369
|
+
className: "code-card__copy",
|
|
370
|
+
onClick: () => copyToClipboard(codeData.code),
|
|
371
|
+
title: "Copy code",
|
|
372
|
+
children: copiedCode === codeData.code ? "✓ Copied" : "Copy"
|
|
373
|
+
})]
|
|
374
|
+
}),
|
|
375
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
376
|
+
className: "code-card__stats",
|
|
377
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
378
|
+
className: "code-card__stat",
|
|
379
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
380
|
+
className: "code-card__stat-value",
|
|
381
|
+
children: codeData.usageCount
|
|
382
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
383
|
+
className: "code-card__stat-label",
|
|
384
|
+
children: "Uses"
|
|
385
|
+
})]
|
|
386
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
387
|
+
className: "code-card__stat",
|
|
388
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
389
|
+
className: "code-card__stat-value",
|
|
390
|
+
children: formatCurrency$1(codeData.totalEarnings, currency)
|
|
391
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
392
|
+
className: "code-card__stat-label",
|
|
393
|
+
children: "Earnings"
|
|
394
|
+
})]
|
|
395
|
+
})]
|
|
396
|
+
}),
|
|
397
|
+
!codeData.isActive && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
398
|
+
className: "code-card__badge code-card__badge--inactive",
|
|
399
|
+
children: "Inactive"
|
|
400
|
+
})
|
|
401
|
+
]
|
|
402
|
+
}, codeData.id))
|
|
403
|
+
})
|
|
404
|
+
})]
|
|
405
|
+
});
|
|
406
|
+
};
|
|
407
|
+
//#endregion
|
|
408
|
+
//#region src/components/PartnerDashboard/ProgramOverview.tsx
|
|
409
|
+
const ProgramOverview = ({ program }) => {
|
|
410
|
+
if (!program) return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
411
|
+
className: "partner-widget partner-widget--program-overview",
|
|
412
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", {
|
|
413
|
+
className: "partner-widget__title",
|
|
414
|
+
children: "Program Overview"
|
|
415
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
416
|
+
className: "partner-widget__content",
|
|
417
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
418
|
+
className: "program-overview program-overview--empty",
|
|
419
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: "No referral program details are available yet." })
|
|
420
|
+
})
|
|
421
|
+
})]
|
|
422
|
+
});
|
|
423
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
424
|
+
className: "partner-widget partner-widget--program-overview",
|
|
425
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", {
|
|
426
|
+
className: "partner-widget__title",
|
|
427
|
+
children: "Program Overview"
|
|
428
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
429
|
+
className: "partner-widget__content",
|
|
430
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
431
|
+
className: "program-overview",
|
|
432
|
+
children: [
|
|
433
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
434
|
+
className: "program-overview__row",
|
|
435
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
436
|
+
className: "program-overview__label",
|
|
437
|
+
children: "Program Name"
|
|
438
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
439
|
+
className: "program-overview__value",
|
|
440
|
+
children: program.name
|
|
441
|
+
})]
|
|
442
|
+
}),
|
|
443
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
444
|
+
className: "program-overview__row",
|
|
445
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
446
|
+
className: "program-overview__label",
|
|
447
|
+
children: "Commission Rate"
|
|
448
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
449
|
+
className: "program-overview__value",
|
|
450
|
+
children: [program.commissionRate, "%"]
|
|
451
|
+
})]
|
|
452
|
+
}),
|
|
453
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
454
|
+
className: "program-overview__row",
|
|
455
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
456
|
+
className: "program-overview__label",
|
|
457
|
+
children: "Customer Discount"
|
|
458
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
459
|
+
className: "program-overview__value",
|
|
460
|
+
children: [program.customerDiscount, "%"]
|
|
461
|
+
})]
|
|
462
|
+
})
|
|
463
|
+
]
|
|
464
|
+
})
|
|
465
|
+
})]
|
|
466
|
+
});
|
|
467
|
+
};
|
|
468
|
+
//#endregion
|
|
469
|
+
//#region src/components/PartnerDashboard/CommissionBreakdown.tsx
|
|
470
|
+
const formatCurrency = (amount, currency) => {
|
|
471
|
+
return new Intl.NumberFormat("en-US", {
|
|
472
|
+
style: "currency",
|
|
473
|
+
currency,
|
|
474
|
+
minimumFractionDigits: 2
|
|
475
|
+
}).format(amount);
|
|
476
|
+
};
|
|
477
|
+
const formatPercent = (value) => {
|
|
478
|
+
if (!Number.isFinite(value)) return "0%";
|
|
479
|
+
return `${value.toFixed(1)}%`;
|
|
480
|
+
};
|
|
481
|
+
const CommissionBreakdown = ({ stats, currency }) => {
|
|
482
|
+
const totalEarnings = Math.max(stats.totalEarnings || 0, 0);
|
|
483
|
+
const paidEarnings = Math.max(stats.paidEarnings || 0, 0);
|
|
484
|
+
const pendingEarnings = Math.max(stats.pendingEarnings || 0, 0);
|
|
485
|
+
const paidPercent = totalEarnings > 0 ? paidEarnings / totalEarnings * 100 : 0;
|
|
486
|
+
const pendingPercent = totalEarnings > 0 ? pendingEarnings / totalEarnings * 100 : 0;
|
|
487
|
+
const unpaidOrOther = Math.max(totalEarnings - (paidEarnings + pendingEarnings), 0);
|
|
488
|
+
const otherPercent = totalEarnings > 0 ? unpaidOrOther / totalEarnings * 100 : 0;
|
|
489
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
490
|
+
className: "partner-widget partner-widget--commission-breakdown",
|
|
491
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", {
|
|
492
|
+
className: "partner-widget__title",
|
|
493
|
+
children: "Commission Breakdown"
|
|
494
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
495
|
+
className: "partner-widget__content",
|
|
496
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
497
|
+
className: "commission-breakdown",
|
|
498
|
+
children: [
|
|
499
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
500
|
+
className: "commission-breakdown__summary",
|
|
501
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
502
|
+
className: "commission-breakdown__total-label",
|
|
503
|
+
children: "Total Commission"
|
|
504
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
505
|
+
className: "commission-breakdown__total-value",
|
|
506
|
+
children: formatCurrency(totalEarnings, currency)
|
|
507
|
+
})]
|
|
508
|
+
}),
|
|
509
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
510
|
+
className: "commission-breakdown__bars",
|
|
511
|
+
role: "img",
|
|
512
|
+
"aria-label": "Commission distribution",
|
|
513
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
514
|
+
className: "commission-breakdown__track",
|
|
515
|
+
children: [
|
|
516
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
517
|
+
className: "commission-breakdown__segment commission-breakdown__segment--paid",
|
|
518
|
+
style: { width: `${Math.max(Math.min(paidPercent, 100), 0)}%` },
|
|
519
|
+
title: `Paid: ${formatCurrency(paidEarnings, currency)} (${formatPercent(paidPercent)})`
|
|
520
|
+
}),
|
|
521
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
522
|
+
className: "commission-breakdown__segment commission-breakdown__segment--pending",
|
|
523
|
+
style: { width: `${Math.max(Math.min(pendingPercent, 100), 0)}%` },
|
|
524
|
+
title: `Pending: ${formatCurrency(pendingEarnings, currency)} (${formatPercent(pendingPercent)})`
|
|
525
|
+
}),
|
|
526
|
+
otherPercent > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
527
|
+
className: "commission-breakdown__segment commission-breakdown__segment--other",
|
|
528
|
+
style: { width: `${Math.max(Math.min(otherPercent, 100), 0)}%` },
|
|
529
|
+
title: `Other: ${formatCurrency(unpaidOrOther, currency)} (${formatPercent(otherPercent)})`
|
|
530
|
+
})
|
|
531
|
+
]
|
|
532
|
+
})
|
|
533
|
+
}),
|
|
534
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
535
|
+
className: "commission-breakdown__legend",
|
|
536
|
+
children: [
|
|
537
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
538
|
+
className: "commission-breakdown__item",
|
|
539
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "commission-breakdown__dot commission-breakdown__dot--paid" }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
540
|
+
className: "commission-breakdown__meta",
|
|
541
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
542
|
+
className: "commission-breakdown__label",
|
|
543
|
+
children: "Paid"
|
|
544
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
545
|
+
className: "commission-breakdown__value",
|
|
546
|
+
children: [
|
|
547
|
+
formatCurrency(paidEarnings, currency),
|
|
548
|
+
" · ",
|
|
549
|
+
formatPercent(paidPercent)
|
|
550
|
+
]
|
|
551
|
+
})]
|
|
552
|
+
})]
|
|
553
|
+
}),
|
|
554
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
555
|
+
className: "commission-breakdown__item",
|
|
556
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "commission-breakdown__dot commission-breakdown__dot--pending" }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
557
|
+
className: "commission-breakdown__meta",
|
|
558
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
559
|
+
className: "commission-breakdown__label",
|
|
560
|
+
children: "Pending"
|
|
561
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
562
|
+
className: "commission-breakdown__value",
|
|
563
|
+
children: [
|
|
564
|
+
formatCurrency(pendingEarnings, currency),
|
|
565
|
+
" · ",
|
|
566
|
+
formatPercent(pendingPercent)
|
|
567
|
+
]
|
|
568
|
+
})]
|
|
569
|
+
})]
|
|
570
|
+
}),
|
|
571
|
+
otherPercent > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
572
|
+
className: "commission-breakdown__item",
|
|
573
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "commission-breakdown__dot commission-breakdown__dot--other" }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
574
|
+
className: "commission-breakdown__meta",
|
|
575
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
576
|
+
className: "commission-breakdown__label",
|
|
577
|
+
children: "Other"
|
|
578
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
579
|
+
className: "commission-breakdown__value",
|
|
580
|
+
children: [
|
|
581
|
+
formatCurrency(unpaidOrOther, currency),
|
|
582
|
+
" · ",
|
|
583
|
+
formatPercent(otherPercent)
|
|
584
|
+
]
|
|
585
|
+
})]
|
|
586
|
+
})]
|
|
587
|
+
})
|
|
588
|
+
]
|
|
589
|
+
}),
|
|
590
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
591
|
+
className: "commission-breakdown__footnote",
|
|
592
|
+
children: "Based on current referral payouts and pending settlements."
|
|
593
|
+
})
|
|
594
|
+
]
|
|
595
|
+
})
|
|
596
|
+
})]
|
|
597
|
+
});
|
|
598
|
+
};
|
|
599
|
+
//#endregion
|
|
600
|
+
//#region src/components/PartnerDashboard/index.tsx
|
|
601
|
+
const PartnerDashboard = ({ showEarningsSummary = true, showReferralPerformance = true, showRecentReferrals = true, showReferralCodes = true, showProgramOverview = true, showCommissionBreakdown = true, apiEndpoint = "/api/referrals/partner-stats" }) => {
|
|
602
|
+
const [data, setData] = (0, import_react.useState)(null);
|
|
603
|
+
const [loading, setLoading] = (0, import_react.useState)(true);
|
|
604
|
+
const [error, setError] = (0, import_react.useState)(null);
|
|
605
|
+
const [currency, setCurrency] = (0, import_react.useState)("USD");
|
|
606
|
+
(0, import_react.useEffect)(() => {
|
|
607
|
+
const fetchData = async () => {
|
|
608
|
+
try {
|
|
609
|
+
setLoading(true);
|
|
610
|
+
const response = await fetch(apiEndpoint, { credentials: "include" });
|
|
611
|
+
if (!response.ok) {
|
|
612
|
+
if (response.status === 401) {
|
|
613
|
+
setError("Please log in to view your partner dashboard");
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
if (response.status === 403) {
|
|
617
|
+
setError("Partner access required");
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
throw new Error("Failed to fetch partner data");
|
|
621
|
+
}
|
|
622
|
+
const result = await response.json();
|
|
623
|
+
if (result.success) {
|
|
624
|
+
setData(result.data ?? null);
|
|
625
|
+
setCurrency(result.currency ?? "USD");
|
|
626
|
+
} else setError(result.error ?? "Failed to load dashboard data");
|
|
627
|
+
} catch (err) {
|
|
628
|
+
setError(err instanceof Error ? err.message : "An error occurred");
|
|
629
|
+
} finally {
|
|
630
|
+
setLoading(false);
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
fetchData();
|
|
634
|
+
}, [apiEndpoint]);
|
|
635
|
+
if (loading) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
636
|
+
className: "partner-dashboard partner-dashboard--loading",
|
|
637
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
638
|
+
className: "partner-dashboard__loader",
|
|
639
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "partner-dashboard__spinner" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: "Loading partner dashboard..." })]
|
|
640
|
+
})
|
|
641
|
+
});
|
|
642
|
+
if (error) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
643
|
+
className: "partner-dashboard partner-dashboard--error",
|
|
644
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
645
|
+
className: "partner-dashboard__error",
|
|
646
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { children: "Unable to load dashboard" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: error })]
|
|
647
|
+
})
|
|
648
|
+
});
|
|
649
|
+
if (!data) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
650
|
+
className: "partner-dashboard partner-dashboard--empty",
|
|
651
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
652
|
+
className: "partner-dashboard__empty",
|
|
653
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { children: "No data available" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: "Your partner dashboard will appear here once you have referral activity." })]
|
|
654
|
+
})
|
|
655
|
+
});
|
|
656
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
657
|
+
className: "partner-dashboard",
|
|
658
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
659
|
+
className: "partner-dashboard__header",
|
|
660
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { children: "Partner Dashboard" }), data.program && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
661
|
+
className: "partner-dashboard__program",
|
|
662
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
663
|
+
className: "partner-dashboard__program-name",
|
|
664
|
+
children: data.program.name
|
|
665
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
666
|
+
className: "partner-dashboard__program-rate",
|
|
667
|
+
children: [data.program.commissionRate, "% commission"]
|
|
668
|
+
})]
|
|
669
|
+
})]
|
|
670
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
671
|
+
className: "partner-dashboard__grid",
|
|
672
|
+
children: [
|
|
673
|
+
showEarningsSummary && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EarningsSummary, {
|
|
674
|
+
stats: data.stats,
|
|
675
|
+
currency
|
|
676
|
+
}),
|
|
677
|
+
showReferralPerformance && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReferralPerformance, { stats: data.stats }),
|
|
678
|
+
showRecentReferrals && data.stats.recentReferrals.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RecentReferrals, {
|
|
679
|
+
referrals: data.stats.recentReferrals,
|
|
680
|
+
currency
|
|
681
|
+
}),
|
|
682
|
+
showReferralCodes && data.referralCodes.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReferralCodes, {
|
|
683
|
+
codes: data.referralCodes,
|
|
684
|
+
currency
|
|
685
|
+
}),
|
|
686
|
+
showProgramOverview && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ProgramOverview, { program: data.program }),
|
|
687
|
+
showCommissionBreakdown && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CommissionBreakdown, {
|
|
688
|
+
stats: data.stats,
|
|
689
|
+
currency
|
|
690
|
+
})
|
|
691
|
+
]
|
|
692
|
+
})]
|
|
693
|
+
});
|
|
694
|
+
};
|
|
695
|
+
//#endregion
|
|
696
|
+
//#region src/client/hooks.ts
|
|
697
|
+
const DEFAULT_ENDPOINTS = {
|
|
698
|
+
applyCoupon: "/api/coupons/apply",
|
|
699
|
+
validateCoupon: "/api/coupons/validate",
|
|
700
|
+
partnerStats: "/api/referrals/partner-stats"
|
|
701
|
+
};
|
|
702
|
+
function normalizePath(path) {
|
|
703
|
+
if (!path) return "";
|
|
704
|
+
return path.startsWith("/") ? path : `/${path}`;
|
|
705
|
+
}
|
|
706
|
+
function withBaseURL(path, baseURL) {
|
|
707
|
+
if (!baseURL) return path;
|
|
708
|
+
return `${baseURL.endsWith("/") ? baseURL.slice(0, -1) : baseURL}${normalizePath(path)}`;
|
|
709
|
+
}
|
|
710
|
+
function resolveEndpoints(input) {
|
|
711
|
+
if (typeof input === "string") return {
|
|
712
|
+
...DEFAULT_ENDPOINTS,
|
|
713
|
+
partnerStats: input
|
|
714
|
+
};
|
|
715
|
+
const baseURL = input?.baseURL;
|
|
716
|
+
return {
|
|
717
|
+
applyCoupon: withBaseURL(input?.applyCoupon || DEFAULT_ENDPOINTS.applyCoupon, baseURL),
|
|
718
|
+
validateCoupon: withBaseURL(input?.validateCoupon || DEFAULT_ENDPOINTS.validateCoupon, baseURL),
|
|
719
|
+
partnerStats: withBaseURL(input?.partnerStats || DEFAULT_ENDPOINTS.partnerStats, baseURL)
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
723
|
+
* Apply a coupon/referral code to a cart
|
|
724
|
+
* @param options - Code, cart ID, and optional customerEmail
|
|
725
|
+
* @param endpointConfig - Optional endpoint override config
|
|
726
|
+
*/
|
|
727
|
+
async function useCouponCode(options, endpointConfig) {
|
|
728
|
+
const { code, cartID, customerEmail } = options;
|
|
729
|
+
if (!code) return {
|
|
730
|
+
success: false,
|
|
731
|
+
message: "Coupon code is required",
|
|
732
|
+
error: "Code is missing"
|
|
733
|
+
};
|
|
734
|
+
const endpoints = resolveEndpoints(endpointConfig);
|
|
735
|
+
try {
|
|
736
|
+
const response = await fetch(endpoints.applyCoupon, {
|
|
737
|
+
method: "POST",
|
|
738
|
+
headers: { "Content-Type": "application/json" },
|
|
739
|
+
body: JSON.stringify({
|
|
740
|
+
code,
|
|
741
|
+
cartID,
|
|
742
|
+
customerEmail
|
|
743
|
+
})
|
|
744
|
+
});
|
|
745
|
+
const data = await response.json();
|
|
746
|
+
if (!response.ok) return {
|
|
747
|
+
success: false,
|
|
748
|
+
message: data.error || "Failed to apply coupon",
|
|
749
|
+
error: data.error
|
|
750
|
+
};
|
|
751
|
+
const couponData = data.coupon;
|
|
752
|
+
const referralData = data.referralCode;
|
|
753
|
+
return {
|
|
754
|
+
success: Boolean(data.success),
|
|
755
|
+
message: data.message || "Code applied",
|
|
756
|
+
discount: data.discount || data.customerDiscount,
|
|
757
|
+
partnerCommission: data.partnerCommission,
|
|
758
|
+
customerDiscount: data.customerDiscount,
|
|
759
|
+
coupon: couponData ? {
|
|
760
|
+
code: couponData.code || "",
|
|
761
|
+
type: couponData.type || "percentage",
|
|
762
|
+
value: couponData.value || 0
|
|
763
|
+
} : void 0,
|
|
764
|
+
referralCode: referralData ? { code: referralData.code || "" } : void 0
|
|
765
|
+
};
|
|
766
|
+
} catch (error) {
|
|
767
|
+
const message = error instanceof Error ? error.message : "Network error";
|
|
768
|
+
return {
|
|
769
|
+
success: false,
|
|
770
|
+
message,
|
|
771
|
+
error: message
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* Validate a coupon/referral code without applying it
|
|
777
|
+
* @param code - Code to validate
|
|
778
|
+
* @param cartValue - Optional cart value
|
|
779
|
+
* @param cartID - Optional cart ID
|
|
780
|
+
* @param customerEmail - Optional customer email (for per-customer limits)
|
|
781
|
+
* @param endpointConfig - Optional endpoint override config
|
|
782
|
+
*/
|
|
783
|
+
async function validateCouponCode(code, cartValue, cartID, customerEmail, endpointConfig) {
|
|
784
|
+
if (!code) return {
|
|
785
|
+
success: false,
|
|
786
|
+
message: "Code required",
|
|
787
|
+
error: "Code missing"
|
|
788
|
+
};
|
|
789
|
+
const endpoints = resolveEndpoints(endpointConfig);
|
|
790
|
+
try {
|
|
791
|
+
const response = await fetch(endpoints.validateCoupon, {
|
|
792
|
+
method: "POST",
|
|
793
|
+
headers: { "Content-Type": "application/json" },
|
|
794
|
+
body: JSON.stringify({
|
|
795
|
+
code,
|
|
796
|
+
cartValue,
|
|
797
|
+
cartID,
|
|
798
|
+
customerEmail
|
|
799
|
+
})
|
|
800
|
+
});
|
|
801
|
+
const data = await response.json();
|
|
802
|
+
if (!response.ok) return {
|
|
803
|
+
success: false,
|
|
804
|
+
message: data.error || "Invalid coupon",
|
|
805
|
+
error: data.error
|
|
806
|
+
};
|
|
807
|
+
const couponData = data.coupon;
|
|
808
|
+
const referralData = data.referralCode;
|
|
809
|
+
return {
|
|
810
|
+
success: Boolean(data.success),
|
|
811
|
+
message: data.message || "Code is valid",
|
|
812
|
+
coupon: couponData ? {
|
|
813
|
+
code: couponData.code || "",
|
|
814
|
+
type: couponData.type || "percentage",
|
|
815
|
+
value: couponData.value || 0
|
|
816
|
+
} : void 0,
|
|
817
|
+
referralCode: referralData ? { code: referralData.code || "" } : void 0,
|
|
818
|
+
discount: data.discount,
|
|
819
|
+
partnerCommission: data.partnerCommission,
|
|
820
|
+
customerDiscount: data.customerDiscount,
|
|
821
|
+
currency: data.currency
|
|
822
|
+
};
|
|
823
|
+
} catch (error) {
|
|
824
|
+
const message = error instanceof Error ? error.message : "Network error";
|
|
825
|
+
return {
|
|
826
|
+
success: false,
|
|
827
|
+
message,
|
|
828
|
+
error: message
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* Fetch partner dashboard statistics
|
|
834
|
+
* @param endpointConfig - Optional endpoint override config
|
|
835
|
+
*/
|
|
836
|
+
async function usePartnerStats(endpointConfig) {
|
|
837
|
+
const endpoints = resolveEndpoints(endpointConfig);
|
|
838
|
+
try {
|
|
839
|
+
const response = await fetch(endpoints.partnerStats, {
|
|
840
|
+
method: "GET",
|
|
841
|
+
headers: { "Content-Type": "application/json" },
|
|
842
|
+
credentials: "include"
|
|
843
|
+
});
|
|
844
|
+
const data = await response.json();
|
|
845
|
+
if (!response.ok) return {
|
|
846
|
+
success: false,
|
|
847
|
+
error: data.error || "Failed to fetch partner stats"
|
|
848
|
+
};
|
|
849
|
+
return {
|
|
850
|
+
success: Boolean(data.success),
|
|
851
|
+
data: data.data,
|
|
852
|
+
currency: data.currency
|
|
853
|
+
};
|
|
854
|
+
} catch (error) {
|
|
855
|
+
return {
|
|
856
|
+
success: false,
|
|
857
|
+
error: error instanceof Error ? error.message : "Network error"
|
|
858
|
+
};
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
//#endregion
|
|
862
|
+
export { CommissionBreakdown, EarningsSummary, PartnerDashboard, ProgramOverview, RecentReferrals, ReferralCodes, ReferralPerformance, useCouponCode, usePartnerStats, validateCouponCode };
|
|
863
|
+
|
|
864
|
+
//# sourceMappingURL=browser.mjs.map
|