@krak-stack/notifications-admin 0.1.0 → 0.2.1

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.
@@ -1,378 +0,0 @@
1
- import {
2
- cn,
3
- Button,
4
- Dialog,
5
- DialogContent,
6
- DialogHeader,
7
- DialogTitle
8
- } from "./chunk-tck9drx2.js";
9
-
10
- // src/deliveries.tsx
11
- import {
12
- DataTable
13
- } from "@krak-stack/registry/data-table";
14
-
15
- // ../../src/components/ui/tabs.tsx
16
- import { Tabs as TabsPrimitive } from "@base-ui/react/tabs";
17
- import { cva } from "class-variance-authority";
18
- import { jsx } from "react/jsx-runtime";
19
- function Tabs({
20
- className,
21
- orientation = "horizontal",
22
- ...props
23
- }) {
24
- return /* @__PURE__ */ jsx(TabsPrimitive.Root, {
25
- "data-slot": "tabs",
26
- "data-orientation": orientation,
27
- className: cn("group/tabs flex gap-2 data-horizontal:flex-col", className),
28
- ...props
29
- });
30
- }
31
- var tabsListVariants = cva("group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-horizontal/tabs:h-9 group-data-vertical/tabs:h-fit group-data-vertical/tabs:flex-col data-[variant=line]:rounded-none", {
32
- variants: {
33
- variant: {
34
- default: "bg-muted",
35
- line: "gap-1 bg-transparent"
36
- }
37
- },
38
- defaultVariants: {
39
- variant: "default"
40
- }
41
- });
42
- function TabsList({
43
- className,
44
- variant = "default",
45
- ...props
46
- }) {
47
- return /* @__PURE__ */ jsx(TabsPrimitive.List, {
48
- "data-slot": "tabs-list",
49
- "data-variant": variant,
50
- className: cn(tabsListVariants({ variant }), className),
51
- ...props
52
- });
53
- }
54
- function TabsTrigger({ className, ...props }) {
55
- return /* @__PURE__ */ jsx(TabsPrimitive.Tab, {
56
- "data-slot": "tabs-trigger",
57
- className: cn("relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap text-foreground/60 transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 aria-disabled:pointer-events-none aria-disabled:opacity-50 dark:text-muted-foreground dark:hover:text-foreground group-data-[variant=default]/tabs-list:data-active:shadow-sm group-data-[variant=line]/tabs-list:data-active:shadow-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", "group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-active:bg-transparent dark:group-data-[variant=line]/tabs-list:data-active:border-transparent dark:group-data-[variant=line]/tabs-list:data-active:bg-transparent", "data-active:bg-background data-active:text-foreground dark:data-active:border-input dark:data-active:bg-input/30 dark:data-active:text-foreground", "after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-horizontal/tabs:after:inset-x-0 group-data-horizontal/tabs:after:bottom-[-5px] group-data-horizontal/tabs:after:h-0.5 group-data-vertical/tabs:after:inset-y-0 group-data-vertical/tabs:after:-right-1 group-data-vertical/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-active:after:opacity-100", className),
58
- ...props
59
- });
60
- }
61
-
62
- // src/deliveries.tsx
63
- import { jsx as jsx2, jsxs, Fragment } from "react/jsx-runtime";
64
- var metricKeys = [
65
- "total",
66
- "queued",
67
- "processing",
68
- "retrying",
69
- "accepted",
70
- "failed",
71
- "suppressed",
72
- "cancelled",
73
- "feedbackCovered",
74
- "feedbackUnavailable",
75
- "confirmed",
76
- "hardBounced",
77
- "softBounced",
78
- "complained"
79
- ];
80
- var NotificationDeliveries2 = (p) => {
81
- const m = p.messages;
82
- const c = m.common;
83
- const columns = [
84
- { field: "recipientAddress", headerName: c.email },
85
- {
86
- field: "source",
87
- headerName: m.source,
88
- filterOptions: ["contacts", "engine"].map((value) => ({
89
- value,
90
- label: value === "contacts" ? m.sources.contacts : m.sources.engine
91
- })),
92
- cellRenderer: ({ data }) => m.sources[data.source]
93
- },
94
- { field: "recipientUserId", headerName: m.recipientUserId },
95
- { field: "organizationId", headerName: m.organizationId },
96
- { field: "workspaceId", headerName: m.workspaceId },
97
- { field: "eventKey", headerName: m.eventKey },
98
- { field: "template", headerName: m.template },
99
- {
100
- field: "purpose",
101
- headerName: c.purpose,
102
- filterOptions: Object.entries(m.purposes).map(([value, label]) => ({
103
- value,
104
- label
105
- })),
106
- cellRenderer: ({ data }) => m.purposes[data.purpose]
107
- },
108
- {
109
- field: "status",
110
- headerName: c.status,
111
- filterOptions: Object.entries(c.statuses).map(([value, label]) => ({
112
- value,
113
- label
114
- })),
115
- cellRenderer: ({ data }) => c.statuses[data.status]
116
- },
117
- { field: "attempts", headerName: c.attempts, type: "number" },
118
- { field: "provider", headerName: c.provider },
119
- { field: "createdAt", headerName: c.created, type: "date" },
120
- { field: "sentAt", headerName: c.accepted, type: "date" },
121
- {
122
- colId: "inspect",
123
- headerName: c.inspect,
124
- sortable: false,
125
- searchable: false,
126
- filterable: false,
127
- hideable: false,
128
- cellRenderer: ({ data }) => /* @__PURE__ */ jsx2(Button, {
129
- variant: "outline",
130
- onClick: () => p.onInspect(data.id),
131
- children: c.inspect
132
- })
133
- }
134
- ];
135
- const delivery = p.inspection?.delivery;
136
- const metrics = {
137
- ...c.metrics,
138
- feedbackCovered: m.feedbackCovered,
139
- feedbackUnavailable: m.feedbackUnavailable
140
- };
141
- return /* @__PURE__ */ jsxs("section", {
142
- className: "space-y-4",
143
- "aria-busy": p.pending,
144
- children: [
145
- /* @__PURE__ */ jsxs("header", {
146
- className: "flex justify-between gap-4",
147
- children: [
148
- /* @__PURE__ */ jsxs("div", {
149
- children: [
150
- /* @__PURE__ */ jsx2("h1", {
151
- className: "text-2xl font-semibold",
152
- children: m.title
153
- }),
154
- /* @__PURE__ */ jsx2("p", {
155
- children: m.description
156
- })
157
- ]
158
- }),
159
- /* @__PURE__ */ jsx2(Button, {
160
- variant: "outline",
161
- onClick: p.onRefresh,
162
- children: c.refresh
163
- })
164
- ]
165
- }),
166
- /* @__PURE__ */ jsx2(Tabs, {
167
- value: p.source,
168
- onValueChange: (value) => {
169
- if (value === "all" || value === "contacts" || value === "engine")
170
- p.onSource(value);
171
- },
172
- children: /* @__PURE__ */ jsx2(TabsList, {
173
- "aria-label": m.source,
174
- children: ["all", "contacts", "engine"].map((source) => /* @__PURE__ */ jsx2(TabsTrigger, {
175
- value: source,
176
- children: m.sources[source]
177
- }, source))
178
- })
179
- }),
180
- /* @__PURE__ */ jsx2(Tabs, {
181
- value: p.view,
182
- onValueChange: (value) => {
183
- if (value === "overview" || value === "activity")
184
- p.onView(value);
185
- },
186
- children: /* @__PURE__ */ jsx2(TabsList, {
187
- "aria-label": m.title,
188
- children: ["overview", "activity"].map((view) => /* @__PURE__ */ jsx2(TabsTrigger, {
189
- value: view,
190
- children: c.views[view]
191
- }, view))
192
- })
193
- }),
194
- p.error && /* @__PURE__ */ jsx2("p", {
195
- role: "alert",
196
- children: p.error
197
- }),
198
- /* @__PURE__ */ jsx2("p", {
199
- children: m.feedbackNotice
200
- }),
201
- p.view === "overview" && p.overview && /* @__PURE__ */ jsx2("dl", {
202
- className: "grid gap-3 sm:grid-cols-3",
203
- children: metricKeys.map((key) => /* @__PURE__ */ jsxs("div", {
204
- role: "group",
205
- "aria-label": metrics[key],
206
- className: "rounded border p-3",
207
- children: [
208
- /* @__PURE__ */ jsx2("dt", {
209
- children: metrics[key]
210
- }),
211
- /* @__PURE__ */ jsx2("dd", {
212
- className: "text-2xl font-semibold",
213
- children: p.overview?.[key]
214
- })
215
- ]
216
- }, key))
217
- }),
218
- p.view === "activity" && /* @__PURE__ */ jsx2(DataTable, {
219
- rowData: p.activity?.items ?? [],
220
- columnDefs: columns,
221
- getRowId: (row) => row.id,
222
- state: p.table,
223
- onStateChange: p.onTable,
224
- status: { loading: p.pending, error: p.error },
225
- features: {
226
- pagination: { mode: "server", rowCount: p.total },
227
- refresh: p.onRefresh
228
- },
229
- messages: {
230
- en: { empty: c.empty, loading: c.loading },
231
- fr: { empty: c.empty, loading: c.loading }
232
- }
233
- }),
234
- /* @__PURE__ */ jsx2(Dialog, {
235
- open: p.inspecting,
236
- onOpenChange: (open) => {
237
- if (!open)
238
- p.onInspect(undefined);
239
- },
240
- children: /* @__PURE__ */ jsxs(DialogContent, {
241
- className: "max-h-[90vh] overflow-auto sm:max-w-4xl",
242
- children: [
243
- /* @__PURE__ */ jsx2(DialogHeader, {
244
- children: /* @__PURE__ */ jsx2(DialogTitle, {
245
- children: c.inspect
246
- })
247
- }),
248
- p.inspectionError && /* @__PURE__ */ jsx2("p", {
249
- role: "alert",
250
- children: p.inspectionError
251
- }),
252
- !delivery && !p.inspectionError && /* @__PURE__ */ jsx2("p", {
253
- role: "status",
254
- children: c.loading
255
- }),
256
- delivery && /* @__PURE__ */ jsxs(Fragment, {
257
- children: [
258
- /* @__PURE__ */ jsx2("dl", {
259
- className: "grid gap-2 break-all sm:grid-cols-2",
260
- children: [
261
- [c.id, delivery.id],
262
- [m.source, m.sources[delivery.source]],
263
- [c.email, delivery.recipientAddress],
264
- [m.recipientUserId, delivery.recipientUserId],
265
- [m.organizationId, delivery.organizationId],
266
- [m.workspaceId, delivery.workspaceId],
267
- [m.eventKey, delivery.eventKey],
268
- [m.template, delivery.template],
269
- [c.purpose, m.purposes[delivery.purpose]],
270
- [c.status, c.statuses[delivery.status]],
271
- [c.provider, delivery.provider],
272
- [c.providerMessageId, delivery.providerMessageId],
273
- [c.reason, delivery.errorMessage],
274
- [
275
- c.attempts,
276
- `${delivery.attempts} / ${delivery.maxAttempts}`
277
- ]
278
- ].map(([label, value]) => /* @__PURE__ */ jsxs("div", {
279
- children: [
280
- /* @__PURE__ */ jsx2("dt", {
281
- className: "font-semibold",
282
- children: label
283
- }),
284
- /* @__PURE__ */ jsx2("dd", {
285
- children: value ?? "—"
286
- })
287
- ]
288
- }, label))
289
- }),
290
- delivery.contactId && p.onContact && /* @__PURE__ */ jsx2(Button, {
291
- variant: "outline",
292
- onClick: () => p.onContact?.(delivery.contactId),
293
- children: c.contactId
294
- }),
295
- delivery.campaignId && p.onCampaign && /* @__PURE__ */ jsx2(Button, {
296
- variant: "outline",
297
- onClick: () => p.onCampaign?.(delivery.campaignId),
298
- children: c.campaign
299
- }),
300
- /* @__PURE__ */ jsx2("h3", {
301
- children: m.references
302
- }),
303
- /* @__PURE__ */ jsx2("dl", {
304
- children: p.inspection?.references.map((ref) => /* @__PURE__ */ jsxs("div", {
305
- children: [
306
- /* @__PURE__ */ jsx2("dt", {
307
- children: ref.namespace
308
- }),
309
- /* @__PURE__ */ jsx2("dd", {
310
- children: ref.value
311
- })
312
- ]
313
- }, `${ref.namespace}:${ref.value}`))
314
- }),
315
- /* @__PURE__ */ jsx2("h3", {
316
- children: c.attempts
317
- }),
318
- /* @__PURE__ */ jsx2(DataTable, {
319
- rowData: p.inspection?.attempts ?? [],
320
- getRowId: (row) => row.id,
321
- columnDefs: [
322
- {
323
- field: "generation",
324
- headerName: c.generation,
325
- type: "number"
326
- },
327
- { field: "attempt", headerName: c.attempts, type: "number" },
328
- {
329
- colId: "outcome",
330
- headerName: c.outcome,
331
- cellRenderer: ({ data }) => data.outcome ? c.outcomes[data.outcome._tag] : c.pending
332
- },
333
- {
334
- colId: "reason",
335
- headerName: c.reason,
336
- cellRenderer: ({ data }) => {
337
- const o = data.outcome;
338
- if (!o)
339
- return "—";
340
- switch (o._tag) {
341
- case "Sent":
342
- return o.providerMessageId ?? "—";
343
- case "Skipped":
344
- return o.reason;
345
- default:
346
- return o.message;
347
- }
348
- }
349
- },
350
- { field: "startedAt", headerName: c.started, type: "date" },
351
- {
352
- field: "completedAt",
353
- headerName: c.completed,
354
- type: "date"
355
- }
356
- ],
357
- features: { pagination: { mode: "client" } }
358
- })
359
- ]
360
- }),
361
- /* @__PURE__ */ jsx2(Button, {
362
- variant: "outline",
363
- onClick: p.onRefresh,
364
- children: c.refresh
365
- }),
366
- /* @__PURE__ */ jsx2(Button, {
367
- variant: "outline",
368
- onClick: () => p.onInspect(undefined),
369
- children: c.close
370
- })
371
- ]
372
- })
373
- })
374
- ]
375
- });
376
- };
377
-
378
- export { Tabs, TabsList, TabsTrigger, NotificationDeliveries2 };