@vicacha-devs/medusa-plugin-notifications 0.0.0-stage → 0.0.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.
- package/.medusa/server/src/admin/index.cjs +4215 -0
- package/.medusa/server/src/admin/index.js +4193 -0
- package/.medusa/server/src/api/admin/mpn/broadcasts/route.js +99 -0
- package/.medusa/server/src/api/admin/mpn/channels/route.js +109 -0
- package/.medusa/server/src/api/admin/mpn/logs/route.js +33 -0
- package/.medusa/server/src/api/admin/mpn/mappings/[id]/route.js +33 -0
- package/.medusa/server/src/api/admin/mpn/mappings/route.js +51 -0
- package/.medusa/server/src/api/admin/mpn/render-template/route.js +37 -0
- package/.medusa/server/src/api/admin/mpn/sandbox/route.js +36 -0
- package/.medusa/server/src/api/admin/mpn/send/route.js +135 -0
- package/.medusa/server/src/api/admin/mpn/templates/[id]/route.js +77 -0
- package/.medusa/server/src/api/admin/mpn/templates/route.js +71 -0
- package/.medusa/server/src/api/admin/plugin/route.js +4 -0
- package/.medusa/server/src/api/middlewares.js +28 -0
- package/.medusa/server/src/api/store/mpn/consent/route.js +37 -0
- package/.medusa/server/src/api/store/mpn/webhooks/[provider]/route.js +97 -0
- package/.medusa/server/src/api/store/plugin/route.js +4 -0
- package/.medusa/server/src/api/validators.js +118 -0
- package/.medusa/server/src/hooks/index.js +7 -0
- package/.medusa/server/src/hooks/use-mpn-channels.js +13 -0
- package/.medusa/server/src/hooks/use-mpn-dispatch.js +45 -0
- package/.medusa/server/src/hooks/use-mpn-mappings.js +21 -0
- package/.medusa/server/src/hooks/use-mpn-templates.js +34 -0
- package/.medusa/server/src/hooks/use-order-notifications-widget-state.js +79 -0
- package/.medusa/server/src/hooks/use-sdk-primitives.js +113 -0
- package/.medusa/server/src/index.js +14 -0
- package/.medusa/server/src/integrations/automations-action-handler.js +112 -0
- package/.medusa/server/src/jobs/abandoned-cart-recovery.js +123 -0
- package/.medusa/server/src/jobs/log-retention-and-broadcasts.js +15 -0
- package/.medusa/server/src/modules/notifications/i18n/index.js +65 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/ar.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/de.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/en.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/es.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/fr.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/it.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/nl.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/pl.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/pt.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/locales/tr.js +76 -0
- package/.medusa/server/src/modules/notifications/i18n/types.js +2 -0
- package/.medusa/server/src/modules/notifications/index.js +9 -0
- package/.medusa/server/src/modules/notifications/integrations/documents-and-b2b-resolver.js +129 -0
- package/.medusa/server/src/modules/notifications/migrations/Migration20261010000000.js +184 -0
- package/.medusa/server/src/modules/notifications/models/index.js +118 -0
- package/.medusa/server/src/modules/notifications/renderer/block-helpers.js +36 -0
- package/.medusa/server/src/modules/notifications/renderer/email.js +161 -0
- package/.medusa/server/src/modules/notifications/renderer/index.js +240 -0
- package/.medusa/server/src/modules/notifications/renderer/slack.js +114 -0
- package/.medusa/server/src/modules/notifications/renderer/telegram.js +99 -0
- package/.medusa/server/src/modules/notifications/renderer/whatsapp.js +91 -0
- package/.medusa/server/src/modules/notifications/service-helpers/channel-config.js +45 -0
- package/.medusa/server/src/modules/notifications/service-helpers/consent.js +65 -0
- package/.medusa/server/src/modules/notifications/service-helpers/delivery-log.js +29 -0
- package/.medusa/server/src/modules/notifications/service-helpers/event-conditions.js +46 -0
- package/.medusa/server/src/modules/notifications/service-helpers/external-templates.js +80 -0
- package/.medusa/server/src/modules/notifications/service-helpers/recipient-resolution.js +85 -0
- package/.medusa/server/src/modules/notifications/service-helpers/sender-profiles.js +29 -0
- package/.medusa/server/src/modules/notifications/service-helpers/template-blocks.js +81 -0
- package/.medusa/server/src/modules/notifications/service-helpers/template-catalog.js +129 -0
- package/.medusa/server/src/modules/notifications/service-helpers/template-render.js +65 -0
- package/.medusa/server/src/modules/notifications/service.js +340 -0
- package/.medusa/server/src/modules/notifications/types.js +2 -0
- package/.medusa/server/src/modules/notifications/utils/auth-presets.js +140 -0
- package/.medusa/server/src/modules/notifications/utils/interpolation.js +178 -0
- package/.medusa/server/src/modules/notifications/utils/security.js +312 -0
- package/.medusa/server/src/modules/notifications/utils/system-presets.js +651 -0
- package/.medusa/server/src/modules/notifications/utils/transformers.js +358 -0
- package/.medusa/server/src/providers/dummy-sandbox/index.js +96 -0
- package/.medusa/server/src/providers/email-smtp/index.js +187 -0
- package/.medusa/server/src/providers/index.js +7 -0
- package/.medusa/server/src/providers/slack/index.js +54 -0
- package/.medusa/server/src/providers/sms/index.js +254 -0
- package/.medusa/server/src/providers/telegram/index.js +119 -0
- package/.medusa/server/src/providers/whatsapp/index.js +371 -0
- package/.medusa/server/src/rbac.js +109 -0
- package/.medusa/server/src/sdk/client.js +186 -0
- package/.medusa/server/src/sdk/index.js +3 -0
- package/.medusa/server/src/sdk/query-keys.js +61 -0
- package/.medusa/server/src/subscribers/customer-and-document-events.js +33 -0
- package/.medusa/server/src/subscribers/fulfillment-and-inventory-events.js +30 -0
- package/.medusa/server/src/subscribers/order-events.js +28 -0
- package/.medusa/server/src/types/constants.js +129 -0
- package/.medusa/server/src/types/core.js +2 -0
- package/.medusa/server/src/types/domain.js +2 -0
- package/.medusa/server/src/types/enums.js +53 -0
- package/.medusa/server/src/types/errors.js +28 -0
- package/.medusa/server/src/types/hooks.js +2 -0
- package/.medusa/server/src/types/index.js +12 -0
- package/.medusa/server/src/types/providers.js +2 -0
- package/.medusa/server/src/types/records.js +2 -0
- package/.medusa/server/src/types/render.js +2 -0
- package/.medusa/server/src/types/sdk-api.js +2 -0
- package/.medusa/server/src/types/translations.js +2 -0
- package/.medusa/server/src/workflows/index.js +461 -0
- package/LICENSE +21 -0
- package/README.md +389 -2
- package/package.json +133 -3
- package/src/admin/README.md +123 -0
- package/src/admin/components/mpn/broadcast-consent-section.tsx +62 -0
- package/src/admin/components/mpn/broadcasts-tab.tsx +208 -0
- package/src/admin/components/mpn/channels-main-section.tsx +205 -0
- package/src/admin/components/mpn/channels-side-section.tsx +88 -0
- package/src/admin/components/mpn/channels-tab.tsx +130 -0
- package/src/admin/components/mpn/constants.ts +8 -0
- package/src/admin/components/mpn/delivery-logs-tab.tsx +70 -0
- package/src/admin/components/mpn/event-mapping-form.tsx +191 -0
- package/src/admin/components/mpn/event-mappings-tab.tsx +165 -0
- package/src/admin/components/mpn/header-bar.tsx +35 -0
- package/src/admin/components/mpn/index.ts +17 -0
- package/src/admin/components/mpn/overview-cards.tsx +103 -0
- package/src/admin/components/mpn/sandbox-tab.tsx +93 -0
- package/src/admin/components/mpn/template-editor-section.tsx +203 -0
- package/src/admin/components/mpn/template-preview-section.tsx +122 -0
- package/src/admin/components/mpn/templates-list-section.tsx +115 -0
- package/src/admin/components/mpn/templates-tab.tsx +188 -0
- package/src/admin/components/mpn/use-notification-studio.ts +84 -0
- package/src/admin/components/rbac-guard.tsx +153 -0
- package/src/admin/i18n/README.md +134 -0
- package/src/admin/i18n/index.ts +23 -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/mpn/broadcasts/page.tsx +75 -0
- package/src/admin/routes/mpn/channels/page.tsx +66 -0
- package/src/admin/routes/mpn/logs/page.tsx +50 -0
- package/src/admin/routes/mpn/mappings/page.tsx +62 -0
- package/src/admin/routes/mpn/page.tsx +200 -0
- package/src/admin/routes/mpn/sandbox/page.tsx +53 -0
- package/src/admin/routes/mpn/templates/page.tsx +55 -0
- package/src/admin/tsconfig.json +23 -0
- package/src/admin/vite-env.d.ts +1 -0
- package/src/admin/widgets/order-notifications-widget.tsx +178 -0
- package/src/api/README.md +98 -0
- package/src/api/admin/mpn/broadcasts/route.ts +130 -0
- package/src/api/admin/mpn/channels/route.ts +143 -0
- package/src/api/admin/mpn/logs/route.ts +41 -0
- package/src/api/admin/mpn/mappings/[id]/route.ts +45 -0
- package/src/api/admin/mpn/mappings/route.ts +68 -0
- package/src/api/admin/mpn/render-template/route.ts +46 -0
- package/src/api/admin/mpn/sandbox/route.ts +51 -0
- package/src/api/admin/mpn/send/route.ts +163 -0
- package/src/api/admin/mpn/templates/[id]/route.ts +101 -0
- package/src/api/admin/mpn/templates/route.ts +99 -0
- package/src/api/admin/plugin/route.ts +5 -0
- package/src/api/middlewares.ts +42 -0
- package/src/api/store/mpn/consent/route.ts +45 -0
- package/src/api/store/mpn/webhooks/[provider]/route.ts +119 -0
- package/src/api/store/plugin/route.ts +5 -0
- package/src/api/validators.ts +149 -0
- package/src/hooks/index.ts +14 -0
- package/src/hooks/use-mpn-channels.ts +43 -0
- package/src/hooks/use-mpn-dispatch.ts +149 -0
- package/src/hooks/use-mpn-mappings.ts +75 -0
- package/src/hooks/use-mpn-templates.ts +120 -0
- package/src/hooks/use-order-notifications-widget-state.ts +103 -0
- package/src/hooks/use-sdk-primitives.ts +157 -0
- package/src/index.ts +16 -0
- package/src/integrations/automations-action-handler.ts +156 -0
- package/src/jobs/README.md +41 -0
- package/src/jobs/abandoned-cart-recovery.ts +152 -0
- package/src/jobs/log-retention-and-broadcasts.ts +23 -0
- package/src/links/README.md +52 -0
- package/src/modules/README.md +99 -0
- package/src/modules/notifications/i18n/index.ts +83 -0
- package/src/modules/notifications/i18n/locales/ar.ts +84 -0
- package/src/modules/notifications/i18n/locales/de.ts +83 -0
- package/src/modules/notifications/i18n/locales/en.ts +84 -0
- package/src/modules/notifications/i18n/locales/es.ts +84 -0
- package/src/modules/notifications/i18n/locales/fr.ts +82 -0
- package/src/modules/notifications/i18n/locales/it.ts +82 -0
- package/src/modules/notifications/i18n/locales/nl.ts +83 -0
- package/src/modules/notifications/i18n/locales/pl.ts +84 -0
- package/src/modules/notifications/i18n/locales/pt.ts +82 -0
- package/src/modules/notifications/i18n/locales/tr.ts +86 -0
- package/src/modules/notifications/i18n/types.ts +1 -0
- package/src/modules/notifications/index.ts +10 -0
- package/src/modules/notifications/integrations/documents-and-b2b-resolver.ts +168 -0
- package/src/modules/notifications/migrations/Migration20261010000000.ts +185 -0
- package/src/modules/notifications/models/index.ts +125 -0
- package/src/modules/notifications/renderer/block-helpers.ts +51 -0
- package/src/modules/notifications/renderer/email.ts +281 -0
- package/src/modules/notifications/renderer/index.ts +301 -0
- package/src/modules/notifications/renderer/slack.ts +168 -0
- package/src/modules/notifications/renderer/telegram.ts +161 -0
- package/src/modules/notifications/renderer/whatsapp.ts +156 -0
- package/src/modules/notifications/service-helpers/channel-config.ts +65 -0
- package/src/modules/notifications/service-helpers/consent.ts +88 -0
- package/src/modules/notifications/service-helpers/delivery-log.ts +56 -0
- package/src/modules/notifications/service-helpers/event-conditions.ts +66 -0
- package/src/modules/notifications/service-helpers/external-templates.ts +127 -0
- package/src/modules/notifications/service-helpers/recipient-resolution.ts +124 -0
- package/src/modules/notifications/service-helpers/sender-profiles.ts +34 -0
- package/src/modules/notifications/service-helpers/template-blocks.ts +116 -0
- package/src/modules/notifications/service-helpers/template-catalog.ts +170 -0
- package/src/modules/notifications/service-helpers/template-render.ts +113 -0
- package/src/modules/notifications/service.ts +589 -0
- package/src/modules/notifications/types.ts +1 -0
- package/src/modules/notifications/utils/auth-presets.ts +145 -0
- package/src/modules/notifications/utils/interpolation.ts +231 -0
- package/src/modules/notifications/utils/security.ts +378 -0
- package/src/modules/notifications/utils/system-presets.ts +695 -0
- package/src/modules/notifications/utils/transformers.ts +456 -0
- package/src/providers/README.md +92 -0
- package/src/providers/dummy-sandbox/index.ts +143 -0
- package/src/providers/email-smtp/index.ts +257 -0
- package/src/providers/index.ts +38 -0
- package/src/providers/slack/index.ts +82 -0
- package/src/providers/sms/index.ts +342 -0
- package/src/providers/telegram/index.ts +181 -0
- package/src/providers/whatsapp/index.ts +505 -0
- package/src/rbac.ts +123 -0
- package/src/sdk/client.ts +319 -0
- package/src/sdk/index.ts +48 -0
- package/src/sdk/query-keys.ts +89 -0
- package/src/subscribers/README.md +50 -0
- package/src/subscribers/customer-and-document-events.ts +36 -0
- package/src/subscribers/fulfillment-and-inventory-events.ts +35 -0
- package/src/subscribers/order-events.ts +31 -0
- package/src/types/constants.ts +143 -0
- package/src/types/core.ts +96 -0
- package/src/types/domain.ts +84 -0
- package/src/types/enums.ts +73 -0
- package/src/types/errors.ts +32 -0
- package/src/types/hooks.ts +48 -0
- package/src/types/index.ts +11 -0
- package/src/types/providers.ts +96 -0
- package/src/types/records.ts +100 -0
- package/src/types/render.ts +74 -0
- package/src/types/sdk-api.ts +228 -0
- package/src/types/translations.ts +75 -0
- package/src/workflows/README.md +67 -0
- package/src/workflows/index.ts +619 -0
- package/tsconfig.json +40 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from "./broadcast-consent-section"
|
|
2
|
+
export * from "./broadcasts-tab"
|
|
3
|
+
export * from "./channels-main-section"
|
|
4
|
+
export * from "./channels-side-section"
|
|
5
|
+
export * from "./channels-tab"
|
|
6
|
+
export * from "./constants"
|
|
7
|
+
export * from "./delivery-logs-tab"
|
|
8
|
+
export * from "./event-mapping-form"
|
|
9
|
+
export * from "./event-mappings-tab"
|
|
10
|
+
export * from "./header-bar"
|
|
11
|
+
export * from "./overview-cards"
|
|
12
|
+
export * from "./sandbox-tab"
|
|
13
|
+
export * from "./template-editor-section"
|
|
14
|
+
export * from "./template-preview-section"
|
|
15
|
+
export * from "./templates-list-section"
|
|
16
|
+
export * from "./templates-tab"
|
|
17
|
+
export * from "./use-notification-studio"
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Button, clx, Container, Heading, Skeleton, Text } from "@medusajs/ui"
|
|
2
|
+
import React from "react"
|
|
3
|
+
|
|
4
|
+
export type StatCardProps = {
|
|
5
|
+
title: string
|
|
6
|
+
value: number
|
|
7
|
+
icon: React.ReactNode
|
|
8
|
+
loading?: boolean
|
|
9
|
+
onClick?: () => void
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const StatCard: React.FC<StatCardProps> = ({
|
|
13
|
+
title,
|
|
14
|
+
value,
|
|
15
|
+
icon,
|
|
16
|
+
loading = false,
|
|
17
|
+
onClick,
|
|
18
|
+
}) => {
|
|
19
|
+
return (
|
|
20
|
+
<Container
|
|
21
|
+
className={clx(
|
|
22
|
+
"p-0",
|
|
23
|
+
onClick
|
|
24
|
+
? "cursor-pointer hover:bg-ui-bg-subtle-hover transition-colors"
|
|
25
|
+
: ""
|
|
26
|
+
)}
|
|
27
|
+
onClick={onClick}
|
|
28
|
+
>
|
|
29
|
+
<div className="p-5">
|
|
30
|
+
<div className="flex items-center justify-between">
|
|
31
|
+
<Text className="text-ui-fg-subtle">{title}</Text>
|
|
32
|
+
|
|
33
|
+
<div className="flex items-center justify-center w-8 h-8 rounded-md bg-ui-bg-subtle">
|
|
34
|
+
{icon}
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
<div className="mt-3">
|
|
39
|
+
{loading ? (
|
|
40
|
+
<Skeleton className="h-8 w-16" />
|
|
41
|
+
) : (
|
|
42
|
+
<Heading level="h2">{value}</Heading>
|
|
43
|
+
)}
|
|
44
|
+
</div>
|
|
45
|
+
</div>
|
|
46
|
+
</Container>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type NavigationCardPosition =
|
|
51
|
+
| "top-left"
|
|
52
|
+
| "top-right"
|
|
53
|
+
| "middle-left"
|
|
54
|
+
| "middle-right"
|
|
55
|
+
| "bottom-left"
|
|
56
|
+
| "bottom-right"
|
|
57
|
+
|
|
58
|
+
export type NavigationCardProps = {
|
|
59
|
+
icon: React.ReactNode
|
|
60
|
+
title: string
|
|
61
|
+
description: string
|
|
62
|
+
onClick: () => void
|
|
63
|
+
position: NavigationCardPosition
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const NavigationCard: React.FC<NavigationCardProps> = ({
|
|
67
|
+
icon,
|
|
68
|
+
title,
|
|
69
|
+
description,
|
|
70
|
+
onClick,
|
|
71
|
+
position,
|
|
72
|
+
}) => {
|
|
73
|
+
const isBottom = position === "bottom-left" || position === "bottom-right"
|
|
74
|
+
const isLeft =
|
|
75
|
+
position === "top-left" ||
|
|
76
|
+
position === "middle-left" ||
|
|
77
|
+
position === "bottom-left"
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<Button
|
|
81
|
+
type="button"
|
|
82
|
+
variant="transparent"
|
|
83
|
+
className={clx(
|
|
84
|
+
"h-auto w-full justify-start text-left p-6 hover:bg-ui-bg-subtle-hover transition-colors rounded-none",
|
|
85
|
+
!isBottom ? "border-b border-ui-border-base" : "",
|
|
86
|
+
isLeft ? "md:border-r md:border-ui-border-base" : ""
|
|
87
|
+
)}
|
|
88
|
+
onClick={onClick}
|
|
89
|
+
>
|
|
90
|
+
<div className="flex items-start gap-x-3">
|
|
91
|
+
<div className="flex items-center justify-center w-8 h-8 rounded-md bg-ui-bg-subtle shrink-0">
|
|
92
|
+
{icon}
|
|
93
|
+
</div>
|
|
94
|
+
|
|
95
|
+
<div>
|
|
96
|
+
<Heading level="h3">{title}</Heading>
|
|
97
|
+
|
|
98
|
+
<Text className="text-ui-fg-subtle mt-1">{description}</Text>
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
</Button>
|
|
102
|
+
)
|
|
103
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { SectionRow } from "@medusajs/dashboard/components"
|
|
2
|
+
import {
|
|
3
|
+
Badge,
|
|
4
|
+
Button,
|
|
5
|
+
Container,
|
|
6
|
+
Heading,
|
|
7
|
+
StatusBadge,
|
|
8
|
+
Table,
|
|
9
|
+
Text,
|
|
10
|
+
Toaster,
|
|
11
|
+
toast,
|
|
12
|
+
} from "@medusajs/ui"
|
|
13
|
+
import React from "react"
|
|
14
|
+
import { useTranslation } from "react-i18next"
|
|
15
|
+
import { useClearMpnSandbox } from "../../../hooks"
|
|
16
|
+
|
|
17
|
+
interface DummySandboxTabProps {
|
|
18
|
+
sandboxMessages: Array<Record<string, any>>
|
|
19
|
+
onRefresh: () => Promise<void>
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const DummySandboxTab: React.FC<DummySandboxTabProps> = ({
|
|
23
|
+
sandboxMessages,
|
|
24
|
+
onRefresh,
|
|
25
|
+
}) => {
|
|
26
|
+
const { t } = useTranslation()
|
|
27
|
+
const clearSandboxMutation = useClearMpnSandbox()
|
|
28
|
+
|
|
29
|
+
const handleClearSandbox = async () => {
|
|
30
|
+
try {
|
|
31
|
+
await clearSandboxMutation.mutateAsync()
|
|
32
|
+
toast.success(t("sandbox.clearButton"))
|
|
33
|
+
await onRefresh()
|
|
34
|
+
} catch (err: any) {
|
|
35
|
+
toast.error(err?.message || t("messages.loadStudioError"))
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Container className="divide-y p-0">
|
|
41
|
+
<Toaster />
|
|
42
|
+
<div className="flex items-center justify-between px-6 py-4">
|
|
43
|
+
<div>
|
|
44
|
+
<Heading level="h2">{t("sandbox.title")}</Heading>
|
|
45
|
+
<Text className="text-ui-fg-subtle text-xs mt-1">
|
|
46
|
+
{t("sandbox.subtitle")}
|
|
47
|
+
</Text>
|
|
48
|
+
</div>
|
|
49
|
+
<Button
|
|
50
|
+
size="small"
|
|
51
|
+
variant="secondary"
|
|
52
|
+
isLoading={clearSandboxMutation.isPending}
|
|
53
|
+
onClick={() => void handleClearSandbox()}
|
|
54
|
+
>
|
|
55
|
+
{t("sandbox.clearButton")}
|
|
56
|
+
</Button>
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
<SectionRow title={t("sandbox.colOtp")} value={sandboxMessages.length} />
|
|
60
|
+
|
|
61
|
+
<Table>
|
|
62
|
+
<Table.Header>
|
|
63
|
+
<Table.Row>
|
|
64
|
+
<Table.HeaderCell>{t("sandbox.colChannel")}</Table.HeaderCell>
|
|
65
|
+
<Table.HeaderCell>{t("sandbox.colRecipient")}</Table.HeaderCell>
|
|
66
|
+
<Table.HeaderCell>{t("sandbox.colOtp")}</Table.HeaderCell>
|
|
67
|
+
<Table.HeaderCell>{t("sandbox.colBody")}</Table.HeaderCell>
|
|
68
|
+
</Table.Row>
|
|
69
|
+
</Table.Header>
|
|
70
|
+
<Table.Body>
|
|
71
|
+
{sandboxMessages.map((msg) => (
|
|
72
|
+
<Table.Row key={msg.id}>
|
|
73
|
+
<Table.Cell>
|
|
74
|
+
<Badge size="2xsmall" color="blue">
|
|
75
|
+
{msg.channel}
|
|
76
|
+
</Badge>
|
|
77
|
+
</Table.Cell>
|
|
78
|
+
<Table.Cell>{msg.recipient}</Table.Cell>
|
|
79
|
+
<Table.Cell>
|
|
80
|
+
{msg.otp_code ? (
|
|
81
|
+
<StatusBadge color="green">{msg.otp_code}</StatusBadge>
|
|
82
|
+
) : (
|
|
83
|
+
"—"
|
|
84
|
+
)}
|
|
85
|
+
</Table.Cell>
|
|
86
|
+
<Table.Cell className="max-w-md truncate">{msg.body}</Table.Cell>
|
|
87
|
+
</Table.Row>
|
|
88
|
+
))}
|
|
89
|
+
</Table.Body>
|
|
90
|
+
</Table>
|
|
91
|
+
</Container>
|
|
92
|
+
)
|
|
93
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { SectionRow } from "@medusajs/dashboard/components"
|
|
2
|
+
import {
|
|
3
|
+
Badge,
|
|
4
|
+
Button,
|
|
5
|
+
Container,
|
|
6
|
+
Heading,
|
|
7
|
+
Input,
|
|
8
|
+
Label,
|
|
9
|
+
Text,
|
|
10
|
+
Textarea,
|
|
11
|
+
} from "@medusajs/ui"
|
|
12
|
+
import React from "react"
|
|
13
|
+
import { useTranslation } from "react-i18next"
|
|
14
|
+
import { BLOCK_TYPES } from "./constants"
|
|
15
|
+
import { TemplatePreviewSection } from "./template-preview-section"
|
|
16
|
+
|
|
17
|
+
export interface TemplateEditorSectionProps {
|
|
18
|
+
selectedTemplate: Record<string, any> | null
|
|
19
|
+
selectedBlocks: Array<Record<string, any>>
|
|
20
|
+
previewContextType: string
|
|
21
|
+
previewLocale: string
|
|
22
|
+
previewResult: Record<string, any> | null
|
|
23
|
+
isSaving?: boolean
|
|
24
|
+
onTemplateChange: (nextTemplate: Record<string, any>) => void
|
|
25
|
+
onAddBlock: (blockType: string) => void
|
|
26
|
+
onRemoveBlock: (index: number) => void
|
|
27
|
+
onSaveTemplate: () => void
|
|
28
|
+
onContextChange: (contextType: string) => void
|
|
29
|
+
onLocaleChange: (locale: string) => void
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const TemplateEditorSection: React.FC<TemplateEditorSectionProps> = ({
|
|
33
|
+
selectedTemplate,
|
|
34
|
+
selectedBlocks,
|
|
35
|
+
previewContextType,
|
|
36
|
+
previewLocale,
|
|
37
|
+
previewResult,
|
|
38
|
+
isSaving = false,
|
|
39
|
+
onTemplateChange,
|
|
40
|
+
onAddBlock,
|
|
41
|
+
onRemoveBlock,
|
|
42
|
+
onSaveTemplate,
|
|
43
|
+
onContextChange,
|
|
44
|
+
onLocaleChange,
|
|
45
|
+
}) => {
|
|
46
|
+
const { t } = useTranslation()
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<Container className="divide-y p-0 lg:col-span-7">
|
|
50
|
+
{selectedTemplate ? (
|
|
51
|
+
<>
|
|
52
|
+
<div className="flex items-center justify-between px-6 py-4">
|
|
53
|
+
<div>
|
|
54
|
+
<Heading level="h2">{selectedTemplate.label}</Heading>
|
|
55
|
+
<Text className="text-ui-fg-subtle text-xs mt-1">
|
|
56
|
+
ID: {selectedTemplate.id} ({selectedTemplate.channel} /{" "}
|
|
57
|
+
{selectedTemplate.mode})
|
|
58
|
+
</Text>
|
|
59
|
+
</div>
|
|
60
|
+
{selectedTemplate.source === "db" && (
|
|
61
|
+
<Button
|
|
62
|
+
size="small"
|
|
63
|
+
variant="primary"
|
|
64
|
+
isLoading={isSaving}
|
|
65
|
+
onClick={onSaveTemplate}
|
|
66
|
+
>
|
|
67
|
+
{t("templates.saveButton")}
|
|
68
|
+
</Button>
|
|
69
|
+
)}
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
<SectionRow
|
|
73
|
+
title={t("mappings.channelLabel")}
|
|
74
|
+
value={
|
|
75
|
+
<Badge size="2xsmall" color="blue">
|
|
76
|
+
{selectedTemplate.channel}
|
|
77
|
+
</Badge>
|
|
78
|
+
}
|
|
79
|
+
/>
|
|
80
|
+
|
|
81
|
+
{selectedTemplate.source === "db" && (
|
|
82
|
+
<div className="grid grid-cols-1 gap-4 px-6 py-4 md:grid-cols-2">
|
|
83
|
+
<div className="flex flex-col gap-y-2">
|
|
84
|
+
<Label size="small">{t("templates.subjectLabel")}</Label>
|
|
85
|
+
<Input
|
|
86
|
+
size="small"
|
|
87
|
+
value={selectedTemplate.subject || ""}
|
|
88
|
+
onChange={(e) =>
|
|
89
|
+
onTemplateChange({
|
|
90
|
+
...selectedTemplate,
|
|
91
|
+
subject: e.target.value,
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
/>
|
|
95
|
+
</div>
|
|
96
|
+
<div className="flex flex-col gap-y-2">
|
|
97
|
+
<Label size="small">{t("templates.metaTemplateLabel")}</Label>
|
|
98
|
+
<Input
|
|
99
|
+
size="small"
|
|
100
|
+
value={selectedTemplate.meta_template_name || ""}
|
|
101
|
+
onChange={(e) =>
|
|
102
|
+
onTemplateChange({
|
|
103
|
+
...selectedTemplate,
|
|
104
|
+
meta_template_name: e.target.value,
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
/>
|
|
108
|
+
</div>
|
|
109
|
+
</div>
|
|
110
|
+
)}
|
|
111
|
+
|
|
112
|
+
<div className="px-6 py-4">
|
|
113
|
+
{selectedTemplate.mode === "raw" ? (
|
|
114
|
+
<div className="flex flex-col gap-y-2">
|
|
115
|
+
<Label size="small">{t("templates.rawContentLabel")}</Label>
|
|
116
|
+
<Textarea
|
|
117
|
+
rows={5}
|
|
118
|
+
value={selectedTemplate.raw_content || ""}
|
|
119
|
+
disabled={selectedTemplate.source === "system"}
|
|
120
|
+
onChange={(e) =>
|
|
121
|
+
onTemplateChange({
|
|
122
|
+
...selectedTemplate,
|
|
123
|
+
raw_content: e.target.value,
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
/>
|
|
127
|
+
</div>
|
|
128
|
+
) : (
|
|
129
|
+
<div>
|
|
130
|
+
<div className="mb-3 flex flex-wrap items-center justify-between gap-2">
|
|
131
|
+
<Label size="small">
|
|
132
|
+
{t("templates.blockTreeLabel", {
|
|
133
|
+
count: selectedBlocks.length,
|
|
134
|
+
})}
|
|
135
|
+
</Label>
|
|
136
|
+
{selectedTemplate.source === "db" && (
|
|
137
|
+
<div className="flex flex-wrap gap-1">
|
|
138
|
+
{BLOCK_TYPES.slice(0, 6).map((bType) => (
|
|
139
|
+
<Button
|
|
140
|
+
key={bType}
|
|
141
|
+
size="small"
|
|
142
|
+
variant="secondary"
|
|
143
|
+
onClick={() => onAddBlock(bType)}
|
|
144
|
+
>
|
|
145
|
+
+ {bType}
|
|
146
|
+
</Button>
|
|
147
|
+
))}
|
|
148
|
+
</div>
|
|
149
|
+
)}
|
|
150
|
+
</div>
|
|
151
|
+
<div className="flex flex-col gap-y-2">
|
|
152
|
+
{selectedBlocks.map((blk, idx) => (
|
|
153
|
+
<div
|
|
154
|
+
key={blk.id || idx}
|
|
155
|
+
className="flex items-center justify-between rounded border border-ui-border-base p-2.5"
|
|
156
|
+
>
|
|
157
|
+
<div className="flex items-center gap-x-2">
|
|
158
|
+
<Badge size="2xsmall" color="purple">
|
|
159
|
+
{blk.type}
|
|
160
|
+
</Badge>
|
|
161
|
+
<Text className="text-xs">
|
|
162
|
+
{blk.metadata?.text ||
|
|
163
|
+
blk.metadata?.label ||
|
|
164
|
+
blk.metadata?.arrayKey ||
|
|
165
|
+
blk.metadata?.variant ||
|
|
166
|
+
"—"}
|
|
167
|
+
</Text>
|
|
168
|
+
</div>
|
|
169
|
+
{selectedTemplate.source === "db" && (
|
|
170
|
+
<Button
|
|
171
|
+
size="small"
|
|
172
|
+
variant="transparent"
|
|
173
|
+
onClick={() => onRemoveBlock(idx)}
|
|
174
|
+
>
|
|
175
|
+
{t("templates.removeBlock")}
|
|
176
|
+
</Button>
|
|
177
|
+
)}
|
|
178
|
+
</div>
|
|
179
|
+
))}
|
|
180
|
+
</div>
|
|
181
|
+
</div>
|
|
182
|
+
)}
|
|
183
|
+
</div>
|
|
184
|
+
|
|
185
|
+
<TemplatePreviewSection
|
|
186
|
+
templateId={selectedTemplate.id}
|
|
187
|
+
previewContextType={previewContextType}
|
|
188
|
+
previewLocale={previewLocale}
|
|
189
|
+
previewResult={previewResult}
|
|
190
|
+
onContextChange={onContextChange}
|
|
191
|
+
onLocaleChange={onLocaleChange}
|
|
192
|
+
/>
|
|
193
|
+
</>
|
|
194
|
+
) : (
|
|
195
|
+
<div className="px-6 py-8">
|
|
196
|
+
<Text className="text-ui-fg-subtle">
|
|
197
|
+
{t("templates.emptySelection")}
|
|
198
|
+
</Text>
|
|
199
|
+
</div>
|
|
200
|
+
)}
|
|
201
|
+
</Container>
|
|
202
|
+
)
|
|
203
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Badge, Heading, Select, Text } from "@medusajs/ui"
|
|
2
|
+
import React from "react"
|
|
3
|
+
import { useTranslation } from "react-i18next"
|
|
4
|
+
import { CONTEXT_TYPES, SUPPORTED_LOCALES } from "./constants"
|
|
5
|
+
|
|
6
|
+
export interface TemplatePreviewSectionProps {
|
|
7
|
+
templateId: string
|
|
8
|
+
previewContextType: string
|
|
9
|
+
previewLocale: string
|
|
10
|
+
previewResult: Record<string, any> | null
|
|
11
|
+
onContextChange: (contextType: string) => void
|
|
12
|
+
onLocaleChange: (locale: string) => void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const TemplatePreviewSection: React.FC<TemplatePreviewSectionProps> = ({
|
|
16
|
+
previewContextType,
|
|
17
|
+
previewLocale,
|
|
18
|
+
previewResult,
|
|
19
|
+
onContextChange,
|
|
20
|
+
onLocaleChange,
|
|
21
|
+
}) => {
|
|
22
|
+
const { t } = useTranslation()
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<div className="px-6 py-4">
|
|
26
|
+
<div className="mb-3 flex flex-wrap items-center justify-between gap-2">
|
|
27
|
+
<Heading level="h3">
|
|
28
|
+
{t("templates.previewTitle", {
|
|
29
|
+
locale: previewLocale.toUpperCase(),
|
|
30
|
+
})}
|
|
31
|
+
</Heading>
|
|
32
|
+
<div className="flex items-center gap-x-2">
|
|
33
|
+
<Select
|
|
34
|
+
size="small"
|
|
35
|
+
value={previewContextType}
|
|
36
|
+
onValueChange={onContextChange}
|
|
37
|
+
>
|
|
38
|
+
<Select.Trigger>
|
|
39
|
+
<Select.Value placeholder={t("templates.contextPlaceholder")} />
|
|
40
|
+
</Select.Trigger>
|
|
41
|
+
<Select.Content>
|
|
42
|
+
{CONTEXT_TYPES.map((ct) => (
|
|
43
|
+
<Select.Item key={ct} value={ct}>
|
|
44
|
+
{ct}
|
|
45
|
+
</Select.Item>
|
|
46
|
+
))}
|
|
47
|
+
</Select.Content>
|
|
48
|
+
</Select>
|
|
49
|
+
|
|
50
|
+
<Select
|
|
51
|
+
size="small"
|
|
52
|
+
value={previewLocale}
|
|
53
|
+
onValueChange={onLocaleChange}
|
|
54
|
+
>
|
|
55
|
+
<Select.Trigger>
|
|
56
|
+
<Select.Value placeholder={t("templates.localePlaceholder")} />
|
|
57
|
+
</Select.Trigger>
|
|
58
|
+
<Select.Content>
|
|
59
|
+
{SUPPORTED_LOCALES.map((loc) => (
|
|
60
|
+
<Select.Item key={loc} value={loc}>
|
|
61
|
+
{loc.toUpperCase()}
|
|
62
|
+
</Select.Item>
|
|
63
|
+
))}
|
|
64
|
+
</Select.Content>
|
|
65
|
+
</Select>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
|
|
69
|
+
{previewResult && (
|
|
70
|
+
<div className="rounded border border-ui-border-base bg-ui-bg-subtle p-4">
|
|
71
|
+
{previewResult.subject && (
|
|
72
|
+
<Text className="font-semibold mb-2">
|
|
73
|
+
{t("templates.subjectPrefix", {
|
|
74
|
+
subject: previewResult.subject,
|
|
75
|
+
})}
|
|
76
|
+
</Text>
|
|
77
|
+
)}
|
|
78
|
+
{previewResult.sms_options && (
|
|
79
|
+
<div className="mb-2 flex items-center gap-x-2">
|
|
80
|
+
<Badge size="2xsmall" color="green">
|
|
81
|
+
{t("templates.encodingBadge", {
|
|
82
|
+
encoding: previewResult.sms_options.encoding,
|
|
83
|
+
})}
|
|
84
|
+
</Badge>
|
|
85
|
+
<Badge size="2xsmall" color="blue">
|
|
86
|
+
{t("templates.segmentsBadge", {
|
|
87
|
+
segments: previewResult.sms_options.segments,
|
|
88
|
+
chars: previewResult.sms_options.character_count,
|
|
89
|
+
})}
|
|
90
|
+
</Badge>
|
|
91
|
+
</div>
|
|
92
|
+
)}
|
|
93
|
+
<pre className="whitespace-pre-wrap text-xs font-mono">
|
|
94
|
+
{previewResult.text}
|
|
95
|
+
</pre>
|
|
96
|
+
{previewResult.whatsapp_options?.buttons?.length > 0 && (
|
|
97
|
+
<div className="mt-3 flex gap-x-2">
|
|
98
|
+
{previewResult.whatsapp_options.buttons.map((btn: any) => (
|
|
99
|
+
<Badge key={btn.id} size="2xsmall" color="green">
|
|
100
|
+
{t("templates.waButtonPrefix", {
|
|
101
|
+
title: btn.title,
|
|
102
|
+
})}
|
|
103
|
+
</Badge>
|
|
104
|
+
))}
|
|
105
|
+
</div>
|
|
106
|
+
)}
|
|
107
|
+
{previewResult.telegram_options?.inline_keyboard?.length > 0 && (
|
|
108
|
+
<div className="mt-3 flex gap-x-2">
|
|
109
|
+
{previewResult.telegram_options.inline_keyboard
|
|
110
|
+
.flat()
|
|
111
|
+
.map((btn: any, i: number) => (
|
|
112
|
+
<Badge key={i} size="2xsmall" color="blue">
|
|
113
|
+
{t("templates.tgInlinePrefix", { text: btn.text })}
|
|
114
|
+
</Badge>
|
|
115
|
+
))}
|
|
116
|
+
</div>
|
|
117
|
+
)}
|
|
118
|
+
</div>
|
|
119
|
+
)}
|
|
120
|
+
</div>
|
|
121
|
+
)
|
|
122
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Badge,
|
|
3
|
+
Button,
|
|
4
|
+
Container,
|
|
5
|
+
Heading,
|
|
6
|
+
Select,
|
|
7
|
+
StatusBadge,
|
|
8
|
+
Table,
|
|
9
|
+
Text,
|
|
10
|
+
} from "@medusajs/ui"
|
|
11
|
+
import React from "react"
|
|
12
|
+
import { useTranslation } from "react-i18next"
|
|
13
|
+
import { CHANNELS } from "./constants"
|
|
14
|
+
|
|
15
|
+
export interface TemplatesListSectionProps {
|
|
16
|
+
templates: Array<Record<string, any>>
|
|
17
|
+
channelFilter: string
|
|
18
|
+
onChannelFilterChange: (channel: string) => void
|
|
19
|
+
onSelectTemplate: (templateId: string) => void
|
|
20
|
+
onClonePreset: (presetId: string) => void
|
|
21
|
+
isCloning?: boolean
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const TemplatesListSection: React.FC<TemplatesListSectionProps> = ({
|
|
25
|
+
templates,
|
|
26
|
+
channelFilter,
|
|
27
|
+
onChannelFilterChange,
|
|
28
|
+
onSelectTemplate,
|
|
29
|
+
onClonePreset,
|
|
30
|
+
isCloning = false,
|
|
31
|
+
}) => {
|
|
32
|
+
const { t } = useTranslation()
|
|
33
|
+
|
|
34
|
+
const filteredTemplates = templates.filter((tpl) =>
|
|
35
|
+
channelFilter === "all" ? true : tpl.channel === channelFilter
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<Container className="divide-y p-0 lg:col-span-5">
|
|
40
|
+
<div className="flex items-center justify-between px-6 py-4">
|
|
41
|
+
<Heading level="h2">{t("templates.title")}</Heading>
|
|
42
|
+
<div className="w-40">
|
|
43
|
+
<Select
|
|
44
|
+
size="small"
|
|
45
|
+
value={channelFilter}
|
|
46
|
+
onValueChange={onChannelFilterChange}
|
|
47
|
+
>
|
|
48
|
+
<Select.Trigger>
|
|
49
|
+
<Select.Value placeholder={t("templates.filterChannel")} />
|
|
50
|
+
</Select.Trigger>
|
|
51
|
+
<Select.Content>
|
|
52
|
+
<Select.Item value="all">
|
|
53
|
+
{t("templates.allChannels")}
|
|
54
|
+
</Select.Item>
|
|
55
|
+
{CHANNELS.map((ch) => (
|
|
56
|
+
<Select.Item key={ch} value={ch}>
|
|
57
|
+
{ch.toUpperCase()}
|
|
58
|
+
</Select.Item>
|
|
59
|
+
))}
|
|
60
|
+
</Select.Content>
|
|
61
|
+
</Select>
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
|
|
65
|
+
<Table>
|
|
66
|
+
<Table.Body>
|
|
67
|
+
{filteredTemplates.map((tpl) => (
|
|
68
|
+
<Table.Row key={tpl.id}>
|
|
69
|
+
<Table.Cell className="py-3">
|
|
70
|
+
<div className="flex items-center gap-x-2">
|
|
71
|
+
<Badge size="2xsmall" color="blue">
|
|
72
|
+
{tpl.channel}
|
|
73
|
+
</Badge>
|
|
74
|
+
<StatusBadge
|
|
75
|
+
color={tpl.source === "system" ? "grey" : "green"}
|
|
76
|
+
>
|
|
77
|
+
{tpl.source}
|
|
78
|
+
</StatusBadge>
|
|
79
|
+
<Text size="small" weight="plus">
|
|
80
|
+
{tpl.label}
|
|
81
|
+
</Text>
|
|
82
|
+
</div>
|
|
83
|
+
<Text className="text-ui-fg-subtle text-xs mt-1">
|
|
84
|
+
{tpl.name} ·{" "}
|
|
85
|
+
{t("templates.modeLabel", { mode: tpl.mode })}
|
|
86
|
+
</Text>
|
|
87
|
+
</Table.Cell>
|
|
88
|
+
<Table.Cell className="py-3 text-right">
|
|
89
|
+
<div className="flex items-center justify-end gap-x-2">
|
|
90
|
+
<Button
|
|
91
|
+
size="small"
|
|
92
|
+
variant="secondary"
|
|
93
|
+
onClick={() => onSelectTemplate(tpl.id)}
|
|
94
|
+
>
|
|
95
|
+
{t("templates.inspectPreview")}
|
|
96
|
+
</Button>
|
|
97
|
+
{tpl.source === "system" && (
|
|
98
|
+
<Button
|
|
99
|
+
size="small"
|
|
100
|
+
variant="primary"
|
|
101
|
+
isLoading={isCloning}
|
|
102
|
+
onClick={() => onClonePreset(tpl.id)}
|
|
103
|
+
>
|
|
104
|
+
{t("templates.cloneToDb")}
|
|
105
|
+
</Button>
|
|
106
|
+
)}
|
|
107
|
+
</div>
|
|
108
|
+
</Table.Cell>
|
|
109
|
+
</Table.Row>
|
|
110
|
+
))}
|
|
111
|
+
</Table.Body>
|
|
112
|
+
</Table>
|
|
113
|
+
</Container>
|
|
114
|
+
)
|
|
115
|
+
}
|