@lodashventure/medusa-campaign 1.4.16 → 1.4.17
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 +2285 -0
- package/.medusa/server/src/admin/index.mjs +2281 -0
- package/package.json +5 -2
|
@@ -0,0 +1,2285 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
3
|
+
const adminSdk = require("@medusajs/admin-sdk");
|
|
4
|
+
const ui = require("@medusajs/ui");
|
|
5
|
+
const icons = require("@medusajs/icons");
|
|
6
|
+
const react = require("react");
|
|
7
|
+
const reactRouterDom = require("react-router-dom");
|
|
8
|
+
const dayjs = require("dayjs");
|
|
9
|
+
const axios = require("axios");
|
|
10
|
+
const zod = require("@hookform/resolvers/zod");
|
|
11
|
+
const reactHookForm = require("react-hook-form");
|
|
12
|
+
const z = require("zod");
|
|
13
|
+
const lodash = require("lodash");
|
|
14
|
+
const Medusa = require("@medusajs/js-sdk");
|
|
15
|
+
require("@medusajs/admin-shared");
|
|
16
|
+
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
17
|
+
const dayjs__default = /* @__PURE__ */ _interopDefault(dayjs);
|
|
18
|
+
const axios__default = /* @__PURE__ */ _interopDefault(axios);
|
|
19
|
+
const z__default = /* @__PURE__ */ _interopDefault(z);
|
|
20
|
+
const Medusa__default = /* @__PURE__ */ _interopDefault(Medusa);
|
|
21
|
+
const CampaignDetailWidget = ({
|
|
22
|
+
data: promotion
|
|
23
|
+
}) => {
|
|
24
|
+
const navigate = reactRouterDom.useNavigate();
|
|
25
|
+
const [campaign, setCampaign] = react.useState(null);
|
|
26
|
+
const [campaignDetail, setCampaignDetail] = react.useState(
|
|
27
|
+
null
|
|
28
|
+
);
|
|
29
|
+
const [loading, setLoading] = react.useState(true);
|
|
30
|
+
const [error, setError] = react.useState(null);
|
|
31
|
+
react.useEffect(() => {
|
|
32
|
+
if (promotion == null ? void 0 : promotion.campaign_id) {
|
|
33
|
+
fetchCampaignAndDetail();
|
|
34
|
+
} else {
|
|
35
|
+
setLoading(false);
|
|
36
|
+
}
|
|
37
|
+
}, [promotion == null ? void 0 : promotion.campaign_id]);
|
|
38
|
+
const fetchCampaignAndDetail = async () => {
|
|
39
|
+
if (!(promotion == null ? void 0 : promotion.campaign_id)) return;
|
|
40
|
+
setLoading(true);
|
|
41
|
+
setError(null);
|
|
42
|
+
try {
|
|
43
|
+
const campaignResponse = await fetch(
|
|
44
|
+
`/admin/flash-sales/${promotion.campaign_id}`,
|
|
45
|
+
{
|
|
46
|
+
credentials: "include"
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
if (campaignResponse.ok) {
|
|
50
|
+
const campaignData = await campaignResponse.json();
|
|
51
|
+
setCampaign(campaignData);
|
|
52
|
+
if (campaignData.campaign_detail) {
|
|
53
|
+
setCampaignDetail(campaignData.campaign_detail);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
} catch (err) {
|
|
57
|
+
console.error("Error fetching campaign:", err);
|
|
58
|
+
setError("Failed to load campaign information");
|
|
59
|
+
} finally {
|
|
60
|
+
setLoading(false);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const handleEditCampaign = () => {
|
|
64
|
+
if (campaign == null ? void 0 : campaign.id) {
|
|
65
|
+
navigate(`/flash-sales/${campaign.id}`);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const handleViewCampaign = () => {
|
|
69
|
+
if (campaign == null ? void 0 : campaign.id) {
|
|
70
|
+
navigate(`/flash-sales/${campaign.id}#details`);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
if (!(promotion == null ? void 0 : promotion.campaign_id)) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
if (loading) {
|
|
77
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "divide-y px-0 pb-0 pt-0", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-6 py-6", children: [
|
|
78
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3 mb-4", children: [
|
|
79
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.Sparkles, { className: "text-ui-fg-subtle" }),
|
|
80
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: "Campaign" })
|
|
81
|
+
] }),
|
|
82
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle", children: "Loading campaign..." })
|
|
83
|
+
] }) });
|
|
84
|
+
}
|
|
85
|
+
if (error) {
|
|
86
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "divide-y px-0 pb-0 pt-0", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-6 py-6", children: [
|
|
87
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3 mb-4", children: [
|
|
88
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.Sparkles, { className: "text-ui-fg-subtle" }),
|
|
89
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: "Campaign" })
|
|
90
|
+
] }),
|
|
91
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: "error", children: error })
|
|
92
|
+
] }) });
|
|
93
|
+
}
|
|
94
|
+
if (!campaign) {
|
|
95
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "divide-y px-0 pb-0 pt-0", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-6 py-6", children: [
|
|
96
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3 mb-4", children: [
|
|
97
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.Sparkles, { className: "text-ui-fg-subtle" }),
|
|
98
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: "Campaign" })
|
|
99
|
+
] }),
|
|
100
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle", children: "This promotion is not part of a campaign" })
|
|
101
|
+
] }) });
|
|
102
|
+
}
|
|
103
|
+
const hasCampaignDetail = !!campaignDetail;
|
|
104
|
+
const hasImages = (campaignDetail == null ? void 0 : campaignDetail.image_url) || (campaignDetail == null ? void 0 : campaignDetail.thumbnail_url);
|
|
105
|
+
const hasContent = (campaignDetail == null ? void 0 : campaignDetail.detail_content) || (campaignDetail == null ? void 0 : campaignDetail.terms_and_conditions);
|
|
106
|
+
const hasSEO = (campaignDetail == null ? void 0 : campaignDetail.meta_title) || (campaignDetail == null ? void 0 : campaignDetail.meta_description);
|
|
107
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "divide-y px-0 pb-0 pt-0", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-6 py-6", children: [
|
|
108
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-3 mb-4", children: [
|
|
109
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.Sparkles, { className: "text-ui-fg-subtle" }),
|
|
110
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: "Campaign" })
|
|
111
|
+
] }),
|
|
112
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-4 p-4 rounded-lg border bg-ui-bg-subtle", children: [
|
|
113
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start justify-between mb-3", children: [
|
|
114
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1", children: [
|
|
115
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-semibold text-lg mb-1", children: campaign.name }),
|
|
116
|
+
campaign.description && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-sm text-ui-fg-subtle line-clamp-2", children: campaign.description })
|
|
117
|
+
] }),
|
|
118
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Badge, { color: "purple", size: "small", children: [
|
|
119
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.Sparkles, { className: "mr-1" }),
|
|
120
|
+
"Campaign"
|
|
121
|
+
] })
|
|
122
|
+
] }),
|
|
123
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-2 mt-3 pt-3 border-t", children: [
|
|
124
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
125
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
126
|
+
icons.PhotoSolid,
|
|
127
|
+
{
|
|
128
|
+
className: `h-4 w-4 ${hasImages ? "text-green-500" : "text-ui-fg-muted"}`
|
|
129
|
+
}
|
|
130
|
+
),
|
|
131
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-xs", children: hasImages ? "Images added" : "No images" })
|
|
132
|
+
] }),
|
|
133
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
134
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
135
|
+
icons.PencilSquare,
|
|
136
|
+
{
|
|
137
|
+
className: `h-4 w-4 ${hasContent ? "text-green-500" : "text-ui-fg-muted"}`
|
|
138
|
+
}
|
|
139
|
+
),
|
|
140
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-xs", children: hasContent ? "Content added" : "No content" })
|
|
141
|
+
] })
|
|
142
|
+
] })
|
|
143
|
+
] }),
|
|
144
|
+
hasCampaignDetail && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3 mb-4", children: [
|
|
145
|
+
campaignDetail.thumbnail_url && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
146
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-xs font-medium text-ui-fg-subtle mb-2", children: "Thumbnail" }),
|
|
147
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
148
|
+
"img",
|
|
149
|
+
{
|
|
150
|
+
src: campaignDetail.thumbnail_url,
|
|
151
|
+
alt: "Campaign thumbnail",
|
|
152
|
+
className: "w-full h-32 object-cover rounded-lg border"
|
|
153
|
+
}
|
|
154
|
+
)
|
|
155
|
+
] }),
|
|
156
|
+
campaignDetail.detail_content && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
157
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-xs font-medium text-ui-fg-subtle mb-1", children: "Content Preview" }),
|
|
158
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "text-sm line-clamp-3 text-ui-fg-muted", children: [
|
|
159
|
+
campaignDetail.detail_content.substring(0, 150),
|
|
160
|
+
"..."
|
|
161
|
+
] })
|
|
162
|
+
] }),
|
|
163
|
+
campaignDetail.link_url && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 text-xs", children: [
|
|
164
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { size: "xsmall", color: "blue", children: "CTA Link" }),
|
|
165
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle truncate", children: campaignDetail.link_text || campaignDetail.link_url })
|
|
166
|
+
] }),
|
|
167
|
+
hasSEO && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 text-xs", children: [
|
|
168
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { size: "xsmall", color: "green", children: "SEO" }),
|
|
169
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle", children: "Meta fields configured" })
|
|
170
|
+
] })
|
|
171
|
+
] }),
|
|
172
|
+
!hasCampaignDetail && /* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: "info", className: "mb-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-sm", children: "No campaign details added yet. Add images, content, and SEO to enhance this campaign." }) }),
|
|
173
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
|
|
174
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Button, { variant: "secondary", size: "small", onClick: handleEditCampaign, children: [
|
|
175
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, { className: "mr-1" }),
|
|
176
|
+
"Edit Campaign"
|
|
177
|
+
] }),
|
|
178
|
+
hasCampaignDetail && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
179
|
+
ui.Button,
|
|
180
|
+
{
|
|
181
|
+
variant: "secondary",
|
|
182
|
+
size: "small",
|
|
183
|
+
onClick: handleViewCampaign,
|
|
184
|
+
children: [
|
|
185
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.Eye, { className: "mr-1" }),
|
|
186
|
+
"View Details"
|
|
187
|
+
]
|
|
188
|
+
}
|
|
189
|
+
)
|
|
190
|
+
] }),
|
|
191
|
+
campaignDetail && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-4 pt-4 border-t grid grid-cols-2 gap-3 text-xs", children: [
|
|
192
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
193
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle", children: "Display Order" }),
|
|
194
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "font-medium", children: campaignDetail.display_order })
|
|
195
|
+
] }),
|
|
196
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
197
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle", children: "Status" }),
|
|
198
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { color: hasCampaignDetail ? "green" : "grey", size: "xsmall", children: hasCampaignDetail ? "Complete" : "Incomplete" })
|
|
199
|
+
] })
|
|
200
|
+
] })
|
|
201
|
+
] }) });
|
|
202
|
+
};
|
|
203
|
+
adminSdk.defineWidgetConfig({
|
|
204
|
+
zone: "promotion.details.side.after"
|
|
205
|
+
});
|
|
206
|
+
const useCoupons = ({ limit, offset }) => {
|
|
207
|
+
const [data, setData] = react.useState(null);
|
|
208
|
+
const [isLoading, setIsLoading] = react.useState(true);
|
|
209
|
+
const [error, setError] = react.useState(null);
|
|
210
|
+
const fetchCoupons = async () => {
|
|
211
|
+
setIsLoading(true);
|
|
212
|
+
setError(null);
|
|
213
|
+
try {
|
|
214
|
+
const response = await axios__default.default.get("/admin/coupons", {
|
|
215
|
+
params: { limit, offset }
|
|
216
|
+
});
|
|
217
|
+
setData(response.data);
|
|
218
|
+
} catch (err) {
|
|
219
|
+
setError(err instanceof Error ? err : new Error("Failed to fetch coupons"));
|
|
220
|
+
} finally {
|
|
221
|
+
setIsLoading(false);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
react.useEffect(() => {
|
|
225
|
+
fetchCoupons();
|
|
226
|
+
}, [limit, offset]);
|
|
227
|
+
return {
|
|
228
|
+
data,
|
|
229
|
+
isLoading,
|
|
230
|
+
error,
|
|
231
|
+
refetch: fetchCoupons
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
const columnHelper$1 = ui.createDataTableColumnHelper();
|
|
235
|
+
const useCouponColumns = () => react.useMemo(
|
|
236
|
+
() => [
|
|
237
|
+
columnHelper$1.accessor("name", {
|
|
238
|
+
header: "Name",
|
|
239
|
+
cell: (info) => info.getValue()
|
|
240
|
+
}),
|
|
241
|
+
columnHelper$1.display({
|
|
242
|
+
id: "code",
|
|
243
|
+
header: "Code",
|
|
244
|
+
cell: (info) => {
|
|
245
|
+
var _a, _b;
|
|
246
|
+
return ((_b = (_a = info.row.original.promotions) == null ? void 0 : _a[0]) == null ? void 0 : _b.code) ?? "-";
|
|
247
|
+
}
|
|
248
|
+
}),
|
|
249
|
+
columnHelper$1.display({
|
|
250
|
+
id: "status",
|
|
251
|
+
header: "Status",
|
|
252
|
+
cell: (info) => {
|
|
253
|
+
const endsAt = info.row.original.ends_at;
|
|
254
|
+
if (!endsAt) {
|
|
255
|
+
return "";
|
|
256
|
+
}
|
|
257
|
+
const isActive = dayjs__default.default(endsAt).isAfter(dayjs__default.default());
|
|
258
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { color: isActive ? "green" : "grey", children: isActive ? "Active" : "Inactive" });
|
|
259
|
+
}
|
|
260
|
+
}),
|
|
261
|
+
columnHelper$1.accessor("starts_at", {
|
|
262
|
+
header: "Start Date",
|
|
263
|
+
cell: (info) => info.getValue() ? dayjs__default.default(info.getValue()).format("YYYY-MM-DD HH:mm") : ""
|
|
264
|
+
}),
|
|
265
|
+
columnHelper$1.accessor("ends_at", {
|
|
266
|
+
header: "End Date",
|
|
267
|
+
cell: (info) => info.getValue() ? dayjs__default.default(info.getValue()).format("YYYY-MM-DD HH:mm") : ""
|
|
268
|
+
})
|
|
269
|
+
],
|
|
270
|
+
[]
|
|
271
|
+
);
|
|
272
|
+
const CouponPage = () => {
|
|
273
|
+
const navigate = reactRouterDom.useNavigate();
|
|
274
|
+
const limit = 20;
|
|
275
|
+
const [pagination, setPagination] = react.useState({
|
|
276
|
+
pageSize: limit,
|
|
277
|
+
pageIndex: 0
|
|
278
|
+
});
|
|
279
|
+
const offset = pagination.pageIndex * limit;
|
|
280
|
+
const { data } = useCoupons({ limit, offset });
|
|
281
|
+
const columns2 = useCouponColumns();
|
|
282
|
+
const table = ui.useDataTable({
|
|
283
|
+
data: (data == null ? void 0 : data.campaigns) ?? [],
|
|
284
|
+
columns: columns2,
|
|
285
|
+
getRowId: (row) => row.id,
|
|
286
|
+
pagination: {
|
|
287
|
+
state: pagination,
|
|
288
|
+
onPaginationChange: setPagination
|
|
289
|
+
},
|
|
290
|
+
rowCount: (data == null ? void 0 : data.count) ?? 0,
|
|
291
|
+
onRowClick: (_, row) => {
|
|
292
|
+
navigate(`/coupons/${row.id}`);
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { children: [
|
|
296
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-between items-center", children: [
|
|
297
|
+
/* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-xl font-semibold", children: "Coupons" }),
|
|
298
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { onClick: () => navigate("/coupons/create"), children: "Create Coupon" })
|
|
299
|
+
] }),
|
|
300
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.DataTable, { instance: table, children: [
|
|
301
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.DataTable.Table, {}),
|
|
302
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.DataTable.Pagination, {})
|
|
303
|
+
] })
|
|
304
|
+
] });
|
|
305
|
+
};
|
|
306
|
+
const Coupons = () => {
|
|
307
|
+
return /* @__PURE__ */ jsxRuntime.jsx(CouponPage, {});
|
|
308
|
+
};
|
|
309
|
+
const config$3 = adminSdk.defineRouteConfig({
|
|
310
|
+
label: "Coupons",
|
|
311
|
+
icon: icons.Tag
|
|
312
|
+
});
|
|
313
|
+
const useFlashSales = (pagination) => {
|
|
314
|
+
const [data, setData] = react.useState(null);
|
|
315
|
+
const [isLoading, setIsLoading] = react.useState(true);
|
|
316
|
+
const [error, setError] = react.useState(null);
|
|
317
|
+
const fetchFlashSales = async () => {
|
|
318
|
+
setIsLoading(true);
|
|
319
|
+
setError(null);
|
|
320
|
+
try {
|
|
321
|
+
const response = await axios__default.default.get("/admin/flash-sales", {
|
|
322
|
+
params: pagination
|
|
323
|
+
});
|
|
324
|
+
setData(response.data);
|
|
325
|
+
} catch (err) {
|
|
326
|
+
setError(
|
|
327
|
+
err instanceof Error ? err : new Error("Failed to fetch flash sales")
|
|
328
|
+
);
|
|
329
|
+
} finally {
|
|
330
|
+
setIsLoading(false);
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
react.useEffect(() => {
|
|
334
|
+
fetchFlashSales();
|
|
335
|
+
}, [pagination.limit, pagination.offset]);
|
|
336
|
+
return {
|
|
337
|
+
data,
|
|
338
|
+
isLoading,
|
|
339
|
+
error,
|
|
340
|
+
refetch: fetchFlashSales
|
|
341
|
+
};
|
|
342
|
+
};
|
|
343
|
+
const FlashSalePage = () => {
|
|
344
|
+
const navigate = reactRouterDom.useNavigate();
|
|
345
|
+
const limit = 20;
|
|
346
|
+
const [pagination, setPagination] = react.useState({
|
|
347
|
+
pageSize: limit,
|
|
348
|
+
pageIndex: 0
|
|
349
|
+
});
|
|
350
|
+
const offset = react.useMemo(() => {
|
|
351
|
+
return pagination.pageIndex * limit;
|
|
352
|
+
}, [pagination]);
|
|
353
|
+
const columnHelper2 = ui.createDataTableColumnHelper();
|
|
354
|
+
const columns2 = [
|
|
355
|
+
columnHelper2.accessor("name", {
|
|
356
|
+
header: "Name",
|
|
357
|
+
cell: (info) => info.getValue()
|
|
358
|
+
}),
|
|
359
|
+
columnHelper2.accessor("ends_at", {
|
|
360
|
+
header: "Status",
|
|
361
|
+
cell: (info) => {
|
|
362
|
+
const date = info.getValue();
|
|
363
|
+
if (!date) {
|
|
364
|
+
return "";
|
|
365
|
+
}
|
|
366
|
+
const isActive = dayjs__default.default(date).isAfter(dayjs__default.default());
|
|
367
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { color: isActive ? "green" : "grey", children: isActive ? "Active" : "Inactive" });
|
|
368
|
+
}
|
|
369
|
+
}),
|
|
370
|
+
columnHelper2.accessor("starts_at", {
|
|
371
|
+
header: "Start Date",
|
|
372
|
+
cell: (info) => {
|
|
373
|
+
const date = info.getValue();
|
|
374
|
+
if (!date) {
|
|
375
|
+
return "";
|
|
376
|
+
}
|
|
377
|
+
return dayjs__default.default(date).format("YYYY-MM-DD HH:mm");
|
|
378
|
+
}
|
|
379
|
+
}),
|
|
380
|
+
columnHelper2.accessor("ends_at", {
|
|
381
|
+
header: "End Date",
|
|
382
|
+
cell: (info) => {
|
|
383
|
+
const date = info.getValue();
|
|
384
|
+
if (!date) {
|
|
385
|
+
return "";
|
|
386
|
+
}
|
|
387
|
+
return dayjs__default.default(date).format("YYYY-MM-DD HH:mm");
|
|
388
|
+
}
|
|
389
|
+
})
|
|
390
|
+
];
|
|
391
|
+
const { data } = useFlashSales({ limit, offset });
|
|
392
|
+
const table = ui.useDataTable({
|
|
393
|
+
data: (data == null ? void 0 : data.campaigns) || [],
|
|
394
|
+
columns: columns2,
|
|
395
|
+
getRowId: (campaign) => campaign.id,
|
|
396
|
+
pagination: {
|
|
397
|
+
state: pagination,
|
|
398
|
+
onPaginationChange: setPagination
|
|
399
|
+
},
|
|
400
|
+
rowCount: (data == null ? void 0 : data.count) || 0,
|
|
401
|
+
onRowClick: (_, row) => {
|
|
402
|
+
navigate(`/flash-sales/${row.id}`);
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { children: [
|
|
406
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-between items-center", children: [
|
|
407
|
+
/* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-xl font-semibold", children: "Campaigns" }),
|
|
408
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { onClick: () => navigate("/flash-sales/create"), children: "Create Campaign" })
|
|
409
|
+
] }),
|
|
410
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.DataTable, { instance: table, children: [
|
|
411
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.DataTable.Table, {}),
|
|
412
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.DataTable.Pagination, {})
|
|
413
|
+
] })
|
|
414
|
+
] });
|
|
415
|
+
};
|
|
416
|
+
const FlashSale = () => {
|
|
417
|
+
return /* @__PURE__ */ jsxRuntime.jsx(FlashSalePage, {});
|
|
418
|
+
};
|
|
419
|
+
const config$2 = adminSdk.defineRouteConfig({
|
|
420
|
+
label: "Flash Sale",
|
|
421
|
+
icon: icons.Sparkles
|
|
422
|
+
});
|
|
423
|
+
const couponSchema = z__default.default.object({
|
|
424
|
+
name: z__default.default.string().min(1, "Name is required"),
|
|
425
|
+
description: z__default.default.string().min(1, "Description is required"),
|
|
426
|
+
type: z__default.default.literal("coupon"),
|
|
427
|
+
code: z__default.default.string().min(1, "Coupon code is required"),
|
|
428
|
+
discount_type: z__default.default.enum(["percentage", "fixed"]),
|
|
429
|
+
discount_value: z__default.default.number().positive("Discount must be positive"),
|
|
430
|
+
currency_code: z__default.default.string().optional(),
|
|
431
|
+
starts_at: z__default.default.string().min(1, "Start date is required"),
|
|
432
|
+
ends_at: z__default.default.string().min(1, "End date is required"),
|
|
433
|
+
allocation: z__default.default.enum(["each", "total"]).optional(),
|
|
434
|
+
target_type: z__default.default.enum(["order", "items"]).optional()
|
|
435
|
+
}).superRefine((data, ctx) => {
|
|
436
|
+
if (new Date(data.ends_at) < new Date(data.starts_at)) {
|
|
437
|
+
ctx.addIssue({
|
|
438
|
+
code: z__default.default.ZodIssueCode.custom,
|
|
439
|
+
path: ["ends_at"],
|
|
440
|
+
message: "End date must be after start date"
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
if (data.discount_type === "fixed" && !data.currency_code) {
|
|
444
|
+
ctx.addIssue({
|
|
445
|
+
code: z__default.default.ZodIssueCode.custom,
|
|
446
|
+
path: ["currency_code"],
|
|
447
|
+
message: "Currency is required for fixed discount"
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
const CouponForm = ({
|
|
452
|
+
initialData,
|
|
453
|
+
onSubmit,
|
|
454
|
+
onCancel,
|
|
455
|
+
disabled = false
|
|
456
|
+
}) => {
|
|
457
|
+
const {
|
|
458
|
+
register,
|
|
459
|
+
control,
|
|
460
|
+
handleSubmit,
|
|
461
|
+
watch,
|
|
462
|
+
setValue,
|
|
463
|
+
formState: { errors }
|
|
464
|
+
} = reactHookForm.useForm({
|
|
465
|
+
resolver: zod.zodResolver(couponSchema),
|
|
466
|
+
defaultValues: {
|
|
467
|
+
name: (initialData == null ? void 0 : initialData.name) ?? "",
|
|
468
|
+
description: (initialData == null ? void 0 : initialData.description) ?? "",
|
|
469
|
+
type: "coupon",
|
|
470
|
+
code: (initialData == null ? void 0 : initialData.code) ?? "",
|
|
471
|
+
discount_type: (initialData == null ? void 0 : initialData.discount_type) ?? "percentage",
|
|
472
|
+
discount_value: (initialData == null ? void 0 : initialData.discount_value) ?? 0,
|
|
473
|
+
currency_code: (initialData == null ? void 0 : initialData.currency_code) ?? "",
|
|
474
|
+
starts_at: (initialData == null ? void 0 : initialData.starts_at) ?? dayjs__default.default().startOf("day").format("YYYY-MM-DDTHH:mm"),
|
|
475
|
+
ends_at: (initialData == null ? void 0 : initialData.ends_at) ?? dayjs__default.default().endOf("day").format("YYYY-MM-DDTHH:mm"),
|
|
476
|
+
allocation: (initialData == null ? void 0 : initialData.allocation) ?? "total",
|
|
477
|
+
target_type: (initialData == null ? void 0 : initialData.target_type) ?? "order"
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
const discountType = watch("discount_type");
|
|
481
|
+
const startsAt = watch("starts_at");
|
|
482
|
+
const endsAt = watch("ends_at");
|
|
483
|
+
const handleDateTimeChange = (field, type, value) => {
|
|
484
|
+
const currentValue = watch(field);
|
|
485
|
+
if (type === "date") {
|
|
486
|
+
const time = currentValue ? dayjs__default.default(currentValue).format("HH:mm") : field === "starts_at" ? "00:00" : "23:59";
|
|
487
|
+
setValue(field, `${value}T${time}`);
|
|
488
|
+
} else {
|
|
489
|
+
const date = currentValue ? dayjs__default.default(currentValue).format("YYYY-MM-DD") : dayjs__default.default().format("YYYY-MM-DD");
|
|
490
|
+
setValue(field, `${date}T${value}`);
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
const onFormSubmit = (data) => {
|
|
494
|
+
onSubmit(data);
|
|
495
|
+
};
|
|
496
|
+
const onFormError = () => {
|
|
497
|
+
const errorMessages = Object.values(errors).map((err) => err == null ? void 0 : err.message).filter(Boolean).join(", ");
|
|
498
|
+
ui.toast.error("Invalid coupon data", {
|
|
499
|
+
description: errorMessages
|
|
500
|
+
});
|
|
501
|
+
};
|
|
502
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { children: [
|
|
503
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
504
|
+
/* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-xl font-semibold", children: "Coupon" }),
|
|
505
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "transparent", onClick: onCancel, children: "Cancel" })
|
|
506
|
+
] }),
|
|
507
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
508
|
+
"form",
|
|
509
|
+
{
|
|
510
|
+
onSubmit: handleSubmit(onFormSubmit, onFormError),
|
|
511
|
+
className: "space-y-6 my-8",
|
|
512
|
+
children: [
|
|
513
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
514
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Name" }),
|
|
515
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...register("name"), disabled }),
|
|
516
|
+
errors.name && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-red-500 text-sm mt-1", children: errors.name.message })
|
|
517
|
+
] }),
|
|
518
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
519
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Description" }),
|
|
520
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...register("description"), disabled }),
|
|
521
|
+
errors.description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-red-500 text-sm mt-1", children: errors.description.message })
|
|
522
|
+
] }),
|
|
523
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
524
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
525
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Start Date" }),
|
|
526
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
|
|
527
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
528
|
+
ui.Input,
|
|
529
|
+
{
|
|
530
|
+
type: "date",
|
|
531
|
+
value: startsAt ? dayjs__default.default(startsAt).format("YYYY-MM-DD") : "",
|
|
532
|
+
onChange: (e) => handleDateTimeChange("starts_at", "date", e.target.value),
|
|
533
|
+
disabled,
|
|
534
|
+
className: "flex-1"
|
|
535
|
+
}
|
|
536
|
+
),
|
|
537
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
538
|
+
ui.Input,
|
|
539
|
+
{
|
|
540
|
+
type: "time",
|
|
541
|
+
value: startsAt ? dayjs__default.default(startsAt).format("HH:mm") : "",
|
|
542
|
+
onChange: (e) => handleDateTimeChange("starts_at", "time", e.target.value),
|
|
543
|
+
disabled,
|
|
544
|
+
className: "flex-1"
|
|
545
|
+
}
|
|
546
|
+
)
|
|
547
|
+
] }),
|
|
548
|
+
errors.starts_at && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-red-500 text-sm mt-1", children: errors.starts_at.message })
|
|
549
|
+
] }),
|
|
550
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
551
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "End Date" }),
|
|
552
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
|
|
553
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
554
|
+
ui.Input,
|
|
555
|
+
{
|
|
556
|
+
type: "date",
|
|
557
|
+
value: endsAt ? dayjs__default.default(endsAt).format("YYYY-MM-DD") : "",
|
|
558
|
+
onChange: (e) => handleDateTimeChange("ends_at", "date", e.target.value),
|
|
559
|
+
disabled,
|
|
560
|
+
className: "flex-1"
|
|
561
|
+
}
|
|
562
|
+
),
|
|
563
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
564
|
+
ui.Input,
|
|
565
|
+
{
|
|
566
|
+
type: "time",
|
|
567
|
+
value: endsAt ? dayjs__default.default(endsAt).format("HH:mm") : "",
|
|
568
|
+
onChange: (e) => handleDateTimeChange("ends_at", "time", e.target.value),
|
|
569
|
+
disabled,
|
|
570
|
+
className: "flex-1"
|
|
571
|
+
}
|
|
572
|
+
)
|
|
573
|
+
] }),
|
|
574
|
+
errors.ends_at && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-red-500 text-sm mt-1", children: errors.ends_at.message })
|
|
575
|
+
] })
|
|
576
|
+
] }),
|
|
577
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
578
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
579
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Coupon Code" }),
|
|
580
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...register("code"), disabled }),
|
|
581
|
+
errors.code && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-red-500 text-sm mt-1", children: errors.code.message })
|
|
582
|
+
] }),
|
|
583
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
584
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Discount Type" }),
|
|
585
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
586
|
+
reactHookForm.Controller,
|
|
587
|
+
{
|
|
588
|
+
name: "discount_type",
|
|
589
|
+
control,
|
|
590
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
591
|
+
ui.Select,
|
|
592
|
+
{
|
|
593
|
+
value: field.value,
|
|
594
|
+
onValueChange: field.onChange,
|
|
595
|
+
disabled,
|
|
596
|
+
children: [
|
|
597
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, { placeholder: "Select discount type" }) }),
|
|
598
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Select.Content, { children: [
|
|
599
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "percentage", children: "Percentage" }),
|
|
600
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "fixed", children: "Fixed Amount" })
|
|
601
|
+
] })
|
|
602
|
+
]
|
|
603
|
+
}
|
|
604
|
+
)
|
|
605
|
+
}
|
|
606
|
+
)
|
|
607
|
+
] })
|
|
608
|
+
] }),
|
|
609
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
610
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
611
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Discount Value" }),
|
|
612
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
613
|
+
reactHookForm.Controller,
|
|
614
|
+
{
|
|
615
|
+
name: "discount_value",
|
|
616
|
+
control,
|
|
617
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
618
|
+
ui.Input,
|
|
619
|
+
{
|
|
620
|
+
type: "number",
|
|
621
|
+
value: field.value,
|
|
622
|
+
min: 0,
|
|
623
|
+
step: field.value % 1 === 0 ? 1 : 0.01,
|
|
624
|
+
onChange: (e) => field.onChange(Number(e.target.value)),
|
|
625
|
+
disabled
|
|
626
|
+
}
|
|
627
|
+
)
|
|
628
|
+
}
|
|
629
|
+
),
|
|
630
|
+
errors.discount_value && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-red-500 text-sm mt-1", children: errors.discount_value.message })
|
|
631
|
+
] }),
|
|
632
|
+
discountType === "fixed" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
633
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Currency Code" }),
|
|
634
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...register("currency_code"), disabled }),
|
|
635
|
+
errors.currency_code && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-red-500 text-sm mt-1", children: errors.currency_code.message })
|
|
636
|
+
] })
|
|
637
|
+
] }),
|
|
638
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
639
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
640
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Allocation" }),
|
|
641
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
642
|
+
reactHookForm.Controller,
|
|
643
|
+
{
|
|
644
|
+
name: "allocation",
|
|
645
|
+
control,
|
|
646
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
647
|
+
ui.Select,
|
|
648
|
+
{
|
|
649
|
+
value: field.value,
|
|
650
|
+
onValueChange: field.onChange,
|
|
651
|
+
disabled,
|
|
652
|
+
children: [
|
|
653
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, { placeholder: "Select allocation" }) }),
|
|
654
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Select.Content, { children: [
|
|
655
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "total", children: "Order Total" }),
|
|
656
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "each", children: "Each Item" })
|
|
657
|
+
] })
|
|
658
|
+
]
|
|
659
|
+
}
|
|
660
|
+
)
|
|
661
|
+
}
|
|
662
|
+
)
|
|
663
|
+
] }),
|
|
664
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
665
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Target Type" }),
|
|
666
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
667
|
+
reactHookForm.Controller,
|
|
668
|
+
{
|
|
669
|
+
name: "target_type",
|
|
670
|
+
control,
|
|
671
|
+
render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
672
|
+
ui.Select,
|
|
673
|
+
{
|
|
674
|
+
value: field.value,
|
|
675
|
+
onValueChange: field.onChange,
|
|
676
|
+
disabled,
|
|
677
|
+
children: [
|
|
678
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, { placeholder: "Select target" }) }),
|
|
679
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Select.Content, { children: [
|
|
680
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "order", children: "Order" }),
|
|
681
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "items", children: "Items" })
|
|
682
|
+
] })
|
|
683
|
+
]
|
|
684
|
+
}
|
|
685
|
+
)
|
|
686
|
+
}
|
|
687
|
+
)
|
|
688
|
+
] })
|
|
689
|
+
] }),
|
|
690
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
691
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", type: "button", onClick: onCancel, children: "Cancel" }),
|
|
692
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { type: "submit", disabled, children: "Save Coupon" })
|
|
693
|
+
] })
|
|
694
|
+
]
|
|
695
|
+
}
|
|
696
|
+
)
|
|
697
|
+
] });
|
|
698
|
+
};
|
|
699
|
+
const useCouponById = (id) => {
|
|
700
|
+
const [data, setData] = react.useState(null);
|
|
701
|
+
const [isLoading, setIsLoading] = react.useState(true);
|
|
702
|
+
const [error, setError] = react.useState(null);
|
|
703
|
+
const fetchCoupon = async () => {
|
|
704
|
+
if (!id) {
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
setIsLoading(true);
|
|
708
|
+
setError(null);
|
|
709
|
+
try {
|
|
710
|
+
const response = await axios__default.default.get(`/admin/coupons/${id}`);
|
|
711
|
+
setData(response.data);
|
|
712
|
+
} catch (err) {
|
|
713
|
+
setError(err instanceof Error ? err : new Error("Failed to fetch coupon"));
|
|
714
|
+
} finally {
|
|
715
|
+
setIsLoading(false);
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
react.useEffect(() => {
|
|
719
|
+
fetchCoupon();
|
|
720
|
+
}, [id]);
|
|
721
|
+
return {
|
|
722
|
+
data,
|
|
723
|
+
isLoading,
|
|
724
|
+
error,
|
|
725
|
+
refetch: fetchCoupon
|
|
726
|
+
};
|
|
727
|
+
};
|
|
728
|
+
const MarkdownEditor = ({
|
|
729
|
+
label,
|
|
730
|
+
value,
|
|
731
|
+
onChange,
|
|
732
|
+
placeholder,
|
|
733
|
+
helpText,
|
|
734
|
+
rows = 10,
|
|
735
|
+
showPreview = true
|
|
736
|
+
}) => {
|
|
737
|
+
const [activeTab, setActiveTab] = react.useState("write");
|
|
738
|
+
const insertMarkdown = (before, after = "") => {
|
|
739
|
+
const textarea = document.getElementById(
|
|
740
|
+
`markdown-${label}`
|
|
741
|
+
);
|
|
742
|
+
if (!textarea) return;
|
|
743
|
+
const start = textarea.selectionStart;
|
|
744
|
+
const end = textarea.selectionEnd;
|
|
745
|
+
const selectedText = value.substring(start, end);
|
|
746
|
+
const newText = value.substring(0, start) + before + selectedText + after + value.substring(end);
|
|
747
|
+
onChange(newText);
|
|
748
|
+
setTimeout(() => {
|
|
749
|
+
textarea.focus();
|
|
750
|
+
textarea.setSelectionRange(
|
|
751
|
+
start + before.length,
|
|
752
|
+
start + before.length + selectedText.length
|
|
753
|
+
);
|
|
754
|
+
}, 0);
|
|
755
|
+
};
|
|
756
|
+
const renderMarkdownPreview = (markdown) => {
|
|
757
|
+
let html = markdown;
|
|
758
|
+
html = html.replace(/^### (.*$)/gim, "<h3>$1</h3>");
|
|
759
|
+
html = html.replace(/^## (.*$)/gim, "<h2>$1</h2>");
|
|
760
|
+
html = html.replace(/^# (.*$)/gim, "<h1>$1</h1>");
|
|
761
|
+
html = html.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>");
|
|
762
|
+
html = html.replace(/__(.+?)__/g, "<strong>$1</strong>");
|
|
763
|
+
html = html.replace(/\*(.+?)\*/g, "<em>$1</em>");
|
|
764
|
+
html = html.replace(/_(.+?)_/g, "<em>$1</em>");
|
|
765
|
+
html = html.replace(
|
|
766
|
+
/```(\w+)?\n([\s\S]+?)```/g,
|
|
767
|
+
'<pre class="bg-ui-bg-subtle p-4 rounded-lg overflow-x-auto"><code class="language-$1">$2</code></pre>'
|
|
768
|
+
);
|
|
769
|
+
html = html.replace(
|
|
770
|
+
/`([^`]+)`/g,
|
|
771
|
+
'<code class="bg-ui-bg-subtle px-1 py-0.5 rounded text-sm">$1</code>'
|
|
772
|
+
);
|
|
773
|
+
html = html.replace(
|
|
774
|
+
/\[([^\]]+)\]\(([^)]+)\)/g,
|
|
775
|
+
'<a href="$2" class="text-ui-fg-interactive underline">$1</a>'
|
|
776
|
+
);
|
|
777
|
+
html = html.replace(
|
|
778
|
+
/!\[([^\]]*)\]\(([^)]+)\)/g,
|
|
779
|
+
'<img src="$2" alt="$1" class="max-w-full h-auto rounded-lg my-2" />'
|
|
780
|
+
);
|
|
781
|
+
html = html.replace(/^\* (.+)$/gim, "<li>$1</li>");
|
|
782
|
+
html = html.replace(/^\- (.+)$/gim, "<li>$1</li>");
|
|
783
|
+
html = html.replace(
|
|
784
|
+
/(<li>.*<\/li>)/s,
|
|
785
|
+
"<ul class='list-disc ml-6'>$1</ul>"
|
|
786
|
+
);
|
|
787
|
+
html = html.replace(/\n\n/g, "</p><p>");
|
|
788
|
+
html = `<p>${html}</p>`;
|
|
789
|
+
return html;
|
|
790
|
+
};
|
|
791
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
792
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
793
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: `markdown-${label}`, className: "font-medium", children: label }),
|
|
794
|
+
helpText && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1 text-xs text-ui-fg-subtle", children: [
|
|
795
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.InformationCircle, { className: "h-4 w-4" }),
|
|
796
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: helpText })
|
|
797
|
+
] })
|
|
798
|
+
] }),
|
|
799
|
+
showPreview ? /* @__PURE__ */ jsxRuntime.jsxs(ui.Tabs, { value: activeTab, onValueChange: (v) => setActiveTab(v), children: [
|
|
800
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Tabs.List, { children: [
|
|
801
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Tabs.Trigger, { value: "write", children: "Write" }),
|
|
802
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Tabs.Trigger, { value: "preview", children: "Preview" })
|
|
803
|
+
] }),
|
|
804
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Tabs.Content, { value: "write", className: "mt-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
805
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap gap-2 border-b pb-2", children: [
|
|
806
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
807
|
+
ui.Button,
|
|
808
|
+
{
|
|
809
|
+
type: "button",
|
|
810
|
+
variant: "secondary",
|
|
811
|
+
size: "small",
|
|
812
|
+
onClick: () => insertMarkdown("**", "**"),
|
|
813
|
+
title: "Bold",
|
|
814
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "B" })
|
|
815
|
+
}
|
|
816
|
+
),
|
|
817
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
818
|
+
ui.Button,
|
|
819
|
+
{
|
|
820
|
+
type: "button",
|
|
821
|
+
variant: "secondary",
|
|
822
|
+
size: "small",
|
|
823
|
+
onClick: () => insertMarkdown("*", "*"),
|
|
824
|
+
title: "Italic",
|
|
825
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("em", { children: "I" })
|
|
826
|
+
}
|
|
827
|
+
),
|
|
828
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
829
|
+
ui.Button,
|
|
830
|
+
{
|
|
831
|
+
type: "button",
|
|
832
|
+
variant: "secondary",
|
|
833
|
+
size: "small",
|
|
834
|
+
onClick: () => insertMarkdown("`", "`"),
|
|
835
|
+
title: "Inline Code",
|
|
836
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.CommandLine, { className: "h-4 w-4" })
|
|
837
|
+
}
|
|
838
|
+
),
|
|
839
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
840
|
+
ui.Button,
|
|
841
|
+
{
|
|
842
|
+
type: "button",
|
|
843
|
+
variant: "secondary",
|
|
844
|
+
size: "small",
|
|
845
|
+
onClick: () => insertMarkdown("## "),
|
|
846
|
+
title: "Heading",
|
|
847
|
+
children: "H2"
|
|
848
|
+
}
|
|
849
|
+
),
|
|
850
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
851
|
+
ui.Button,
|
|
852
|
+
{
|
|
853
|
+
type: "button",
|
|
854
|
+
variant: "secondary",
|
|
855
|
+
size: "small",
|
|
856
|
+
onClick: () => insertMarkdown("### "),
|
|
857
|
+
title: "Heading",
|
|
858
|
+
children: "H3"
|
|
859
|
+
}
|
|
860
|
+
),
|
|
861
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
862
|
+
ui.Button,
|
|
863
|
+
{
|
|
864
|
+
type: "button",
|
|
865
|
+
variant: "secondary",
|
|
866
|
+
size: "small",
|
|
867
|
+
onClick: () => insertMarkdown("[", "](url)"),
|
|
868
|
+
title: "Link",
|
|
869
|
+
children: "Link"
|
|
870
|
+
}
|
|
871
|
+
),
|
|
872
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
873
|
+
ui.Button,
|
|
874
|
+
{
|
|
875
|
+
type: "button",
|
|
876
|
+
variant: "secondary",
|
|
877
|
+
size: "small",
|
|
878
|
+
onClick: () => insertMarkdown(""),
|
|
879
|
+
title: "Image",
|
|
880
|
+
children: "Image"
|
|
881
|
+
}
|
|
882
|
+
),
|
|
883
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
884
|
+
ui.Button,
|
|
885
|
+
{
|
|
886
|
+
type: "button",
|
|
887
|
+
variant: "secondary",
|
|
888
|
+
size: "small",
|
|
889
|
+
onClick: () => insertMarkdown("```\n", "\n```"),
|
|
890
|
+
title: "Code Block",
|
|
891
|
+
children: "Code"
|
|
892
|
+
}
|
|
893
|
+
),
|
|
894
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
895
|
+
ui.Button,
|
|
896
|
+
{
|
|
897
|
+
type: "button",
|
|
898
|
+
variant: "secondary",
|
|
899
|
+
size: "small",
|
|
900
|
+
onClick: () => insertMarkdown("- "),
|
|
901
|
+
title: "List",
|
|
902
|
+
children: "List"
|
|
903
|
+
}
|
|
904
|
+
)
|
|
905
|
+
] }),
|
|
906
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
907
|
+
ui.Textarea,
|
|
908
|
+
{
|
|
909
|
+
id: `markdown-${label}`,
|
|
910
|
+
value,
|
|
911
|
+
onChange: (e) => onChange(e.target.value),
|
|
912
|
+
placeholder,
|
|
913
|
+
rows,
|
|
914
|
+
className: "font-mono text-sm"
|
|
915
|
+
}
|
|
916
|
+
)
|
|
917
|
+
] }) }),
|
|
918
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Tabs.Content, { value: "preview", className: "mt-4", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
919
|
+
"div",
|
|
920
|
+
{
|
|
921
|
+
className: ui.clx(
|
|
922
|
+
"min-h-[200px] rounded-lg border border-ui-border-base bg-ui-bg-subtle p-4",
|
|
923
|
+
"prose prose-sm max-w-none"
|
|
924
|
+
),
|
|
925
|
+
dangerouslySetInnerHTML: {
|
|
926
|
+
__html: value ? renderMarkdownPreview(value) : '<p class="text-ui-fg-subtle">Nothing to preview</p>'
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
) })
|
|
930
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
931
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-wrap gap-2 border-b pb-2", children: [
|
|
932
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
933
|
+
ui.Button,
|
|
934
|
+
{
|
|
935
|
+
type: "button",
|
|
936
|
+
variant: "secondary",
|
|
937
|
+
size: "small",
|
|
938
|
+
onClick: () => insertMarkdown("**", "**"),
|
|
939
|
+
title: "Bold",
|
|
940
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "B" })
|
|
941
|
+
}
|
|
942
|
+
),
|
|
943
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
944
|
+
ui.Button,
|
|
945
|
+
{
|
|
946
|
+
type: "button",
|
|
947
|
+
variant: "secondary",
|
|
948
|
+
size: "small",
|
|
949
|
+
onClick: () => insertMarkdown("*", "*"),
|
|
950
|
+
title: "Italic",
|
|
951
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("em", { children: "I" })
|
|
952
|
+
}
|
|
953
|
+
),
|
|
954
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
955
|
+
ui.Button,
|
|
956
|
+
{
|
|
957
|
+
type: "button",
|
|
958
|
+
variant: "secondary",
|
|
959
|
+
size: "small",
|
|
960
|
+
onClick: () => insertMarkdown("`", "`"),
|
|
961
|
+
title: "Inline Code",
|
|
962
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.CommandLine, { className: "h-4 w-4" })
|
|
963
|
+
}
|
|
964
|
+
),
|
|
965
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
966
|
+
ui.Button,
|
|
967
|
+
{
|
|
968
|
+
type: "button",
|
|
969
|
+
variant: "secondary",
|
|
970
|
+
size: "small",
|
|
971
|
+
onClick: () => insertMarkdown("```\n", "\n```"),
|
|
972
|
+
title: "Code Block",
|
|
973
|
+
children: "Code"
|
|
974
|
+
}
|
|
975
|
+
)
|
|
976
|
+
] }),
|
|
977
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
978
|
+
ui.Textarea,
|
|
979
|
+
{
|
|
980
|
+
id: `markdown-${label}`,
|
|
981
|
+
value,
|
|
982
|
+
onChange: (e) => onChange(e.target.value),
|
|
983
|
+
placeholder,
|
|
984
|
+
rows,
|
|
985
|
+
className: "font-mono text-sm"
|
|
986
|
+
}
|
|
987
|
+
)
|
|
988
|
+
] }),
|
|
989
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-ui-fg-subtle", children: "Supports Markdown formatting: **bold**, *italic*, `code`, ```code blocks```, [links](url), , and lists" })
|
|
990
|
+
] });
|
|
991
|
+
};
|
|
992
|
+
const CampaignImageUploader = ({
|
|
993
|
+
campaignId,
|
|
994
|
+
imageType,
|
|
995
|
+
currentImageUrl,
|
|
996
|
+
onClose,
|
|
997
|
+
onSuccess
|
|
998
|
+
}) => {
|
|
999
|
+
const [displayImage, setDisplayImage] = react.useState(currentImageUrl || null);
|
|
1000
|
+
const [isUploading, setIsUploading] = react.useState(false);
|
|
1001
|
+
const [isDragging, setIsDragging] = react.useState(false);
|
|
1002
|
+
const [error, setError] = react.useState(null);
|
|
1003
|
+
const [previewUrl, setPreviewUrl] = react.useState(null);
|
|
1004
|
+
const isThumbnail = imageType === "thumbnail";
|
|
1005
|
+
const maxSize = 5;
|
|
1006
|
+
const allowedTypes = ["image/jpeg", "image/png", "image/gif", "image/webp"];
|
|
1007
|
+
const formatFileTypes = () => {
|
|
1008
|
+
return "JPEG, PNG, GIF, or WebP";
|
|
1009
|
+
};
|
|
1010
|
+
const validateFile = (file) => {
|
|
1011
|
+
if (!allowedTypes.includes(file.type)) {
|
|
1012
|
+
setError(`Please upload a valid image file (${formatFileTypes()})`);
|
|
1013
|
+
return false;
|
|
1014
|
+
}
|
|
1015
|
+
if (file.size > maxSize * 1024 * 1024) {
|
|
1016
|
+
setError(`File size must be less than ${maxSize}MB`);
|
|
1017
|
+
return false;
|
|
1018
|
+
}
|
|
1019
|
+
return true;
|
|
1020
|
+
};
|
|
1021
|
+
const handleFileUpload = async (file) => {
|
|
1022
|
+
var _a, _b;
|
|
1023
|
+
if (!validateFile(file)) return;
|
|
1024
|
+
setError(null);
|
|
1025
|
+
const reader = new FileReader();
|
|
1026
|
+
reader.onloadend = () => {
|
|
1027
|
+
setPreviewUrl(reader.result);
|
|
1028
|
+
};
|
|
1029
|
+
reader.readAsDataURL(file);
|
|
1030
|
+
setIsUploading(true);
|
|
1031
|
+
const formData = new FormData();
|
|
1032
|
+
formData.append("file", file);
|
|
1033
|
+
try {
|
|
1034
|
+
const response = await fetch(
|
|
1035
|
+
`/admin/campaigns/${campaignId}/${imageType}`,
|
|
1036
|
+
{
|
|
1037
|
+
method: "POST",
|
|
1038
|
+
body: formData,
|
|
1039
|
+
credentials: "include"
|
|
1040
|
+
}
|
|
1041
|
+
);
|
|
1042
|
+
if (response.ok) {
|
|
1043
|
+
const result = await response.json();
|
|
1044
|
+
const newImageUrl = imageType === "image" ? (_a = result.campaign_detail) == null ? void 0 : _a.image_url : (_b = result.campaign_detail) == null ? void 0 : _b.thumbnail_url;
|
|
1045
|
+
setDisplayImage(newImageUrl);
|
|
1046
|
+
setPreviewUrl(null);
|
|
1047
|
+
onSuccess == null ? void 0 : onSuccess();
|
|
1048
|
+
setTimeout(() => {
|
|
1049
|
+
onClose();
|
|
1050
|
+
}, 1e3);
|
|
1051
|
+
} else {
|
|
1052
|
+
const errorData = await response.json();
|
|
1053
|
+
setError(errorData.error || `Failed to upload ${imageType}`);
|
|
1054
|
+
setPreviewUrl(null);
|
|
1055
|
+
}
|
|
1056
|
+
} catch (err) {
|
|
1057
|
+
setError(`Error uploading ${imageType}`);
|
|
1058
|
+
setPreviewUrl(null);
|
|
1059
|
+
console.error(`Error uploading ${imageType}:`, err);
|
|
1060
|
+
} finally {
|
|
1061
|
+
setIsUploading(false);
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
const handleDelete = async () => {
|
|
1065
|
+
if (!confirm(`Are you sure you want to delete the ${imageType}?`)) return;
|
|
1066
|
+
setIsUploading(true);
|
|
1067
|
+
setError(null);
|
|
1068
|
+
try {
|
|
1069
|
+
const response = await fetch(
|
|
1070
|
+
`/admin/campaigns/${campaignId}/${imageType}`,
|
|
1071
|
+
{
|
|
1072
|
+
method: "DELETE",
|
|
1073
|
+
credentials: "include"
|
|
1074
|
+
}
|
|
1075
|
+
);
|
|
1076
|
+
if (response.ok) {
|
|
1077
|
+
setDisplayImage(null);
|
|
1078
|
+
setPreviewUrl(null);
|
|
1079
|
+
onSuccess == null ? void 0 : onSuccess();
|
|
1080
|
+
setTimeout(() => {
|
|
1081
|
+
onClose();
|
|
1082
|
+
}, 500);
|
|
1083
|
+
} else {
|
|
1084
|
+
const errorData = await response.json();
|
|
1085
|
+
setError(errorData.error || `Failed to delete ${imageType}`);
|
|
1086
|
+
}
|
|
1087
|
+
} catch (err) {
|
|
1088
|
+
setError(`Error deleting ${imageType}`);
|
|
1089
|
+
console.error(`Error deleting ${imageType}:`, err);
|
|
1090
|
+
} finally {
|
|
1091
|
+
setIsUploading(false);
|
|
1092
|
+
}
|
|
1093
|
+
};
|
|
1094
|
+
const handleDragEnter = react.useCallback((e) => {
|
|
1095
|
+
e.preventDefault();
|
|
1096
|
+
e.stopPropagation();
|
|
1097
|
+
setIsDragging(true);
|
|
1098
|
+
}, []);
|
|
1099
|
+
const handleDragLeave = react.useCallback((e) => {
|
|
1100
|
+
e.preventDefault();
|
|
1101
|
+
e.stopPropagation();
|
|
1102
|
+
setIsDragging(false);
|
|
1103
|
+
}, []);
|
|
1104
|
+
const handleDragOver = react.useCallback((e) => {
|
|
1105
|
+
e.preventDefault();
|
|
1106
|
+
e.stopPropagation();
|
|
1107
|
+
}, []);
|
|
1108
|
+
const handleDrop = react.useCallback((e) => {
|
|
1109
|
+
var _a;
|
|
1110
|
+
e.preventDefault();
|
|
1111
|
+
e.stopPropagation();
|
|
1112
|
+
setIsDragging(false);
|
|
1113
|
+
const file = (_a = e.dataTransfer.files) == null ? void 0 : _a[0];
|
|
1114
|
+
if (file) {
|
|
1115
|
+
handleFileUpload(file);
|
|
1116
|
+
}
|
|
1117
|
+
}, []);
|
|
1118
|
+
const imageToDisplay = previewUrl || displayImage;
|
|
1119
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "fixed inset-0 z-50 flex items-center justify-center bg-black/50", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full max-w-2xl rounded-lg bg-ui-bg-base p-6", children: [
|
|
1120
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-6 flex items-center justify-between", children: [
|
|
1121
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1122
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Heading, { level: "h2", children: [
|
|
1123
|
+
"Upload Campaign ",
|
|
1124
|
+
isThumbnail ? "Thumbnail" : "Image"
|
|
1125
|
+
] }),
|
|
1126
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle", children: isThumbnail ? "Thumbnail for campaign listing" : "Main campaign image" })
|
|
1127
|
+
] }),
|
|
1128
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", onClick: onClose, children: /* @__PURE__ */ jsxRuntime.jsx(icons.X, {}) })
|
|
1129
|
+
] }),
|
|
1130
|
+
error && /* @__PURE__ */ jsxRuntime.jsx(ui.Alert, { variant: "error", dismissible: true, className: "mb-4", children: error }),
|
|
1131
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4", children: [
|
|
1132
|
+
imageToDisplay ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4", children: [
|
|
1133
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative overflow-hidden rounded-lg border border-ui-border-base bg-ui-bg-subtle", children: [
|
|
1134
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1135
|
+
"img",
|
|
1136
|
+
{
|
|
1137
|
+
src: imageToDisplay,
|
|
1138
|
+
alt: `Campaign ${imageType}`,
|
|
1139
|
+
className: ui.clx(
|
|
1140
|
+
"w-full object-contain",
|
|
1141
|
+
isThumbnail ? "h-32" : "h-64"
|
|
1142
|
+
)
|
|
1143
|
+
}
|
|
1144
|
+
),
|
|
1145
|
+
isUploading && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-black/50", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-white", children: "Uploading..." }) })
|
|
1146
|
+
] }),
|
|
1147
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
|
|
1148
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1149
|
+
ui.Button,
|
|
1150
|
+
{
|
|
1151
|
+
variant: "secondary",
|
|
1152
|
+
disabled: isUploading,
|
|
1153
|
+
onClick: () => {
|
|
1154
|
+
var _a;
|
|
1155
|
+
return (_a = document.getElementById(`${imageType}-file-input`)) == null ? void 0 : _a.click();
|
|
1156
|
+
},
|
|
1157
|
+
children: [
|
|
1158
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.CloudArrowUp, { className: "mr-2" }),
|
|
1159
|
+
"Replace"
|
|
1160
|
+
]
|
|
1161
|
+
}
|
|
1162
|
+
),
|
|
1163
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1164
|
+
ui.Button,
|
|
1165
|
+
{
|
|
1166
|
+
variant: "danger",
|
|
1167
|
+
disabled: isUploading,
|
|
1168
|
+
onClick: handleDelete,
|
|
1169
|
+
children: [
|
|
1170
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "mr-2" }),
|
|
1171
|
+
"Delete"
|
|
1172
|
+
]
|
|
1173
|
+
}
|
|
1174
|
+
)
|
|
1175
|
+
] })
|
|
1176
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1177
|
+
"div",
|
|
1178
|
+
{
|
|
1179
|
+
className: ui.clx(
|
|
1180
|
+
"flex flex-col items-center justify-center rounded-lg border-2 border-dashed transition-colors",
|
|
1181
|
+
isThumbnail ? "h-48" : "h-64",
|
|
1182
|
+
isDragging ? "border-ui-border-interactive bg-ui-bg-highlight" : "border-ui-border-base bg-ui-bg-subtle",
|
|
1183
|
+
!isUploading && "cursor-pointer"
|
|
1184
|
+
),
|
|
1185
|
+
onDragEnter: handleDragEnter,
|
|
1186
|
+
onDragLeave: handleDragLeave,
|
|
1187
|
+
onDragOver: handleDragOver,
|
|
1188
|
+
onDrop: handleDrop,
|
|
1189
|
+
onClick: () => {
|
|
1190
|
+
var _a;
|
|
1191
|
+
return !isUploading && ((_a = document.getElementById(`${imageType}-file-input`)) == null ? void 0 : _a.click());
|
|
1192
|
+
},
|
|
1193
|
+
children: [
|
|
1194
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.PhotoSolid, { className: "mb-4 h-12 w-12 text-ui-fg-subtle" }),
|
|
1195
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mb-2 text-lg font-medium", children: isDragging ? `Drop ${imageType} here` : `Upload ${isThumbnail ? "Thumbnail" : "Image"}` }),
|
|
1196
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mb-4 text-center text-ui-fg-subtle", children: "Drag and drop an image here, or click to select" }),
|
|
1197
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { className: "text-sm text-ui-fg-subtle", children: [
|
|
1198
|
+
formatFileTypes(),
|
|
1199
|
+
" • Max ",
|
|
1200
|
+
maxSize,
|
|
1201
|
+
"MB"
|
|
1202
|
+
] }),
|
|
1203
|
+
isThumbnail && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-2 text-xs text-ui-fg-subtle", children: "Recommended: 16:9 aspect ratio, minimum 400x225px" }),
|
|
1204
|
+
!isThumbnail && /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "mt-2 text-xs text-ui-fg-subtle", children: "Recommended: High resolution, minimum 1200x600px" }),
|
|
1205
|
+
isUploading && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mt-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: "Uploading..." }) })
|
|
1206
|
+
]
|
|
1207
|
+
}
|
|
1208
|
+
),
|
|
1209
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1210
|
+
"input",
|
|
1211
|
+
{
|
|
1212
|
+
id: `${imageType}-file-input`,
|
|
1213
|
+
type: "file",
|
|
1214
|
+
accept: allowedTypes.join(","),
|
|
1215
|
+
onChange: (e) => {
|
|
1216
|
+
var _a;
|
|
1217
|
+
const file = (_a = e.target.files) == null ? void 0 : _a[0];
|
|
1218
|
+
if (file) handleFileUpload(file);
|
|
1219
|
+
e.target.value = "";
|
|
1220
|
+
},
|
|
1221
|
+
className: "hidden"
|
|
1222
|
+
}
|
|
1223
|
+
)
|
|
1224
|
+
] }),
|
|
1225
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-6 flex items-center justify-between border-t pt-4", children: [
|
|
1226
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-sm text-ui-fg-subtle", children: isThumbnail ? "Thumbnail will be displayed in campaign listings" : "Main image for the campaign detail page" }),
|
|
1227
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: onClose, children: "Close" })
|
|
1228
|
+
] })
|
|
1229
|
+
] }) });
|
|
1230
|
+
};
|
|
1231
|
+
const CampaignDetailForm = ({
|
|
1232
|
+
campaignId,
|
|
1233
|
+
campaignName
|
|
1234
|
+
}) => {
|
|
1235
|
+
const [campaignDetail, setCampaignDetail] = react.useState(
|
|
1236
|
+
null
|
|
1237
|
+
);
|
|
1238
|
+
const [isLoading, setIsLoading] = react.useState(true);
|
|
1239
|
+
const [isSaving, setIsSaving] = react.useState(false);
|
|
1240
|
+
const [showImageUploader, setShowImageUploader] = react.useState(null);
|
|
1241
|
+
const [formData, setFormData] = react.useState({
|
|
1242
|
+
detail_content: "",
|
|
1243
|
+
terms_and_conditions: "",
|
|
1244
|
+
meta_title: "",
|
|
1245
|
+
meta_description: "",
|
|
1246
|
+
meta_keywords: "",
|
|
1247
|
+
link_url: "",
|
|
1248
|
+
link_text: "",
|
|
1249
|
+
display_order: 0
|
|
1250
|
+
});
|
|
1251
|
+
react.useEffect(() => {
|
|
1252
|
+
fetchCampaignDetail();
|
|
1253
|
+
}, [campaignId]);
|
|
1254
|
+
const fetchCampaignDetail = async () => {
|
|
1255
|
+
setIsLoading(true);
|
|
1256
|
+
try {
|
|
1257
|
+
const response = await fetch(`/admin/campaigns/${campaignId}/detail`, {
|
|
1258
|
+
credentials: "include"
|
|
1259
|
+
});
|
|
1260
|
+
if (response.ok) {
|
|
1261
|
+
const data = await response.json();
|
|
1262
|
+
if (data.campaign_detail) {
|
|
1263
|
+
console.log("Campaign detail loaded:", {
|
|
1264
|
+
image_url: data.campaign_detail.image_url,
|
|
1265
|
+
thumbnail_url: data.campaign_detail.thumbnail_url,
|
|
1266
|
+
decoded_image: data.campaign_detail.image_url ? decodeURIComponent(data.campaign_detail.image_url) : null,
|
|
1267
|
+
decoded_thumbnail: data.campaign_detail.thumbnail_url ? decodeURIComponent(data.campaign_detail.thumbnail_url) : null
|
|
1268
|
+
});
|
|
1269
|
+
setCampaignDetail(data.campaign_detail);
|
|
1270
|
+
setFormData({
|
|
1271
|
+
detail_content: data.campaign_detail.detail_content || "",
|
|
1272
|
+
terms_and_conditions: data.campaign_detail.terms_and_conditions || "",
|
|
1273
|
+
meta_title: data.campaign_detail.meta_title || "",
|
|
1274
|
+
meta_description: data.campaign_detail.meta_description || "",
|
|
1275
|
+
meta_keywords: data.campaign_detail.meta_keywords || "",
|
|
1276
|
+
link_url: data.campaign_detail.link_url || "",
|
|
1277
|
+
link_text: data.campaign_detail.link_text || "",
|
|
1278
|
+
display_order: data.campaign_detail.display_order || 0
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
} else if (response.status !== 404) {
|
|
1282
|
+
console.error("Failed to fetch campaign detail");
|
|
1283
|
+
}
|
|
1284
|
+
} catch (error) {
|
|
1285
|
+
console.error("Error fetching campaign detail:", error);
|
|
1286
|
+
} finally {
|
|
1287
|
+
setIsLoading(false);
|
|
1288
|
+
}
|
|
1289
|
+
};
|
|
1290
|
+
const handleSave = async () => {
|
|
1291
|
+
setIsSaving(true);
|
|
1292
|
+
try {
|
|
1293
|
+
const response = await fetch(`/admin/campaigns/${campaignId}/detail`, {
|
|
1294
|
+
method: "POST",
|
|
1295
|
+
headers: {
|
|
1296
|
+
"Content-Type": "application/json"
|
|
1297
|
+
},
|
|
1298
|
+
body: JSON.stringify(formData),
|
|
1299
|
+
credentials: "include"
|
|
1300
|
+
});
|
|
1301
|
+
if (response.ok) {
|
|
1302
|
+
const data = await response.json();
|
|
1303
|
+
setCampaignDetail(data.campaign_detail);
|
|
1304
|
+
ui.toast.success("Campaign details saved successfully");
|
|
1305
|
+
} else {
|
|
1306
|
+
const errorData = await response.json();
|
|
1307
|
+
ui.toast.error(errorData.error || "Failed to save campaign details");
|
|
1308
|
+
}
|
|
1309
|
+
} catch (error) {
|
|
1310
|
+
console.error("Error saving campaign detail:", error);
|
|
1311
|
+
ui.toast.error("Error saving campaign details");
|
|
1312
|
+
} finally {
|
|
1313
|
+
setIsSaving(false);
|
|
1314
|
+
}
|
|
1315
|
+
};
|
|
1316
|
+
if (isLoading) {
|
|
1317
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "py-8 text-center", children: "Loading campaign details..." }) });
|
|
1318
|
+
}
|
|
1319
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1320
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "space-y-6", children: [
|
|
1321
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
1322
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1323
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: "Campaign Details" }),
|
|
1324
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-ui-fg-subtle", children: campaignName })
|
|
1325
|
+
] }),
|
|
1326
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { onClick: handleSave, isLoading: isSaving, children: "Save Details" })
|
|
1327
|
+
] }),
|
|
1328
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4", children: [
|
|
1329
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", children: "Images" }),
|
|
1330
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
1331
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
1332
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Main Campaign Image" }),
|
|
1333
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1334
|
+
"div",
|
|
1335
|
+
{
|
|
1336
|
+
className: ui.clx(
|
|
1337
|
+
"relative flex h-64 items-center justify-center overflow-hidden rounded-lg border-2 border-dashed",
|
|
1338
|
+
(campaignDetail == null ? void 0 : campaignDetail.image_url) ? "border-ui-border-base" : "border-ui-border-base bg-ui-bg-subtle"
|
|
1339
|
+
),
|
|
1340
|
+
children: (campaignDetail == null ? void 0 : campaignDetail.image_url) ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1341
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1342
|
+
"img",
|
|
1343
|
+
{
|
|
1344
|
+
src: campaignDetail.image_url,
|
|
1345
|
+
alt: "Campaign",
|
|
1346
|
+
className: "h-full w-full object-cover",
|
|
1347
|
+
onError: (e) => {
|
|
1348
|
+
console.error(
|
|
1349
|
+
"Failed to load image:",
|
|
1350
|
+
campaignDetail.image_url
|
|
1351
|
+
);
|
|
1352
|
+
e.currentTarget.style.display = "none";
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
),
|
|
1356
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1357
|
+
ui.Button,
|
|
1358
|
+
{
|
|
1359
|
+
variant: "secondary",
|
|
1360
|
+
size: "small",
|
|
1361
|
+
className: "absolute bottom-2 right-2",
|
|
1362
|
+
onClick: () => setShowImageUploader("image"),
|
|
1363
|
+
children: [
|
|
1364
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, { className: "mr-1" }),
|
|
1365
|
+
"Change"
|
|
1366
|
+
]
|
|
1367
|
+
}
|
|
1368
|
+
)
|
|
1369
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1370
|
+
ui.Button,
|
|
1371
|
+
{
|
|
1372
|
+
variant: "secondary",
|
|
1373
|
+
onClick: () => setShowImageUploader("image"),
|
|
1374
|
+
children: [
|
|
1375
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.PhotoSolid, { className: "mr-2" }),
|
|
1376
|
+
"Upload Image"
|
|
1377
|
+
]
|
|
1378
|
+
}
|
|
1379
|
+
)
|
|
1380
|
+
}
|
|
1381
|
+
)
|
|
1382
|
+
] }),
|
|
1383
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
1384
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Thumbnail" }),
|
|
1385
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1386
|
+
"div",
|
|
1387
|
+
{
|
|
1388
|
+
className: ui.clx(
|
|
1389
|
+
"relative flex h-64 items-center justify-center overflow-hidden rounded-lg border-2 border-dashed",
|
|
1390
|
+
(campaignDetail == null ? void 0 : campaignDetail.thumbnail_url) ? "border-ui-border-base" : "border-ui-border-base bg-ui-bg-subtle"
|
|
1391
|
+
),
|
|
1392
|
+
children: (campaignDetail == null ? void 0 : campaignDetail.thumbnail_url) ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1393
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1394
|
+
"img",
|
|
1395
|
+
{
|
|
1396
|
+
src: campaignDetail.thumbnail_url,
|
|
1397
|
+
alt: "Thumbnail",
|
|
1398
|
+
className: "h-full w-full object-cover",
|
|
1399
|
+
onError: (e) => {
|
|
1400
|
+
console.error(
|
|
1401
|
+
"Failed to load thumbnail:",
|
|
1402
|
+
campaignDetail.thumbnail_url
|
|
1403
|
+
);
|
|
1404
|
+
e.currentTarget.style.display = "none";
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
),
|
|
1408
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1409
|
+
ui.Button,
|
|
1410
|
+
{
|
|
1411
|
+
variant: "secondary",
|
|
1412
|
+
size: "small",
|
|
1413
|
+
className: "absolute bottom-2 right-2",
|
|
1414
|
+
onClick: () => setShowImageUploader("thumbnail"),
|
|
1415
|
+
children: [
|
|
1416
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, { className: "mr-1" }),
|
|
1417
|
+
"Change"
|
|
1418
|
+
]
|
|
1419
|
+
}
|
|
1420
|
+
)
|
|
1421
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1422
|
+
ui.Button,
|
|
1423
|
+
{
|
|
1424
|
+
variant: "secondary",
|
|
1425
|
+
onClick: () => setShowImageUploader("thumbnail"),
|
|
1426
|
+
children: [
|
|
1427
|
+
/* @__PURE__ */ jsxRuntime.jsx(icons.PhotoSolid, { className: "mr-2" }),
|
|
1428
|
+
"Upload Thumbnail"
|
|
1429
|
+
]
|
|
1430
|
+
}
|
|
1431
|
+
)
|
|
1432
|
+
}
|
|
1433
|
+
)
|
|
1434
|
+
] })
|
|
1435
|
+
] })
|
|
1436
|
+
] }),
|
|
1437
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-4", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1438
|
+
MarkdownEditor,
|
|
1439
|
+
{
|
|
1440
|
+
label: "Campaign Detail Content",
|
|
1441
|
+
value: formData.detail_content,
|
|
1442
|
+
onChange: (value) => setFormData({ ...formData, detail_content: value }),
|
|
1443
|
+
placeholder: "Enter campaign details in Markdown format. You can include images, links, code blocks, and more...",
|
|
1444
|
+
helpText: "Supports Markdown and code syntax",
|
|
1445
|
+
rows: 12,
|
|
1446
|
+
showPreview: true
|
|
1447
|
+
}
|
|
1448
|
+
) }),
|
|
1449
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-4", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1450
|
+
MarkdownEditor,
|
|
1451
|
+
{
|
|
1452
|
+
label: "Terms and Conditions",
|
|
1453
|
+
value: formData.terms_and_conditions,
|
|
1454
|
+
onChange: (value) => setFormData({ ...formData, terms_and_conditions: value }),
|
|
1455
|
+
placeholder: "Enter terms and conditions for this campaign...",
|
|
1456
|
+
helpText: "Optional - Campaign specific terms",
|
|
1457
|
+
rows: 8,
|
|
1458
|
+
showPreview: true
|
|
1459
|
+
}
|
|
1460
|
+
) }),
|
|
1461
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4", children: [
|
|
1462
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", children: "Call to Action Link" }),
|
|
1463
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
1464
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
1465
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "link-url", children: "Link URL" }),
|
|
1466
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1467
|
+
ui.Input,
|
|
1468
|
+
{
|
|
1469
|
+
id: "link-url",
|
|
1470
|
+
type: "url",
|
|
1471
|
+
value: formData.link_url,
|
|
1472
|
+
onChange: (e) => setFormData({ ...formData, link_url: e.target.value }),
|
|
1473
|
+
placeholder: "https://example.com/campaign"
|
|
1474
|
+
}
|
|
1475
|
+
)
|
|
1476
|
+
] }),
|
|
1477
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
1478
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "link-text", children: "Link Text" }),
|
|
1479
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1480
|
+
ui.Input,
|
|
1481
|
+
{
|
|
1482
|
+
id: "link-text",
|
|
1483
|
+
value: formData.link_text,
|
|
1484
|
+
onChange: (e) => setFormData({ ...formData, link_text: e.target.value }),
|
|
1485
|
+
placeholder: "Shop Now"
|
|
1486
|
+
}
|
|
1487
|
+
)
|
|
1488
|
+
] })
|
|
1489
|
+
] })
|
|
1490
|
+
] }),
|
|
1491
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4", children: [
|
|
1492
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h3", children: "SEO & Metadata" }),
|
|
1493
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-4", children: [
|
|
1494
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
1495
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "meta-title", children: "Meta Title" }),
|
|
1496
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1497
|
+
ui.Input,
|
|
1498
|
+
{
|
|
1499
|
+
id: "meta-title",
|
|
1500
|
+
value: formData.meta_title,
|
|
1501
|
+
onChange: (e) => setFormData({ ...formData, meta_title: e.target.value }),
|
|
1502
|
+
placeholder: "Campaign meta title for SEO"
|
|
1503
|
+
}
|
|
1504
|
+
)
|
|
1505
|
+
] }),
|
|
1506
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
1507
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "meta-description", children: "Meta Description" }),
|
|
1508
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1509
|
+
ui.Input,
|
|
1510
|
+
{
|
|
1511
|
+
id: "meta-description",
|
|
1512
|
+
value: formData.meta_description,
|
|
1513
|
+
onChange: (e) => setFormData({
|
|
1514
|
+
...formData,
|
|
1515
|
+
meta_description: e.target.value
|
|
1516
|
+
}),
|
|
1517
|
+
placeholder: "Campaign meta description for SEO"
|
|
1518
|
+
}
|
|
1519
|
+
)
|
|
1520
|
+
] }),
|
|
1521
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
1522
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "meta-keywords", children: "Meta Keywords" }),
|
|
1523
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1524
|
+
ui.Input,
|
|
1525
|
+
{
|
|
1526
|
+
id: "meta-keywords",
|
|
1527
|
+
value: formData.meta_keywords,
|
|
1528
|
+
onChange: (e) => setFormData({
|
|
1529
|
+
...formData,
|
|
1530
|
+
meta_keywords: e.target.value
|
|
1531
|
+
}),
|
|
1532
|
+
placeholder: "keyword1, keyword2, keyword3"
|
|
1533
|
+
}
|
|
1534
|
+
),
|
|
1535
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-ui-fg-subtle", children: "Comma-separated keywords for SEO" })
|
|
1536
|
+
] }),
|
|
1537
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
|
|
1538
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "display-order", children: "Display Order" }),
|
|
1539
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1540
|
+
ui.Input,
|
|
1541
|
+
{
|
|
1542
|
+
id: "display-order",
|
|
1543
|
+
type: "number",
|
|
1544
|
+
value: formData.display_order,
|
|
1545
|
+
onChange: (e) => setFormData({
|
|
1546
|
+
...formData,
|
|
1547
|
+
display_order: parseInt(e.target.value) || 0
|
|
1548
|
+
}),
|
|
1549
|
+
placeholder: "0"
|
|
1550
|
+
}
|
|
1551
|
+
),
|
|
1552
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-ui-fg-subtle", children: "Lower numbers appear first in listings" })
|
|
1553
|
+
] })
|
|
1554
|
+
] })
|
|
1555
|
+
] }),
|
|
1556
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-end border-t pt-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { onClick: handleSave, isLoading: isSaving, children: "Save Campaign Details" }) })
|
|
1557
|
+
] }),
|
|
1558
|
+
showImageUploader && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1559
|
+
CampaignImageUploader,
|
|
1560
|
+
{
|
|
1561
|
+
campaignId,
|
|
1562
|
+
imageType: showImageUploader,
|
|
1563
|
+
currentImageUrl: showImageUploader === "image" ? campaignDetail == null ? void 0 : campaignDetail.image_url : campaignDetail == null ? void 0 : campaignDetail.thumbnail_url,
|
|
1564
|
+
onClose: () => setShowImageUploader(null),
|
|
1565
|
+
onSuccess: fetchCampaignDetail
|
|
1566
|
+
}
|
|
1567
|
+
)
|
|
1568
|
+
] });
|
|
1569
|
+
};
|
|
1570
|
+
const CouponDetail = () => {
|
|
1571
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1572
|
+
const { id } = reactRouterDom.useParams();
|
|
1573
|
+
const navigate = reactRouterDom.useNavigate();
|
|
1574
|
+
const [isEditing, setIsEditing] = react.useState(false);
|
|
1575
|
+
const { data, isLoading, refetch } = useCouponById(id ?? "");
|
|
1576
|
+
if (isLoading) {
|
|
1577
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "flex items-center justify-center h-screen", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "animate-spin h-10 w-10 border-4 border-primary rounded-full border-t-transparent" }) });
|
|
1578
|
+
}
|
|
1579
|
+
if (!(data == null ? void 0 : data.campaign)) {
|
|
1580
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { children: /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Coupon not found" }) });
|
|
1581
|
+
}
|
|
1582
|
+
const campaign = data.campaign;
|
|
1583
|
+
const promotion = (_a = campaign.promotions) == null ? void 0 : _a[0];
|
|
1584
|
+
const initialValues = {
|
|
1585
|
+
name: campaign.name ?? "",
|
|
1586
|
+
description: campaign.description ?? "",
|
|
1587
|
+
type: "coupon",
|
|
1588
|
+
code: (promotion == null ? void 0 : promotion.code) ?? "",
|
|
1589
|
+
discount_type: ((_b = promotion == null ? void 0 : promotion.application_method) == null ? void 0 : _b.type) ?? "percentage",
|
|
1590
|
+
discount_value: Number(((_c = promotion == null ? void 0 : promotion.application_method) == null ? void 0 : _c.value) ?? 0),
|
|
1591
|
+
currency_code: ((_d = promotion == null ? void 0 : promotion.application_method) == null ? void 0 : _d.currency_code) ?? void 0,
|
|
1592
|
+
starts_at: campaign.starts_at ? dayjs__default.default(campaign.starts_at).format("YYYY-MM-DDTHH:mm") : void 0,
|
|
1593
|
+
ends_at: campaign.ends_at ? dayjs__default.default(campaign.ends_at).format("YYYY-MM-DDTHH:mm") : void 0,
|
|
1594
|
+
allocation: ((_e = promotion == null ? void 0 : promotion.application_method) == null ? void 0 : _e.allocation) ?? "total",
|
|
1595
|
+
target_type: ((_f = promotion == null ? void 0 : promotion.application_method) == null ? void 0 : _f.target_type) ?? "order"
|
|
1596
|
+
};
|
|
1597
|
+
const handleSubmit = async (formData) => {
|
|
1598
|
+
var _a2, _b2;
|
|
1599
|
+
if (!id) {
|
|
1600
|
+
return;
|
|
1601
|
+
}
|
|
1602
|
+
try {
|
|
1603
|
+
await axios__default.default.put(`/admin/coupons/${id}`, {
|
|
1604
|
+
...formData,
|
|
1605
|
+
starts_at: new Date(formData.starts_at).toUTCString(),
|
|
1606
|
+
ends_at: new Date(formData.ends_at).toUTCString(),
|
|
1607
|
+
currency_code: formData.discount_type === "fixed" ? formData.currency_code : void 0
|
|
1608
|
+
});
|
|
1609
|
+
ui.toast.success("Coupon updated successfully");
|
|
1610
|
+
setIsEditing(false);
|
|
1611
|
+
refetch();
|
|
1612
|
+
} catch (error) {
|
|
1613
|
+
let message = "Failed to update coupon";
|
|
1614
|
+
if (axios__default.default.isAxiosError(error)) {
|
|
1615
|
+
message = ((_b2 = (_a2 = error.response) == null ? void 0 : _a2.data) == null ? void 0 : _b2.message) ?? message;
|
|
1616
|
+
} else if (error instanceof Error) {
|
|
1617
|
+
message = error.message;
|
|
1618
|
+
}
|
|
1619
|
+
ui.toast.error("Failed to update coupon", {
|
|
1620
|
+
description: message
|
|
1621
|
+
});
|
|
1622
|
+
}
|
|
1623
|
+
};
|
|
1624
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { children: [
|
|
1625
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-6 flex items-center justify-between", children: [
|
|
1626
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1627
|
+
/* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-2xl font-semibold mb-1", children: campaign.name }),
|
|
1628
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-ui-fg-subtle", children: "Manage coupon configuration and content" })
|
|
1629
|
+
] }),
|
|
1630
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
|
|
1631
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => navigate("/coupons"), children: "Back to Coupons" }),
|
|
1632
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { onClick: () => setIsEditing((prev) => !prev), children: isEditing ? "View Mode" : "Edit Mode" })
|
|
1633
|
+
] })
|
|
1634
|
+
] }),
|
|
1635
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Tabs, { defaultValue: "settings", children: [
|
|
1636
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Tabs.List, { children: [
|
|
1637
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Tabs.Trigger, { value: "settings", children: "Coupon Settings" }),
|
|
1638
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Tabs.Trigger, { value: "details", children: "Coupon Details" })
|
|
1639
|
+
] }),
|
|
1640
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Tabs.Content, { value: "settings", className: "mt-6", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1641
|
+
CouponForm,
|
|
1642
|
+
{
|
|
1643
|
+
initialData: initialValues,
|
|
1644
|
+
onSubmit: handleSubmit,
|
|
1645
|
+
onCancel: () => navigate("/coupons"),
|
|
1646
|
+
disabled: !isEditing
|
|
1647
|
+
}
|
|
1648
|
+
) }),
|
|
1649
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Tabs.Content, { value: "details", className: "mt-6", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1650
|
+
CampaignDetailForm,
|
|
1651
|
+
{
|
|
1652
|
+
campaignId: campaign.id,
|
|
1653
|
+
campaignName: campaign.name ?? ""
|
|
1654
|
+
}
|
|
1655
|
+
) })
|
|
1656
|
+
] })
|
|
1657
|
+
] });
|
|
1658
|
+
};
|
|
1659
|
+
const config$1 = adminSdk.defineRouteConfig({
|
|
1660
|
+
label: "Coupon Detail",
|
|
1661
|
+
icon: icons.Tag
|
|
1662
|
+
});
|
|
1663
|
+
const CouponCreate = () => {
|
|
1664
|
+
const navigate = reactRouterDom.useNavigate();
|
|
1665
|
+
const handleSubmit = async (formData) => {
|
|
1666
|
+
var _a, _b;
|
|
1667
|
+
try {
|
|
1668
|
+
await axios__default.default.post("/admin/coupons", {
|
|
1669
|
+
...formData,
|
|
1670
|
+
starts_at: new Date(formData.starts_at).toUTCString(),
|
|
1671
|
+
ends_at: new Date(formData.ends_at).toUTCString(),
|
|
1672
|
+
currency_code: formData.discount_type === "fixed" ? formData.currency_code : void 0
|
|
1673
|
+
});
|
|
1674
|
+
ui.toast.success("Coupon created successfully");
|
|
1675
|
+
navigate("/coupons");
|
|
1676
|
+
} catch (error) {
|
|
1677
|
+
let message = "Failed to create coupon";
|
|
1678
|
+
if (axios__default.default.isAxiosError(error)) {
|
|
1679
|
+
message = ((_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) ?? message;
|
|
1680
|
+
} else if (error instanceof Error) {
|
|
1681
|
+
message = error.message;
|
|
1682
|
+
}
|
|
1683
|
+
ui.toast.error("Failed to create coupon", {
|
|
1684
|
+
description: message
|
|
1685
|
+
});
|
|
1686
|
+
}
|
|
1687
|
+
};
|
|
1688
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1689
|
+
CouponForm,
|
|
1690
|
+
{
|
|
1691
|
+
onSubmit: handleSubmit,
|
|
1692
|
+
onCancel: () => navigate("/coupons")
|
|
1693
|
+
}
|
|
1694
|
+
);
|
|
1695
|
+
};
|
|
1696
|
+
const sdk = new Medusa__default.default({
|
|
1697
|
+
baseUrl: "/",
|
|
1698
|
+
debug: false,
|
|
1699
|
+
auth: {
|
|
1700
|
+
type: "session"
|
|
1701
|
+
}
|
|
1702
|
+
});
|
|
1703
|
+
const columnHelper = ui.createDataTableColumnHelper();
|
|
1704
|
+
const columns = [
|
|
1705
|
+
columnHelper.accessor("title", {
|
|
1706
|
+
header: "Title",
|
|
1707
|
+
cell: (info) => /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "large", className: "py-2", children: info.getValue() })
|
|
1708
|
+
}),
|
|
1709
|
+
columnHelper.accessor("description", {
|
|
1710
|
+
header: "Description",
|
|
1711
|
+
cell: (info) => /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "large", className: "py-2", children: info.getValue() })
|
|
1712
|
+
})
|
|
1713
|
+
];
|
|
1714
|
+
const ProductSelector = ({
|
|
1715
|
+
selectedProductIds,
|
|
1716
|
+
onSelectProduct
|
|
1717
|
+
}) => {
|
|
1718
|
+
const [search, setSearch] = react.useState("");
|
|
1719
|
+
const debouncedSearchHandler = lodash.debounce((value) => {
|
|
1720
|
+
setSearch(value);
|
|
1721
|
+
}, 500);
|
|
1722
|
+
const [products, setProducts] = react.useState(null);
|
|
1723
|
+
const [isLoading, setIsLoading] = react.useState(true);
|
|
1724
|
+
react.useEffect(() => {
|
|
1725
|
+
const fetchProducts = async () => {
|
|
1726
|
+
setIsLoading(true);
|
|
1727
|
+
try {
|
|
1728
|
+
const result = await sdk.admin.product.list({
|
|
1729
|
+
q: search,
|
|
1730
|
+
limit: 100
|
|
1731
|
+
});
|
|
1732
|
+
setProducts(result);
|
|
1733
|
+
} catch (error) {
|
|
1734
|
+
console.error("Failed to fetch products:", error);
|
|
1735
|
+
} finally {
|
|
1736
|
+
setIsLoading(false);
|
|
1737
|
+
}
|
|
1738
|
+
};
|
|
1739
|
+
fetchProducts();
|
|
1740
|
+
}, [selectedProductIds, search]);
|
|
1741
|
+
const selectableProducts = react.useMemo(() => {
|
|
1742
|
+
var _a;
|
|
1743
|
+
return (_a = products == null ? void 0 : products.products) == null ? void 0 : _a.filter(
|
|
1744
|
+
(product) => !selectedProductIds.includes(product.id)
|
|
1745
|
+
);
|
|
1746
|
+
}, [products == null ? void 0 : products.products, selectedProductIds]);
|
|
1747
|
+
const table = ui.useDataTable({
|
|
1748
|
+
data: selectableProducts || [],
|
|
1749
|
+
columns,
|
|
1750
|
+
getRowId: (product) => product.id,
|
|
1751
|
+
onRowClick: (_, row) => {
|
|
1752
|
+
onSelectProduct == null ? void 0 : onSelectProduct(row.original);
|
|
1753
|
+
}
|
|
1754
|
+
});
|
|
1755
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { children: [
|
|
1756
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1757
|
+
ui.Input,
|
|
1758
|
+
{
|
|
1759
|
+
className: "text-lg py-2",
|
|
1760
|
+
placeholder: "Search products...",
|
|
1761
|
+
onChange: (e) => debouncedSearchHandler(e.target.value)
|
|
1762
|
+
}
|
|
1763
|
+
),
|
|
1764
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.DataTable, { instance: table, children: /* @__PURE__ */ jsxRuntime.jsx(ui.DataTable.Table, {}) })
|
|
1765
|
+
] });
|
|
1766
|
+
};
|
|
1767
|
+
const customCampaignSchema = z__default.default.object({
|
|
1768
|
+
name: z__default.default.string().min(1, "Name is required"),
|
|
1769
|
+
description: z__default.default.string().min(1, "Description is required"),
|
|
1770
|
+
type: z__default.default.literal("flash-sale"),
|
|
1771
|
+
starts_at: z__default.default.string().min(1, "Start date is required"),
|
|
1772
|
+
ends_at: z__default.default.string().min(1, "End date is required")
|
|
1773
|
+
});
|
|
1774
|
+
const campaignProductSchema = z__default.default.object({
|
|
1775
|
+
product: z__default.default.object({
|
|
1776
|
+
id: z__default.default.string(),
|
|
1777
|
+
title: z__default.default.string()
|
|
1778
|
+
}),
|
|
1779
|
+
discountType: z__default.default.enum([
|
|
1780
|
+
"percentage"
|
|
1781
|
+
// , "fixed"
|
|
1782
|
+
]),
|
|
1783
|
+
discountValue: z__default.default.number().min(1),
|
|
1784
|
+
limit: z__default.default.number().min(1),
|
|
1785
|
+
maxQty: z__default.default.number().min(1)
|
|
1786
|
+
});
|
|
1787
|
+
const campaignDataSchema = customCampaignSchema.extend({
|
|
1788
|
+
products: z__default.default.array(campaignProductSchema).min(1, "At least one product is required")
|
|
1789
|
+
}).refine(
|
|
1790
|
+
(data) => new Date(data.starts_at) < new Date(data.ends_at),
|
|
1791
|
+
"End date must be after start date"
|
|
1792
|
+
);
|
|
1793
|
+
const FlashSaleForm = ({
|
|
1794
|
+
initialData,
|
|
1795
|
+
initialProducts,
|
|
1796
|
+
onSubmit,
|
|
1797
|
+
onCancel,
|
|
1798
|
+
disabled = false
|
|
1799
|
+
}) => {
|
|
1800
|
+
var _a;
|
|
1801
|
+
const {
|
|
1802
|
+
control,
|
|
1803
|
+
register,
|
|
1804
|
+
handleSubmit,
|
|
1805
|
+
watch,
|
|
1806
|
+
setValue,
|
|
1807
|
+
formState: { errors }
|
|
1808
|
+
} = reactHookForm.useForm({
|
|
1809
|
+
resolver: zod.zodResolver(campaignDataSchema),
|
|
1810
|
+
defaultValues: {
|
|
1811
|
+
name: (initialData == null ? void 0 : initialData.name) || "",
|
|
1812
|
+
description: (initialData == null ? void 0 : initialData.description) || "",
|
|
1813
|
+
type: "flash-sale",
|
|
1814
|
+
starts_at: (initialData == null ? void 0 : initialData.starts_at) || "",
|
|
1815
|
+
ends_at: (initialData == null ? void 0 : initialData.ends_at) || "",
|
|
1816
|
+
products: initialProducts ? Array.from(initialProducts.values()) : []
|
|
1817
|
+
}
|
|
1818
|
+
});
|
|
1819
|
+
const { fields, append, remove, update } = reactHookForm.useFieldArray({
|
|
1820
|
+
control,
|
|
1821
|
+
name: "products"
|
|
1822
|
+
});
|
|
1823
|
+
const [openProductModal, setOpenProductModal] = react.useState(false);
|
|
1824
|
+
const startsAt = watch("starts_at");
|
|
1825
|
+
const endsAt = watch("ends_at");
|
|
1826
|
+
const handleDateTimeChange = (field, type, value) => {
|
|
1827
|
+
const currentValue = watch(field);
|
|
1828
|
+
if (type === "date") {
|
|
1829
|
+
const time = currentValue ? dayjs__default.default(currentValue).format("HH:mm") : field === "starts_at" ? "00:00" : "23:59";
|
|
1830
|
+
setValue(field, `${value}T${time}`);
|
|
1831
|
+
} else {
|
|
1832
|
+
const date = currentValue ? dayjs__default.default(currentValue).format("YYYY-MM-DD") : dayjs__default.default().format("YYYY-MM-DD");
|
|
1833
|
+
setValue(field, `${date}T${value}`);
|
|
1834
|
+
}
|
|
1835
|
+
};
|
|
1836
|
+
const onFormSubmit = (data) => {
|
|
1837
|
+
onSubmit(data);
|
|
1838
|
+
};
|
|
1839
|
+
const onFormError = () => {
|
|
1840
|
+
const errorMessages = Object.entries(errors).map(([key, value]) => {
|
|
1841
|
+
var _a2;
|
|
1842
|
+
if (key === "products" && Array.isArray(value)) {
|
|
1843
|
+
return value.map(
|
|
1844
|
+
(item, index) => item ? `Product ${index + 1}: ${Object.values(item).join(", ")}` : ""
|
|
1845
|
+
).filter(Boolean).join(", ");
|
|
1846
|
+
}
|
|
1847
|
+
return (value == null ? void 0 : value.message) || ((_a2 = value == null ? void 0 : value.root) == null ? void 0 : _a2.message);
|
|
1848
|
+
}).filter(Boolean).join(", ");
|
|
1849
|
+
ui.toast.error("Invalid data", {
|
|
1850
|
+
description: errorMessages
|
|
1851
|
+
});
|
|
1852
|
+
};
|
|
1853
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { children: [
|
|
1854
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
|
|
1855
|
+
/* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-xl font-semibold", children: "Flash sale campaign" }),
|
|
1856
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "transparent", onClick: onCancel, children: "Cancel" })
|
|
1857
|
+
] }),
|
|
1858
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1859
|
+
"form",
|
|
1860
|
+
{
|
|
1861
|
+
onSubmit: handleSubmit(onFormSubmit, onFormError),
|
|
1862
|
+
className: "space-y-4 my-8",
|
|
1863
|
+
children: [
|
|
1864
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1865
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Name" }),
|
|
1866
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...register("name"), disabled }),
|
|
1867
|
+
errors.name && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-red-500 text-sm mt-1", children: errors.name.message })
|
|
1868
|
+
] }),
|
|
1869
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1870
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Description" }),
|
|
1871
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Textarea, { ...register("description"), disabled }),
|
|
1872
|
+
errors.description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-red-500 text-sm mt-1", children: errors.description.message })
|
|
1873
|
+
] }),
|
|
1874
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
1875
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1876
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Start Date" }),
|
|
1877
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
|
|
1878
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1879
|
+
ui.Input,
|
|
1880
|
+
{
|
|
1881
|
+
type: "date",
|
|
1882
|
+
value: startsAt ? dayjs__default.default(startsAt).format("YYYY-MM-DD") : "",
|
|
1883
|
+
onChange: (e) => handleDateTimeChange("starts_at", "date", e.target.value),
|
|
1884
|
+
disabled,
|
|
1885
|
+
className: "flex-1"
|
|
1886
|
+
}
|
|
1887
|
+
),
|
|
1888
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1889
|
+
ui.Input,
|
|
1890
|
+
{
|
|
1891
|
+
type: "time",
|
|
1892
|
+
value: startsAt ? dayjs__default.default(startsAt).format("HH:mm") : "",
|
|
1893
|
+
onChange: (e) => handleDateTimeChange("starts_at", "time", e.target.value),
|
|
1894
|
+
disabled,
|
|
1895
|
+
className: "w-32"
|
|
1896
|
+
}
|
|
1897
|
+
)
|
|
1898
|
+
] }),
|
|
1899
|
+
errors.starts_at && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-red-500 text-sm mt-1", children: errors.starts_at.message })
|
|
1900
|
+
] }),
|
|
1901
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
1902
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "End Date" }),
|
|
1903
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
|
|
1904
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1905
|
+
ui.Input,
|
|
1906
|
+
{
|
|
1907
|
+
type: "date",
|
|
1908
|
+
value: endsAt ? dayjs__default.default(endsAt).format("YYYY-MM-DD") : "",
|
|
1909
|
+
onChange: (e) => handleDateTimeChange("ends_at", "date", e.target.value),
|
|
1910
|
+
disabled,
|
|
1911
|
+
className: "flex-1"
|
|
1912
|
+
}
|
|
1913
|
+
),
|
|
1914
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1915
|
+
ui.Input,
|
|
1916
|
+
{
|
|
1917
|
+
type: "time",
|
|
1918
|
+
value: endsAt ? dayjs__default.default(endsAt).format("HH:mm") : "",
|
|
1919
|
+
onChange: (e) => handleDateTimeChange("ends_at", "time", e.target.value),
|
|
1920
|
+
disabled,
|
|
1921
|
+
className: "w-32"
|
|
1922
|
+
}
|
|
1923
|
+
)
|
|
1924
|
+
] }),
|
|
1925
|
+
errors.ends_at && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-red-500 text-sm mt-1", children: errors.ends_at.message })
|
|
1926
|
+
] })
|
|
1927
|
+
] }),
|
|
1928
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-between items-center", children: [
|
|
1929
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { children: "Products" }),
|
|
1930
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1931
|
+
ui.Button,
|
|
1932
|
+
{
|
|
1933
|
+
type: "button",
|
|
1934
|
+
variant: "secondary",
|
|
1935
|
+
onClick: () => setOpenProductModal(true),
|
|
1936
|
+
disabled,
|
|
1937
|
+
children: "Add Product"
|
|
1938
|
+
}
|
|
1939
|
+
)
|
|
1940
|
+
] }),
|
|
1941
|
+
((_a = errors.products) == null ? void 0 : _a.root) && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-red-500 text-sm", children: errors.products.root.message }),
|
|
1942
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Table, { children: [
|
|
1943
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Header, { children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Table.Row, { children: [
|
|
1944
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Product" }),
|
|
1945
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Discount Type" }),
|
|
1946
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Discount Value" }),
|
|
1947
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Limit" }),
|
|
1948
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Max Qty per Order" }),
|
|
1949
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.HeaderCell, { children: "Actions" })
|
|
1950
|
+
] }) }),
|
|
1951
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Body, { children: fields.map((field, index) => /* @__PURE__ */ jsxRuntime.jsxs(ui.Table.Row, { children: [
|
|
1952
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: field.product.title }),
|
|
1953
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1954
|
+
reactHookForm.Controller,
|
|
1955
|
+
{
|
|
1956
|
+
name: `products.${index}.discountType`,
|
|
1957
|
+
control,
|
|
1958
|
+
render: ({ field: field2 }) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1959
|
+
ui.Select,
|
|
1960
|
+
{
|
|
1961
|
+
value: field2.value,
|
|
1962
|
+
onValueChange: field2.onChange,
|
|
1963
|
+
disabled,
|
|
1964
|
+
children: [
|
|
1965
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, { placeholder: "Select discount type" }) }),
|
|
1966
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: "percentage", children: "Percentage" }) })
|
|
1967
|
+
]
|
|
1968
|
+
}
|
|
1969
|
+
)
|
|
1970
|
+
}
|
|
1971
|
+
) }),
|
|
1972
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1973
|
+
reactHookForm.Controller,
|
|
1974
|
+
{
|
|
1975
|
+
name: `products.${index}.discountValue`,
|
|
1976
|
+
control,
|
|
1977
|
+
render: ({ field: field2 }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1978
|
+
ui.Input,
|
|
1979
|
+
{
|
|
1980
|
+
type: "number",
|
|
1981
|
+
value: field2.value,
|
|
1982
|
+
onChange: (e) => field2.onChange(Number(e.target.value)),
|
|
1983
|
+
disabled
|
|
1984
|
+
}
|
|
1985
|
+
)
|
|
1986
|
+
}
|
|
1987
|
+
) }),
|
|
1988
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1989
|
+
reactHookForm.Controller,
|
|
1990
|
+
{
|
|
1991
|
+
name: `products.${index}.limit`,
|
|
1992
|
+
control,
|
|
1993
|
+
render: ({ field: field2 }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1994
|
+
ui.Input,
|
|
1995
|
+
{
|
|
1996
|
+
type: "number",
|
|
1997
|
+
value: field2.value,
|
|
1998
|
+
onChange: (e) => field2.onChange(Number(e.target.value)),
|
|
1999
|
+
disabled
|
|
2000
|
+
}
|
|
2001
|
+
)
|
|
2002
|
+
}
|
|
2003
|
+
) }),
|
|
2004
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2005
|
+
reactHookForm.Controller,
|
|
2006
|
+
{
|
|
2007
|
+
name: `products.${index}.maxQty`,
|
|
2008
|
+
control,
|
|
2009
|
+
render: ({ field: field2 }) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2010
|
+
ui.Input,
|
|
2011
|
+
{
|
|
2012
|
+
type: "number",
|
|
2013
|
+
value: field2.value,
|
|
2014
|
+
onChange: (e) => field2.onChange(Number(e.target.value)),
|
|
2015
|
+
disabled
|
|
2016
|
+
}
|
|
2017
|
+
)
|
|
2018
|
+
}
|
|
2019
|
+
) }),
|
|
2020
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2021
|
+
ui.Button,
|
|
2022
|
+
{
|
|
2023
|
+
type: "button",
|
|
2024
|
+
variant: "danger",
|
|
2025
|
+
onClick: () => remove(index),
|
|
2026
|
+
disabled,
|
|
2027
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {})
|
|
2028
|
+
}
|
|
2029
|
+
) })
|
|
2030
|
+
] }, field.id)) })
|
|
2031
|
+
] }),
|
|
2032
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { type: "submit", disabled, children: "Save" })
|
|
2033
|
+
]
|
|
2034
|
+
}
|
|
2035
|
+
),
|
|
2036
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.FocusModal, { open: openProductModal, onOpenChange: setOpenProductModal, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.FocusModal.Content, { children: [
|
|
2037
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.FocusModal.Header, { title: "Add Product" }),
|
|
2038
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.FocusModal.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2039
|
+
ProductSelector,
|
|
2040
|
+
{
|
|
2041
|
+
selectedProductIds: fields.map((f) => f.product.id),
|
|
2042
|
+
onSelectProduct: (product) => {
|
|
2043
|
+
append({
|
|
2044
|
+
product,
|
|
2045
|
+
discountType: "percentage",
|
|
2046
|
+
discountValue: 10,
|
|
2047
|
+
limit: 10,
|
|
2048
|
+
maxQty: 1
|
|
2049
|
+
});
|
|
2050
|
+
setOpenProductModal(false);
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
) })
|
|
2054
|
+
] }) })
|
|
2055
|
+
] });
|
|
2056
|
+
};
|
|
2057
|
+
const useFlashSaleById = (id) => {
|
|
2058
|
+
const [data, setData] = react.useState(null);
|
|
2059
|
+
const [isLoading, setIsLoading] = react.useState(true);
|
|
2060
|
+
const [error, setError] = react.useState(null);
|
|
2061
|
+
const fetchFlashSale = async () => {
|
|
2062
|
+
if (!id) {
|
|
2063
|
+
setIsLoading(false);
|
|
2064
|
+
return;
|
|
2065
|
+
}
|
|
2066
|
+
setIsLoading(true);
|
|
2067
|
+
setError(null);
|
|
2068
|
+
try {
|
|
2069
|
+
const response = await axios__default.default.get(`/admin/flash-sales/${id}`);
|
|
2070
|
+
setData(response.data);
|
|
2071
|
+
} catch (err) {
|
|
2072
|
+
setError(
|
|
2073
|
+
err instanceof Error ? err : new Error("Failed to fetch flash sale")
|
|
2074
|
+
);
|
|
2075
|
+
} finally {
|
|
2076
|
+
setIsLoading(false);
|
|
2077
|
+
}
|
|
2078
|
+
};
|
|
2079
|
+
react.useEffect(() => {
|
|
2080
|
+
fetchFlashSale();
|
|
2081
|
+
}, [id]);
|
|
2082
|
+
return {
|
|
2083
|
+
data,
|
|
2084
|
+
isLoading,
|
|
2085
|
+
error,
|
|
2086
|
+
refetch: fetchFlashSale
|
|
2087
|
+
};
|
|
2088
|
+
};
|
|
2089
|
+
const FlashSaleDetail = () => {
|
|
2090
|
+
const { id } = reactRouterDom.useParams();
|
|
2091
|
+
const navigate = reactRouterDom.useNavigate();
|
|
2092
|
+
const { data, isLoading, refetch } = useFlashSaleById(id || "");
|
|
2093
|
+
const [isEditing, setIsEditing] = react.useState(false);
|
|
2094
|
+
async function handleSubmit(campaignData2) {
|
|
2095
|
+
var _a;
|
|
2096
|
+
try {
|
|
2097
|
+
await axios__default.default.put(`/admin/flash-sales/${id}`, {
|
|
2098
|
+
...campaignData2,
|
|
2099
|
+
starts_at: new Date(campaignData2.starts_at).toUTCString(),
|
|
2100
|
+
ends_at: new Date(campaignData2.ends_at).toUTCString()
|
|
2101
|
+
});
|
|
2102
|
+
ui.toast.success("Flash sale updated successfully");
|
|
2103
|
+
refetch();
|
|
2104
|
+
navigate("/flash-sales");
|
|
2105
|
+
} catch (error) {
|
|
2106
|
+
let message;
|
|
2107
|
+
if (axios__default.default.isAxiosError(error)) {
|
|
2108
|
+
console.log(error);
|
|
2109
|
+
message = (_a = error.response) == null ? void 0 : _a.data.message;
|
|
2110
|
+
} else if (error instanceof Error) {
|
|
2111
|
+
message = error.message;
|
|
2112
|
+
} else {
|
|
2113
|
+
message = "Failed to update flash sale";
|
|
2114
|
+
}
|
|
2115
|
+
ui.toast.error("Failed to update flash sale", {
|
|
2116
|
+
description: message
|
|
2117
|
+
});
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
if (isLoading) {
|
|
2121
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { className: "flex items-center justify-center h-screen", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "animate-spin h-10 w-10 border-4 border-primary rounded-full border-t-transparent" }) });
|
|
2122
|
+
}
|
|
2123
|
+
if (!data) {
|
|
2124
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ui.Container, { children: /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Flash sale not found" }) });
|
|
2125
|
+
}
|
|
2126
|
+
const campaignData = {
|
|
2127
|
+
name: data.name || "",
|
|
2128
|
+
description: data.description || "",
|
|
2129
|
+
type: "flash-sale",
|
|
2130
|
+
starts_at: data.starts_at,
|
|
2131
|
+
ends_at: data.ends_at
|
|
2132
|
+
};
|
|
2133
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { children: [
|
|
2134
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mb-6 flex items-center justify-between", children: [
|
|
2135
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
2136
|
+
/* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-2xl font-semibold mb-1", children: data.name }),
|
|
2137
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-ui-fg-subtle", children: "Manage campaign settings and content" })
|
|
2138
|
+
] }),
|
|
2139
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex gap-2", children: [
|
|
2140
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", onClick: () => navigate("/flash-sales"), children: "Back to Campaigns" }),
|
|
2141
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { onClick: () => setIsEditing((prev) => !prev), children: isEditing ? "View Mode" : "Edit Mode" })
|
|
2142
|
+
] })
|
|
2143
|
+
] }),
|
|
2144
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Tabs, { defaultValue: "settings", children: [
|
|
2145
|
+
/* @__PURE__ */ jsxRuntime.jsxs(ui.Tabs.List, { children: [
|
|
2146
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Tabs.Trigger, { value: "settings", children: "Campaign Settings" }),
|
|
2147
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Tabs.Trigger, { value: "details", children: "Campaign Details" })
|
|
2148
|
+
] }),
|
|
2149
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Tabs.Content, { value: "settings", className: "mt-6", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2150
|
+
FlashSaleForm,
|
|
2151
|
+
{
|
|
2152
|
+
initialData: campaignData,
|
|
2153
|
+
initialProducts: new Map(
|
|
2154
|
+
data.products.map((product) => [product.product.id, product])
|
|
2155
|
+
),
|
|
2156
|
+
onSubmit: handleSubmit,
|
|
2157
|
+
onCancel: () => navigate("/flash-sales"),
|
|
2158
|
+
disabled: !isEditing
|
|
2159
|
+
}
|
|
2160
|
+
) }),
|
|
2161
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Tabs.Content, { value: "details", className: "mt-6", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2162
|
+
CampaignDetailForm,
|
|
2163
|
+
{
|
|
2164
|
+
campaignId: id || "",
|
|
2165
|
+
campaignName: data.name || ""
|
|
2166
|
+
}
|
|
2167
|
+
) })
|
|
2168
|
+
] })
|
|
2169
|
+
] });
|
|
2170
|
+
};
|
|
2171
|
+
const config = adminSdk.defineRouteConfig({
|
|
2172
|
+
label: "Flash Sale Detail",
|
|
2173
|
+
icon: icons.Sparkles
|
|
2174
|
+
});
|
|
2175
|
+
const FlashSaleCreate = () => {
|
|
2176
|
+
const navigate = reactRouterDom.useNavigate();
|
|
2177
|
+
async function handleSubmit(campaignData) {
|
|
2178
|
+
var _a;
|
|
2179
|
+
try {
|
|
2180
|
+
await axios__default.default.post("/admin/flash-sales", {
|
|
2181
|
+
...campaignData,
|
|
2182
|
+
starts_at: new Date(campaignData.starts_at).toUTCString(),
|
|
2183
|
+
ends_at: new Date(campaignData.ends_at).toUTCString()
|
|
2184
|
+
});
|
|
2185
|
+
ui.toast.success("Flash sale created successfully");
|
|
2186
|
+
navigate("/flash-sales");
|
|
2187
|
+
} catch (error) {
|
|
2188
|
+
let message;
|
|
2189
|
+
if (axios__default.default.isAxiosError(error)) {
|
|
2190
|
+
console.log(error);
|
|
2191
|
+
message = (_a = error.response) == null ? void 0 : _a.data.message;
|
|
2192
|
+
} else if (error instanceof Error) {
|
|
2193
|
+
message = error.message;
|
|
2194
|
+
} else {
|
|
2195
|
+
message = "Failed to create flash sale";
|
|
2196
|
+
}
|
|
2197
|
+
ui.toast.error("Failed to create flash sale", {
|
|
2198
|
+
description: message
|
|
2199
|
+
});
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2203
|
+
FlashSaleForm,
|
|
2204
|
+
{
|
|
2205
|
+
onSubmit: handleSubmit,
|
|
2206
|
+
onCancel: () => navigate("/flash-sales")
|
|
2207
|
+
}
|
|
2208
|
+
);
|
|
2209
|
+
};
|
|
2210
|
+
const widgetModule = { widgets: [
|
|
2211
|
+
{
|
|
2212
|
+
Component: CampaignDetailWidget,
|
|
2213
|
+
zone: ["promotion.details.side.after"]
|
|
2214
|
+
}
|
|
2215
|
+
] };
|
|
2216
|
+
const routeModule = {
|
|
2217
|
+
routes: [
|
|
2218
|
+
{
|
|
2219
|
+
Component: Coupons,
|
|
2220
|
+
path: "/coupons"
|
|
2221
|
+
},
|
|
2222
|
+
{
|
|
2223
|
+
Component: FlashSale,
|
|
2224
|
+
path: "/flash-sales"
|
|
2225
|
+
},
|
|
2226
|
+
{
|
|
2227
|
+
Component: CouponDetail,
|
|
2228
|
+
path: "/coupons/:id"
|
|
2229
|
+
},
|
|
2230
|
+
{
|
|
2231
|
+
Component: CouponCreate,
|
|
2232
|
+
path: "/coupons/create"
|
|
2233
|
+
},
|
|
2234
|
+
{
|
|
2235
|
+
Component: FlashSaleDetail,
|
|
2236
|
+
path: "/flash-sales/:id"
|
|
2237
|
+
},
|
|
2238
|
+
{
|
|
2239
|
+
Component: FlashSaleCreate,
|
|
2240
|
+
path: "/flash-sales/create"
|
|
2241
|
+
}
|
|
2242
|
+
]
|
|
2243
|
+
};
|
|
2244
|
+
const menuItemModule = {
|
|
2245
|
+
menuItems: [
|
|
2246
|
+
{
|
|
2247
|
+
label: config$3.label,
|
|
2248
|
+
icon: config$3.icon,
|
|
2249
|
+
path: "/coupons",
|
|
2250
|
+
nested: void 0
|
|
2251
|
+
},
|
|
2252
|
+
{
|
|
2253
|
+
label: config$2.label,
|
|
2254
|
+
icon: config$2.icon,
|
|
2255
|
+
path: "/flash-sales",
|
|
2256
|
+
nested: void 0
|
|
2257
|
+
},
|
|
2258
|
+
{
|
|
2259
|
+
label: config$1.label,
|
|
2260
|
+
icon: config$1.icon,
|
|
2261
|
+
path: "/coupons/:id",
|
|
2262
|
+
nested: void 0
|
|
2263
|
+
},
|
|
2264
|
+
{
|
|
2265
|
+
label: config.label,
|
|
2266
|
+
icon: config.icon,
|
|
2267
|
+
path: "/flash-sales/:id",
|
|
2268
|
+
nested: void 0
|
|
2269
|
+
}
|
|
2270
|
+
]
|
|
2271
|
+
};
|
|
2272
|
+
const formModule = { customFields: {} };
|
|
2273
|
+
const displayModule = {
|
|
2274
|
+
displays: {}
|
|
2275
|
+
};
|
|
2276
|
+
const i18nModule = { resources: {} };
|
|
2277
|
+
const plugin = {
|
|
2278
|
+
widgetModule,
|
|
2279
|
+
routeModule,
|
|
2280
|
+
menuItemModule,
|
|
2281
|
+
formModule,
|
|
2282
|
+
displayModule,
|
|
2283
|
+
i18nModule
|
|
2284
|
+
};
|
|
2285
|
+
module.exports = plugin;
|