@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.
Files changed (176) hide show
  1. package/.medusa/server/src/admin/index.cjs +3960 -0
  2. package/.medusa/server/src/admin/index.js +3938 -0
  3. package/.medusa/server/src/api/admin/barcodes/[barcode]/route.js +43 -0
  4. package/.medusa/server/src/api/admin/barcodes/batch/route.js +9 -0
  5. package/.medusa/server/src/api/admin/barcodes/bulk-generate/route.js +9 -0
  6. package/.medusa/server/src/api/admin/barcodes/cache/route.js +25 -0
  7. package/.medusa/server/src/api/admin/barcodes/count-sessions/[id]/apply/route.js +13 -0
  8. package/.medusa/server/src/api/admin/barcodes/count-sessions/[id]/scan/route.js +13 -0
  9. package/.medusa/server/src/api/admin/barcodes/count-sessions/route.js +27 -0
  10. package/.medusa/server/src/api/admin/barcodes/create-from-barcode/route.js +9 -0
  11. package/.medusa/server/src/api/admin/barcodes/lookup/route.js +12 -0
  12. package/.medusa/server/src/api/admin/barcodes/print/route.js +11 -0
  13. package/.medusa/server/src/api/admin/barcodes/route.js +27 -0
  14. package/.medusa/server/src/api/admin/barcodes/scan/route.js +23 -0
  15. package/.medusa/server/src/api/admin/barcodes/tags/[id]/route.js +28 -0
  16. package/.medusa/server/src/api/admin/barcodes/tags/route.js +25 -0
  17. package/.medusa/server/src/api/admin/barcodes/templates/route.js +40 -0
  18. package/.medusa/server/src/api/admin/plugin/route.js +4 -0
  19. package/.medusa/server/src/api/admin/variants/barcode/[code]/route.js +28 -0
  20. package/.medusa/server/src/api/middlewares.js +73 -0
  21. package/.medusa/server/src/api/store/barcodes/[code]/route.js +28 -0
  22. package/.medusa/server/src/api/store/barcodes/[code]/verify/route.js +20 -0
  23. package/.medusa/server/src/api/store/plugin/route.js +4 -0
  24. package/.medusa/server/src/api/store/variants/barcode/[code]/route.js +28 -0
  25. package/.medusa/server/src/api/validators.js +173 -0
  26. package/.medusa/server/src/hooks/index.js +202 -0
  27. package/.medusa/server/src/index.js +5 -0
  28. package/.medusa/server/src/jobs/purge-expired-barcode-cache.js +10 -0
  29. package/.medusa/server/src/modules/barcode/index.js +16 -0
  30. package/.medusa/server/src/modules/barcode/migrations/Migration20260522000000.js +165 -0
  31. package/.medusa/server/src/modules/barcode/models/index.js +162 -0
  32. package/.medusa/server/src/modules/barcode/operations/context.js +2 -0
  33. package/.medusa/server/src/modules/barcode/operations/data-service.js +10 -0
  34. package/.medusa/server/src/modules/barcode/operations/generation.js +33 -0
  35. package/.medusa/server/src/modules/barcode/operations/index.js +9 -0
  36. package/.medusa/server/src/modules/barcode/operations/labels.js +57 -0
  37. package/.medusa/server/src/modules/barcode/operations/lookup.js +135 -0
  38. package/.medusa/server/src/modules/barcode/operations/maintenance.js +37 -0
  39. package/.medusa/server/src/modules/barcode/operations/stock-count.js +129 -0
  40. package/.medusa/server/src/modules/barcode/operations/tags.js +298 -0
  41. package/.medusa/server/src/modules/barcode/providers/index.js +721 -0
  42. package/.medusa/server/src/modules/barcode/service.js +161 -0
  43. package/.medusa/server/src/modules/barcode/types.js +21 -0
  44. package/.medusa/server/src/modules/barcode/utils/barcode-parser.js +399 -0
  45. package/.medusa/server/src/modules/barcode/utils/label-printer.js +533 -0
  46. package/.medusa/server/src/modules/barcode/utils/normalize-product.js +443 -0
  47. package/.medusa/server/src/modules/barcode/utils/security.js +114 -0
  48. package/.medusa/server/src/modules/barcode/utils/svg-renderer.js +492 -0
  49. package/.medusa/server/src/rbac.js +130 -0
  50. package/.medusa/server/src/sdk/index.js +164 -0
  51. package/.medusa/server/src/subscribers/product-created.js +34 -0
  52. package/.medusa/server/src/types/index.js +2 -0
  53. package/.medusa/server/src/ui/index.js +138 -0
  54. package/.medusa/server/src/workflows/apply-inventory-count.js +68 -0
  55. package/.medusa/server/src/workflows/batch-barcode-import.js +153 -0
  56. package/.medusa/server/src/workflows/bulk-generate-variant-barcodes.js +143 -0
  57. package/.medusa/server/src/workflows/generate-barcode-tag.js +44 -0
  58. package/.medusa/server/src/workflows/helpers.js +15 -0
  59. package/.medusa/server/src/workflows/index.js +7 -0
  60. package/.medusa/server/src/workflows/lookup-and-create-product.js +215 -0
  61. package/.medusa/server/src/workflows/scan-inventory-count.js +15 -0
  62. package/LICENSE +21 -0
  63. package/README.md +844 -2
  64. package/package.json +134 -3
  65. package/src/__tests__/barcode.spec.ts +836 -0
  66. package/src/__tests__/medusa-shim.mjs +331 -0
  67. package/src/__tests__/register-ts-resolver.mjs +135 -0
  68. package/src/admin/README.md +134 -0
  69. package/src/admin/components/barcode-studio-header.tsx +73 -0
  70. package/src/admin/components/batch-import-section.tsx +99 -0
  71. package/src/admin/components/dynamic-qr-tag-drawer-form.tsx +230 -0
  72. package/src/admin/components/dynamic-qr-tag-form.tsx +129 -0
  73. package/src/admin/components/dynamic-qr-tags-table.tsx +136 -0
  74. package/src/admin/components/gtin-lookup-section.tsx +155 -0
  75. package/src/admin/components/index.tsx +14 -0
  76. package/src/admin/components/label-designer-section.tsx +151 -0
  77. package/src/admin/components/label-output-section.tsx +63 -0
  78. package/src/admin/components/overview-cards.tsx +98 -0
  79. package/src/admin/components/product-barcode-card.tsx +127 -0
  80. package/src/admin/components/providers-cache-table.tsx +61 -0
  81. package/src/admin/components/providers-overview-section.tsx +49 -0
  82. package/src/admin/components/rbac-guard.tsx +153 -0
  83. package/src/admin/components/stock-take-scanner-section.tsx +116 -0
  84. package/src/admin/components/stock-take-sessions-section.tsx +109 -0
  85. package/src/admin/hooks/use-barcode-studio.ts +466 -0
  86. package/src/admin/hooks/use-product-barcodes.ts +139 -0
  87. package/src/admin/i18n/README.md +130 -0
  88. package/src/admin/i18n/index.ts +36 -0
  89. package/src/admin/i18n/json/ar.json +157 -0
  90. package/src/admin/i18n/json/de.json +157 -0
  91. package/src/admin/i18n/json/en.json +157 -0
  92. package/src/admin/i18n/json/es.json +157 -0
  93. package/src/admin/i18n/json/fr.json +157 -0
  94. package/src/admin/i18n/json/it.json +157 -0
  95. package/src/admin/i18n/json/nl.json +157 -0
  96. package/src/admin/i18n/json/pl.json +157 -0
  97. package/src/admin/i18n/json/pt.json +157 -0
  98. package/src/admin/i18n/json/tr.json +157 -0
  99. package/src/admin/routes/barcodes/lookup/page.tsx +75 -0
  100. package/src/admin/routes/barcodes/page.tsx +212 -0
  101. package/src/admin/routes/barcodes/print/page.tsx +67 -0
  102. package/src/admin/routes/barcodes/providers/page.tsx +66 -0
  103. package/src/admin/routes/barcodes/stock-take/page.tsx +74 -0
  104. package/src/admin/routes/barcodes/tags/@create/page.tsx +56 -0
  105. package/src/admin/routes/barcodes/tags/page.tsx +72 -0
  106. package/src/admin/tsconfig.json +20 -0
  107. package/src/admin/vite-env.d.ts +1 -0
  108. package/src/admin/widgets/product-barcode-widget.tsx +43 -0
  109. package/src/api/README.md +117 -0
  110. package/src/api/admin/barcodes/[barcode]/route.ts +64 -0
  111. package/src/api/admin/barcodes/batch/route.ts +12 -0
  112. package/src/api/admin/barcodes/bulk-generate/route.ts +12 -0
  113. package/src/api/admin/barcodes/cache/route.ts +35 -0
  114. package/src/api/admin/barcodes/count-sessions/[id]/apply/route.ts +17 -0
  115. package/src/api/admin/barcodes/count-sessions/[id]/scan/route.ts +17 -0
  116. package/src/api/admin/barcodes/count-sessions/route.ts +43 -0
  117. package/src/api/admin/barcodes/create-from-barcode/route.ts +16 -0
  118. package/src/api/admin/barcodes/lookup/route.ts +19 -0
  119. package/src/api/admin/barcodes/print/route.ts +18 -0
  120. package/src/api/admin/barcodes/route.ts +36 -0
  121. package/src/api/admin/barcodes/scan/route.ts +32 -0
  122. package/src/api/admin/barcodes/tags/[id]/route.ts +41 -0
  123. package/src/api/admin/barcodes/tags/route.ts +36 -0
  124. package/src/api/admin/barcodes/templates/route.ts +51 -0
  125. package/src/api/admin/plugin/route.ts +5 -0
  126. package/src/api/admin/variants/barcode/[code]/route.ts +36 -0
  127. package/src/api/middlewares.ts +91 -0
  128. package/src/api/store/barcodes/[code]/route.ts +43 -0
  129. package/src/api/store/barcodes/[code]/verify/route.ts +35 -0
  130. package/src/api/store/plugin/route.ts +5 -0
  131. package/src/api/store/variants/barcode/[code]/route.ts +36 -0
  132. package/src/api/validators.ts +217 -0
  133. package/src/hooks/index.ts +270 -0
  134. package/src/index.ts +4 -0
  135. package/src/jobs/README.md +54 -0
  136. package/src/jobs/purge-expired-barcode-cache.ts +18 -0
  137. package/src/links/README.md +44 -0
  138. package/src/modules/README.md +85 -0
  139. package/src/modules/barcode/index.ts +18 -0
  140. package/src/modules/barcode/migrations/Migration20260522000000.ts +225 -0
  141. package/src/modules/barcode/models/index.ts +168 -0
  142. package/src/modules/barcode/operations/context.ts +14 -0
  143. package/src/modules/barcode/operations/data-service.ts +10 -0
  144. package/src/modules/barcode/operations/generation.ts +57 -0
  145. package/src/modules/barcode/operations/index.ts +8 -0
  146. package/src/modules/barcode/operations/labels.ts +90 -0
  147. package/src/modules/barcode/operations/lookup.ts +202 -0
  148. package/src/modules/barcode/operations/maintenance.ts +53 -0
  149. package/src/modules/barcode/operations/stock-count.ts +217 -0
  150. package/src/modules/barcode/operations/tags.ts +425 -0
  151. package/src/modules/barcode/providers/index.ts +958 -0
  152. package/src/modules/barcode/service.ts +243 -0
  153. package/src/modules/barcode/types.ts +297 -0
  154. package/src/modules/barcode/utils/barcode-parser.ts +453 -0
  155. package/src/modules/barcode/utils/label-printer.ts +641 -0
  156. package/src/modules/barcode/utils/normalize-product.ts +524 -0
  157. package/src/modules/barcode/utils/security.ts +136 -0
  158. package/src/modules/barcode/utils/svg-renderer.ts +574 -0
  159. package/src/providers/README.md +105 -0
  160. package/src/rbac.ts +144 -0
  161. package/src/sdk/index.ts +253 -0
  162. package/src/subscribers/README.md +73 -0
  163. package/src/subscribers/product-created.ts +45 -0
  164. package/src/types/index.ts +1 -0
  165. package/src/types/medusa-ui.d.ts +118 -0
  166. package/src/ui/index.tsx +311 -0
  167. package/src/workflows/README.md +56 -0
  168. package/src/workflows/apply-inventory-count.ts +115 -0
  169. package/src/workflows/batch-barcode-import.ts +218 -0
  170. package/src/workflows/bulk-generate-variant-barcodes.ts +214 -0
  171. package/src/workflows/generate-barcode-tag.ts +85 -0
  172. package/src/workflows/helpers.ts +21 -0
  173. package/src/workflows/index.ts +6 -0
  174. package/src/workflows/lookup-and-create-product.ts +298 -0
  175. package/src/workflows/scan-inventory-count.ts +45 -0
  176. package/tsconfig.json +40 -0
@@ -0,0 +1,99 @@
1
+ import {
2
+ Badge,
3
+ Button,
4
+ Container,
5
+ Heading,
6
+ Table,
7
+ Text,
8
+ Textarea,
9
+ } from "@medusajs/ui"
10
+ import { useTranslation } from "react-i18next"
11
+
12
+ import type { LookupFormState } from "../hooks/use-barcode-studio"
13
+
14
+ export interface GtinLookupBatchSectionProps {
15
+ form: LookupFormState
16
+ onFormChange: React.Dispatch<React.SetStateAction<LookupFormState>>
17
+ barcodes: Array<Record<string, unknown>>
18
+ onBatchImport: () => void
19
+ }
20
+
21
+ export const GtinLookupBatchSection = ({
22
+ form,
23
+ onFormChange,
24
+ barcodes,
25
+ onBatchImport,
26
+ }: GtinLookupBatchSectionProps) => {
27
+ const { t } = useTranslation()
28
+
29
+ return (
30
+ <div className="flex flex-col gap-y-4">
31
+ <Container className="divide-y p-0">
32
+ <div className="px-6 py-4">
33
+ <Heading level="h2">{t("lookupTab.batchTitle")}</Heading>
34
+ <Text size="small" className="text-ui-fg-subtle mt-1">
35
+ {t("lookupTab.batchSubtitle")}
36
+ </Text>
37
+ </div>
38
+
39
+ <div className="flex flex-col gap-3 px-6 py-4">
40
+ <Textarea
41
+ rows={4}
42
+ value={form.batchInput}
43
+ onChange={(e) =>
44
+ onFormChange((prev) => ({ ...prev, batchInput: e.target.value }))
45
+ }
46
+ />
47
+ <div>
48
+ <Button variant="secondary" size="small" onClick={onBatchImport}>
49
+ {t("lookupTab.batchRunButton")}
50
+ </Button>
51
+ </div>
52
+ </div>
53
+ </Container>
54
+
55
+ <Container className="divide-y p-0">
56
+ <div className="flex items-center justify-between px-6 py-4">
57
+ <Heading level="h2">
58
+ {t("lookupTab.recentlyLinkedTitle", { count: barcodes.length })}
59
+ </Heading>
60
+ <Badge size="xsmall" color="grey">
61
+ {barcodes.length}
62
+ </Badge>
63
+ </div>
64
+ {barcodes.length === 0 ? (
65
+ <div className="px-6 py-4">
66
+ <Text size="small" className="text-ui-fg-subtle">
67
+ {t("lookupTab.noLinkedProducts")}
68
+ </Text>
69
+ </div>
70
+ ) : (
71
+ <Table>
72
+ <Table.Header>
73
+ <Table.Row>
74
+ <Table.HeaderCell>GTIN / Barcode</Table.HeaderCell>
75
+ <Table.HeaderCell>Product ID</Table.HeaderCell>
76
+ <Table.HeaderCell>Provider</Table.HeaderCell>
77
+ </Table.Row>
78
+ </Table.Header>
79
+ <Table.Body>
80
+ {barcodes.map((row) => (
81
+ <Table.Row key={String(row.id)}>
82
+ <Table.Cell className="font-mono font-semibold">
83
+ {String(row.barcode)}
84
+ </Table.Cell>
85
+ <Table.Cell>{String(row.product_id)}</Table.Cell>
86
+ <Table.Cell>
87
+ <Badge size="xsmall" color="blue">
88
+ {String(row.provider)}
89
+ </Badge>
90
+ </Table.Cell>
91
+ </Table.Row>
92
+ ))}
93
+ </Table.Body>
94
+ </Table>
95
+ )}
96
+ </Container>
97
+ </div>
98
+ )
99
+ }
@@ -0,0 +1,230 @@
1
+ import { zodResolver } from "@hookform/resolvers/zod"
2
+ import { Form, KeyboundForm, RouteDrawer } from "@medusajs/dashboard/components"
3
+ import { Button, Input, Select } from "@medusajs/ui"
4
+ import { useForm } from "react-hook-form"
5
+ import { useTranslation } from "react-i18next"
6
+ import { z } from "zod"
7
+
8
+ import type {
9
+ BarcodeScanAction,
10
+ BarcodeSymbology,
11
+ } from "../../modules/barcode/types"
12
+ import type { TagFormState } from "../hooks/use-barcode-studio"
13
+
14
+ export const tagFormSchema = z.object({
15
+ target_id: z.string().min(1),
16
+ label: z.string().optional(),
17
+ symbology: z.enum(["qr", "datamatrix", "ean13", "upca", "code128", "code39"]),
18
+ scan_action: z.enum(["view", "add_to_cart", "verify", "gs1_digital_link"]),
19
+ gs1_gtin: z.string().optional(),
20
+ batch_lot: z.string().optional(),
21
+ serial_number: z.string().optional(),
22
+ })
23
+
24
+ export type TagFormSchemaValues = z.infer<typeof tagFormSchema>
25
+
26
+ export interface DynamicQrTagDrawerFormProps {
27
+ defaultValues?: Partial<TagFormState>
28
+ loading?: boolean
29
+ onSubmit: (values: TagFormState) => Promise<void>
30
+ }
31
+
32
+ export const DynamicQrTagDrawerForm = ({
33
+ defaultValues,
34
+ loading = false,
35
+ onSubmit,
36
+ }: DynamicQrTagDrawerFormProps) => {
37
+ const { t } = useTranslation()
38
+
39
+ const form = useForm<TagFormSchemaValues>({
40
+ resolver: zodResolver(tagFormSchema),
41
+ defaultValues: {
42
+ target_id: defaultValues?.target_id ?? "prod_01",
43
+ label: defaultValues?.label ?? "",
44
+ symbology:
45
+ (defaultValues?.symbology as TagFormSchemaValues["symbology"]) ?? "qr",
46
+ scan_action:
47
+ (defaultValues?.scan_action as TagFormSchemaValues["scan_action"]) ??
48
+ "verify",
49
+ gs1_gtin: defaultValues?.gs1_gtin ?? "",
50
+ batch_lot: defaultValues?.batch_lot ?? "",
51
+ serial_number: defaultValues?.serial_number ?? "",
52
+ },
53
+ })
54
+
55
+ return (
56
+ <RouteDrawer.Form form={form}>
57
+ <KeyboundForm
58
+ onSubmit={form.handleSubmit((values) =>
59
+ onSubmit({
60
+ target_id: values.target_id,
61
+ label: values.label ?? "",
62
+ symbology: values.symbology as BarcodeSymbology,
63
+ scan_action: values.scan_action as BarcodeScanAction,
64
+ gs1_gtin: values.gs1_gtin ?? "",
65
+ batch_lot: values.batch_lot ?? "",
66
+ serial_number: values.serial_number ?? "",
67
+ })
68
+ )}
69
+ className="flex flex-1 flex-col overflow-hidden"
70
+ >
71
+ <RouteDrawer.Body className="flex flex-1 flex-col gap-y-4 overflow-auto p-6">
72
+ <Form.Field
73
+ control={form.control}
74
+ name="target_id"
75
+ render={({ field }: any) => (
76
+ <Form.Item>
77
+ <Form.Label>{t("tagsTab.targetIdPlaceholder")}</Form.Label>
78
+ <Form.Control>
79
+ <Input {...field} />
80
+ </Form.Control>
81
+ <Form.ErrorMessage />
82
+ </Form.Item>
83
+ )}
84
+ />
85
+ <Form.Field
86
+ control={form.control}
87
+ name="label"
88
+ render={({ field }: any) => (
89
+ <Form.Item>
90
+ <Form.Label optional>
91
+ {t("tagsTab.labelPlaceholder")}
92
+ </Form.Label>
93
+ <Form.Control>
94
+ <Input {...field} />
95
+ </Form.Control>
96
+ <Form.ErrorMessage />
97
+ </Form.Item>
98
+ )}
99
+ />
100
+ <Form.Field
101
+ control={form.control}
102
+ name="symbology"
103
+ render={({ field }: any) => (
104
+ <Form.Item>
105
+ <Form.Label>{t("tagsTab.symbologyQr")}</Form.Label>
106
+ <Form.Control>
107
+ <Select value={field.value} onValueChange={field.onChange}>
108
+ <Select.Trigger>
109
+ <Select.Value />
110
+ </Select.Trigger>
111
+ <Select.Content>
112
+ <Select.Item value="qr">
113
+ {t("tagsTab.symbologyQr")}
114
+ </Select.Item>
115
+ <Select.Item value="datamatrix">
116
+ {t("tagsTab.symbologyDatamatrix")}
117
+ </Select.Item>
118
+ <Select.Item value="ean13">
119
+ {t("tagsTab.symbologyEan13")}
120
+ </Select.Item>
121
+ <Select.Item value="upca">
122
+ {t("tagsTab.symbologyUpca")}
123
+ </Select.Item>
124
+ <Select.Item value="code128">
125
+ {t("tagsTab.symbologyCode128")}
126
+ </Select.Item>
127
+ <Select.Item value="code39">
128
+ {t("tagsTab.symbologyCode39")}
129
+ </Select.Item>
130
+ </Select.Content>
131
+ </Select>
132
+ </Form.Control>
133
+ <Form.ErrorMessage />
134
+ </Form.Item>
135
+ )}
136
+ />
137
+ <Form.Field
138
+ control={form.control}
139
+ name="scan_action"
140
+ render={({ field }: any) => (
141
+ <Form.Item>
142
+ <Form.Label>{t("tagsTab.actionVerify")}</Form.Label>
143
+ <Form.Control>
144
+ <Select value={field.value} onValueChange={field.onChange}>
145
+ <Select.Trigger>
146
+ <Select.Value />
147
+ </Select.Trigger>
148
+ <Select.Content>
149
+ <Select.Item value="view">
150
+ {t("tagsTab.actionView")}
151
+ </Select.Item>
152
+ <Select.Item value="add_to_cart">
153
+ {t("tagsTab.actionAddToCart")}
154
+ </Select.Item>
155
+ <Select.Item value="verify">
156
+ {t("tagsTab.actionVerify")}
157
+ </Select.Item>
158
+ <Select.Item value="gs1_digital_link">
159
+ {t("tagsTab.actionDigitalLink")}
160
+ </Select.Item>
161
+ </Select.Content>
162
+ </Select>
163
+ </Form.Control>
164
+ <Form.ErrorMessage />
165
+ </Form.Item>
166
+ )}
167
+ />
168
+ <Form.Field
169
+ control={form.control}
170
+ name="gs1_gtin"
171
+ render={({ field }: any) => (
172
+ <Form.Item>
173
+ <Form.Label optional>
174
+ {t("tagsTab.gs1GtinPlaceholder")}
175
+ </Form.Label>
176
+ <Form.Control>
177
+ <Input {...field} />
178
+ </Form.Control>
179
+ <Form.ErrorMessage />
180
+ </Form.Item>
181
+ )}
182
+ />
183
+ <Form.Field
184
+ control={form.control}
185
+ name="batch_lot"
186
+ render={({ field }: any) => (
187
+ <Form.Item>
188
+ <Form.Label optional>
189
+ {t("tagsTab.batchLotPlaceholder")}
190
+ </Form.Label>
191
+ <Form.Control>
192
+ <Input {...field} />
193
+ </Form.Control>
194
+ <Form.ErrorMessage />
195
+ </Form.Item>
196
+ )}
197
+ />
198
+ <Form.Field
199
+ control={form.control}
200
+ name="serial_number"
201
+ render={({ field }: any) => (
202
+ <Form.Item>
203
+ <Form.Label optional>
204
+ {t("tagsTab.serialNumberPlaceholder")}
205
+ </Form.Label>
206
+ <Form.Control>
207
+ <Input {...field} />
208
+ </Form.Control>
209
+ <Form.ErrorMessage />
210
+ </Form.Item>
211
+ )}
212
+ />
213
+ </RouteDrawer.Body>
214
+
215
+ <RouteDrawer.Footer>
216
+ <div className="flex items-center justify-end gap-x-2">
217
+ <RouteDrawer.Close asChild>
218
+ <Button size="small" variant="secondary">
219
+ {t("header.dismiss")}
220
+ </Button>
221
+ </RouteDrawer.Close>
222
+ <Button size="small" type="submit" isLoading={loading}>
223
+ {t("tagsTab.generateButton")}
224
+ </Button>
225
+ </div>
226
+ </RouteDrawer.Footer>
227
+ </KeyboundForm>
228
+ </RouteDrawer.Form>
229
+ )
230
+ }
@@ -0,0 +1,129 @@
1
+ import { Button, Container, Heading, Input, Select } from "@medusajs/ui"
2
+ import { useTranslation } from "react-i18next"
3
+
4
+ import type {
5
+ BarcodeScanAction,
6
+ BarcodeSymbology,
7
+ } from "../../modules/barcode/types"
8
+ import type { TagFormState } from "../hooks/use-barcode-studio"
9
+
10
+ export interface DynamicQrTagCreateSectionProps {
11
+ form: TagFormState
12
+ onFormChange: React.Dispatch<React.SetStateAction<TagFormState>>
13
+ onCreateTag: () => void
14
+ }
15
+
16
+ export const DynamicQrTagCreateSection = ({
17
+ form,
18
+ onFormChange,
19
+ onCreateTag,
20
+ }: DynamicQrTagCreateSectionProps) => {
21
+ const { t } = useTranslation()
22
+
23
+ return (
24
+ <Container className="divide-y p-0">
25
+ <div className="px-6 py-4">
26
+ <Heading level="h2">{t("tagsTab.createTitle")}</Heading>
27
+ </div>
28
+ <div className="grid grid-cols-1 gap-3 px-6 py-4 sm:grid-cols-2">
29
+ <Input
30
+ value={form.target_id}
31
+ onChange={(e) =>
32
+ onFormChange((prev) => ({ ...prev, target_id: e.target.value }))
33
+ }
34
+ placeholder={t("tagsTab.targetIdPlaceholder")}
35
+ />
36
+ <Input
37
+ value={form.label}
38
+ onChange={(e) =>
39
+ onFormChange((prev) => ({ ...prev, label: e.target.value }))
40
+ }
41
+ placeholder={t("tagsTab.labelPlaceholder")}
42
+ />
43
+ <Select
44
+ value={form.symbology}
45
+ onValueChange={(val) =>
46
+ onFormChange((prev) => ({
47
+ ...prev,
48
+ symbology: val as BarcodeSymbology,
49
+ }))
50
+ }
51
+ >
52
+ <Select.Trigger>
53
+ <Select.Value />
54
+ </Select.Trigger>
55
+ <Select.Content>
56
+ <Select.Item value="qr">{t("tagsTab.symbologyQr")}</Select.Item>
57
+ <Select.Item value="datamatrix">
58
+ {t("tagsTab.symbologyDatamatrix")}
59
+ </Select.Item>
60
+ <Select.Item value="ean13">
61
+ {t("tagsTab.symbologyEan13")}
62
+ </Select.Item>
63
+ <Select.Item value="upca">{t("tagsTab.symbologyUpca")}</Select.Item>
64
+ <Select.Item value="code128">
65
+ {t("tagsTab.symbologyCode128")}
66
+ </Select.Item>
67
+ <Select.Item value="code39">
68
+ {t("tagsTab.symbologyCode39")}
69
+ </Select.Item>
70
+ </Select.Content>
71
+ </Select>
72
+ <Select
73
+ value={form.scan_action}
74
+ onValueChange={(val) =>
75
+ onFormChange((prev) => ({
76
+ ...prev,
77
+ scan_action: val as BarcodeScanAction,
78
+ }))
79
+ }
80
+ >
81
+ <Select.Trigger>
82
+ <Select.Value />
83
+ </Select.Trigger>
84
+ <Select.Content>
85
+ <Select.Item value="view">{t("tagsTab.actionView")}</Select.Item>
86
+ <Select.Item value="add_to_cart">
87
+ {t("tagsTab.actionAddToCart")}
88
+ </Select.Item>
89
+ <Select.Item value="verify">
90
+ {t("tagsTab.actionVerify")}
91
+ </Select.Item>
92
+ <Select.Item value="gs1_digital_link">
93
+ {t("tagsTab.actionDigitalLink")}
94
+ </Select.Item>
95
+ </Select.Content>
96
+ </Select>
97
+ <Input
98
+ value={form.gs1_gtin}
99
+ onChange={(e) =>
100
+ onFormChange((prev) => ({ ...prev, gs1_gtin: e.target.value }))
101
+ }
102
+ placeholder={t("tagsTab.gs1GtinPlaceholder")}
103
+ />
104
+ <Input
105
+ value={form.batch_lot}
106
+ onChange={(e) =>
107
+ onFormChange((prev) => ({ ...prev, batch_lot: e.target.value }))
108
+ }
109
+ placeholder={t("tagsTab.batchLotPlaceholder")}
110
+ />
111
+ <Input
112
+ value={form.serial_number}
113
+ onChange={(e) =>
114
+ onFormChange((prev) => ({
115
+ ...prev,
116
+ serial_number: e.target.value,
117
+ }))
118
+ }
119
+ placeholder={t("tagsTab.serialNumberPlaceholder")}
120
+ />
121
+ </div>
122
+ <div className="px-6 py-4">
123
+ <Button variant="primary" size="small" onClick={onCreateTag}>
124
+ {t("tagsTab.generateButton")}
125
+ </Button>
126
+ </div>
127
+ </Container>
128
+ )
129
+ }
@@ -0,0 +1,136 @@
1
+ import {
2
+ Badge,
3
+ Button,
4
+ Container,
5
+ Heading,
6
+ StatusBadge,
7
+ Table,
8
+ Text,
9
+ } from "@medusajs/ui"
10
+ import { useTranslation } from "react-i18next"
11
+
12
+ import type { BarcodeSymbology } from "../../modules/barcode/types"
13
+ import { BarcodeImage } from "../../ui"
14
+ import type { TagFormState } from "../hooks/use-barcode-studio"
15
+ import { DynamicQrTagCreateSection } from "./dynamic-qr-tag-form"
16
+
17
+ export interface DynamicQrTagsTabProps {
18
+ form: TagFormState
19
+ onFormChange: React.Dispatch<React.SetStateAction<TagFormState>>
20
+ tags: Array<Record<string, unknown>>
21
+ onCreateTag: () => void
22
+ onDeleteTag: (id: string) => void
23
+ onOpenCreateDrawer?: () => void
24
+ }
25
+
26
+ export const DynamicQrTagsTableSection = ({
27
+ tags,
28
+ onDeleteTag,
29
+ onOpenCreateDrawer,
30
+ }: Pick<
31
+ DynamicQrTagsTabProps,
32
+ "tags" | "onDeleteTag" | "onOpenCreateDrawer"
33
+ >) => {
34
+ const { t } = useTranslation()
35
+
36
+ return (
37
+ <Container className="divide-y p-0">
38
+ <div className="flex items-center justify-between px-6 py-4">
39
+ <Heading level="h2">
40
+ {t("tagsTab.listTitle", { count: tags.length })}
41
+ </Heading>
42
+ {onOpenCreateDrawer ? (
43
+ <Button variant="secondary" size="small" onClick={onOpenCreateDrawer}>
44
+ {t("tagsTab.generateButton")}
45
+ </Button>
46
+ ) : null}
47
+ </div>
48
+
49
+ <Table>
50
+ <Table.Header>
51
+ <Table.Row>
52
+ <Table.HeaderCell>{t("widget.codeLabel")}</Table.HeaderCell>
53
+ <Table.HeaderCell>{t("widget.actionLabel")}</Table.HeaderCell>
54
+ <Table.HeaderCell>{t("widget.scansLabel")}</Table.HeaderCell>
55
+ <Table.HeaderCell />
56
+ </Table.Row>
57
+ </Table.Header>
58
+ <Table.Body>
59
+ {tags.map((tag) => (
60
+ <Table.Row key={String(tag.id)}>
61
+ <Table.Cell>
62
+ <div className="flex flex-col gap-1">
63
+ <div className="flex items-center gap-2">
64
+ <span className="font-mono text-xs font-bold">
65
+ {String(tag.code)}
66
+ </span>
67
+ <Badge size="xsmall" color="purple">
68
+ {String(tag.symbology)}
69
+ </Badge>
70
+ </div>
71
+ {tag.hmac_signature ? (
72
+ <Text size="xsmall" className="font-mono text-ui-fg-subtle">
73
+ {t("tagsTab.hmacLabel", {
74
+ signature: String(tag.hmac_signature).slice(0, 16),
75
+ })}
76
+ </Text>
77
+ ) : null}
78
+ </div>
79
+ </Table.Cell>
80
+ <Table.Cell>
81
+ <StatusBadge color="green">
82
+ {String(tag.scan_action)}
83
+ </StatusBadge>
84
+ </Table.Cell>
85
+ <Table.Cell>
86
+ <Text size="small">
87
+ {t("tagsTab.tagMeta", {
88
+ target: String(tag.target_id),
89
+ scans: String(tag.scan_count ?? 0),
90
+ })}
91
+ </Text>
92
+ </Table.Cell>
93
+ <Table.Cell>
94
+ <div className="flex items-center justify-end gap-2">
95
+ {typeof tag.svg_markup === "string" ? (
96
+ <BarcodeImage
97
+ code={String(tag.code)}
98
+ symbology={tag.symbology as BarcodeSymbology}
99
+ svgMarkup={tag.svg_markup}
100
+ width={80}
101
+ height={44}
102
+ />
103
+ ) : null}
104
+ <Button
105
+ variant="secondary"
106
+ size="small"
107
+ onClick={() => onDeleteTag(String(tag.id))}
108
+ >
109
+ {t("tagsTab.deleteButton")}
110
+ </Button>
111
+ </div>
112
+ </Table.Cell>
113
+ </Table.Row>
114
+ ))}
115
+ </Table.Body>
116
+ </Table>
117
+ </Container>
118
+ )
119
+ }
120
+
121
+ export const DynamicQrTagsTab = (props: DynamicQrTagsTabProps) => {
122
+ return (
123
+ <div className="grid grid-cols-1 gap-4 lg:grid-cols-2">
124
+ <DynamicQrTagCreateSection
125
+ form={props.form}
126
+ onFormChange={props.onFormChange}
127
+ onCreateTag={props.onCreateTag}
128
+ />
129
+ <DynamicQrTagsTableSection
130
+ tags={props.tags}
131
+ onDeleteTag={props.onDeleteTag}
132
+ onOpenCreateDrawer={props.onOpenCreateDrawer}
133
+ />
134
+ </div>
135
+ )
136
+ }