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