@zosmaai/medusa-documents-v2 0.2.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/.medusa/server/src/admin/index.js +1884 -0
  2. package/.medusa/server/src/admin/index.mjs +1881 -0
  3. package/.medusa/server/src/api/admin/documents/document-invoice-settings/invoice-template/route.js +40 -0
  4. package/.medusa/server/src/api/admin/documents/document-invoice-settings/route.js +62 -0
  5. package/.medusa/server/src/api/admin/documents/document-packing-slip-settings/route.js +62 -0
  6. package/.medusa/server/src/api/admin/documents/document-packing-slip-settings/template/route.js +40 -0
  7. package/.medusa/server/src/api/admin/documents/document-settings/document-address/route.js +47 -0
  8. package/.medusa/server/src/api/admin/documents/document-settings/india-gst/route.js +67 -0
  9. package/.medusa/server/src/api/admin/documents/document-settings/logo/route.js +67 -0
  10. package/.medusa/server/src/api/admin/documents/document-settings/route.js +36 -0
  11. package/.medusa/server/src/api/admin/documents/invoice/display-number/route.js +34 -0
  12. package/.medusa/server/src/api/admin/documents/invoice/generate/route.js +47 -0
  13. package/.medusa/server/src/api/admin/documents/invoice/route.js +112 -0
  14. package/.medusa/server/src/api/admin/documents/packing-slip/preview/route.js +47 -0
  15. package/.medusa/server/src/api/admin/documents/packing-slip/route.js +112 -0
  16. package/.medusa/server/src/links/invoice-order.js +13 -0
  17. package/.medusa/server/src/links/packing-slip-order.js +13 -0
  18. package/.medusa/server/src/modules/documents/assets/fonts/IBMPlexSans-Bold.ttf +0 -0
  19. package/.medusa/server/src/modules/documents/assets/fonts/IBMPlexSans-Regular.ttf +0 -0
  20. package/.medusa/server/src/modules/documents/assets/i18n/locales/de-AT/translation.json +26 -0
  21. package/.medusa/server/src/modules/documents/assets/i18n/locales/en/translation.json +26 -0
  22. package/.medusa/server/src/modules/documents/assets/i18n/locales/es/translation.json +26 -0
  23. package/.medusa/server/src/modules/documents/assets/i18n/locales/fr/translation.json +26 -0
  24. package/.medusa/server/src/modules/documents/assets/i18n/locales/pl/translation.json +26 -0
  25. package/.medusa/server/src/modules/documents/index.js +26 -0
  26. package/.medusa/server/src/modules/documents/loaders/i18next.js +49 -0
  27. package/.medusa/server/src/modules/documents/migrations/Migration20250228142557.js +39 -0
  28. package/.medusa/server/src/modules/documents/migrations/Migration20260810120000.js +14 -0
  29. package/.medusa/server/src/modules/documents/models/document-invoice-settings.js +29 -0
  30. package/.medusa/server/src/modules/documents/models/document-invoice.js +32 -0
  31. package/.medusa/server/src/modules/documents/models/document-packing-slip-settings.js +29 -0
  32. package/.medusa/server/src/modules/documents/models/document-packing-slip.js +32 -0
  33. package/.medusa/server/src/modules/documents/models/document-settings.js +33 -0
  34. package/.medusa/server/src/modules/documents/service.js +502 -0
  35. package/.medusa/server/src/modules/documents/services/generators/invoice-generator.js +78 -0
  36. package/.medusa/server/src/modules/documents/services/generators/packing-slip-generator.js +73 -0
  37. package/.medusa/server/src/modules/documents/services/templates/invoices/basic/basic-logo.js +55 -0
  38. package/.medusa/server/src/modules/documents/services/templates/invoices/basic/basic.js +52 -0
  39. package/.medusa/server/src/modules/documents/services/templates/invoices/basic/parts/customer-info.js +69 -0
  40. package/.medusa/server/src/modules/documents/services/templates/invoices/basic/parts/header-for-logo.js +32 -0
  41. package/.medusa/server/src/modules/documents/services/templates/invoices/basic/parts/header-logo.js +29 -0
  42. package/.medusa/server/src/modules/documents/services/templates/invoices/basic/parts/header.js +35 -0
  43. package/.medusa/server/src/modules/documents/services/templates/invoices/basic/parts/hr.js +23 -0
  44. package/.medusa/server/src/modules/documents/services/templates/invoices/basic/parts/invoice-info.js +35 -0
  45. package/.medusa/server/src/modules/documents/services/templates/invoices/basic/parts/table.js +97 -0
  46. package/.medusa/server/src/modules/documents/services/templates/invoices/india-gst/india-gst.js +72 -0
  47. package/.medusa/server/src/modules/documents/services/templates/invoices/india-gst/parts/footer.js +41 -0
  48. package/.medusa/server/src/modules/documents/services/templates/invoices/india-gst/parts/invoice-meta.js +22 -0
  49. package/.medusa/server/src/modules/documents/services/templates/invoices/india-gst/parts/seller-info.js +42 -0
  50. package/.medusa/server/src/modules/documents/services/templates/invoices/india-gst/parts/table.js +88 -0
  51. package/.medusa/server/src/modules/documents/services/templates/packing-slips/basic/basic.js +52 -0
  52. package/.medusa/server/src/modules/documents/services/templates/packing-slips/basic/parts/customer-info-small.js +69 -0
  53. package/.medusa/server/src/modules/documents/services/templates/packing-slips/basic/parts/customer-info.js +65 -0
  54. package/.medusa/server/src/modules/documents/services/templates/packing-slips/basic/parts/header-small.js +37 -0
  55. package/.medusa/server/src/modules/documents/services/templates/packing-slips/basic/parts/header.js +37 -0
  56. package/.medusa/server/src/modules/documents/services/templates/packing-slips/basic/parts/hr.js +32 -0
  57. package/.medusa/server/src/modules/documents/services/templates/packing-slips/basic/parts/table-items-small.js +44 -0
  58. package/.medusa/server/src/modules/documents/services/templates/packing-slips/basic/parts/table-items.js +44 -0
  59. package/.medusa/server/src/modules/documents/services/templates/packing-slips/basic/parts/table-order-info-small.js +35 -0
  60. package/.medusa/server/src/modules/documents/services/templates/packing-slips/basic/parts/table-order-info.js +36 -0
  61. package/.medusa/server/src/modules/documents/services/templates/packing-slips/basic/small.js +53 -0
  62. package/.medusa/server/src/modules/documents/types/api.js +14 -0
  63. package/.medusa/server/src/modules/documents/types/constants.js +17 -0
  64. package/.medusa/server/src/modules/documents/types/dto.js +14 -0
  65. package/.medusa/server/src/modules/documents/types/template-kind.js +26 -0
  66. package/.medusa/server/src/modules/documents/utils/currency.js +18 -0
  67. package/.medusa/server/src/ui-components/actions-dropdown/actions-dropdown.js +15 -0
  68. package/.medusa/server/src/ui-components/actions-dropdown/invoice/button-generate-invoice.js +75 -0
  69. package/.medusa/server/src/ui-components/actions-dropdown/packing-slip/button-generate-packing-slip.js +72 -0
  70. package/.medusa/server/src/ui-components/index.js +21 -0
  71. package/.medusa/server/src/ui-components/orders/order-table/invoice-number-from-order.js +107 -0
  72. package/.medusa/server/src/ui-components/orders/order-table/packing-slip-number.js +107 -0
  73. package/.medusa/server/src/ui-components/orders/order-table/use-columns.js +172 -0
  74. package/.medusa/server/src/ui-components/orders/order-table/use-orders.js +145 -0
  75. package/.medusa/server/src/ui-components/orders/order-table/utils/currencies.js +1077 -0
  76. package/.medusa/server/src/ui-components/orders/order-table/utils/time.js +53 -0
  77. package/.medusa/server/src/ui-components/orders/order-table.js +134 -0
  78. package/.medusa/server/src/ui-components/settings/settings-address.js +90 -0
  79. package/.medusa/server/src/ui-components/settings/settings-india-gst.js +90 -0
  80. package/.medusa/server/src/ui-components/settings/settings-invoice-display-number.js +55 -0
  81. package/.medusa/server/src/ui-components/settings/settings-invoice.js +139 -0
  82. package/.medusa/server/src/ui-components/settings/settings-logo.js +108 -0
  83. package/.medusa/server/src/ui-components/tabs/orders-tab.js +28 -0
  84. package/.medusa/server/src/ui-components/tabs/pro-tab.js +23 -0
  85. package/.medusa/server/src/ui-components/tabs/settings-tab.js +29 -0
  86. package/.medusa/server/src/ui-components/tabs/templates-tab/templates-invoice-tab.js +153 -0
  87. package/.medusa/server/src/ui-components/tabs/templates-tab/templates-packing-slip-tab.js +155 -0
  88. package/.medusa/server/src/ui-components/tabs/templates-tab/templates-tab.js +24 -0
  89. package/.medusa/server/src/ui-components/types/api.js +14 -0
  90. package/.medusa/server/src/ui-components/types/invoice.js +14 -0
  91. package/.medusa/server/src/ui-components/types/packing-slip.js +14 -0
  92. package/.medusa/server/src/ui-components/types/template-kind.js +26 -0
  93. package/.medusa/server/src/workflows/assign-invoice.js +31 -0
  94. package/.medusa/server/src/workflows/assign-packing-slip.js +31 -0
  95. package/README.md +171 -0
  96. package/package.json +103 -0
@@ -0,0 +1,1881 @@
1
+ import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
+ import { defineRouteConfig } from "@medusajs/admin-sdk";
3
+ import { toast, DropdownMenu, IconButton, TooltipProvider, Tooltip, Text, StatusBadge, Table, Container, Alert, Heading, Button, RadioGroup, Label, Tabs, FocusModal, Input, Toaster } from "@medusajs/ui";
4
+ import { FlyingBox, EllipsisHorizontal, InformationCircle, DocumentText } from "@medusajs/icons";
5
+ import { Grid, CircularProgress, Link, Box } from "@mui/material";
6
+ import React, { useState, useEffect, useMemo, useReducer } from "react";
7
+ import clsx from "clsx";
8
+ import { useLocation } from "react-router-dom";
9
+ import { useTable, usePagination } from "react-table";
10
+ import moment from "moment";
11
+ import { useForm } from "react-hook-form";
12
+ import "@medusajs/admin-shared";
13
+ const GenerateInvoiceDropdownButton = ({ order, updateInvoiceNumber }) => {
14
+ const [isLoading, setLoading] = useState(false);
15
+ const [error, setError] = useState(void 0);
16
+ useEffect(() => {
17
+ if (!isLoading) {
18
+ return;
19
+ }
20
+ fetch(`/admin/documents/invoice`, {
21
+ method: "POST",
22
+ credentials: "include",
23
+ headers: {
24
+ "Content-Type": "application/json"
25
+ },
26
+ body: JSON.stringify({
27
+ order_id: order.id
28
+ })
29
+ }).then((res) => res.json()).then((responseJson) => {
30
+ if (responseJson && responseJson.message) {
31
+ setError({
32
+ message: responseJson.message
33
+ });
34
+ toast.error("Invoice", {
35
+ description: `Problem happened when generating invoice. ${responseJson.message}`
36
+ });
37
+ } else {
38
+ if (responseJson.buffer) {
39
+ updateInvoiceNumber(order.id, responseJson.invoice.displayNumber);
40
+ const anyBuffer = responseJson.buffer;
41
+ const blob = new Blob([new Uint8Array(anyBuffer.data)], { type: "application/pdf" });
42
+ toast.dismiss();
43
+ const pdfURL = URL.createObjectURL(blob);
44
+ window.open(pdfURL, "_blank");
45
+ } else {
46
+ toast.dismiss();
47
+ toast.error("Invoice", {
48
+ description: "Problem happened when generating invoice"
49
+ });
50
+ }
51
+ }
52
+ setLoading(false);
53
+ }).catch((error2) => {
54
+ var _a, _b;
55
+ console.error(error2);
56
+ toast.dismiss();
57
+ const trueError = error2;
58
+ toast.error("Invoice", {
59
+ description: (_b = (_a = trueError == null ? void 0 : trueError.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message
60
+ });
61
+ });
62
+ }, [isLoading]);
63
+ return /* @__PURE__ */ jsxs(DropdownMenu.Item, { className: "gap-x-2", onClick: () => setLoading(true), children: [
64
+ /* @__PURE__ */ jsx(FlyingBox, {}),
65
+ "Generate new invoice"
66
+ ] });
67
+ };
68
+ const GeneratePackingSlipDropdownButton = ({ order, updatePackingSlipNumber }) => {
69
+ const [isLoading, setLoading] = useState(false);
70
+ const [error, setError] = useState(void 0);
71
+ useEffect(() => {
72
+ if (!isLoading) {
73
+ return;
74
+ }
75
+ fetch(`/admin/documents/packing-slip`, {
76
+ method: "POST",
77
+ credentials: "include",
78
+ headers: {
79
+ "Content-Type": "application/json"
80
+ },
81
+ body: JSON.stringify({
82
+ order_id: order.id
83
+ })
84
+ }).then((res) => res.json()).then((responseJson) => {
85
+ if (responseJson && responseJson.message) {
86
+ toast.error("Packing slip", {
87
+ description: `Problem happened when generating packing slip. ${responseJson.message}`
88
+ });
89
+ } else {
90
+ if (responseJson.buffer) {
91
+ updatePackingSlipNumber(order.id, responseJson.packingSlip.displayNumber);
92
+ const anyBuffer = responseJson.buffer;
93
+ const blob = new Blob([new Uint8Array(anyBuffer.data)], { type: "application/pdf" });
94
+ toast.dismiss();
95
+ const pdfURL = URL.createObjectURL(blob);
96
+ window.open(pdfURL, "_blank");
97
+ } else {
98
+ toast.dismiss();
99
+ toast.error("Packing slip", {
100
+ description: "Problem happened when generating packing slip"
101
+ });
102
+ }
103
+ }
104
+ setLoading(false);
105
+ }).catch((error2) => {
106
+ var _a, _b;
107
+ console.error(error2);
108
+ toast.dismiss();
109
+ const trueError = error2;
110
+ toast.error("Packing slip", {
111
+ description: (_b = (_a = trueError == null ? void 0 : trueError.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message
112
+ });
113
+ });
114
+ }, [isLoading]);
115
+ return /* @__PURE__ */ jsxs(DropdownMenu.Item, { className: "gap-x-2", onClick: () => setLoading(true), children: [
116
+ /* @__PURE__ */ jsx(FlyingBox, {}),
117
+ "Generate new packing slip"
118
+ ] });
119
+ };
120
+ function ActionsDropdown({ order, updateInvoiceNumber, updatePackingSlipNumber }) {
121
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(DropdownMenu, { children: [
122
+ /* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { children: /* @__PURE__ */ jsx(EllipsisHorizontal, {}) }) }),
123
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
124
+ /* @__PURE__ */ jsx(GenerateInvoiceDropdownButton, { order, updateInvoiceNumber }),
125
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
126
+ /* @__PURE__ */ jsx(GeneratePackingSlipDropdownButton, { order, updatePackingSlipNumber })
127
+ ] })
128
+ ] }) });
129
+ }
130
+ const InvoiceNumberFromOrder = ({
131
+ orderId,
132
+ invoiceNumber
133
+ }) => {
134
+ const [data, setData] = useState(void 0);
135
+ const [error, setError] = useState(void 0);
136
+ const [isHovered, setIsHovered] = useState(false);
137
+ const [isLoading, setLoading] = useState(true);
138
+ const handleClick = async () => {
139
+ toast.loading("Invoice", {
140
+ description: "Preparing invoice...",
141
+ duration: Infinity
142
+ });
143
+ const result2 = new URLSearchParams({
144
+ includeBuffer: "true",
145
+ orderId
146
+ });
147
+ fetch(`/admin/documents/invoice?${result2.toString()}`, {
148
+ credentials: "include"
149
+ }).then((res) => res.json()).then((result3) => {
150
+ if (result3 && result3.buffer) {
151
+ toast.dismiss();
152
+ openPdf(result3);
153
+ } else {
154
+ toast.dismiss();
155
+ toast.error("Invoice", {
156
+ description: "Problem happened when preparing invoice"
157
+ });
158
+ }
159
+ }).catch((error2) => {
160
+ setError(error2);
161
+ console.error(error2);
162
+ toast.dismiss();
163
+ toast.error("Invoice", {
164
+ description: error2
165
+ });
166
+ });
167
+ };
168
+ const openPdf = (invoiceResult) => {
169
+ if (invoiceResult && invoiceResult.buffer) {
170
+ const anyBuffer = invoiceResult.buffer;
171
+ const blob = new Blob([new Uint8Array(anyBuffer.data)], {
172
+ type: "application/pdf"
173
+ });
174
+ const pdfURL = URL.createObjectURL(blob);
175
+ window.open(pdfURL, "_blank");
176
+ }
177
+ };
178
+ const result = new URLSearchParams({
179
+ orderId
180
+ });
181
+ useEffect(() => {
182
+ setLoading(true);
183
+ }, [invoiceNumber, orderId]);
184
+ useEffect(() => {
185
+ if (!isLoading) {
186
+ return;
187
+ }
188
+ fetch(`/admin/documents/invoice?${result.toString()}`, {
189
+ credentials: "include"
190
+ }).then((res) => res.json()).then((result2) => {
191
+ setData(result2);
192
+ setLoading(false);
193
+ }).catch((error2) => {
194
+ setError(error2);
195
+ console.error(error2);
196
+ });
197
+ }, [isLoading]);
198
+ if (isLoading) {
199
+ return /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(CircularProgress, { size: 8 }) });
200
+ }
201
+ if (data && data.invoice) {
202
+ return /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(
203
+ "p",
204
+ {
205
+ className: "text-grey-90 hover:text-violet-60 cursor-pointer pl-2 transition-colors duration-200",
206
+ onClick: () => handleClick(),
207
+ style: {
208
+ cursor: "pointer",
209
+ color: isHovered ? "violet" : "grey",
210
+ textDecoration: isHovered ? "underline" : "none",
211
+ transition: "color 0.2s, text-decoration 0.2s"
212
+ },
213
+ onMouseEnter: () => setIsHovered(true),
214
+ onMouseLeave: () => setIsHovered(false),
215
+ children: `Invoice: ${data.invoice.displayNumber}`
216
+ }
217
+ ) });
218
+ } else {
219
+ return /* @__PURE__ */ jsx(Fragment, {});
220
+ }
221
+ };
222
+ const PackingSlipNumber = ({
223
+ orderId,
224
+ packingSlipNumber
225
+ }) => {
226
+ const [data, setData] = useState(void 0);
227
+ const [error, setError] = useState(void 0);
228
+ const [isHovered, setIsHovered] = useState(false);
229
+ const [isLoading, setLoading] = useState(true);
230
+ const handleClick = async () => {
231
+ toast.loading("Packing slip", {
232
+ description: "Preparing packing slip...",
233
+ duration: Infinity
234
+ });
235
+ const result2 = new URLSearchParams({
236
+ includeBuffer: "true",
237
+ orderId
238
+ });
239
+ fetch(`/admin/documents/packing-slip?${result2.toString()}`, {
240
+ credentials: "include"
241
+ }).then((res) => res.json()).then((result3) => {
242
+ if (result3 && result3.buffer) {
243
+ toast.dismiss();
244
+ openPdf(result3);
245
+ } else {
246
+ toast.dismiss();
247
+ toast.error("Packing slip", {
248
+ description: "Problem happened when preparing packing slip"
249
+ });
250
+ }
251
+ }).catch((error2) => {
252
+ setError(error2);
253
+ console.error(error2);
254
+ toast.dismiss();
255
+ toast.error("Packing slip", {
256
+ description: error2
257
+ });
258
+ });
259
+ };
260
+ const openPdf = (packingSlipResult) => {
261
+ if (packingSlipResult && packingSlipResult.buffer) {
262
+ const anyBuffer = packingSlipResult.buffer;
263
+ const blob = new Blob([new Uint8Array(anyBuffer.data)], {
264
+ type: "application/pdf"
265
+ });
266
+ const pdfURL = URL.createObjectURL(blob);
267
+ window.open(pdfURL, "_blank");
268
+ }
269
+ };
270
+ const result = new URLSearchParams({
271
+ orderId
272
+ });
273
+ useEffect(() => {
274
+ setLoading(true);
275
+ }, [packingSlipNumber, orderId]);
276
+ useEffect(() => {
277
+ if (!isLoading) {
278
+ return;
279
+ }
280
+ fetch(`/admin/documents/packing-slip?${result.toString()}`, {
281
+ credentials: "include"
282
+ }).then((res) => res.json()).then((result2) => {
283
+ setData(result2);
284
+ setLoading(false);
285
+ }).catch((error2) => {
286
+ setError(error2);
287
+ console.error(error2);
288
+ });
289
+ }, [isLoading]);
290
+ if (isLoading) {
291
+ return /* @__PURE__ */ jsx(CircularProgress, { size: 8 });
292
+ }
293
+ if (data && data.packingSlip) {
294
+ return /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(
295
+ "p",
296
+ {
297
+ className: "text-grey-90 hover:text-violet-60 cursor-pointer pl-2 transition-colors duration-200",
298
+ onClick: () => handleClick(),
299
+ style: {
300
+ cursor: "pointer",
301
+ color: isHovered ? "violet" : "grey",
302
+ textDecoration: isHovered ? "underline" : "none",
303
+ transition: "color 0.2s, text-decoration 0.2s"
304
+ },
305
+ onMouseEnter: () => setIsHovered(true),
306
+ onMouseLeave: () => setIsHovered(false),
307
+ children: `Packing slip: ${data.packingSlip.displayNumber}`
308
+ }
309
+ ) });
310
+ } else {
311
+ return /* @__PURE__ */ jsx(Fragment, {});
312
+ }
313
+ };
314
+ function formatAmountWithSymbol({
315
+ amount,
316
+ currency,
317
+ digits
318
+ }) {
319
+ let locale = "en-US";
320
+ if (currency.toLowerCase() === "dkk") {
321
+ locale = "da-DK";
322
+ }
323
+ const taxRate = 0;
324
+ return new Intl.NumberFormat(locale, {
325
+ style: "currency",
326
+ currency,
327
+ minimumFractionDigits: digits
328
+ }).format(amount * (1 + taxRate / 100));
329
+ }
330
+ const useOrderTableColumns = () => {
331
+ const [documentNumbers, setDocumentNumbers] = useState({});
332
+ const decideStatus = (status) => {
333
+ switch (status) {
334
+ case "captured":
335
+ return /* @__PURE__ */ jsx(StatusBadge, { color: "green", children: "Paid" });
336
+ case "awaiting":
337
+ return /* @__PURE__ */ jsx(StatusBadge, { color: "grey", children: "Awaiting" });
338
+ case "requires_action":
339
+ return /* @__PURE__ */ jsx(StatusBadge, { color: "red", children: "Requires action" });
340
+ case "canceled":
341
+ return /* @__PURE__ */ jsx(StatusBadge, { color: "orange", children: "Canceled" });
342
+ default:
343
+ return /* @__PURE__ */ jsx(StatusBadge, { color: "purple", children: "N/A" });
344
+ }
345
+ };
346
+ const decideFullfillmentStatus = (status) => {
347
+ switch (status) {
348
+ case "not_fulfilled":
349
+ return /* @__PURE__ */ jsx(StatusBadge, { color: "grey", children: "Not fulfilled" });
350
+ case "partially_fulfilled":
351
+ return /* @__PURE__ */ jsx(StatusBadge, { color: "blue", children: "Partially fulfilled" });
352
+ case "fulfilled":
353
+ return /* @__PURE__ */ jsx(StatusBadge, { color: "green", children: "Fulfilled" });
354
+ case "partially_shipped":
355
+ return /* @__PURE__ */ jsx(StatusBadge, { color: "blue", children: "Partially shipped" });
356
+ case "shipped":
357
+ return /* @__PURE__ */ jsx(StatusBadge, { color: "green", children: "Shipped" });
358
+ case "partially_returned":
359
+ return /* @__PURE__ */ jsx(StatusBadge, { color: "blue", children: "Partially returned" });
360
+ case "returned":
361
+ return /* @__PURE__ */ jsx(StatusBadge, { color: "green", children: "Returned" });
362
+ case "canceled":
363
+ return /* @__PURE__ */ jsx(StatusBadge, { color: "red", children: "Canceled" });
364
+ case "requires_action":
365
+ return /* @__PURE__ */ jsx(StatusBadge, { color: "purple", children: "Requires action" });
366
+ default:
367
+ return /* @__PURE__ */ jsx(StatusBadge, { color: "grey", children: "N/A" });
368
+ }
369
+ };
370
+ const updateInvoiceNumber = (orderId, invoiceNumber) => {
371
+ setDocumentNumbers((prev) => ({
372
+ ...prev,
373
+ [orderId]: {
374
+ ...prev[orderId],
375
+ invoiceNumber
376
+ }
377
+ }));
378
+ };
379
+ const updatePackingSlipNumber = (orderId, packingSlipNumber) => {
380
+ setDocumentNumbers((prev) => ({
381
+ ...prev,
382
+ [orderId]: {
383
+ ...prev[orderId],
384
+ packingSlipNumber
385
+ }
386
+ }));
387
+ };
388
+ const columns = useMemo(
389
+ () => [
390
+ {
391
+ Header: /* @__PURE__ */ jsx("div", { className: "pl-2", children: "Order" }),
392
+ accessor: "display_id",
393
+ Cell: ({ cell: { value } }) => /* @__PURE__ */ jsx("p", { className: "text-grey-90 group-hover:text-violet-60 pl-2", children: `#${value}` })
394
+ },
395
+ {
396
+ Header: "Date added",
397
+ accessor: "created_at",
398
+ Cell: ({ cell: { value } }) => {
399
+ return /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsx(Text, { children: moment(value).format("DD MMM YYYY hh:mm a") }), children: /* @__PURE__ */ jsx("p", { className: "text-grey-90 group-hover:text-violet-60 min-w-[40px]", children: moment(value).format("DD MMM YYYY") }) }) });
400
+ }
401
+ },
402
+ {
403
+ Header: "Customer",
404
+ accessor: "customer",
405
+ Cell: ({ row, cell: { value } }) => {
406
+ var _a, _b;
407
+ const customer = {
408
+ first_name: (value == null ? void 0 : value.first_name) || ((_a = row.original.shipping_address) == null ? void 0 : _a.first_name),
409
+ last_name: (value == null ? void 0 : value.last_name) || ((_b = row.original.shipping_address) == null ? void 0 : _b.last_name),
410
+ email: row.original.email
411
+ };
412
+ return /* @__PURE__ */ jsx("p", { className: "text-grey-90 group-hover:text-violet-60 min-w-[100px]", children: `${customer.first_name || customer.last_name ? `${customer.first_name} ${customer.last_name}` : customer.email ? customer.email : "-"}` });
413
+ }
414
+ },
415
+ {
416
+ Header: "Fulfillment",
417
+ accessor: "fulfillment_status",
418
+ Cell: ({ cell: { value } }) => decideFullfillmentStatus(value)
419
+ },
420
+ {
421
+ Header: "Payment status",
422
+ accessor: "payment_status",
423
+ Cell: ({ cell: { value } }) => decideStatus(value)
424
+ },
425
+ {
426
+ Header: () => /* @__PURE__ */ jsx("div", { className: "text-right", children: "Total" }),
427
+ accessor: "total",
428
+ Cell: ({ row, cell: { value } }) => /* @__PURE__ */ jsx("div", { className: "text-grey-90 group-hover:text-violet-60 text-right", children: formatAmountWithSymbol({
429
+ amount: value,
430
+ currency: row.original.currency_code
431
+ }) })
432
+ },
433
+ {
434
+ Header: "Documents",
435
+ id: "documents",
436
+ Cell: ({ row }) => {
437
+ const orderId = row.original.id;
438
+ const currentDocumentNumbers = documentNumbers[orderId] || void 0;
439
+ return /* @__PURE__ */ jsx("p", { className: "text-grey-90 group-hover:text-violet-60 pl-2", children: /* @__PURE__ */ jsxs(Grid, { container: true, justifyContent: "flex-start", direction: "column", spacing: 1, children: [
440
+ /* @__PURE__ */ jsx(
441
+ InvoiceNumberFromOrder,
442
+ {
443
+ orderId,
444
+ invoiceNumber: currentDocumentNumbers ? currentDocumentNumbers.invoiceNumber : void 0
445
+ }
446
+ ),
447
+ /* @__PURE__ */ jsx(
448
+ PackingSlipNumber,
449
+ {
450
+ orderId,
451
+ packingSlipNumber: currentDocumentNumbers ? currentDocumentNumbers.packingSlipNumber : void 0
452
+ }
453
+ )
454
+ ] }) });
455
+ }
456
+ },
457
+ {
458
+ Header: () => /* @__PURE__ */ jsxs(Grid, { container: true, justifyContent: "flex-end", alignItems: "flex-end", spacing: 1, children: [
459
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsx(Tooltip, { content: /* @__PURE__ */ jsxs(Grid, { item: true, children: [
460
+ /* @__PURE__ */ jsx(Text, { size: "small", children: "We do not store documents. " }),
461
+ /* @__PURE__ */ jsx(Link, { fontSize: 12, href: "https://github.com/RSC-Labs/medusa-documents?tab=readme-ov-file#what-means-we-do-not-store-documents", children: "Learn more what it means." })
462
+ ] }), children: /* @__PURE__ */ jsx(InformationCircle, {}) }) }) }),
463
+ /* @__PURE__ */ jsx(Grid, { item: true, children: "Actions" })
464
+ ] }),
465
+ id: "actions",
466
+ Cell: ({ row }) => {
467
+ return /* @__PURE__ */ jsx(Grid, { container: true, justifyContent: "flex-end", children: /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(
468
+ ActionsDropdown,
469
+ {
470
+ order: row.original,
471
+ updateInvoiceNumber,
472
+ updatePackingSlipNumber
473
+ }
474
+ ) }) });
475
+ }
476
+ }
477
+ ],
478
+ [documentNumbers]
479
+ // Add documentNumbers as a dependency to ensure it re-renders
480
+ );
481
+ return [columns, documentNumbers];
482
+ };
483
+ const atMidnight = (date) => {
484
+ const result = moment(date);
485
+ if (!moment.isMoment(result)) {
486
+ console.log("date is not instance of Moment: ", date);
487
+ return null;
488
+ }
489
+ result.hour(0);
490
+ result.minute(0);
491
+ result.second(0);
492
+ result.millisecond(0);
493
+ return result;
494
+ };
495
+ const relativeDateFormatToTimestamp = (value) => {
496
+ const [count, option] = value.split("|");
497
+ let date = moment();
498
+ date.subtract(parseInt(count), option);
499
+ date = atMidnight(date);
500
+ const result = `${date.format("X")}`;
501
+ return result;
502
+ };
503
+ const formatDateFilter = (filter) => {
504
+ if (filter === null) {
505
+ return filter;
506
+ }
507
+ const dateFormatted = Object.entries(filter).reduce((acc, [key, value]) => {
508
+ if (value.includes("|")) {
509
+ acc[key] = relativeDateFormatToTimestamp(value);
510
+ } else {
511
+ acc[key] = value;
512
+ }
513
+ return acc;
514
+ }, {});
515
+ return dateFormatted;
516
+ };
517
+ const reducer = (state, action) => {
518
+ var _a;
519
+ switch (action.type) {
520
+ case "setFilters": {
521
+ return {
522
+ ...state,
523
+ region: action.payload.region,
524
+ salesChannel: action.payload.salesChannel,
525
+ fulfillment: action.payload.fulfillment,
526
+ payment: action.payload.payment,
527
+ status: action.payload.status,
528
+ date: action.payload.date,
529
+ query: (_a = action == null ? void 0 : action.payload) == null ? void 0 : _a.query
530
+ };
531
+ }
532
+ case "setQuery": {
533
+ return {
534
+ ...state,
535
+ offset: 0,
536
+ // reset offset when query changes
537
+ query: action.payload
538
+ };
539
+ }
540
+ case "setDate": {
541
+ const newDateFilters = state.date;
542
+ return {
543
+ ...state,
544
+ date: newDateFilters
545
+ };
546
+ }
547
+ case "setOffset": {
548
+ return {
549
+ ...state,
550
+ offset: action.payload
551
+ };
552
+ }
553
+ case "reset": {
554
+ return action.payload;
555
+ }
556
+ default: {
557
+ return state;
558
+ }
559
+ }
560
+ };
561
+ const useOrderFilters = (defaultFilters = null) => {
562
+ const initial = useMemo(
563
+ () => parseQueryString(defaultFilters),
564
+ [defaultFilters]
565
+ );
566
+ const [state, dispatch] = useReducer(reducer, initial);
567
+ const paginate = (direction) => {
568
+ if (direction > 0) {
569
+ const nextOffset = state.offset + state.limit;
570
+ dispatch({ type: "setOffset", payload: nextOffset });
571
+ } else {
572
+ const nextOffset = Math.max(state.offset - state.limit, 0);
573
+ dispatch({ type: "setOffset", payload: nextOffset });
574
+ }
575
+ };
576
+ const getQueryObject = () => {
577
+ const toQuery = { ...state.additionalFilters };
578
+ for (const [key, value] of Object.entries(state)) {
579
+ if (key === "query") {
580
+ if (value && typeof value === "string") {
581
+ toQuery["q"] = value;
582
+ }
583
+ } else if (key === "offset" || key === "limit") {
584
+ toQuery[key] = value;
585
+ } else if (value.open) {
586
+ if (key === "date") {
587
+ toQuery[stateFilterMap[key]] = formatDateFilter(
588
+ value.filter
589
+ );
590
+ } else {
591
+ toQuery[stateFilterMap[key]] = value.filter;
592
+ }
593
+ }
594
+ }
595
+ return toQuery;
596
+ };
597
+ const queryObject = useMemo(() => getQueryObject(), [state]);
598
+ return {
599
+ queryObject,
600
+ paginate
601
+ };
602
+ };
603
+ const stateFilterMap = {
604
+ region: "region_id",
605
+ salesChannel: "sales_channel_id",
606
+ status: "status",
607
+ fulfillment: "fulfillment_status",
608
+ payment: "payment_status",
609
+ date: "created_at"
610
+ };
611
+ const parseQueryString = (additionals = null) => {
612
+ const defaultVal = {
613
+ status: {
614
+ open: false,
615
+ filter: null
616
+ },
617
+ fulfillment: {
618
+ open: false,
619
+ filter: null
620
+ },
621
+ region: {
622
+ open: false,
623
+ filter: null
624
+ },
625
+ salesChannel: {
626
+ open: false,
627
+ filter: null
628
+ },
629
+ payment: {
630
+ open: false,
631
+ filter: null
632
+ },
633
+ date: {
634
+ open: false,
635
+ filter: null
636
+ },
637
+ offset: 0,
638
+ limit: 15,
639
+ additionalFilters: additionals
640
+ };
641
+ return defaultVal;
642
+ };
643
+ const defaultQueryProps = {
644
+ expand: "customer,shipping_address,billing_address,items",
645
+ fields: "id,status,display_id,created_at,email,fulfillment_status,payment_status,total,currency_code,metadata"
646
+ };
647
+ const OrderTable = ({ setContextFilters }) => {
648
+ useLocation();
649
+ const [ordersResult, setOrdersResult] = useState(
650
+ void 0
651
+ );
652
+ const [isLoading, setLoading] = useState(true);
653
+ let hiddenColumns = ["sales_channel"];
654
+ const { paginate, queryObject } = useOrderFilters(defaultQueryProps);
655
+ const offs = 0;
656
+ const lim = queryObject.limit;
657
+ const [numPages, setNumPages] = useState(0);
658
+ useEffect(() => {
659
+ if (!isLoading) {
660
+ return;
661
+ }
662
+ fetch(
663
+ `/admin/orders?order=-created_at&fields=id,status,display_id,created_at,email,fulfillment_status,payment_status,total,currency_code,metadata,items,*customer&limit=${(ordersResult == null ? void 0 : ordersResult.limit) ?? queryObject.limit}`,
664
+ {
665
+ credentials: "include"
666
+ }
667
+ ).then((res) => res.json()).then((result) => {
668
+ setOrdersResult(result);
669
+ setLoading(false);
670
+ }).catch((error) => {
671
+ console.error(error);
672
+ });
673
+ }, []);
674
+ useEffect(() => {
675
+ const controlledPageCount = Math.ceil(
676
+ ordersResult ? ordersResult.count / queryObject.limit : 0
677
+ );
678
+ setNumPages(controlledPageCount);
679
+ }, [ordersResult]);
680
+ const [columns] = useOrderTableColumns();
681
+ const {
682
+ getTableProps,
683
+ getTableBodyProps,
684
+ headerGroups,
685
+ rows,
686
+ prepareRow,
687
+ canPreviousPage,
688
+ canNextPage,
689
+ pageCount,
690
+ gotoPage,
691
+ nextPage,
692
+ previousPage,
693
+ // Get the state from the instance
694
+ state: { pageIndex }
695
+ } = useTable(
696
+ {
697
+ columns,
698
+ data: ordersResult ? ordersResult.orders : [],
699
+ manualPagination: true,
700
+ initialState: {
701
+ pageSize: lim,
702
+ pageIndex: offs / lim,
703
+ hiddenColumns
704
+ },
705
+ pageCount: numPages,
706
+ autoResetPage: false
707
+ },
708
+ usePagination
709
+ );
710
+ const handleNext = () => {
711
+ if (canNextPage) {
712
+ paginate(1);
713
+ nextPage();
714
+ }
715
+ };
716
+ const handlePrev = () => {
717
+ if (canPreviousPage) {
718
+ paginate(-1);
719
+ previousPage();
720
+ }
721
+ };
722
+ useEffect(() => {
723
+ setLoading(true);
724
+ fetch(
725
+ `/admin/orders?order=-created_at&fields=id,status,display_id,created_at,email,fulfillment_status,payment_status,total,currency_code,metadata,items,*customer&offset=${pageIndex * queryObject.limit}&limit=${queryObject.limit}`,
726
+ {
727
+ credentials: "include"
728
+ }
729
+ ).then((res) => res.json()).then((result) => {
730
+ setOrdersResult(result);
731
+ setLoading(false);
732
+ }).catch((error) => {
733
+ console.error(error);
734
+ });
735
+ }, [pageIndex]);
736
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
737
+ /* @__PURE__ */ jsxs(Table, { ...getTableProps(), className: clsx({ ["relative"]: isLoading }), children: [
738
+ /* @__PURE__ */ jsx(Table.Header, { children: headerGroups == null ? void 0 : headerGroups.map((headerGroup, i) => /* @__PURE__ */ jsx(
739
+ Table.Row,
740
+ {
741
+ ...headerGroup.getHeaderGroupProps(),
742
+ children: headerGroup.headers.map((col, j) => /* @__PURE__ */ jsx(Table.HeaderCell, { ...col.getHeaderProps(), children: col.render("Header") }, "header_" + j))
743
+ },
744
+ "headerGroup_" + i
745
+ )) }),
746
+ /* @__PURE__ */ jsx(Table.Body, { ...getTableBodyProps(), children: rows.map((row, i) => {
747
+ prepareRow(row);
748
+ return /* @__PURE__ */ jsx(
749
+ Table.Row,
750
+ {
751
+ color: "inherit",
752
+ linkTo: row.original.id,
753
+ ...row.getRowProps(),
754
+ className: "group",
755
+ children: row.cells.map((cell, j) => {
756
+ return /* @__PURE__ */ jsx(
757
+ Table.Cell,
758
+ {
759
+ ...cell.getCellProps(),
760
+ className: "inter-small-regular h-[40px]",
761
+ children: cell.render("Cell")
762
+ },
763
+ "body_cell_" + j
764
+ );
765
+ })
766
+ },
767
+ "body_row_" + i
768
+ );
769
+ }) })
770
+ ] }),
771
+ /* @__PURE__ */ jsx(
772
+ Table.Pagination,
773
+ {
774
+ count: ordersResult ? ordersResult.count : 0,
775
+ pageSize: queryObject.limit,
776
+ pageIndex,
777
+ pageCount,
778
+ canPreviousPage,
779
+ canNextPage,
780
+ previousPage: handlePrev,
781
+ nextPage: handleNext
782
+ }
783
+ )
784
+ ] });
785
+ };
786
+ const OrderTable$1 = React.memo(OrderTable);
787
+ const OrdersTab = () => {
788
+ const [contextFilters, setContextFilters] = useState();
789
+ return /* @__PURE__ */ jsx(Grid, { container: true, spacing: 2, children: /* @__PURE__ */ jsx(Grid, { item: true, xs: 12, md: 12, xl: 12, children: /* @__PURE__ */ jsx(Container, { children: /* @__PURE__ */ jsx(OrderTable$1, { setContextFilters }) }) }) });
790
+ };
791
+ var InvoiceTemplateKind = /* @__PURE__ */ ((InvoiceTemplateKind2) => {
792
+ InvoiceTemplateKind2["BASIC"] = "BASIC";
793
+ InvoiceTemplateKind2["BASIC_LOGO"] = "BASIC_LOGO";
794
+ InvoiceTemplateKind2["INDIA_GST"] = "INDIA_GST";
795
+ return InvoiceTemplateKind2;
796
+ })(InvoiceTemplateKind || {});
797
+ var PackingSlipTemplateKind = /* @__PURE__ */ ((PackingSlipTemplateKind2) => {
798
+ PackingSlipTemplateKind2["BASIC"] = "BASIC";
799
+ PackingSlipTemplateKind2["BASIC_SMALL"] = "BASIC_SMALL";
800
+ return PackingSlipTemplateKind2;
801
+ })(PackingSlipTemplateKind || {});
802
+ const ViewExampleInvoice = ({ kind }) => {
803
+ var _a, _b;
804
+ const [data, setData] = useState(void 0);
805
+ const [error, setError] = useState(void 0);
806
+ const [isLoading, setLoading] = useState(true);
807
+ const [lastKind, setLastKind] = useState(kind);
808
+ useEffect(() => {
809
+ if (lastKind !== kind) {
810
+ setLastKind(kind);
811
+ if (!isLoading) {
812
+ setLoading(true);
813
+ }
814
+ }
815
+ }, [kind]);
816
+ useEffect(() => {
817
+ if (!isLoading) {
818
+ return;
819
+ }
820
+ const result = new URLSearchParams({
821
+ template: kind
822
+ });
823
+ fetch(`/admin/documents/invoice/generate?${result.toString()}`, {
824
+ credentials: "include"
825
+ }).then((res) => res.json()).then((result2) => {
826
+ if (result2 && result2.message) {
827
+ setError({
828
+ message: result2.message
829
+ });
830
+ } else {
831
+ toast.dismiss();
832
+ setError(void 0);
833
+ setData(result2);
834
+ }
835
+ setLoading(false);
836
+ }).catch((error2) => {
837
+ setError(error2);
838
+ console.error(error2);
839
+ });
840
+ }, [isLoading]);
841
+ if (isLoading) {
842
+ return /* @__PURE__ */ jsx(Grid, { container: true, justifyContent: "center", children: /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(CircularProgress, { size: 12 }) }) });
843
+ }
844
+ if (error) {
845
+ const trueError = error;
846
+ if (((_b = (_a = trueError.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || trueError.message) {
847
+ if (trueError.message) {
848
+ return /* @__PURE__ */ jsx(Alert, { variant: "error", children: trueError.message });
849
+ }
850
+ return /* @__PURE__ */ jsx(Alert, { variant: "error", children: trueError.response.data.message });
851
+ } else {
852
+ return /* @__PURE__ */ jsx(Alert, { variant: "error", children: "Preview can't be generated" });
853
+ }
854
+ }
855
+ if (data && data.buffer) {
856
+ const anyBuffer = data.buffer;
857
+ const blob = new Blob([new Uint8Array(anyBuffer.data)], { type: "application/pdf" });
858
+ const pdfURL = URL.createObjectURL(blob);
859
+ return /* @__PURE__ */ jsx("iframe", { src: pdfURL, width: 660, height: 1e3 });
860
+ } else {
861
+ return /* @__PURE__ */ jsx(Alert, { variant: "error", children: "Preview can't be generated" });
862
+ }
863
+ };
864
+ const ChooseTemplate$1 = (props) => {
865
+ const handleChange = (checked) => {
866
+ props.setKind(checked);
867
+ };
868
+ return /* @__PURE__ */ jsxs(RadioGroup, { onValueChange: handleChange, defaultValue: props.lastKind.toString(), children: [
869
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
870
+ /* @__PURE__ */ jsx(RadioGroup.Item, { value: InvoiceTemplateKind.BASIC.toString(), id: InvoiceTemplateKind.BASIC.toString() }),
871
+ /* @__PURE__ */ jsx(Label, { htmlFor: "radio_1", weight: "plus", children: "Basic" })
872
+ ] }),
873
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
874
+ /* @__PURE__ */ jsx(RadioGroup.Item, { value: InvoiceTemplateKind.BASIC_LOGO.toString(), id: InvoiceTemplateKind.BASIC_LOGO.toString() }),
875
+ /* @__PURE__ */ jsx(Label, { htmlFor: "radio_1", weight: "plus", children: "Basic with logo" })
876
+ ] }),
877
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
878
+ /* @__PURE__ */ jsx(RadioGroup.Item, { value: InvoiceTemplateKind.INDIA_GST.toString(), id: InvoiceTemplateKind.INDIA_GST.toString() }),
879
+ /* @__PURE__ */ jsx(Label, { htmlFor: "radio_1", weight: "plus", children: "India GST" })
880
+ ] })
881
+ ] });
882
+ };
883
+ const TemplatesTabContent$1 = ({ lastKind }) => {
884
+ const [templateKind, setTemplateKind] = useState(lastKind !== void 0 && lastKind !== null ? lastKind : InvoiceTemplateKind.BASIC);
885
+ const onSubmit = () => {
886
+ fetch(`/admin/documents/document-invoice-settings/invoice-template`, {
887
+ method: "POST",
888
+ credentials: "include",
889
+ headers: {
890
+ "Content-Type": "application/json"
891
+ },
892
+ body: JSON.stringify({
893
+ template: templateKind
894
+ })
895
+ }).then(async (response) => {
896
+ if (response.ok) {
897
+ toast.success("Template", {
898
+ description: "New template saved"
899
+ });
900
+ } else {
901
+ const error = await response.json();
902
+ toast.error("Template", {
903
+ description: `New template cannot be saved, some error happened. ${error.message}`
904
+ });
905
+ }
906
+ }).catch((e) => {
907
+ toast.error("Template", {
908
+ description: `New template cannot be saved, some error happened. ${e.toString()}`
909
+ });
910
+ console.error(e);
911
+ });
912
+ };
913
+ return /* @__PURE__ */ jsxs(Grid, { container: true, spacing: 2, children: [
914
+ /* @__PURE__ */ jsx(Grid, { item: true, xs: 3, md: 3, xl: 3, children: /* @__PURE__ */ jsxs(Grid, { container: true, rowSpacing: 3, children: [
915
+ /* @__PURE__ */ jsx(Grid, { item: true, xs: 12, md: 12, xl: 12, children: /* @__PURE__ */ jsx(Alert, { children: "Preview is based on the last order" }) }),
916
+ /* @__PURE__ */ jsx(Grid, { item: true, xs: 12, md: 12, xl: 12, children: /* @__PURE__ */ jsx(Container, { children: /* @__PURE__ */ jsxs(Grid, { container: true, rowSpacing: 3, direction: "column", children: [
917
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Choose template" }) }),
918
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(ChooseTemplate$1, { lastKind: templateKind, setKind: setTemplateKind }) }),
919
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Button, { variant: "primary", onClick: onSubmit, children: "Save" }) })
920
+ ] }) }) })
921
+ ] }) }),
922
+ /* @__PURE__ */ jsx(Grid, { item: true, xs: 6, md: 6, xl: 6, children: /* @__PURE__ */ jsx(ViewExampleInvoice, { kind: templateKind }) })
923
+ ] });
924
+ };
925
+ const InvoiceTemplatesTab = () => {
926
+ var _a;
927
+ const [data, setData] = useState(void 0);
928
+ const [error, setError] = useState(void 0);
929
+ const [isLoading, setLoading] = useState(true);
930
+ useEffect(() => {
931
+ fetch(`/admin/documents/document-invoice-settings`, {
932
+ credentials: "include"
933
+ }).then((res) => res.json()).then((result) => {
934
+ setData(result);
935
+ setLoading(false);
936
+ }).catch((error2) => {
937
+ setError(error2);
938
+ console.error(error2);
939
+ });
940
+ }, []);
941
+ if (isLoading) {
942
+ return /* @__PURE__ */ jsx(CircularProgress, { size: 12 });
943
+ }
944
+ return /* @__PURE__ */ jsx(TemplatesTabContent$1, { lastKind: (_a = data == null ? void 0 : data.settings) == null ? void 0 : _a.template });
945
+ };
946
+ const ViewExample = ({ kind }) => {
947
+ var _a, _b;
948
+ const [data, setData] = useState(void 0);
949
+ const [error, setError] = useState(void 0);
950
+ const [isLoading, setLoading] = useState(true);
951
+ const [lastKind, setLastKind] = useState(kind);
952
+ useEffect(() => {
953
+ if (lastKind !== kind) {
954
+ setLastKind(kind);
955
+ if (!isLoading) {
956
+ setLoading(true);
957
+ }
958
+ }
959
+ }, [kind]);
960
+ useEffect(() => {
961
+ if (!isLoading) {
962
+ return;
963
+ }
964
+ const result = new URLSearchParams({
965
+ template: kind
966
+ });
967
+ fetch(`/admin/documents/packing-slip/preview?${result.toString()}`, {
968
+ credentials: "include"
969
+ }).then((res) => res.json()).then((result2) => {
970
+ if (result2 && result2.message) {
971
+ setError({
972
+ message: result2.message
973
+ });
974
+ } else {
975
+ toast.dismiss();
976
+ setData(result2);
977
+ }
978
+ setLoading(false);
979
+ }).catch((error2) => {
980
+ setError(error2);
981
+ console.error(error2);
982
+ });
983
+ }, [isLoading]);
984
+ if (isLoading) {
985
+ return /* @__PURE__ */ jsx(Grid, { container: true, justifyContent: "center", children: /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(CircularProgress, { size: 12 }) }) });
986
+ }
987
+ if (error) {
988
+ const trueError = error;
989
+ if (((_b = (_a = trueError.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || trueError.message) {
990
+ if (trueError.message) {
991
+ return /* @__PURE__ */ jsx(Alert, { variant: "error", children: trueError.message });
992
+ }
993
+ return /* @__PURE__ */ jsx(Alert, { variant: "error", children: trueError.response.data.message });
994
+ } else {
995
+ return /* @__PURE__ */ jsx(Alert, { variant: "error", children: "Preview can't be generated" });
996
+ }
997
+ }
998
+ if (data && data.buffer) {
999
+ const anyBuffer = data.buffer;
1000
+ const blob = new Blob([new Uint8Array(anyBuffer.data)], { type: "application/pdf" });
1001
+ const pdfURL = URL.createObjectURL(blob);
1002
+ return /* @__PURE__ */ jsx("iframe", { src: pdfURL, width: 660, height: 1e3 });
1003
+ } else {
1004
+ return /* @__PURE__ */ jsx(Alert, { variant: "error", children: "Preview can't be generated" });
1005
+ }
1006
+ };
1007
+ const ChooseTemplate = (props) => {
1008
+ const handleChange = (checked) => {
1009
+ props.setKind(checked);
1010
+ };
1011
+ return /* @__PURE__ */ jsxs(RadioGroup, { onValueChange: handleChange, defaultValue: props.lastKind.toString(), children: [
1012
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
1013
+ /* @__PURE__ */ jsx(RadioGroup.Item, { value: PackingSlipTemplateKind.BASIC.toString(), id: PackingSlipTemplateKind.BASIC.toString() }),
1014
+ /* @__PURE__ */ jsx(Label, { htmlFor: "radio_1", weight: "plus", children: "Basic" })
1015
+ ] }),
1016
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
1017
+ /* @__PURE__ */ jsx(RadioGroup.Item, { value: PackingSlipTemplateKind.BASIC_SMALL.toString(), id: PackingSlipTemplateKind.BASIC_SMALL.toString() }),
1018
+ /* @__PURE__ */ jsx(Label, { htmlFor: "radio_1", weight: "plus", children: "Basic A7" })
1019
+ ] })
1020
+ ] });
1021
+ };
1022
+ const TemplatesTabContent = ({ lastKind }) => {
1023
+ const [templateKind, setTemplateKind] = useState(lastKind !== void 0 && lastKind !== null ? lastKind : PackingSlipTemplateKind.BASIC);
1024
+ const onSubmit = () => {
1025
+ fetch(`/admin/documents/document-packing-slip-settings/template`, {
1026
+ method: "POST",
1027
+ credentials: "include",
1028
+ headers: {
1029
+ "Content-Type": "application/json"
1030
+ },
1031
+ body: JSON.stringify({
1032
+ template: templateKind
1033
+ })
1034
+ }).then(async (response) => {
1035
+ if (response.ok) {
1036
+ toast.success("Template", {
1037
+ description: "New template saved"
1038
+ });
1039
+ } else {
1040
+ const error = await response.json();
1041
+ toast.error("Template", {
1042
+ description: `New template cannot be saved, some error happened. ${error.message}`
1043
+ });
1044
+ }
1045
+ }).catch((e) => {
1046
+ toast.error("Template", {
1047
+ description: `New template cannot be saved, some error happened. ${e.toString()}`
1048
+ });
1049
+ console.error(e);
1050
+ });
1051
+ };
1052
+ return /* @__PURE__ */ jsxs(Grid, { container: true, spacing: 2, children: [
1053
+ /* @__PURE__ */ jsx(Grid, { item: true, xs: 3, md: 3, xl: 3, children: /* @__PURE__ */ jsxs(Grid, { container: true, rowSpacing: 3, children: [
1054
+ /* @__PURE__ */ jsx(Grid, { item: true, xs: 12, md: 12, xl: 12, children: /* @__PURE__ */ jsx(Alert, { children: "Preview is based on the last order" }) }),
1055
+ /* @__PURE__ */ jsx(Grid, { item: true, xs: 12, md: 12, xl: 12, children: /* @__PURE__ */ jsx(Container, { children: /* @__PURE__ */ jsxs(Grid, { container: true, rowSpacing: 3, direction: "column", children: [
1056
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Choose template" }) }),
1057
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(ChooseTemplate, { lastKind: templateKind, setKind: setTemplateKind }) }),
1058
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Button, { variant: "primary", onClick: onSubmit, children: "Save" }) })
1059
+ ] }) }) })
1060
+ ] }) }),
1061
+ /* @__PURE__ */ jsx(Grid, { item: true, xs: 6, md: 6, xl: 6, children: /* @__PURE__ */ jsx(ViewExample, { kind: templateKind }) })
1062
+ ] });
1063
+ };
1064
+ const PackingSlipTemplatesTab = () => {
1065
+ var _a;
1066
+ const [data, setData] = useState(void 0);
1067
+ const [error, setError] = useState(void 0);
1068
+ const [isLoading, setLoading] = useState(true);
1069
+ useEffect(() => {
1070
+ if (!isLoading) {
1071
+ return;
1072
+ }
1073
+ fetch(`/admin/documents/document-packing-slip-settings`, {
1074
+ credentials: "include"
1075
+ }).then((res) => res.json()).then((result) => {
1076
+ setData(result);
1077
+ setLoading(false);
1078
+ }).catch((error2) => {
1079
+ setError(error2);
1080
+ console.error(error2);
1081
+ });
1082
+ }, [isLoading]);
1083
+ if (isLoading) {
1084
+ return /* @__PURE__ */ jsx(CircularProgress, { size: 12 });
1085
+ }
1086
+ return /* @__PURE__ */ jsx(TemplatesTabContent, { lastKind: (_a = data == null ? void 0 : data.settings) == null ? void 0 : _a.template });
1087
+ };
1088
+ const TemplatesTab = () => {
1089
+ return /* @__PURE__ */ jsxs(Tabs, { defaultValue: "invoice", children: [
1090
+ /* @__PURE__ */ jsxs(Tabs.List, { children: [
1091
+ /* @__PURE__ */ jsx(Tabs.Trigger, { value: "invoice", children: "Invoice" }),
1092
+ /* @__PURE__ */ jsx(Tabs.Trigger, { value: "packing-slip", children: "Packing slip" })
1093
+ ] }),
1094
+ /* @__PURE__ */ jsxs(Tabs.Content, { value: "invoice", children: [
1095
+ /* @__PURE__ */ jsx(Box, { height: 20 }),
1096
+ /* @__PURE__ */ jsx(InvoiceTemplatesTab, {})
1097
+ ] }),
1098
+ /* @__PURE__ */ jsxs(Tabs.Content, { value: "packing-slip", children: [
1099
+ /* @__PURE__ */ jsx(Box, { height: 20 }),
1100
+ /* @__PURE__ */ jsx(PackingSlipTemplatesTab, {})
1101
+ ] })
1102
+ ] });
1103
+ };
1104
+ const AddressField = ({ name, placeholder, initValue, register }) => {
1105
+ return /* @__PURE__ */ jsxs(Grid, { container: true, direction: "column", spacing: 1, marginTop: 2, children: [
1106
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Label, { size: "small", children: name }) }),
1107
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(
1108
+ Input,
1109
+ {
1110
+ placeholder,
1111
+ ...register,
1112
+ defaultValue: initValue
1113
+ }
1114
+ ) })
1115
+ ] });
1116
+ };
1117
+ const AddressForm = ({ address, setOpenModal }) => {
1118
+ const { register, handleSubmit } = useForm();
1119
+ const onSubmit = (data) => {
1120
+ fetch(`/admin/documents/document-settings/document-address`, {
1121
+ method: "POST",
1122
+ credentials: "include",
1123
+ headers: {
1124
+ "Content-Type": "application/json"
1125
+ },
1126
+ body: JSON.stringify({
1127
+ address: data
1128
+ })
1129
+ }).then(async (response) => {
1130
+ if (response.ok) {
1131
+ toast.success("Address", {
1132
+ description: "New address saved"
1133
+ });
1134
+ setOpenModal(false);
1135
+ } else {
1136
+ const error = await response.json();
1137
+ toast.error("Address", {
1138
+ description: `Address cannot be saved. ${error.message}`
1139
+ });
1140
+ }
1141
+ }).catch((e) => {
1142
+ toast.error("Address", {
1143
+ description: `Address cannot be saved. ${e.toString()}`
1144
+ });
1145
+ console.error(e);
1146
+ });
1147
+ };
1148
+ return /* @__PURE__ */ jsx("form", { children: /* @__PURE__ */ jsxs(Grid, { container: true, direction: "column", rowSpacing: 4, paddingTop: 8, children: [
1149
+ /* @__PURE__ */ jsx(
1150
+ AddressField,
1151
+ {
1152
+ name: "Company name",
1153
+ placeholder: "My store",
1154
+ register: register("company"),
1155
+ initValue: address == null ? void 0 : address.company
1156
+ }
1157
+ ),
1158
+ /* @__PURE__ */ jsx(
1159
+ AddressField,
1160
+ {
1161
+ name: "First name",
1162
+ placeholder: "John",
1163
+ register: register("first_name"),
1164
+ initValue: address == null ? void 0 : address.first_name
1165
+ }
1166
+ ),
1167
+ /* @__PURE__ */ jsx(
1168
+ AddressField,
1169
+ {
1170
+ name: "Last name",
1171
+ placeholder: "Doe",
1172
+ register: register("last_name"),
1173
+ initValue: address == null ? void 0 : address.last_name
1174
+ }
1175
+ ),
1176
+ /* @__PURE__ */ jsx(
1177
+ AddressField,
1178
+ {
1179
+ name: "Address",
1180
+ placeholder: "56 Street",
1181
+ register: register("address_1"),
1182
+ initValue: address == null ? void 0 : address.address_1
1183
+ }
1184
+ ),
1185
+ /* @__PURE__ */ jsx(
1186
+ AddressField,
1187
+ {
1188
+ name: "City",
1189
+ placeholder: "Warsaw",
1190
+ register: register("city"),
1191
+ initValue: address == null ? void 0 : address.city
1192
+ }
1193
+ ),
1194
+ /* @__PURE__ */ jsx(
1195
+ AddressField,
1196
+ {
1197
+ name: "Postal code",
1198
+ placeholder: "55-200",
1199
+ register: register("postal_code"),
1200
+ initValue: address == null ? void 0 : address.postal_code
1201
+ }
1202
+ ),
1203
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(
1204
+ Button,
1205
+ {
1206
+ type: "submit",
1207
+ variant: "primary",
1208
+ onClick: handleSubmit(onSubmit),
1209
+ children: "Save"
1210
+ }
1211
+ ) })
1212
+ ] }) });
1213
+ };
1214
+ const AddressModalDetails = ({ setOpenModal }) => {
1215
+ var _a;
1216
+ const [data, setData] = useState(void 0);
1217
+ const [error, setError] = useState(void 0);
1218
+ const [isLoading, setLoading] = useState(true);
1219
+ useEffect(() => {
1220
+ if (!isLoading) {
1221
+ return;
1222
+ }
1223
+ fetch(`/admin/documents/document-settings`, {
1224
+ credentials: "include"
1225
+ }).then((res) => res.json()).then((result) => {
1226
+ setData(result);
1227
+ setLoading(false);
1228
+ }).catch((error2) => {
1229
+ setError(error2);
1230
+ console.error(error2);
1231
+ });
1232
+ }, [isLoading]);
1233
+ if (isLoading) {
1234
+ return /* @__PURE__ */ jsx(FocusModal.Body, { children: /* @__PURE__ */ jsx(CircularProgress, {}) });
1235
+ }
1236
+ return /* @__PURE__ */ jsx(FocusModal.Body, { children: /* @__PURE__ */ jsxs(Grid, { container: true, direction: "column", alignContent: "center", paddingTop: 8, children: [
1237
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Heading, { children: "Store address" }) }),
1238
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Text, { children: "This address will be used on your documents." }) }),
1239
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Text, { children: "Presence of field on document depends on template." }) }),
1240
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(AddressForm, { address: (_a = data == null ? void 0 : data.settings) == null ? void 0 : _a.storeAddress, setOpenModal }) })
1241
+ ] }) });
1242
+ };
1243
+ const AddressChangeModal = () => {
1244
+ const [open, setOpen] = useState(false);
1245
+ return /* @__PURE__ */ jsxs(
1246
+ FocusModal,
1247
+ {
1248
+ open,
1249
+ onOpenChange: setOpen,
1250
+ children: [
1251
+ /* @__PURE__ */ jsx(FocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(Button, { children: "Change address" }) }),
1252
+ /* @__PURE__ */ jsxs(FocusModal.Content, { children: [
1253
+ /* @__PURE__ */ jsx(FocusModal.Header, {}),
1254
+ /* @__PURE__ */ jsx(AddressModalDetails, { setOpenModal: setOpen })
1255
+ ] })
1256
+ ]
1257
+ }
1258
+ );
1259
+ };
1260
+ const LogoFields = ({ logoSource, register }) => {
1261
+ const [logoUrl, setLogoUrl] = useState(logoSource);
1262
+ const [isValidUrl, setIsValidUrl] = useState(true);
1263
+ const [imgLoaded, setIsImageLoaded] = useState(false);
1264
+ const [error, setError] = useState(void 0);
1265
+ const handleInputChange = (event) => {
1266
+ setLogoUrl(event.target.value);
1267
+ setIsValidUrl(true);
1268
+ };
1269
+ const handleImageError = () => {
1270
+ setIsValidUrl(false);
1271
+ setIsImageLoaded(false);
1272
+ };
1273
+ const handleOnLoad = (event) => {
1274
+ setIsImageLoaded(true);
1275
+ };
1276
+ return /* @__PURE__ */ jsxs(Grid, { container: true, direction: "column", spacing: 1, children: [
1277
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Label, { size: "small", children: "Link to logo" }) }),
1278
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(
1279
+ Input,
1280
+ {
1281
+ placeholder: "https://raw.githubusercontent.com/RSC-Labs/medusa-store-analytics/main/docs/store-analytics-logo.PNG",
1282
+ ...register,
1283
+ defaultValue: logoSource,
1284
+ onChange: handleInputChange
1285
+ }
1286
+ ) }),
1287
+ /* @__PURE__ */ jsx(Grid, { container: true, justifyContent: "center", alignContent: "center", marginTop: 5, children: /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx("div", { style: { height: "200px", width: "300px", overflow: "hidden", border: imgLoaded ? void 0 : "1px solid rgba(0, 0, 0, 0.12)" }, children: logoUrl && isValidUrl && /* @__PURE__ */ jsx(Grid, { item: true, textAlign: "center", children: /* @__PURE__ */ jsx("img", { src: logoUrl, alt: "Preview", style: { maxWidth: 300, maxHeight: 200 }, onLoad: handleOnLoad, onError: handleImageError }) }) }) }) })
1288
+ ] });
1289
+ };
1290
+ const LogoForm = ({ logoSource, setOpenModal }) => {
1291
+ const { register, handleSubmit } = useForm();
1292
+ const onSubmit = (data) => {
1293
+ fetch(`/admin/documents/document-settings/logo`, {
1294
+ method: "POST",
1295
+ credentials: "include",
1296
+ headers: {
1297
+ "Content-Type": "application/json"
1298
+ },
1299
+ body: JSON.stringify({
1300
+ logoSource: data.logoSource
1301
+ })
1302
+ }).then(async (response) => {
1303
+ if (response.ok) {
1304
+ toast.success("Logo", {
1305
+ description: "New logo saved"
1306
+ });
1307
+ setOpenModal(false);
1308
+ } else {
1309
+ const error = await response.json();
1310
+ toast.error("Logo", {
1311
+ description: `Logo cannot be saved, some error happened. ${error.message}`
1312
+ });
1313
+ toast.error("Invoice settings", {
1314
+ description: `New invoice settings cannot be saved, some error happened.`
1315
+ });
1316
+ }
1317
+ }).catch((e) => {
1318
+ toast.error("Logo", {
1319
+ description: `Logo cannot be saved, some error happened. ${e.toString()}`
1320
+ });
1321
+ console.error(e);
1322
+ });
1323
+ };
1324
+ return /* @__PURE__ */ jsx("form", { children: /* @__PURE__ */ jsxs(Grid, { container: true, direction: "column", rowSpacing: 4, paddingTop: 8, children: [
1325
+ /* @__PURE__ */ jsx(LogoFields, { logoSource, register: register("logoSource") }),
1326
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(
1327
+ Button,
1328
+ {
1329
+ type: "submit",
1330
+ variant: "primary",
1331
+ onClick: handleSubmit(onSubmit),
1332
+ children: "Save"
1333
+ }
1334
+ ) })
1335
+ ] }) });
1336
+ };
1337
+ const LogoModalDetails = ({ setOpenModal }) => {
1338
+ const [data, setData] = useState(void 0);
1339
+ const [error, setError] = useState(void 0);
1340
+ const [isLoading, setLoading] = useState(true);
1341
+ useEffect(() => {
1342
+ if (!isLoading) {
1343
+ return;
1344
+ }
1345
+ fetch(`/admin/documents/document-settings`, {
1346
+ credentials: "include"
1347
+ }).then((res) => res.json()).then((result) => {
1348
+ setData(result);
1349
+ setLoading(false);
1350
+ }).catch((error2) => {
1351
+ setError(error2);
1352
+ console.error(error2);
1353
+ });
1354
+ }, [isLoading]);
1355
+ if (isLoading) {
1356
+ return /* @__PURE__ */ jsx(FocusModal.Body, { children: /* @__PURE__ */ jsx(CircularProgress, {}) });
1357
+ }
1358
+ return /* @__PURE__ */ jsx(FocusModal.Body, { children: /* @__PURE__ */ jsxs(Grid, { container: true, direction: "column", alignContent: "center", paddingTop: 8, children: [
1359
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Heading, { children: "Store logo" }) }),
1360
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Text, { children: "This logo will be used on your documents." }) }),
1361
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Text, { children: "Presence of logo on document depends on template." }) }),
1362
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(LogoForm, { logoSource: data.settings && data.settings.storeLogoSource ? data.settings.storeLogoSource : void 0, setOpenModal }) })
1363
+ ] }) });
1364
+ };
1365
+ const LogoChangeModal = () => {
1366
+ const [open, setOpen] = useState(false);
1367
+ return /* @__PURE__ */ jsxs(
1368
+ FocusModal,
1369
+ {
1370
+ open,
1371
+ onOpenChange: setOpen,
1372
+ children: [
1373
+ /* @__PURE__ */ jsx(FocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(Button, { children: "Change logo" }) }),
1374
+ /* @__PURE__ */ jsxs(FocusModal.Content, { children: [
1375
+ /* @__PURE__ */ jsx(FocusModal.Header, {}),
1376
+ /* @__PURE__ */ jsx(LogoModalDetails, { setOpenModal: setOpen })
1377
+ ] })
1378
+ ]
1379
+ }
1380
+ );
1381
+ };
1382
+ const InvoiceSettingsDisplayNumber = ({ formatNumber, forcedNumber }) => {
1383
+ const result = new URLSearchParams();
1384
+ if (formatNumber) {
1385
+ result.append("formatNumber", formatNumber);
1386
+ }
1387
+ if (forcedNumber) {
1388
+ result.append("forcedNumber", forcedNumber.toString());
1389
+ }
1390
+ const [data, setData] = useState(void 0);
1391
+ const [error, setError] = useState(void 0);
1392
+ const [isLoading, setLoading] = useState(true);
1393
+ useEffect(() => {
1394
+ setLoading(true);
1395
+ }, [formatNumber, forcedNumber]);
1396
+ useEffect(() => {
1397
+ if (!isLoading) {
1398
+ return;
1399
+ }
1400
+ fetch(`/admin/documents/invoice/display-number?${result.toString()}`, {
1401
+ credentials: "include"
1402
+ }).then((res) => res.json()).then((result2) => {
1403
+ setData(result2);
1404
+ setLoading(false);
1405
+ }).catch((error2) => {
1406
+ setError(error2);
1407
+ console.error(error2);
1408
+ });
1409
+ }, [isLoading]);
1410
+ if (isLoading) {
1411
+ return /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(
1412
+ Input,
1413
+ {
1414
+ readOnly: true
1415
+ }
1416
+ ) });
1417
+ }
1418
+ return /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(
1419
+ Input,
1420
+ {
1421
+ defaultValue: data.displayNumber,
1422
+ readOnly: true
1423
+ },
1424
+ `display-number-${data.displayNumber}`
1425
+ ) });
1426
+ };
1427
+ const InvoiceSettingsForm = ({ invoiceSettings, setOpenModal }) => {
1428
+ const { register, handleSubmit, formState: { errors } } = useForm();
1429
+ const [formatNumber, setFormatNumber] = useState(invoiceSettings == null ? void 0 : invoiceSettings.numberFormat);
1430
+ const [forcedNumber, setForcedNumber] = useState(invoiceSettings == null ? void 0 : invoiceSettings.forcedNumber);
1431
+ const [error, setError] = useState(void 0);
1432
+ const onSubmit = (data) => {
1433
+ fetch(`/admin/documents/document-invoice-settings`, {
1434
+ method: "POST",
1435
+ credentials: "include",
1436
+ headers: {
1437
+ "Content-Type": "application/json"
1438
+ },
1439
+ body: JSON.stringify({
1440
+ formatNumber: data.formatNumber,
1441
+ forcedNumber: data.forcedNumber !== void 0 && data.forcedNumber.toString().length ? data.forcedNumber : void 0
1442
+ })
1443
+ }).then(async (response) => {
1444
+ if (response.ok) {
1445
+ toast.success("Invoice settings", {
1446
+ description: "New invoice settings saved"
1447
+ });
1448
+ setOpenModal(false);
1449
+ } else {
1450
+ const error2 = await response.json();
1451
+ toast.error("Invoice settings", {
1452
+ description: `New invoice settings cannot be saved, some error happened. ${error2.message}`
1453
+ });
1454
+ }
1455
+ }).catch((e) => {
1456
+ toast.error("Invoice settings", {
1457
+ description: `New invoice settings cannot be saved, some error happened. ${e.toString()}`
1458
+ });
1459
+ console.error(e);
1460
+ });
1461
+ };
1462
+ const INVOICE_NUMBER_PLACEHOLDER = "{invoice_number}";
1463
+ const errorText = `Text ${INVOICE_NUMBER_PLACEHOLDER} needs to be included in input.`;
1464
+ const LABEL_MUST_FORMAT = `Format must include ${INVOICE_NUMBER_PLACEHOLDER}`;
1465
+ const LABEL_MUST_FORCED = `Forced number must be a number`;
1466
+ const LABEL_INFO_FORCED = `It will auto-increment starting from this number.`;
1467
+ const validateFormatNumber = (value) => {
1468
+ if (!value.includes(INVOICE_NUMBER_PLACEHOLDER)) {
1469
+ return LABEL_MUST_FORMAT;
1470
+ }
1471
+ return true;
1472
+ };
1473
+ const validateForcedNumber = (value) => {
1474
+ if (value.length && isNaN(Number(value))) {
1475
+ return LABEL_MUST_FORCED;
1476
+ }
1477
+ return true;
1478
+ };
1479
+ return /* @__PURE__ */ jsx("form", { children: /* @__PURE__ */ jsxs(Grid, { container: true, direction: "column", rowSpacing: 4, paddingTop: 8, children: [
1480
+ /* @__PURE__ */ jsxs(Grid, { container: true, direction: "column", spacing: 1, marginTop: 2, children: [
1481
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsxs(Grid, { container: true, direction: "column", children: [
1482
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Label, { size: "small", children: "Number format" }) }),
1483
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Label, { size: "xsmall", children: LABEL_MUST_FORMAT }) })
1484
+ ] }) }),
1485
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(
1486
+ Input,
1487
+ {
1488
+ placeholder: INVOICE_NUMBER_PLACEHOLDER,
1489
+ defaultValue: (invoiceSettings == null ? void 0 : invoiceSettings.numberFormat) ? invoiceSettings.numberFormat : INVOICE_NUMBER_PLACEHOLDER,
1490
+ ...register("formatNumber", {
1491
+ validate: validateFormatNumber,
1492
+ onChange(e) {
1493
+ const value = e.target.value;
1494
+ if (typeof validateFormatNumber(value) === "string") {
1495
+ const result = validateFormatNumber(value);
1496
+ setError(result);
1497
+ } else {
1498
+ setError(void 0);
1499
+ setFormatNumber(value);
1500
+ }
1501
+ }
1502
+ })
1503
+ }
1504
+ ) })
1505
+ ] }),
1506
+ /* @__PURE__ */ jsxs(Grid, { container: true, direction: "column", spacing: 1, marginTop: 2, children: [
1507
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsxs(Grid, { container: true, direction: "column", children: [
1508
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Label, { size: "small", children: "Forced number" }) }),
1509
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Label, { size: "xsmall", children: LABEL_INFO_FORCED }) })
1510
+ ] }) }),
1511
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(
1512
+ Input,
1513
+ {
1514
+ defaultValue: (invoiceSettings == null ? void 0 : invoiceSettings.forcedNumber) !== void 0 && invoiceSettings.forcedNumber !== null ? invoiceSettings.forcedNumber : "",
1515
+ type: "number",
1516
+ ...register("forcedNumber", {
1517
+ validate: validateForcedNumber,
1518
+ onChange(e) {
1519
+ const value = e.target.value;
1520
+ if (typeof validateForcedNumber(value) === "string") {
1521
+ const result = validateForcedNumber(value);
1522
+ setError(result);
1523
+ } else {
1524
+ setError(void 0);
1525
+ setForcedNumber(value);
1526
+ }
1527
+ }
1528
+ })
1529
+ }
1530
+ ) })
1531
+ ] }),
1532
+ /* @__PURE__ */ jsxs(Grid, { container: true, direction: "column", spacing: 1, marginTop: 2, children: [
1533
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Label, { size: "small", children: "Your next invoice number will be:" }) }),
1534
+ errors.formatNumber == void 0 && errors.forcedNumber == void 0 && error == void 0 && /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(InvoiceSettingsDisplayNumber, { formatNumber, forcedNumber: forcedNumber !== void 0 && forcedNumber !== null ? parseInt(forcedNumber) : void 0 }) })
1535
+ ] }),
1536
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(
1537
+ Button,
1538
+ {
1539
+ type: "submit",
1540
+ variant: "primary",
1541
+ onClick: handleSubmit(onSubmit),
1542
+ children: "Save"
1543
+ }
1544
+ ) }),
1545
+ (errors.formatNumber || errors.forcedNumber) && /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Alert, { variant: "error", children: errorText }) }),
1546
+ error && /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Alert, { variant: "error", children: error }) })
1547
+ ] }) });
1548
+ };
1549
+ const InvoiceSettingsModalDetails = ({ setOpenModal }) => {
1550
+ const [data, setData] = useState(void 0);
1551
+ const [error, setError] = useState(void 0);
1552
+ const [isLoading, setLoading] = useState(true);
1553
+ useEffect(() => {
1554
+ if (!isLoading) {
1555
+ return;
1556
+ }
1557
+ fetch(`/admin/documents/document-invoice-settings`, {
1558
+ credentials: "include"
1559
+ }).then((res) => res.json()).then((result) => {
1560
+ setData(result);
1561
+ setLoading(false);
1562
+ }).catch((error2) => {
1563
+ setError(error2);
1564
+ console.error(error2);
1565
+ });
1566
+ }, [isLoading]);
1567
+ if (isLoading) {
1568
+ return /* @__PURE__ */ jsx(FocusModal.Body, { children: /* @__PURE__ */ jsx(CircularProgress, {}) });
1569
+ }
1570
+ return /* @__PURE__ */ jsx(FocusModal.Body, { children: /* @__PURE__ */ jsxs(Grid, { container: true, direction: "column", alignContent: "center", paddingTop: 8, children: [
1571
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Heading, { children: "Invoice settings" }) }),
1572
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Text, { children: "These settings will be applied for newly generated invoices." }) }),
1573
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(InvoiceSettingsForm, { invoiceSettings: data == null ? void 0 : data.settings, setOpenModal }) })
1574
+ ] }) });
1575
+ };
1576
+ const InvoiceSettingsModal = () => {
1577
+ const [open, setOpen] = useState(false);
1578
+ return /* @__PURE__ */ jsxs(
1579
+ FocusModal,
1580
+ {
1581
+ open,
1582
+ onOpenChange: setOpen,
1583
+ children: [
1584
+ /* @__PURE__ */ jsx(FocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(Button, { children: "Change settings" }) }),
1585
+ /* @__PURE__ */ jsxs(FocusModal.Content, { children: [
1586
+ /* @__PURE__ */ jsx(FocusModal.Header, {}),
1587
+ /* @__PURE__ */ jsx(InvoiceSettingsModalDetails, { setOpenModal: setOpen })
1588
+ ] })
1589
+ ]
1590
+ }
1591
+ );
1592
+ };
1593
+ const GstField = ({ name, placeholder, initValue, register }) => {
1594
+ return /* @__PURE__ */ jsxs(Grid, { container: true, direction: "column", spacing: 1, marginTop: 2, children: [
1595
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Label, { size: "small", children: name }) }),
1596
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(
1597
+ Input,
1598
+ {
1599
+ placeholder,
1600
+ ...register,
1601
+ defaultValue: initValue
1602
+ }
1603
+ ) })
1604
+ ] });
1605
+ };
1606
+ const IndiaGstForm = ({ details, setOpenModal }) => {
1607
+ const { register, handleSubmit } = useForm();
1608
+ const onSubmit = (data) => {
1609
+ fetch(`/admin/documents/document-settings/india-gst`, {
1610
+ method: "POST",
1611
+ credentials: "include",
1612
+ headers: {
1613
+ "Content-Type": "application/json"
1614
+ },
1615
+ body: JSON.stringify({
1616
+ indiaGstDetails: data
1617
+ })
1618
+ }).then(async (response) => {
1619
+ if (response.ok) {
1620
+ toast.success("India GST details", {
1621
+ description: "New details saved"
1622
+ });
1623
+ setOpenModal(false);
1624
+ } else {
1625
+ const error = await response.json();
1626
+ toast.error("India GST details", {
1627
+ description: `Details cannot be saved. ${error.message}`
1628
+ });
1629
+ }
1630
+ }).catch((e) => {
1631
+ toast.error("India GST details", {
1632
+ description: `Details cannot be saved. ${e.toString()}`
1633
+ });
1634
+ console.error(e);
1635
+ });
1636
+ };
1637
+ return /* @__PURE__ */ jsx("form", { children: /* @__PURE__ */ jsxs(Grid, { container: true, direction: "column", rowSpacing: 4, paddingTop: 8, children: [
1638
+ /* @__PURE__ */ jsx(
1639
+ GstField,
1640
+ {
1641
+ name: "Legal Name",
1642
+ placeholder: "SensaLabs Wellness Private Limited",
1643
+ register: register("legalName"),
1644
+ initValue: details == null ? void 0 : details.legalName
1645
+ }
1646
+ ),
1647
+ /* @__PURE__ */ jsx(
1648
+ GstField,
1649
+ {
1650
+ name: "GSTIN",
1651
+ placeholder: "27ABSCS6019B1ZX",
1652
+ register: register("gstin"),
1653
+ initValue: details == null ? void 0 : details.gstin
1654
+ }
1655
+ ),
1656
+ /* @__PURE__ */ jsx(
1657
+ GstField,
1658
+ {
1659
+ name: "PAN",
1660
+ placeholder: "ABSCS6019B",
1661
+ register: register("pan"),
1662
+ initValue: details == null ? void 0 : details.pan
1663
+ }
1664
+ ),
1665
+ /* @__PURE__ */ jsx(
1666
+ GstField,
1667
+ {
1668
+ name: "CIN (optional)",
1669
+ placeholder: "U12345MH2020PTC123456",
1670
+ register: register("cin"),
1671
+ initValue: details == null ? void 0 : details.cin
1672
+ }
1673
+ ),
1674
+ /* @__PURE__ */ jsx(
1675
+ GstField,
1676
+ {
1677
+ name: "Signature image URL (optional)",
1678
+ placeholder: "https://.../signature.png",
1679
+ register: register("signatureSource"),
1680
+ initValue: details == null ? void 0 : details.signatureSource
1681
+ }
1682
+ ),
1683
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(
1684
+ Button,
1685
+ {
1686
+ type: "submit",
1687
+ variant: "primary",
1688
+ onClick: handleSubmit(onSubmit),
1689
+ children: "Save"
1690
+ }
1691
+ ) })
1692
+ ] }) });
1693
+ };
1694
+ const IndiaGstModalDetails = ({ setOpenModal }) => {
1695
+ const [data, setData] = useState(void 0);
1696
+ const [error, setError] = useState(void 0);
1697
+ const [isLoading, setLoading] = useState(true);
1698
+ useEffect(() => {
1699
+ if (!isLoading) {
1700
+ return;
1701
+ }
1702
+ fetch(`/admin/documents/document-settings/india-gst`, {
1703
+ credentials: "include"
1704
+ }).then((res) => res.json()).then((result) => {
1705
+ setData(result);
1706
+ setLoading(false);
1707
+ }).catch((error2) => {
1708
+ setError(error2);
1709
+ console.error(error2);
1710
+ });
1711
+ }, [isLoading]);
1712
+ if (isLoading) {
1713
+ return /* @__PURE__ */ jsx(FocusModal.Body, { children: /* @__PURE__ */ jsx(CircularProgress, {}) });
1714
+ }
1715
+ return /* @__PURE__ */ jsx(FocusModal.Body, { children: /* @__PURE__ */ jsxs(Grid, { container: true, direction: "column", alignContent: "center", paddingTop: 8, children: [
1716
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Heading, { children: "India GST details" }) }),
1717
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Text, { children: "Used on the India GST invoice template. GSTIN and Legal Name are required to generate that template." }) }),
1718
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Text, { children: "Optional fields (CIN, signature) are only printed when a value is set." }) }),
1719
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(IndiaGstForm, { details: data == null ? void 0 : data.indiaGstDetails, setOpenModal }) })
1720
+ ] }) });
1721
+ };
1722
+ const IndiaGstChangeModal = () => {
1723
+ const [open, setOpen] = useState(false);
1724
+ return /* @__PURE__ */ jsxs(
1725
+ FocusModal,
1726
+ {
1727
+ open,
1728
+ onOpenChange: setOpen,
1729
+ children: [
1730
+ /* @__PURE__ */ jsx(FocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(Button, { children: "India GST details" }) }),
1731
+ /* @__PURE__ */ jsxs(FocusModal.Content, { children: [
1732
+ /* @__PURE__ */ jsx(FocusModal.Header, {}),
1733
+ /* @__PURE__ */ jsx(IndiaGstModalDetails, { setOpenModal: setOpen })
1734
+ ] })
1735
+ ]
1736
+ }
1737
+ );
1738
+ };
1739
+ const SettingsTab = () => {
1740
+ return /* @__PURE__ */ jsxs(Grid, { container: true, spacing: 2, children: [
1741
+ /* @__PURE__ */ jsx(Grid, { item: true, xs: 6, md: 6, xl: 6, children: /* @__PURE__ */ jsxs(Container, { children: [
1742
+ /* @__PURE__ */ jsxs(Grid, { container: true, direction: "column", children: [
1743
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Store information" }) }),
1744
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Text, { size: "small", children: "Change information about your store to have it included in generated documents" }) })
1745
+ ] }),
1746
+ /* @__PURE__ */ jsxs(Grid, { container: true, marginTop: 5, direction: "row", columnSpacing: 2, children: [
1747
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(AddressChangeModal, {}) }),
1748
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(LogoChangeModal, {}) }),
1749
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(IndiaGstChangeModal, {}) })
1750
+ ] })
1751
+ ] }) }),
1752
+ /* @__PURE__ */ jsx(Grid, { item: true, xs: 6, md: 6, xl: 6, children: /* @__PURE__ */ jsxs(Container, { children: [
1753
+ /* @__PURE__ */ jsxs(Grid, { container: true, direction: "column", children: [
1754
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Invoice" }) }),
1755
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Text, { size: "small", children: "Change settings how invoices are generated" }) })
1756
+ ] }),
1757
+ /* @__PURE__ */ jsx(Grid, { container: true, marginTop: 5, direction: "row", columnSpacing: 2, children: /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(InvoiceSettingsModal, {}) }) })
1758
+ ] }) })
1759
+ ] });
1760
+ };
1761
+ const HEIGHT = 330;
1762
+ const ProTab = () => {
1763
+ return /* @__PURE__ */ jsxs(Grid, { container: true, spacing: 2, justifyContent: "center", children: [
1764
+ /* @__PURE__ */ jsx(Grid, { container: true, justifyContent: "center", marginTop: 6, children: /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Heading, { level: "h1", style: { color: "purple" }, children: "Manage documents on the next level" }) }) }),
1765
+ /* @__PURE__ */ jsxs(Grid, { container: true, justifyContent: "center", marginTop: 1, spacing: 5, children: [
1766
+ /* @__PURE__ */ jsx(Grid, { item: true, xs: 3, md: 3, xl: 3, children: /* @__PURE__ */ jsx(Container, { style: { borderColor: "purple", borderWidth: 1, height: HEIGHT }, children: /* @__PURE__ */ jsxs(Grid, { container: true, rowSpacing: 3, children: [
1767
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Automation" }) }),
1768
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsxs("ul", { style: { listStyleType: "circle" }, children: [
1769
+ /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(Text, { children: "Automatically send invoices to customers" }) }),
1770
+ /* @__PURE__ */ jsx("li", { style: { marginTop: 3 }, children: /* @__PURE__ */ jsx(Text, { children: "Automatically send packing slips to fulfillment providers" }) }),
1771
+ /* @__PURE__ */ jsx("li", { style: { marginTop: 3 }, children: /* @__PURE__ */ jsx(Text, { children: "Automatically detect the language of your customer" }) })
1772
+ ] }) })
1773
+ ] }) }) }),
1774
+ /* @__PURE__ */ jsx(Grid, { item: true, xs: 3, md: 3, xl: 3, children: /* @__PURE__ */ jsx(Container, { style: { borderColor: "purple", borderWidth: 1, height: HEIGHT }, children: /* @__PURE__ */ jsxs(Grid, { container: true, rowSpacing: 3, children: [
1775
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Heading, { level: "h1", children: "New templates" }) }),
1776
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsxs("ul", { style: { listStyleType: "circle" }, children: [
1777
+ /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(Text, { children: "Access new premium templates for invoices and other documents" }) }),
1778
+ /* @__PURE__ */ jsx("li", { style: { marginTop: 3 }, children: /* @__PURE__ */ jsx(Text, { children: "Send us your custom template, and we will create it for you" }) })
1779
+ ] }) })
1780
+ ] }) }) }),
1781
+ /* @__PURE__ */ jsx(Grid, { item: true, xs: 3, md: 3, xl: 3, children: /* @__PURE__ */ jsx(Container, { style: { borderColor: "purple", borderWidth: 1, height: HEIGHT }, children: /* @__PURE__ */ jsxs(Grid, { container: true, rowSpacing: 3, children: [
1782
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Advanced configuration" }) }),
1783
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsxs("ul", { style: { listStyleType: "circle" }, children: [
1784
+ /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(Text, { children: "Set different addresses for various document types" }) }),
1785
+ /* @__PURE__ */ jsx("li", { style: { marginTop: 3 }, children: /* @__PURE__ */ jsx(Text, { children: "Customize settings for sending invoices to customers" }) }),
1786
+ /* @__PURE__ */ jsx("li", { style: { marginTop: 3 }, children: /* @__PURE__ */ jsx(Text, { children: "Tailor settings for sending packing slips to fulfillment providers" }) })
1787
+ ] }) })
1788
+ ] }) }) }),
1789
+ /* @__PURE__ */ jsx(Grid, { item: true, xs: 3, md: 3, xl: 3, children: /* @__PURE__ */ jsx(Container, { style: { borderColor: "purple", borderWidth: 1, height: HEIGHT }, children: /* @__PURE__ */ jsxs(Grid, { container: true, rowSpacing: 3, children: [
1790
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Heading, { level: "h1", children: "Professional support" }) }),
1791
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsxs("ul", { style: { listStyleType: "circle" }, children: [
1792
+ /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(Text, { children: "Priority bug resolution" }) }),
1793
+ /* @__PURE__ */ jsx("li", { style: { marginTop: 3 }, children: /* @__PURE__ */ jsx(Text, { children: "Dedicated channel for evaluating your feature requests" }) }),
1794
+ /* @__PURE__ */ jsx("li", { style: { marginTop: 3 }, children: /* @__PURE__ */ jsx(Text, { children: "Long-term cooperation, including support for other plugins" }) })
1795
+ ] }) })
1796
+ ] }) }) })
1797
+ ] }),
1798
+ /* @__PURE__ */ jsx(Grid, { container: true, spacing: 3, direction: "column", alignContent: "center", marginTop: 6, children: /* @__PURE__ */ jsxs(Grid, { container: true, direction: "row", justifyContent: "center", columnSpacing: 1, children: [
1799
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Heading, { level: "h1", color: "purple", children: "Contact:" }) }),
1800
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Link, { href: "mailto:labs@rsoftcon.com", children: /* @__PURE__ */ jsx(Heading, { level: "h1", color: "purple", children: "labs@rsoftcon.com" }) }) })
1801
+ ] }) }),
1802
+ /* @__PURE__ */ jsx(Grid, { container: true, spacing: 3, direction: "column", alignContent: "center", marginTop: 6, children: /* @__PURE__ */ jsxs(Grid, { container: true, direction: "row", justifyContent: "center", columnSpacing: 1, children: [
1803
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Text, { children: "You can hide this tab if you feel it is intruisive. See:" }) }),
1804
+ /* @__PURE__ */ jsx(Grid, { item: true, children: /* @__PURE__ */ jsx(Link, { href: "https://github.com/RSC-Labs/medusa-documents?tab=readme-ov-file#hide-pro-version-tab", children: /* @__PURE__ */ jsx(Text, { children: "How to hide this tab?" }) }) })
1805
+ ] }) })
1806
+ ] });
1807
+ };
1808
+ const DocumentsPage = () => {
1809
+ console.log(void 0);
1810
+ return /* @__PURE__ */ jsxs(Tabs, { defaultValue: "orders", children: [
1811
+ /* @__PURE__ */ jsx(Toaster, { position: "top-right" }),
1812
+ /* @__PURE__ */ jsxs(Tabs.List, { children: [
1813
+ /* @__PURE__ */ jsx(Tabs.Trigger, { value: "orders", children: "Orders" }),
1814
+ /* @__PURE__ */ jsx(Tabs.Trigger, { value: "templates", children: "Templates" }),
1815
+ /* @__PURE__ */ jsx(Tabs.Trigger, { value: "settings", children: "Settings" }),
1816
+ /* @__PURE__ */ jsx(Grid, { container: true, justifyContent: "end", children: /* @__PURE__ */ jsx(Tabs.Trigger, { value: "pro", style: { color: "purple" }, children: "Pro version" }) })
1817
+ ] }),
1818
+ /* @__PURE__ */ jsxs(Tabs.Content, { value: "orders", children: [
1819
+ /* @__PURE__ */ jsx(Box, { height: 20 }),
1820
+ /* @__PURE__ */ jsx(OrdersTab, {})
1821
+ ] }),
1822
+ /* @__PURE__ */ jsxs(Tabs.Content, { value: "templates", children: [
1823
+ /* @__PURE__ */ jsx(Box, { height: 20 }),
1824
+ /* @__PURE__ */ jsx(TemplatesTab, {})
1825
+ ] }),
1826
+ /* @__PURE__ */ jsxs(Tabs.Content, { value: "settings", children: [
1827
+ /* @__PURE__ */ jsx(Box, { height: 20 }),
1828
+ /* @__PURE__ */ jsx(SettingsTab, {})
1829
+ ] }),
1830
+ /* @__PURE__ */ jsxs(Tabs.Content, { value: "pro", children: [
1831
+ /* @__PURE__ */ jsx(Box, { height: 20 }),
1832
+ /* @__PURE__ */ jsx(ProTab, {})
1833
+ ] })
1834
+ ] });
1835
+ };
1836
+ const config = defineRouteConfig({
1837
+ label: "Documents",
1838
+ icon: DocumentText
1839
+ });
1840
+ const widgetModule = { widgets: [] };
1841
+ const routeModule = {
1842
+ routes: [
1843
+ {
1844
+ Component: DocumentsPage,
1845
+ path: "/documents",
1846
+ handle: { label: config.label, translationNs: config.translationNs }
1847
+ }
1848
+ ]
1849
+ };
1850
+ const menuItemModule = {
1851
+ menuItems: [
1852
+ {
1853
+ label: config.label,
1854
+ icon: config.icon,
1855
+ path: "/documents",
1856
+ nested: void 0,
1857
+ rank: void 0,
1858
+ translationNs: void 0
1859
+ }
1860
+ ]
1861
+ };
1862
+ const formModule = { customFields: {} };
1863
+ const displayModule = {
1864
+ displays: {}
1865
+ };
1866
+ const i18nModule = { resources: {} };
1867
+ const cellRendererModule = {};
1868
+ const layoutModule = { layouts: [] };
1869
+ const plugin = {
1870
+ widgetModule,
1871
+ routeModule,
1872
+ menuItemModule,
1873
+ formModule,
1874
+ displayModule,
1875
+ i18nModule,
1876
+ cellRendererModule,
1877
+ layoutModule
1878
+ };
1879
+ export {
1880
+ plugin as default
1881
+ };