@vicacha-devs/medusa-plugin-barcode 0.0.0-stage → 0.1.0
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.cjs +3960 -0
- package/.medusa/server/src/admin/index.js +3938 -0
- package/.medusa/server/src/api/admin/barcodes/[barcode]/route.js +43 -0
- package/.medusa/server/src/api/admin/barcodes/batch/route.js +9 -0
- package/.medusa/server/src/api/admin/barcodes/bulk-generate/route.js +9 -0
- package/.medusa/server/src/api/admin/barcodes/cache/route.js +25 -0
- package/.medusa/server/src/api/admin/barcodes/count-sessions/[id]/apply/route.js +13 -0
- package/.medusa/server/src/api/admin/barcodes/count-sessions/[id]/scan/route.js +13 -0
- package/.medusa/server/src/api/admin/barcodes/count-sessions/route.js +27 -0
- package/.medusa/server/src/api/admin/barcodes/create-from-barcode/route.js +9 -0
- package/.medusa/server/src/api/admin/barcodes/lookup/route.js +12 -0
- package/.medusa/server/src/api/admin/barcodes/print/route.js +11 -0
- package/.medusa/server/src/api/admin/barcodes/route.js +27 -0
- package/.medusa/server/src/api/admin/barcodes/scan/route.js +23 -0
- package/.medusa/server/src/api/admin/barcodes/tags/[id]/route.js +28 -0
- package/.medusa/server/src/api/admin/barcodes/tags/route.js +25 -0
- package/.medusa/server/src/api/admin/barcodes/templates/route.js +40 -0
- package/.medusa/server/src/api/admin/plugin/route.js +4 -0
- package/.medusa/server/src/api/admin/variants/barcode/[code]/route.js +28 -0
- package/.medusa/server/src/api/middlewares.js +73 -0
- package/.medusa/server/src/api/store/barcodes/[code]/route.js +28 -0
- package/.medusa/server/src/api/store/barcodes/[code]/verify/route.js +20 -0
- package/.medusa/server/src/api/store/plugin/route.js +4 -0
- package/.medusa/server/src/api/store/variants/barcode/[code]/route.js +28 -0
- package/.medusa/server/src/api/validators.js +173 -0
- package/.medusa/server/src/hooks/index.js +202 -0
- package/.medusa/server/src/index.js +5 -0
- package/.medusa/server/src/jobs/purge-expired-barcode-cache.js +10 -0
- package/.medusa/server/src/modules/barcode/index.js +16 -0
- package/.medusa/server/src/modules/barcode/migrations/Migration20260522000000.js +165 -0
- package/.medusa/server/src/modules/barcode/models/index.js +162 -0
- package/.medusa/server/src/modules/barcode/operations/context.js +2 -0
- package/.medusa/server/src/modules/barcode/operations/data-service.js +10 -0
- package/.medusa/server/src/modules/barcode/operations/generation.js +33 -0
- package/.medusa/server/src/modules/barcode/operations/index.js +9 -0
- package/.medusa/server/src/modules/barcode/operations/labels.js +57 -0
- package/.medusa/server/src/modules/barcode/operations/lookup.js +135 -0
- package/.medusa/server/src/modules/barcode/operations/maintenance.js +37 -0
- package/.medusa/server/src/modules/barcode/operations/stock-count.js +129 -0
- package/.medusa/server/src/modules/barcode/operations/tags.js +298 -0
- package/.medusa/server/src/modules/barcode/providers/index.js +721 -0
- package/.medusa/server/src/modules/barcode/service.js +161 -0
- package/.medusa/server/src/modules/barcode/types.js +21 -0
- package/.medusa/server/src/modules/barcode/utils/barcode-parser.js +399 -0
- package/.medusa/server/src/modules/barcode/utils/label-printer.js +533 -0
- package/.medusa/server/src/modules/barcode/utils/normalize-product.js +443 -0
- package/.medusa/server/src/modules/barcode/utils/security.js +114 -0
- package/.medusa/server/src/modules/barcode/utils/svg-renderer.js +492 -0
- package/.medusa/server/src/rbac.js +130 -0
- package/.medusa/server/src/sdk/index.js +164 -0
- package/.medusa/server/src/subscribers/product-created.js +34 -0
- package/.medusa/server/src/types/index.js +2 -0
- package/.medusa/server/src/ui/index.js +138 -0
- package/.medusa/server/src/workflows/apply-inventory-count.js +68 -0
- package/.medusa/server/src/workflows/batch-barcode-import.js +153 -0
- package/.medusa/server/src/workflows/bulk-generate-variant-barcodes.js +143 -0
- package/.medusa/server/src/workflows/generate-barcode-tag.js +44 -0
- package/.medusa/server/src/workflows/helpers.js +15 -0
- package/.medusa/server/src/workflows/index.js +7 -0
- package/.medusa/server/src/workflows/lookup-and-create-product.js +215 -0
- package/.medusa/server/src/workflows/scan-inventory-count.js +15 -0
- package/LICENSE +21 -0
- package/README.md +844 -2
- package/package.json +134 -3
- package/src/__tests__/barcode.spec.ts +836 -0
- package/src/__tests__/medusa-shim.mjs +331 -0
- package/src/__tests__/register-ts-resolver.mjs +135 -0
- package/src/admin/README.md +134 -0
- package/src/admin/components/barcode-studio-header.tsx +73 -0
- package/src/admin/components/batch-import-section.tsx +99 -0
- package/src/admin/components/dynamic-qr-tag-drawer-form.tsx +230 -0
- package/src/admin/components/dynamic-qr-tag-form.tsx +129 -0
- package/src/admin/components/dynamic-qr-tags-table.tsx +136 -0
- package/src/admin/components/gtin-lookup-section.tsx +155 -0
- package/src/admin/components/index.tsx +14 -0
- package/src/admin/components/label-designer-section.tsx +151 -0
- package/src/admin/components/label-output-section.tsx +63 -0
- package/src/admin/components/overview-cards.tsx +98 -0
- package/src/admin/components/product-barcode-card.tsx +127 -0
- package/src/admin/components/providers-cache-table.tsx +61 -0
- package/src/admin/components/providers-overview-section.tsx +49 -0
- package/src/admin/components/rbac-guard.tsx +153 -0
- package/src/admin/components/stock-take-scanner-section.tsx +116 -0
- package/src/admin/components/stock-take-sessions-section.tsx +109 -0
- package/src/admin/hooks/use-barcode-studio.ts +466 -0
- package/src/admin/hooks/use-product-barcodes.ts +139 -0
- package/src/admin/i18n/README.md +130 -0
- package/src/admin/i18n/index.ts +36 -0
- package/src/admin/i18n/json/ar.json +157 -0
- package/src/admin/i18n/json/de.json +157 -0
- package/src/admin/i18n/json/en.json +157 -0
- package/src/admin/i18n/json/es.json +157 -0
- package/src/admin/i18n/json/fr.json +157 -0
- package/src/admin/i18n/json/it.json +157 -0
- package/src/admin/i18n/json/nl.json +157 -0
- package/src/admin/i18n/json/pl.json +157 -0
- package/src/admin/i18n/json/pt.json +157 -0
- package/src/admin/i18n/json/tr.json +157 -0
- package/src/admin/routes/barcodes/lookup/page.tsx +75 -0
- package/src/admin/routes/barcodes/page.tsx +212 -0
- package/src/admin/routes/barcodes/print/page.tsx +67 -0
- package/src/admin/routes/barcodes/providers/page.tsx +66 -0
- package/src/admin/routes/barcodes/stock-take/page.tsx +74 -0
- package/src/admin/routes/barcodes/tags/@create/page.tsx +56 -0
- package/src/admin/routes/barcodes/tags/page.tsx +72 -0
- package/src/admin/tsconfig.json +20 -0
- package/src/admin/vite-env.d.ts +1 -0
- package/src/admin/widgets/product-barcode-widget.tsx +43 -0
- package/src/api/README.md +117 -0
- package/src/api/admin/barcodes/[barcode]/route.ts +64 -0
- package/src/api/admin/barcodes/batch/route.ts +12 -0
- package/src/api/admin/barcodes/bulk-generate/route.ts +12 -0
- package/src/api/admin/barcodes/cache/route.ts +35 -0
- package/src/api/admin/barcodes/count-sessions/[id]/apply/route.ts +17 -0
- package/src/api/admin/barcodes/count-sessions/[id]/scan/route.ts +17 -0
- package/src/api/admin/barcodes/count-sessions/route.ts +43 -0
- package/src/api/admin/barcodes/create-from-barcode/route.ts +16 -0
- package/src/api/admin/barcodes/lookup/route.ts +19 -0
- package/src/api/admin/barcodes/print/route.ts +18 -0
- package/src/api/admin/barcodes/route.ts +36 -0
- package/src/api/admin/barcodes/scan/route.ts +32 -0
- package/src/api/admin/barcodes/tags/[id]/route.ts +41 -0
- package/src/api/admin/barcodes/tags/route.ts +36 -0
- package/src/api/admin/barcodes/templates/route.ts +51 -0
- package/src/api/admin/plugin/route.ts +5 -0
- package/src/api/admin/variants/barcode/[code]/route.ts +36 -0
- package/src/api/middlewares.ts +91 -0
- package/src/api/store/barcodes/[code]/route.ts +43 -0
- package/src/api/store/barcodes/[code]/verify/route.ts +35 -0
- package/src/api/store/plugin/route.ts +5 -0
- package/src/api/store/variants/barcode/[code]/route.ts +36 -0
- package/src/api/validators.ts +217 -0
- package/src/hooks/index.ts +270 -0
- package/src/index.ts +4 -0
- package/src/jobs/README.md +54 -0
- package/src/jobs/purge-expired-barcode-cache.ts +18 -0
- package/src/links/README.md +44 -0
- package/src/modules/README.md +85 -0
- package/src/modules/barcode/index.ts +18 -0
- package/src/modules/barcode/migrations/Migration20260522000000.ts +225 -0
- package/src/modules/barcode/models/index.ts +168 -0
- package/src/modules/barcode/operations/context.ts +14 -0
- package/src/modules/barcode/operations/data-service.ts +10 -0
- package/src/modules/barcode/operations/generation.ts +57 -0
- package/src/modules/barcode/operations/index.ts +8 -0
- package/src/modules/barcode/operations/labels.ts +90 -0
- package/src/modules/barcode/operations/lookup.ts +202 -0
- package/src/modules/barcode/operations/maintenance.ts +53 -0
- package/src/modules/barcode/operations/stock-count.ts +217 -0
- package/src/modules/barcode/operations/tags.ts +425 -0
- package/src/modules/barcode/providers/index.ts +958 -0
- package/src/modules/barcode/service.ts +243 -0
- package/src/modules/barcode/types.ts +297 -0
- package/src/modules/barcode/utils/barcode-parser.ts +453 -0
- package/src/modules/barcode/utils/label-printer.ts +641 -0
- package/src/modules/barcode/utils/normalize-product.ts +524 -0
- package/src/modules/barcode/utils/security.ts +136 -0
- package/src/modules/barcode/utils/svg-renderer.ts +574 -0
- package/src/providers/README.md +105 -0
- package/src/rbac.ts +144 -0
- package/src/sdk/index.ts +253 -0
- package/src/subscribers/README.md +73 -0
- package/src/subscribers/product-created.ts +45 -0
- package/src/types/index.ts +1 -0
- package/src/types/medusa-ui.d.ts +118 -0
- package/src/ui/index.tsx +311 -0
- package/src/workflows/README.md +56 -0
- package/src/workflows/apply-inventory-count.ts +115 -0
- package/src/workflows/batch-barcode-import.ts +218 -0
- package/src/workflows/bulk-generate-variant-barcodes.ts +214 -0
- package/src/workflows/generate-barcode-tag.ts +85 -0
- package/src/workflows/helpers.ts +21 -0
- package/src/workflows/index.ts +6 -0
- package/src/workflows/lookup-and-create-product.ts +298 -0
- package/src/workflows/scan-inventory-count.ts +45 -0
- package/tsconfig.json +40 -0
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
const chainableField = () => {
|
|
2
|
+
const field = {
|
|
3
|
+
primaryKey: () => field,
|
|
4
|
+
searchable: () => field,
|
|
5
|
+
nullable: () => field,
|
|
6
|
+
default: () => field,
|
|
7
|
+
}
|
|
8
|
+
return field
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const model = {
|
|
12
|
+
define(name, schema) {
|
|
13
|
+
return {
|
|
14
|
+
name,
|
|
15
|
+
schema,
|
|
16
|
+
indexes() {
|
|
17
|
+
return this
|
|
18
|
+
},
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
id: chainableField,
|
|
22
|
+
text: chainableField,
|
|
23
|
+
number: chainableField,
|
|
24
|
+
boolean: chainableField,
|
|
25
|
+
json: chainableField,
|
|
26
|
+
dateTime: chainableField,
|
|
27
|
+
enum: chainableField,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const Modules = {
|
|
31
|
+
PRODUCT: "product",
|
|
32
|
+
FILE: "file",
|
|
33
|
+
INVENTORY: "inventory",
|
|
34
|
+
EVENT_BUS: "event_bus",
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class Migration {
|
|
38
|
+
constructor() {
|
|
39
|
+
this.queries = []
|
|
40
|
+
}
|
|
41
|
+
addSql(sql) {
|
|
42
|
+
this.queries.push(sql)
|
|
43
|
+
}
|
|
44
|
+
async up() {}
|
|
45
|
+
async down() {}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function MedusaService(models = {}) {
|
|
49
|
+
return class BaseMedusaService {
|
|
50
|
+
constructor() {
|
|
51
|
+
this.__stores = {}
|
|
52
|
+
let counter = 1
|
|
53
|
+
for (const key of Object.keys(models)) {
|
|
54
|
+
const plural = key.endsWith("y") ? `${key.slice(0, -1)}ies` : `${key}s`
|
|
55
|
+
this.__stores[plural] = []
|
|
56
|
+
|
|
57
|
+
if (typeof this[`list${plural}`] !== "function") {
|
|
58
|
+
this[`list${plural}`] = async (filter = {}) => {
|
|
59
|
+
const rows = this.__stores[plural]
|
|
60
|
+
return rows.filter((row) =>
|
|
61
|
+
Object.entries(filter).every(([k, v]) =>
|
|
62
|
+
v === undefined ? true : row[k] === v
|
|
63
|
+
)
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (typeof this[`create${plural}`] !== "function") {
|
|
68
|
+
this[`create${plural}`] = async (data) => {
|
|
69
|
+
const record = {
|
|
70
|
+
id: data.id ?? `${key.toLowerCase()}_${counter++}`,
|
|
71
|
+
created_at: new Date(),
|
|
72
|
+
updated_at: new Date(),
|
|
73
|
+
...data,
|
|
74
|
+
}
|
|
75
|
+
this.__stores[plural].push(record)
|
|
76
|
+
return record
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (typeof this[`update${plural}`] !== "function") {
|
|
80
|
+
this[`update${plural}`] = async (data) => {
|
|
81
|
+
const rows = this.__stores[plural]
|
|
82
|
+
const idx = rows.findIndex((r) => r.id === data.id)
|
|
83
|
+
if (idx >= 0) {
|
|
84
|
+
rows[idx] = { ...rows[idx], ...data, updated_at: new Date() }
|
|
85
|
+
return rows[idx]
|
|
86
|
+
}
|
|
87
|
+
return data
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (typeof this[`delete${plural}`] !== "function") {
|
|
91
|
+
this[`delete${plural}`] = async (ids) => {
|
|
92
|
+
const idSet = new Set(Array.isArray(ids) ? ids : [ids])
|
|
93
|
+
this.__stores[plural] = this.__stores[plural].filter(
|
|
94
|
+
(r) => !idSet.has(r.id)
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export class MedusaError extends Error {
|
|
104
|
+
static Types = {
|
|
105
|
+
DB_ERROR: "database_error",
|
|
106
|
+
DUPLICATE_ERROR: "duplicate_error",
|
|
107
|
+
INVALID_ARGUMENT: "invalid_argument",
|
|
108
|
+
INVALID_DATA: "invalid_data",
|
|
109
|
+
UNAUTHORIZED: "unauthorized",
|
|
110
|
+
NOT_FOUND: "not_found",
|
|
111
|
+
NOT_ALLOWED: "not_allowed",
|
|
112
|
+
UNEXPECTED_STATE: "unexpected_state",
|
|
113
|
+
CONFLICT: "conflict",
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
constructor(type, message, code) {
|
|
117
|
+
super(message)
|
|
118
|
+
this.type = type
|
|
119
|
+
this.code = code
|
|
120
|
+
this.name = "MedusaError"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function Module(name, config) {
|
|
125
|
+
return { name, ...config }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export class StepResponse {
|
|
129
|
+
constructor(output, compensateInput) {
|
|
130
|
+
this.output = output
|
|
131
|
+
this.compensateInput = compensateInput
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export class WorkflowResponse {
|
|
136
|
+
constructor(output) {
|
|
137
|
+
this.output = output
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export function createStep(name, invokeFn, compensateFn) {
|
|
142
|
+
const stepFn = (input) => ({
|
|
143
|
+
__stepName: name,
|
|
144
|
+
input,
|
|
145
|
+
invokeFn,
|
|
146
|
+
compensateFn,
|
|
147
|
+
})
|
|
148
|
+
stepFn.__stepName = name
|
|
149
|
+
stepFn.invoke = invokeFn
|
|
150
|
+
stepFn.compensate = compensateFn
|
|
151
|
+
return stepFn
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function createWorkflow(name, composerFn) {
|
|
155
|
+
const wf = (container) => ({
|
|
156
|
+
async run({ input } = {}) {
|
|
157
|
+
const composed = composerFn(input)
|
|
158
|
+
const stepDescriptor =
|
|
159
|
+
composed instanceof WorkflowResponse ? composed.output : composed
|
|
160
|
+
if (stepDescriptor && typeof stepDescriptor.invokeFn === "function") {
|
|
161
|
+
const stepRes = await stepDescriptor.invokeFn(stepDescriptor.input, {
|
|
162
|
+
container,
|
|
163
|
+
})
|
|
164
|
+
const result =
|
|
165
|
+
stepRes instanceof StepResponse ? stepRes.output : stepRes
|
|
166
|
+
return {
|
|
167
|
+
result,
|
|
168
|
+
compensate: async () => {
|
|
169
|
+
if (typeof stepDescriptor.compensateFn === "function") {
|
|
170
|
+
await stepDescriptor.compensateFn(stepRes?.compensateInput, {
|
|
171
|
+
container,
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return { result: stepDescriptor }
|
|
178
|
+
},
|
|
179
|
+
})
|
|
180
|
+
wf.getName = () => name
|
|
181
|
+
return wf
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const createZodChain = (shape = {}) => {
|
|
185
|
+
const schema = {
|
|
186
|
+
shape,
|
|
187
|
+
min: () => schema,
|
|
188
|
+
max: () => schema,
|
|
189
|
+
int: () => schema,
|
|
190
|
+
regex: () => schema,
|
|
191
|
+
or: () => schema,
|
|
192
|
+
positive: () => schema,
|
|
193
|
+
nonnegative: () => schema,
|
|
194
|
+
email: () => schema,
|
|
195
|
+
url: () => schema,
|
|
196
|
+
optional: () => schema,
|
|
197
|
+
nullable: () => schema,
|
|
198
|
+
default: () => schema,
|
|
199
|
+
partial: () => createZodChain(shape),
|
|
200
|
+
omit: () => createZodChain(shape),
|
|
201
|
+
passthrough: () => schema,
|
|
202
|
+
parse: (val) => val,
|
|
203
|
+
safeParse: (val) => ({ success: true, data: val }),
|
|
204
|
+
}
|
|
205
|
+
return schema
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export const z = {
|
|
209
|
+
object: (shape) => createZodChain(shape),
|
|
210
|
+
string: () => createZodChain(),
|
|
211
|
+
number: () => createZodChain(),
|
|
212
|
+
boolean: () => createZodChain(),
|
|
213
|
+
enum: (values) => createZodChain({ values }),
|
|
214
|
+
array: (item) => createZodChain({ item }),
|
|
215
|
+
record: (key, val) => createZodChain({ key, val }),
|
|
216
|
+
unknown: () => createZodChain(),
|
|
217
|
+
union: (items) => createZodChain({ items }),
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export function defineMiddlewares(config) {
|
|
221
|
+
return config
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function validateAndTransformBody(schema) {
|
|
225
|
+
return schema
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export function defineRouteConfig(config) {
|
|
229
|
+
return config
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export function defineWidgetConfig(config) {
|
|
233
|
+
return config
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export const useState = (init) => [
|
|
237
|
+
typeof init === "function" ? init() : init,
|
|
238
|
+
() => {},
|
|
239
|
+
]
|
|
240
|
+
export const useEffect = () => {}
|
|
241
|
+
export const useCallback = (fn) => fn
|
|
242
|
+
export const useRef = (init) => ({ current: init })
|
|
243
|
+
export const createElement = (type, props, ...children) => ({
|
|
244
|
+
type,
|
|
245
|
+
props: { ...props, children },
|
|
246
|
+
})
|
|
247
|
+
export const jsx = createElement
|
|
248
|
+
export const jsxs = createElement
|
|
249
|
+
export const Fragment = "Fragment"
|
|
250
|
+
|
|
251
|
+
export const useTranslation = () => ({
|
|
252
|
+
t: (key) => key,
|
|
253
|
+
i18n: {
|
|
254
|
+
language: "en",
|
|
255
|
+
resolvedLanguage: "en",
|
|
256
|
+
changeLanguage: async () => {},
|
|
257
|
+
dir: () => "ltr",
|
|
258
|
+
},
|
|
259
|
+
ready: true,
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
export const CORE_LAYOUT_IDS = {
|
|
263
|
+
SINGLE_COLUMN: "single_column",
|
|
264
|
+
TWO_COLUMN: "two_column",
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const dummyComponent = (name) => {
|
|
268
|
+
const fn = (props) => ({ type: name, props })
|
|
269
|
+
return new Proxy(fn, {
|
|
270
|
+
get(target, prop) {
|
|
271
|
+
if (prop in target) return target[prop]
|
|
272
|
+
return dummyComponent(`${name}.${String(prop)}`)
|
|
273
|
+
},
|
|
274
|
+
})
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export const LayoutComposer = dummyComponent("LayoutComposer")
|
|
278
|
+
export const SectionRow = dummyComponent("SectionRow")
|
|
279
|
+
export const RouteDrawer = dummyComponent("RouteDrawer")
|
|
280
|
+
export const RouteFocusModal = dummyComponent("RouteFocusModal")
|
|
281
|
+
export const Form = dummyComponent("Form")
|
|
282
|
+
export const KeyboundForm = dummyComponent("KeyboundForm")
|
|
283
|
+
export const useRouteModal = () => ({ handleSuccess: () => {} })
|
|
284
|
+
|
|
285
|
+
export const Badge = dummyComponent("Badge")
|
|
286
|
+
export const Button = dummyComponent("Button")
|
|
287
|
+
export const Container = dummyComponent("Container")
|
|
288
|
+
export const Heading = dummyComponent("Heading")
|
|
289
|
+
export const Input = dummyComponent("Input")
|
|
290
|
+
export const Select = dummyComponent("Select")
|
|
291
|
+
export const Skeleton = dummyComponent("Skeleton")
|
|
292
|
+
export const StatusBadge = dummyComponent("StatusBadge")
|
|
293
|
+
export const Table = dummyComponent("Table")
|
|
294
|
+
export const Tabs = dummyComponent("Tabs")
|
|
295
|
+
export const Text = dummyComponent("Text")
|
|
296
|
+
export const Textarea = dummyComponent("Textarea")
|
|
297
|
+
export const Toaster = dummyComponent("Toaster")
|
|
298
|
+
export const clx = (...classes) => classes.filter(Boolean).join(" ")
|
|
299
|
+
export const toast = {
|
|
300
|
+
success: () => {},
|
|
301
|
+
error: () => {},
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export const Buildings = dummyComponent("Buildings")
|
|
305
|
+
export const BuildingStorefront = dummyComponent("BuildingStorefront")
|
|
306
|
+
export const CheckCircle = dummyComponent("CheckCircle")
|
|
307
|
+
export const DocumentText = dummyComponent("DocumentText")
|
|
308
|
+
export const MagnifyingGlass = dummyComponent("MagnifyingGlass")
|
|
309
|
+
export const Tag = dummyComponent("Tag")
|
|
310
|
+
|
|
311
|
+
export const useNavigate = () => () => {}
|
|
312
|
+
export const useParams = () => ({})
|
|
313
|
+
export const useForm = (opts = {}) => ({
|
|
314
|
+
control: {},
|
|
315
|
+
register: () => ({}),
|
|
316
|
+
handleSubmit: (fn) => (_e) => fn(opts.defaultValues || {}),
|
|
317
|
+
watch: () => opts.defaultValues || {},
|
|
318
|
+
reset: () => {},
|
|
319
|
+
setValue: () => {},
|
|
320
|
+
})
|
|
321
|
+
export const zodResolver = (schema) => schema
|
|
322
|
+
|
|
323
|
+
export default {
|
|
324
|
+
useState,
|
|
325
|
+
useEffect,
|
|
326
|
+
useCallback,
|
|
327
|
+
useRef,
|
|
328
|
+
createElement,
|
|
329
|
+
Fragment,
|
|
330
|
+
useTranslation,
|
|
331
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { registerHooks } from "node:module"
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs"
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from "node:url"
|
|
4
|
+
import { dirname, resolve as resolvePath } from "node:path"
|
|
5
|
+
|
|
6
|
+
const currentDir = dirname(fileURLToPath(import.meta.url))
|
|
7
|
+
const shimUrl = pathToFileURL(resolvePath(currentDir, "medusa-shim.mjs")).href
|
|
8
|
+
|
|
9
|
+
let tsModule = null
|
|
10
|
+
try {
|
|
11
|
+
const mod = await import("typescript")
|
|
12
|
+
tsModule = mod.default || mod
|
|
13
|
+
} catch {
|
|
14
|
+
const fallbackTsPath = resolvePath(
|
|
15
|
+
currentDir,
|
|
16
|
+
"../../../strapi-plugin-tiptap-editor/node_modules/typescript/lib/typescript.js"
|
|
17
|
+
)
|
|
18
|
+
if (existsSync(fallbackTsPath)) {
|
|
19
|
+
const mod = await import(pathToFileURL(fallbackTsPath).href)
|
|
20
|
+
tsModule = mod.default || mod
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
registerHooks({
|
|
25
|
+
resolve(specifier, context, nextResolve) {
|
|
26
|
+
if (
|
|
27
|
+
specifier.startsWith("@medusajs/") ||
|
|
28
|
+
specifier === "react" ||
|
|
29
|
+
specifier.startsWith("react/") ||
|
|
30
|
+
specifier === "react-i18next" ||
|
|
31
|
+
specifier === "react-router-dom" ||
|
|
32
|
+
specifier === "react-hook-form" ||
|
|
33
|
+
specifier.startsWith("@hookform/") ||
|
|
34
|
+
specifier === "zod"
|
|
35
|
+
) {
|
|
36
|
+
return { url: shimUrl, shortCircuit: true }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (
|
|
40
|
+
(specifier.startsWith("./") || specifier.startsWith("../")) &&
|
|
41
|
+
context.parentURL
|
|
42
|
+
) {
|
|
43
|
+
const parentDir = dirname(fileURLToPath(context.parentURL))
|
|
44
|
+
const baseCandidate = resolvePath(parentDir, specifier)
|
|
45
|
+
|
|
46
|
+
const candidates = [
|
|
47
|
+
`${baseCandidate}.ts`,
|
|
48
|
+
`${baseCandidate}.tsx`,
|
|
49
|
+
resolvePath(baseCandidate, "index.ts"),
|
|
50
|
+
resolvePath(baseCandidate, "index.tsx"),
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
for (const candidate of candidates) {
|
|
54
|
+
if (existsSync(candidate)) {
|
|
55
|
+
return nextResolve(pathToFileURL(candidate).href, context)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return nextResolve(specifier, context)
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
load(url, context, nextLoad) {
|
|
64
|
+
if (url.endsWith(".json") && !url.includes("/node_modules/")) {
|
|
65
|
+
const filePath = fileURLToPath(url)
|
|
66
|
+
const source = readFileSync(filePath, "utf8")
|
|
67
|
+
return {
|
|
68
|
+
format: "module",
|
|
69
|
+
source: `export default ${source}`,
|
|
70
|
+
shortCircuit: true,
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if ((url.endsWith(".tsx") || url.endsWith(".ts")) && tsModule) {
|
|
74
|
+
const filePath = fileURLToPath(url)
|
|
75
|
+
const source = readFileSync(filePath, "utf8")
|
|
76
|
+
const transpiled = tsModule.transpileModule(source, {
|
|
77
|
+
compilerOptions: {
|
|
78
|
+
module: tsModule.ModuleKind.ESNext,
|
|
79
|
+
target: tsModule.ScriptTarget.ES2022,
|
|
80
|
+
jsx: tsModule.JsxEmit.ReactJSX,
|
|
81
|
+
},
|
|
82
|
+
fileName: filePath,
|
|
83
|
+
})
|
|
84
|
+
return {
|
|
85
|
+
format: "module",
|
|
86
|
+
source: transpiled.outputText,
|
|
87
|
+
shortCircuit: true,
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (url.endsWith(".tsx")) {
|
|
91
|
+
const filePath = fileURLToPath(url)
|
|
92
|
+
const source = readFileSync(filePath, "utf8")
|
|
93
|
+
const lines = []
|
|
94
|
+
const reExports = [
|
|
95
|
+
...source.matchAll(/^export\s+\*\s+from\s+["'][^"']+["']/gm),
|
|
96
|
+
]
|
|
97
|
+
for (const reExp of reExports) {
|
|
98
|
+
lines.push(reExp[0])
|
|
99
|
+
}
|
|
100
|
+
const configMatch = source.match(
|
|
101
|
+
/export\s+const\s+config\s*=\s*(defineRouteConfig|defineWidgetConfig)\s*\(\{[\s\S]*?\}\)/
|
|
102
|
+
)
|
|
103
|
+
if (configMatch) {
|
|
104
|
+
lines.push(
|
|
105
|
+
`import { defineRouteConfig, defineWidgetConfig } from "@medusajs/admin-sdk"`
|
|
106
|
+
)
|
|
107
|
+
lines.push(
|
|
108
|
+
`import { Buildings, BuildingStorefront, CheckCircle, DocumentText, MagnifyingGlass, Tag } from "@medusajs/icons"`
|
|
109
|
+
)
|
|
110
|
+
lines.push(configMatch[0])
|
|
111
|
+
}
|
|
112
|
+
if (/export\s+const\s+handle\s*=/.test(source)) {
|
|
113
|
+
lines.push(`export const handle = { breadcrumb: () => null }`)
|
|
114
|
+
}
|
|
115
|
+
const namedExports = [
|
|
116
|
+
...source.matchAll(/export\s+(?:const|function)\s+([A-Za-z0-9_]+)\b/g),
|
|
117
|
+
]
|
|
118
|
+
for (const match of namedExports) {
|
|
119
|
+
const name = match[1]
|
|
120
|
+
if (name !== "config" && name !== "handle") {
|
|
121
|
+
lines.push(`export const ${name} = () => null`)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (/export\s+default\b/.test(source)) {
|
|
125
|
+
lines.push(`export default function Component() { return null }`)
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
format: "module",
|
|
129
|
+
source: lines.join("\n"),
|
|
130
|
+
shortCircuit: true,
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return nextLoad(url, context)
|
|
134
|
+
},
|
|
135
|
+
})
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# Admin
|
|
2
|
+
|
|
3
|
+
Medusa Admin extension — multi-route pages, drawer modals, product detail widgets, decoupled presentation components, and state hooks for `medusa-plugin-barcode`.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
admin/
|
|
7
|
+
├── tsconfig.json TypeScript config (moduleResolution: bundler, noEmit: true)
|
|
8
|
+
├── vite-env.d.ts Vite ambient client type declarations
|
|
9
|
+
├── i18n/ react-i18next setup and 10-locale translation bundles
|
|
10
|
+
├── hooks/
|
|
11
|
+
│ ├── use-barcode-studio.ts Studio state, SDK queries, mutations, HID scanner & i18n
|
|
12
|
+
│ └── use-product-barcodes.ts Product detail widget state, variant EAN-13 gen & label print
|
|
13
|
+
├── components/
|
|
14
|
+
│ ├── index.tsx Barrel re-exporting all Admin UI presentation components
|
|
15
|
+
│ ├── overview-cards.tsx StatCard and NavigationCard components for studio overview
|
|
16
|
+
│ ├── barcode-studio-header.tsx BarcodeStudioHeader with language switcher, HID scan badge & KPIs
|
|
17
|
+
│ ├── gtin-lookup-section.tsx GtinLookupLookupSection and GtinLookupTab
|
|
18
|
+
│ ├── batch-import-section.tsx GtinLookupBatchSection (Textarea + recently linked Table)
|
|
19
|
+
│ ├── dynamic-qr-tag-drawer-form.tsx RouteDrawer + KeyboundForm + Form tag creator
|
|
20
|
+
│ ├── dynamic-qr-tag-form.tsx DynamicQrTagCreateSection inline tag form
|
|
21
|
+
│ ├── dynamic-qr-tags-table.tsx DynamicQrTagsTableSection and DynamicQrTagsTab
|
|
22
|
+
│ ├── label-designer-section.tsx LabelPrintDesignerSection and LabelPrintCenterTab
|
|
23
|
+
│ ├── label-output-section.tsx LabelPrintOutputSection (ZPL II & HTML+SVG Textarea preview)
|
|
24
|
+
│ ├── stock-take-scanner-section.tsx StockTakeControlsSection and WarehouseStockTakeTab
|
|
25
|
+
│ ├── stock-take-sessions-section.tsx StockTakeSessionsSection (SectionRow + variance Table)
|
|
26
|
+
│ ├── providers-overview-section.tsx ProvidersRegistrySection and ProvidersCacheTab
|
|
27
|
+
│ ├── providers-cache-table.tsx ProvidersCacheSection (cached lookups Table + purge controls)
|
|
28
|
+
│ └── product-barcode-card.tsx ProductBarcodeCard rendered in product.details.after widget
|
|
29
|
+
├── routes/
|
|
30
|
+
│ └── barcodes/ Page routes registered in the Medusa Admin shell
|
|
31
|
+
│ ├── page.tsx /barcodes — Overview dashboard (SINGLE_COLUMN LayoutComposer)
|
|
32
|
+
│ ├── lookup/
|
|
33
|
+
│ │ └── page.tsx /barcodes/lookup — GTIN Lookup & Batch Importer (TWO_COLUMN)
|
|
34
|
+
│ ├── tags/
|
|
35
|
+
│ │ ├── page.tsx /barcodes/tags — Dynamic 1D/2D & HMAC QR Tags (TWO_COLUMN)
|
|
36
|
+
│ │ └── @create/
|
|
37
|
+
│ │ └── page.tsx /barcodes/tags/create — RouteDrawer modal for creating tags
|
|
38
|
+
│ ├── print/
|
|
39
|
+
│ │ └── page.tsx /barcodes/print — Thermal & Sheet Label Designer (TWO_COLUMN)
|
|
40
|
+
│ ├── stock-take/
|
|
41
|
+
│ │ └── page.tsx /barcodes/stock-take — Warehouse Stock-Take Scanner (TWO_COLUMN)
|
|
42
|
+
│ └── providers/
|
|
43
|
+
│ └── page.tsx /barcodes/providers — Providers & Lookup Cache (TWO_COLUMN)
|
|
44
|
+
└── widgets/
|
|
45
|
+
└── product-barcode-widget.tsx Product detail widget (zone: "product.details.after")
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Route registration
|
|
51
|
+
|
|
52
|
+
The root `/barcodes` page (`routes/barcodes/page.tsx`) exports a `config` object created with `defineRouteConfig` from `@medusajs/admin-sdk` to register the sidebar navigation item, and each sub-route exports a `handle.breadcrumb` component:
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
import { defineRouteConfig } from "@medusajs/admin-sdk"
|
|
56
|
+
import { Tag } from "@medusajs/icons"
|
|
57
|
+
|
|
58
|
+
export const config = defineRouteConfig({
|
|
59
|
+
label: "nav.label",
|
|
60
|
+
translationNs: "barcodes",
|
|
61
|
+
icon: Tag,
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
export const handle = {
|
|
65
|
+
breadcrumb: () => <Breadcrumb />,
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
| Route File | Admin Path | Layout Mode | Purpose |
|
|
70
|
+
| --------------------------------------- | --------------------------- | --------------- | ------------------------------------------------------------------------ |
|
|
71
|
+
| `routes/barcodes/page.tsx` | `/app/barcodes` | `SINGLE_COLUMN` | Studio overview KPIs & navigation cards to sub-routes |
|
|
72
|
+
| `routes/barcodes/lookup/page.tsx` | `/app/barcodes/lookup` | `TWO_COLUMN` | Single GTIN/ISBN lookup, 1-click product creation & batch importer |
|
|
73
|
+
| `routes/barcodes/tags/page.tsx` | `/app/barcodes/tags` | `TWO_COLUMN` | Dynamic 1D/2D barcode & HMAC-SHA256 QR tag management |
|
|
74
|
+
| `routes/barcodes/tags/@create/page.tsx` | `/app/barcodes/tags/create` | `RouteDrawer` | Drawer modal form (`KeyboundForm` + `Form`) to create signed tags |
|
|
75
|
+
| `routes/barcodes/print/page.tsx` | `/app/barcodes/print` | `TWO_COLUMN` | Thermal roll & A4 sheet price/barcode label designer (HTML+SVG & ZPL II) |
|
|
76
|
+
| `routes/barcodes/stock-take/page.tsx` | `/app/barcodes/stock-take` | `TWO_COLUMN` | Warehouse stock-take count sessions, live scan variance & reconciliation |
|
|
77
|
+
| `routes/barcodes/providers/page.tsx` | `/app/barcodes/providers` | `TWO_COLUMN` | 10-provider chain status & `barcode_cache` inspection/purging |
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## Widget registration
|
|
82
|
+
|
|
83
|
+
`widgets/product-barcode-widget.tsx` registers in the `product.details.after` injection zone using `defineWidgetConfig`:
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
import { defineWidgetConfig } from "@medusajs/admin-sdk"
|
|
87
|
+
|
|
88
|
+
export const config = defineWidgetConfig({
|
|
89
|
+
zone: "product.details.after",
|
|
90
|
+
})
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
It delegates state and API mutations to `useProductBarcodes(productId)` and renders `<ProductBarcodeCard />` for one-click GS1 in-store (`200`–`299`) variant EAN-13 generation and thermal label printing.
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## State & data-fetching hooks
|
|
98
|
+
|
|
99
|
+
All Admin routes and widgets remain thin entrypoints and delegate state management, hardware HID keyboard-wedge scanning (`useHidBarcodeScanner`), and API calls to hooks in `hooks/`:
|
|
100
|
+
|
|
101
|
+
| Hook | File | Responsibilities |
|
|
102
|
+
| -------------------- | ------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
103
|
+
| `useBarcodeStudio` | `hooks/use-barcode-studio.ts` | Manages studio overview state, single/batch GTIN lookups, dynamic tag creation/deletion, thermal/A4 label rendering, warehouse count sessions, cache purging, USB HID scanner routing, and active UI locale (`en`, `es`, `fr`, `de`, `it`, `pt`, `nl`, `pl`, `tr`, `ar` with RTL direction). |
|
|
104
|
+
| `useProductBarcodes` | `hooks/use-product-barcodes.ts` | Fetches `BarcodeProduct` mappings and `BarcodeTag` rows for a specific Medusa product ID, triggers `POST /admin/barcodes/bulk-generate` for missing variant barcodes, and prints `thermal_50x25` labels. |
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Decoupled presentation components
|
|
109
|
+
|
|
110
|
+
Located in `components/`. Every component file is kept modular and concise (< 170 lines per file), using `@medusajs/ui` primitives (`Container`, `Heading`, `Text`, `Table`, `Badge`, `Button`, `Input`, `Select`, `Textarea`, `Toaster`) and `@medusajs/dashboard/components` (`LayoutComposer`, `SectionRow`, `RouteDrawer`, `KeyboundForm`, `Form`).
|
|
111
|
+
|
|
112
|
+
| Component File | Exported Components | Purpose |
|
|
113
|
+
| --------------------------------- | --------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
|
|
114
|
+
| `overview-cards.tsx` | `StatCard`, `NavigationCard` | KPI metric cards and clickable sub-route navigation cards |
|
|
115
|
+
| `barcode-studio-header.tsx` | `BarcodeStudioHeader` | Studio header with 10-locale selector, HID scan indicator & bulk EAN-13 button |
|
|
116
|
+
| `gtin-lookup-section.tsx` | `GtinLookupLookupSection`, `GtinLookupTab` | Single GTIN/ISBN lookup form, strategy selector (`first-hit` / `deep-merge`) & product preview |
|
|
117
|
+
| `batch-import-section.tsx` | `GtinLookupBatchSection` | Multi-line batch GTIN importer (up to 100 codes) & recently linked products table |
|
|
118
|
+
| `dynamic-qr-tag-drawer-form.tsx` | `DynamicQrTagDrawerForm` | `react-hook-form` + Zod drawer form inside `RouteDrawer` for creating tags |
|
|
119
|
+
| `dynamic-qr-tag-form.tsx` | `DynamicQrTagCreateSection` | Inline card form for creating 1D/2D & anti-counterfeit HMAC QR tags |
|
|
120
|
+
| `dynamic-qr-tags-table.tsx` | `DynamicQrTagsTableSection`, `DynamicQrTagsTab` | Table of generated tags with SVG preview, scan count, HMAC seal & delete action |
|
|
121
|
+
| `label-designer-section.tsx` | `LabelPrintDesignerSection`, `LabelPrintCenterTab` | Preset selector (7 thermal/A4 layouts), MRP/Sale price inputs & print trigger |
|
|
122
|
+
| `label-output-section.tsx` | `LabelPrintOutputSection` | Print-ready HTML+SVG window launcher and raw Zebra ZPL II (`^XA...^XZ`) output |
|
|
123
|
+
| `stock-take-scanner-section.tsx` | `StockTakeControlsSection`, `WarehouseStockTakeTab` | New count session form and rapid barcode scan (`+1` / `-1`) controls |
|
|
124
|
+
| `stock-take-sessions-section.tsx` | `StockTakeSessionsSection` | Active/completed stock-take sessions list, variance badges & Inventory Module apply action |
|
|
125
|
+
| `providers-overview-section.tsx` | `ProvidersRegistrySection`, `ProvidersCacheTab` | Displays the 10 external GTIN/ISBN lookup providers and priorities |
|
|
126
|
+
| `providers-cache-table.tsx` | `ProvidersCacheSection` | Displays `barcode_cache` entries, hit counts, expiration & purge actions |
|
|
127
|
+
| `product-barcode-card.tsx` | `ProductBarcodeCard` | Product detail widget UI for variant EAN-13 assignment and label printing |
|
|
128
|
+
| `index.tsx` | Barrel re-exports | Re-exports all presentation components |
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## i18n
|
|
133
|
+
|
|
134
|
+
Translations are configured in `i18n/` with 10 built-in locales (`ar`, `de`, `en`, `es`, `fr`, `it`, `nl`, `pl`, `pt`, `tr`) and automatic RTL support for Arabic (`ar`). See [`i18n/README.md`](./i18n/README.md) for details on adding translation keys and locales.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { SectionRow } from "@medusajs/dashboard/components"
|
|
2
|
+
import {
|
|
3
|
+
Badge,
|
|
4
|
+
Button,
|
|
5
|
+
Container,
|
|
6
|
+
Heading,
|
|
7
|
+
StatusBadge,
|
|
8
|
+
Text,
|
|
9
|
+
} from "@medusajs/ui"
|
|
10
|
+
import { useTranslation } from "react-i18next"
|
|
11
|
+
|
|
12
|
+
export interface BarcodeStudioHeaderProps {
|
|
13
|
+
overview: Record<string, unknown>
|
|
14
|
+
lastScanned: string | null
|
|
15
|
+
bannerMessage?: string | null
|
|
16
|
+
bannerTone?: "success" | "error"
|
|
17
|
+
onDismissBanner?: () => void
|
|
18
|
+
onRefresh: () => void
|
|
19
|
+
onBulkGenerate: () => void
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const BarcodeStudioHeader = ({
|
|
23
|
+
overview,
|
|
24
|
+
lastScanned,
|
|
25
|
+
onRefresh,
|
|
26
|
+
onBulkGenerate,
|
|
27
|
+
}: BarcodeStudioHeaderProps) => {
|
|
28
|
+
const { t } = useTranslation()
|
|
29
|
+
const providers = Array.isArray(overview.active_providers)
|
|
30
|
+
? (overview.active_providers as string[])
|
|
31
|
+
: []
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<Container className="divide-y p-0">
|
|
35
|
+
<div className="flex flex-wrap items-center justify-between gap-4 px-6 py-4">
|
|
36
|
+
<div>
|
|
37
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
38
|
+
<Heading className="font-sans font-medium h1-core">
|
|
39
|
+
{t("header.title")}
|
|
40
|
+
</Heading>
|
|
41
|
+
<StatusBadge color="green">
|
|
42
|
+
{t("header.providersBadge")}
|
|
43
|
+
</StatusBadge>
|
|
44
|
+
{lastScanned ? (
|
|
45
|
+
<Badge color="blue">
|
|
46
|
+
{t("header.lastHidScan", { code: lastScanned })}
|
|
47
|
+
</Badge>
|
|
48
|
+
) : null}
|
|
49
|
+
</div>
|
|
50
|
+
<Text className="text-ui-fg-subtle mt-1">{t("header.subtitle")}</Text>
|
|
51
|
+
</div>
|
|
52
|
+
|
|
53
|
+
<div className="flex items-center gap-2">
|
|
54
|
+
<Button variant="secondary" size="small" onClick={onBulkGenerate}>
|
|
55
|
+
{t("header.bulkGenerateButton")}
|
|
56
|
+
</Button>
|
|
57
|
+
<Button variant="secondary" size="small" onClick={onRefresh}>
|
|
58
|
+
{t("header.refreshButton")}
|
|
59
|
+
</Button>
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
|
|
63
|
+
<SectionRow
|
|
64
|
+
title={t("header.activeProvidersStat")}
|
|
65
|
+
value={
|
|
66
|
+
<Badge size="xsmall" color="green">
|
|
67
|
+
{providers.length}
|
|
68
|
+
</Badge>
|
|
69
|
+
}
|
|
70
|
+
/>
|
|
71
|
+
</Container>
|
|
72
|
+
)
|
|
73
|
+
}
|