@agent-native/dispatch 0.17.3 → 0.18.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/dist/actions/provider-api-register.d.ts +8 -8
- package/dist/client/transactional-emails.d.ts +57 -0
- package/dist/client/transactional-emails.d.ts.map +1 -0
- package/dist/client/transactional-emails.js +116 -0
- package/dist/client/transactional-emails.js.map +1 -0
- package/dist/components/layout/Layout.d.ts.map +1 -1
- package/dist/components/layout/Layout.js +8 -1
- package/dist/components/layout/Layout.js.map +1 -1
- package/dist/components/transactional-email-activity.d.ts +24 -0
- package/dist/components/transactional-email-activity.d.ts.map +1 -0
- package/dist/components/transactional-email-activity.js +31 -0
- package/dist/components/transactional-email-activity.js.map +1 -0
- package/dist/components/transactional-email-metrics.d.ts +40 -0
- package/dist/components/transactional-email-metrics.d.ts.map +1 -0
- package/dist/components/transactional-email-metrics.js +44 -0
- package/dist/components/transactional-email-metrics.js.map +1 -0
- package/dist/components/transactional-email-preview.d.ts +7 -0
- package/dist/components/transactional-email-preview.d.ts.map +1 -0
- package/dist/components/transactional-email-preview.js +41 -0
- package/dist/components/transactional-email-preview.js.map +1 -0
- package/dist/routes/index.d.ts.map +1 -1
- package/dist/routes/index.js +2 -0
- package/dist/routes/index.js.map +1 -1
- package/dist/routes/pages/transactional-email.$appId.$id.d.ts +5 -0
- package/dist/routes/pages/transactional-email.$appId.$id.d.ts.map +1 -0
- package/dist/routes/pages/transactional-email.$appId.$id.js +144 -0
- package/dist/routes/pages/transactional-email.$appId.$id.js.map +1 -0
- package/dist/routes/pages/transactional-email.d.ts +5 -0
- package/dist/routes/pages/transactional-email.d.ts.map +1 -0
- package/dist/routes/pages/transactional-email.js +139 -0
- package/dist/routes/pages/transactional-email.js.map +1 -0
- package/package.json +2 -2
- package/src/client/transactional-emails.spec.ts +91 -0
- package/src/client/transactional-emails.ts +201 -0
- package/src/components/layout/Layout.tsx +8 -0
- package/src/components/transactional-email-activity.tsx +102 -0
- package/src/components/transactional-email-metrics.tsx +127 -0
- package/src/components/transactional-email-preview.tsx +88 -0
- package/src/routes/index.ts +5 -0
- package/src/routes/pages/transactional-email.$appId.$id.tsx +362 -0
- package/src/routes/pages/transactional-email.tsx +571 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { useT } from "@agent-native/core/client/i18n";
|
|
2
|
+
|
|
3
|
+
import { Skeleton } from "./ui/skeleton";
|
|
4
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "./ui/tooltip";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Shared between the transactional email list and detail pages so both
|
|
8
|
+
* render the same "unknown vs. zero" and provider-availability rules.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export interface EmailEngagement {
|
|
12
|
+
templateId: string;
|
|
13
|
+
delivered: number;
|
|
14
|
+
uniqueOpens: number;
|
|
15
|
+
uniqueClicks: number;
|
|
16
|
+
/** null when nothing was delivered in the window, so there is no rate yet. */
|
|
17
|
+
openRate: number | null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type ProviderMetricsResult<T> =
|
|
21
|
+
| { available: true; data: T }
|
|
22
|
+
| { available: false; reason: string };
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Renders a metric the backend could not read. "Unknown" and "zero" must stay
|
|
26
|
+
* visibly different — a dash with a reason is the only honest rendering.
|
|
27
|
+
*/
|
|
28
|
+
export function UnknownMetric({ reason }: { reason: string }) {
|
|
29
|
+
return (
|
|
30
|
+
<Tooltip>
|
|
31
|
+
<TooltipTrigger asChild>
|
|
32
|
+
<span className="cursor-help text-muted-foreground underline decoration-dotted underline-offset-2">
|
|
33
|
+
—
|
|
34
|
+
</span>
|
|
35
|
+
</TooltipTrigger>
|
|
36
|
+
<TooltipContent className="max-w-64">{reason}</TooltipContent>
|
|
37
|
+
</Tooltip>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function SendsCell({
|
|
42
|
+
sent,
|
|
43
|
+
failed,
|
|
44
|
+
}: {
|
|
45
|
+
sent: number | null;
|
|
46
|
+
failed: number | null;
|
|
47
|
+
}) {
|
|
48
|
+
const t = useT();
|
|
49
|
+
if (sent === null) {
|
|
50
|
+
return (
|
|
51
|
+
<UnknownMetric reason={t("dispatch.transactionalEmail.sendLogUnread")} />
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
return (
|
|
55
|
+
<span className="tabular-nums">
|
|
56
|
+
{sent}
|
|
57
|
+
{failed !== null && failed > 0 ? (
|
|
58
|
+
<span className="ml-2 text-xs text-destructive">
|
|
59
|
+
{t("dispatch.transactionalEmail.failedCount", { count: failed })}
|
|
60
|
+
</span>
|
|
61
|
+
) : null}
|
|
62
|
+
{failed === null ? (
|
|
63
|
+
<span className="ml-2 text-xs text-muted-foreground">
|
|
64
|
+
{t("dispatch.transactionalEmail.failuresUnknown")}
|
|
65
|
+
</span>
|
|
66
|
+
) : null}
|
|
67
|
+
</span>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function OpenRateCell({
|
|
72
|
+
engagement,
|
|
73
|
+
unavailableReason,
|
|
74
|
+
loading,
|
|
75
|
+
}: {
|
|
76
|
+
engagement: EmailEngagement | undefined;
|
|
77
|
+
unavailableReason: string | null;
|
|
78
|
+
loading: boolean;
|
|
79
|
+
}) {
|
|
80
|
+
const t = useT();
|
|
81
|
+
if (unavailableReason) {
|
|
82
|
+
return <UnknownMetric reason={unavailableReason} />;
|
|
83
|
+
}
|
|
84
|
+
if (loading) return <Skeleton className="h-4 w-10" />;
|
|
85
|
+
if (!engagement) {
|
|
86
|
+
return (
|
|
87
|
+
<UnknownMetric
|
|
88
|
+
reason={t("dispatch.transactionalEmail.noProviderRecord")}
|
|
89
|
+
/>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
if (engagement.openRate === null) {
|
|
93
|
+
return (
|
|
94
|
+
<span className="text-xs text-muted-foreground">
|
|
95
|
+
{t("dispatch.transactionalEmail.noDeliveredMail")}
|
|
96
|
+
</span>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
return (
|
|
100
|
+
<span className="tabular-nums">
|
|
101
|
+
{`${(engagement.openRate * 100).toFixed(1)}%`}
|
|
102
|
+
</span>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function LastSentCell({
|
|
107
|
+
lastSentAt,
|
|
108
|
+
sent,
|
|
109
|
+
}: {
|
|
110
|
+
lastSentAt: number | null;
|
|
111
|
+
sent: number | null;
|
|
112
|
+
}) {
|
|
113
|
+
const t = useT();
|
|
114
|
+
if (lastSentAt !== null) {
|
|
115
|
+
return <>{new Date(lastSentAt).toLocaleString()}</>;
|
|
116
|
+
}
|
|
117
|
+
if (sent === 0) {
|
|
118
|
+
return (
|
|
119
|
+
<span className="text-xs text-muted-foreground">
|
|
120
|
+
{t("dispatch.transactionalEmail.neverSent")}
|
|
121
|
+
</span>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
return (
|
|
125
|
+
<UnknownMetric reason={t("dispatch.transactionalEmail.lastSentUnknown")} />
|
|
126
|
+
);
|
|
127
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { useActionQuery } from "@agent-native/core/client/hooks";
|
|
2
|
+
import { useT } from "@agent-native/core/client/i18n";
|
|
3
|
+
import { IconAlertTriangle } from "@tabler/icons-react";
|
|
4
|
+
import { useQuery } from "@tanstack/react-query";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
fetchEmailPreview,
|
|
8
|
+
type EmailPreview,
|
|
9
|
+
} from "../client/transactional-emails";
|
|
10
|
+
import { Alert, AlertDescription, AlertTitle } from "./ui/alert";
|
|
11
|
+
import { Skeleton } from "./ui/skeleton";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The "core" app id means the email was read from Dispatch's own local
|
|
15
|
+
* catalog (see transactional-email.tsx), not a cross-app fetch, so its
|
|
16
|
+
* preview must render the same way — Dispatch always has the definition
|
|
17
|
+
* registered locally and a cross-app fetch would have no real appPath to hit.
|
|
18
|
+
*/
|
|
19
|
+
function useEmailPreviewQuery(appId: string, appPath: string, id: string) {
|
|
20
|
+
const isCore = appId === "core";
|
|
21
|
+
const local = useActionQuery<EmailPreview>(
|
|
22
|
+
"render-transactional-email-preview",
|
|
23
|
+
{ id },
|
|
24
|
+
{ enabled: isCore, retry: false },
|
|
25
|
+
);
|
|
26
|
+
const remote = useQuery({
|
|
27
|
+
queryKey: ["transactional-email-preview", appPath, id],
|
|
28
|
+
queryFn: () => fetchEmailPreview(appPath, id),
|
|
29
|
+
enabled: !isCore,
|
|
30
|
+
retry: false,
|
|
31
|
+
});
|
|
32
|
+
return isCore ? local : remote;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function EmailPreviewPane({
|
|
36
|
+
appId,
|
|
37
|
+
appPath,
|
|
38
|
+
id,
|
|
39
|
+
name,
|
|
40
|
+
}: {
|
|
41
|
+
appId: string;
|
|
42
|
+
appPath: string;
|
|
43
|
+
id: string;
|
|
44
|
+
name: string;
|
|
45
|
+
}) {
|
|
46
|
+
const t = useT();
|
|
47
|
+
const preview = useEmailPreviewQuery(appId, appPath, id);
|
|
48
|
+
|
|
49
|
+
if (preview.isError) {
|
|
50
|
+
return (
|
|
51
|
+
<Alert variant="destructive">
|
|
52
|
+
<IconAlertTriangle className="size-4" />
|
|
53
|
+
<AlertTitle>
|
|
54
|
+
{t("dispatch.transactionalEmail.previewFailed")}
|
|
55
|
+
</AlertTitle>
|
|
56
|
+
<AlertDescription>
|
|
57
|
+
{preview.error instanceof Error
|
|
58
|
+
? preview.error.message
|
|
59
|
+
: String(preview.error)}
|
|
60
|
+
</AlertDescription>
|
|
61
|
+
</Alert>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
if (preview.isLoading || !preview.data) {
|
|
65
|
+
return <Skeleton className="h-96 w-full" />;
|
|
66
|
+
}
|
|
67
|
+
return (
|
|
68
|
+
<div className="space-y-3">
|
|
69
|
+
<div>
|
|
70
|
+
<div className="text-xs text-muted-foreground">
|
|
71
|
+
{t("dispatch.transactionalEmail.subject")}
|
|
72
|
+
</div>
|
|
73
|
+
<div className="text-sm font-medium text-foreground">
|
|
74
|
+
{preview.data.subject}
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
{/* sandbox="" (no allow-scripts) keeps arbitrary email HTML from
|
|
78
|
+
running script in the Dispatch origin. */}
|
|
79
|
+
<iframe
|
|
80
|
+
title={t("dispatch.transactionalEmail.previewFrameTitle", { name })}
|
|
81
|
+
sandbox=""
|
|
82
|
+
srcDoc={preview.data.html}
|
|
83
|
+
// guard:allow-raw-color — the frame previews email HTML, which renders on white in mail clients regardless of app theme.
|
|
84
|
+
className="h-96 w-full rounded-xl border bg-white"
|
|
85
|
+
/>
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
}
|
package/src/routes/index.ts
CHANGED
|
@@ -47,6 +47,11 @@ export const dispatchRoutes: RouteConfig = [
|
|
|
47
47
|
route("workspace", "./pages/workspace.js"),
|
|
48
48
|
route("messaging", "./pages/messaging.js"),
|
|
49
49
|
route("destinations", "./pages/destinations.js"),
|
|
50
|
+
route("transactional-email", "./pages/transactional-email.js"),
|
|
51
|
+
route(
|
|
52
|
+
"transactional-email/:appId/:id",
|
|
53
|
+
"./pages/transactional-email.$appId.$id.js",
|
|
54
|
+
),
|
|
50
55
|
route("identities", "./pages/identities.js"),
|
|
51
56
|
route("approval", "./pages/approval.js"),
|
|
52
57
|
route("approvals", "./pages/approvals.js"),
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import { callAction, useActionQuery } from "@agent-native/core/client/hooks";
|
|
2
|
+
import { useT } from "@agent-native/core/client/i18n";
|
|
3
|
+
import { IconAlertTriangle, IconArrowLeft } from "@tabler/icons-react";
|
|
4
|
+
import { useQueries, useQuery } from "@tanstack/react-query";
|
|
5
|
+
import { useMemo } from "react";
|
|
6
|
+
import { Link, useParams } from "react-router";
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
aggregateSharedEmails,
|
|
10
|
+
callAppAction,
|
|
11
|
+
fetchAppEmailCatalog,
|
|
12
|
+
type AppEmailCatalog,
|
|
13
|
+
type AppTransactionalEmail,
|
|
14
|
+
type LocalTransactionalEmailCatalog,
|
|
15
|
+
} from "../../client/transactional-emails";
|
|
16
|
+
import { ActionQueryError } from "../../components/action-query-error";
|
|
17
|
+
import { DispatchShell } from "../../components/dispatch-shell";
|
|
18
|
+
import {
|
|
19
|
+
ActivityTable,
|
|
20
|
+
type EmailActivityEntry,
|
|
21
|
+
} from "../../components/transactional-email-activity";
|
|
22
|
+
import {
|
|
23
|
+
OpenRateCell,
|
|
24
|
+
SendsCell,
|
|
25
|
+
LastSentCell,
|
|
26
|
+
type EmailEngagement,
|
|
27
|
+
type ProviderMetricsResult,
|
|
28
|
+
} from "../../components/transactional-email-metrics";
|
|
29
|
+
import { EmailPreviewPane } from "../../components/transactional-email-preview";
|
|
30
|
+
import { Alert, AlertDescription, AlertTitle } from "../../components/ui/alert";
|
|
31
|
+
import { Button } from "../../components/ui/button";
|
|
32
|
+
import { Skeleton } from "../../components/ui/skeleton";
|
|
33
|
+
|
|
34
|
+
export function meta() {
|
|
35
|
+
return [{ title: "Transactional email detail — Dispatch" }];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const WINDOW_DAYS = 30;
|
|
39
|
+
const ACTIVITY_LIMIT = 50;
|
|
40
|
+
|
|
41
|
+
interface WorkspaceAppRef {
|
|
42
|
+
id: string;
|
|
43
|
+
name: string;
|
|
44
|
+
path: string;
|
|
45
|
+
status?: "ready" | "pending";
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Resolves the one email this page shows, plus the app name/path to display.
|
|
50
|
+
* The "core" appId is Dispatch's own registry, not a cross-app fetch — see
|
|
51
|
+
* the same split in transactional-email.tsx.
|
|
52
|
+
*/
|
|
53
|
+
function useEmailDetail(appId: string, id: string) {
|
|
54
|
+
const isCore = appId === "core";
|
|
55
|
+
const t = useT();
|
|
56
|
+
|
|
57
|
+
const localQuery = useActionQuery<LocalTransactionalEmailCatalog>(
|
|
58
|
+
"list-transactional-emails",
|
|
59
|
+
{ windowDays: WINDOW_DAYS },
|
|
60
|
+
{ enabled: isCore },
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const appsQuery = useActionQuery<WorkspaceAppRef[]>("list-workspace-apps", {
|
|
64
|
+
includeAgentCards: false,
|
|
65
|
+
});
|
|
66
|
+
const readyApps = useMemo(
|
|
67
|
+
() =>
|
|
68
|
+
(appsQuery.data ?? []).filter(
|
|
69
|
+
(candidate) => candidate.status !== "pending",
|
|
70
|
+
),
|
|
71
|
+
[appsQuery.data],
|
|
72
|
+
);
|
|
73
|
+
const app = useMemo(
|
|
74
|
+
() => readyApps.find((candidate) => candidate.id === appId),
|
|
75
|
+
[readyApps, appId],
|
|
76
|
+
);
|
|
77
|
+
const coreCatalogQueries = useQueries({
|
|
78
|
+
queries: readyApps.map((candidate) => ({
|
|
79
|
+
queryKey: ["transactional-email-catalog", candidate.id, WINDOW_DAYS],
|
|
80
|
+
queryFn: () => fetchAppEmailCatalog(candidate, WINDOW_DAYS),
|
|
81
|
+
enabled: isCore,
|
|
82
|
+
staleTime: Infinity,
|
|
83
|
+
})),
|
|
84
|
+
});
|
|
85
|
+
const remoteQuery = useQuery({
|
|
86
|
+
queryKey: ["transactional-email-catalog", appId, WINDOW_DAYS],
|
|
87
|
+
queryFn: () => fetchAppEmailCatalog(app!, WINDOW_DAYS),
|
|
88
|
+
enabled: !isCore && !!app,
|
|
89
|
+
staleTime: Infinity,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
if (isCore) {
|
|
93
|
+
const appCatalogs = coreCatalogQueries
|
|
94
|
+
.map((query) => query.data)
|
|
95
|
+
.filter((catalog): catalog is AppEmailCatalog => Boolean(catalog));
|
|
96
|
+
const aggregate = localQuery.data
|
|
97
|
+
? aggregateSharedEmails(localQuery.data, appCatalogs)
|
|
98
|
+
: undefined;
|
|
99
|
+
const email = aggregate?.emails.find((candidate) => candidate.id === id);
|
|
100
|
+
const catalogError = coreCatalogQueries.find(
|
|
101
|
+
(query) => query.data?.error || query.data?.statsError,
|
|
102
|
+
)?.data;
|
|
103
|
+
const queryError = coreCatalogQueries.find((query) => query.isError)?.error;
|
|
104
|
+
const isLoading =
|
|
105
|
+
localQuery.isLoading ||
|
|
106
|
+
appsQuery.isLoading ||
|
|
107
|
+
coreCatalogQueries.some((query) => query.isLoading);
|
|
108
|
+
const isError =
|
|
109
|
+
localQuery.isError || appsQuery.isError || Boolean(queryError);
|
|
110
|
+
return {
|
|
111
|
+
isLoading,
|
|
112
|
+
isError,
|
|
113
|
+
error: localQuery.error ?? appsQuery.error ?? queryError,
|
|
114
|
+
onRetry: () => {
|
|
115
|
+
void localQuery.refetch();
|
|
116
|
+
void appsQuery.refetch();
|
|
117
|
+
for (const query of coreCatalogQueries) void query.refetch();
|
|
118
|
+
},
|
|
119
|
+
appName: t("dispatch.transactionalEmail.sharedTitle"),
|
|
120
|
+
appPath: t("dispatch.transactionalEmail.sharedSubtitle"),
|
|
121
|
+
email,
|
|
122
|
+
catalogError:
|
|
123
|
+
aggregate?.statsError ??
|
|
124
|
+
catalogError?.error ??
|
|
125
|
+
catalogError?.statsError ??
|
|
126
|
+
null,
|
|
127
|
+
notFound: !isLoading && !isError && !email,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const notFound =
|
|
132
|
+
!appsQuery.isLoading &&
|
|
133
|
+
!appsQuery.isError &&
|
|
134
|
+
(!app ||
|
|
135
|
+
(!remoteQuery.isLoading &&
|
|
136
|
+
!remoteQuery.isError &&
|
|
137
|
+
!remoteQuery.data?.error &&
|
|
138
|
+
!remoteQuery.data?.emails.some((candidate) => candidate.id === id)));
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
isLoading: appsQuery.isLoading || remoteQuery.isLoading,
|
|
142
|
+
isError: appsQuery.isError || remoteQuery.isError,
|
|
143
|
+
error: appsQuery.error ?? remoteQuery.error,
|
|
144
|
+
onRetry: () => {
|
|
145
|
+
void appsQuery.refetch();
|
|
146
|
+
void remoteQuery.refetch();
|
|
147
|
+
},
|
|
148
|
+
appName: app?.name ?? appId,
|
|
149
|
+
appPath: app?.path ?? "",
|
|
150
|
+
email: remoteQuery.data?.emails.find((candidate) => candidate.id === id),
|
|
151
|
+
catalogError: remoteQuery.data?.error ?? null,
|
|
152
|
+
notFound,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export default function TransactionalEmailDetailRoute() {
|
|
157
|
+
const t = useT();
|
|
158
|
+
const params = useParams<{ appId: string; id: string }>();
|
|
159
|
+
const appId = params.appId ?? "";
|
|
160
|
+
const id = params.id ?? "";
|
|
161
|
+
|
|
162
|
+
const detail = useEmailDetail(appId, id);
|
|
163
|
+
|
|
164
|
+
const sharedProviderReason = t(
|
|
165
|
+
"dispatch.transactionalEmail.sharedProviderMetricsUnavailable",
|
|
166
|
+
);
|
|
167
|
+
const engagementQuery = useQuery({
|
|
168
|
+
queryKey: ["list-email-engagement", detail.appPath, id, WINDOW_DAYS],
|
|
169
|
+
queryFn: () =>
|
|
170
|
+
callAppAction<ProviderMetricsResult<EmailEngagement[]>>(
|
|
171
|
+
detail.appPath,
|
|
172
|
+
"list-email-engagement",
|
|
173
|
+
{ templateIds: [id], windowDays: WINDOW_DAYS },
|
|
174
|
+
"POST",
|
|
175
|
+
),
|
|
176
|
+
enabled: appId !== "core" && id.length > 0 && detail.appPath.length > 0,
|
|
177
|
+
});
|
|
178
|
+
const engagementResult = engagementQuery.data;
|
|
179
|
+
const engagementUnavailable =
|
|
180
|
+
appId === "core"
|
|
181
|
+
? sharedProviderReason
|
|
182
|
+
: engagementResult && !engagementResult.available
|
|
183
|
+
? engagementResult.reason
|
|
184
|
+
: engagementQuery.isError
|
|
185
|
+
? engagementQuery.error instanceof Error
|
|
186
|
+
? engagementQuery.error.message
|
|
187
|
+
: String(engagementQuery.error)
|
|
188
|
+
: null;
|
|
189
|
+
const engagement = engagementResult?.available
|
|
190
|
+
? engagementResult.data.find((entry) => entry.templateId === id)
|
|
191
|
+
: undefined;
|
|
192
|
+
|
|
193
|
+
const activityQuery = useQuery({
|
|
194
|
+
queryKey: ["list-email-activity", detail.appPath, id, ACTIVITY_LIMIT],
|
|
195
|
+
queryFn: () =>
|
|
196
|
+
callAppAction<ProviderMetricsResult<EmailActivityEntry[]>>(
|
|
197
|
+
detail.appPath,
|
|
198
|
+
"list-email-activity",
|
|
199
|
+
{ templateId: id, limit: ACTIVITY_LIMIT },
|
|
200
|
+
"GET",
|
|
201
|
+
),
|
|
202
|
+
enabled:
|
|
203
|
+
appId !== "core" &&
|
|
204
|
+
id.length > 0 &&
|
|
205
|
+
detail.appPath.length > 0 &&
|
|
206
|
+
!engagementUnavailable,
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
return (
|
|
210
|
+
<DispatchShell
|
|
211
|
+
title={detail.email?.name ?? t("dispatch.transactionalEmail.title")}
|
|
212
|
+
description={t("dispatch.transactionalEmail.description")}
|
|
213
|
+
>
|
|
214
|
+
<div className="max-w-3xl space-y-4">
|
|
215
|
+
<Button asChild size="sm" variant="ghost" className="-ml-2">
|
|
216
|
+
<Link to="/transactional-email">
|
|
217
|
+
<IconArrowLeft size={15} className="mr-1.5" />
|
|
218
|
+
{t("dispatch.transactionalEmail.title")}
|
|
219
|
+
</Link>
|
|
220
|
+
</Button>
|
|
221
|
+
|
|
222
|
+
{detail.isError ? (
|
|
223
|
+
<ActionQueryError error={detail.error} onRetry={detail.onRetry} />
|
|
224
|
+
) : detail.isLoading ? (
|
|
225
|
+
<div className="space-y-3">
|
|
226
|
+
<Skeleton className="h-6 w-64" />
|
|
227
|
+
<Skeleton className="h-32 w-full" />
|
|
228
|
+
</div>
|
|
229
|
+
) : detail.notFound || !detail.email ? (
|
|
230
|
+
<Alert variant="destructive">
|
|
231
|
+
<IconAlertTriangle className="size-4" />
|
|
232
|
+
<AlertTitle>
|
|
233
|
+
{t("dispatch.transactionalEmail.emailNotFound")}
|
|
234
|
+
</AlertTitle>
|
|
235
|
+
<AlertDescription>
|
|
236
|
+
{detail.catalogError ??
|
|
237
|
+
t("dispatch.transactionalEmail.emailNotFoundDescription")}
|
|
238
|
+
</AlertDescription>
|
|
239
|
+
</Alert>
|
|
240
|
+
) : (
|
|
241
|
+
<>
|
|
242
|
+
<section className="rounded-2xl bg-card p-5">
|
|
243
|
+
<div className="text-lg font-semibold text-foreground">
|
|
244
|
+
{detail.email.name}
|
|
245
|
+
</div>
|
|
246
|
+
<div className="mt-1 font-mono text-xs text-muted-foreground">
|
|
247
|
+
{detail.email.id}
|
|
248
|
+
</div>
|
|
249
|
+
<div className="mt-1 text-xs text-muted-foreground">
|
|
250
|
+
{detail.appName}
|
|
251
|
+
{detail.appPath ? ` · ${detail.appPath}` : ""}
|
|
252
|
+
</div>
|
|
253
|
+
|
|
254
|
+
<dl className="mt-4 space-y-3 text-sm">
|
|
255
|
+
<div>
|
|
256
|
+
<dt className="text-xs font-medium text-muted-foreground">
|
|
257
|
+
{t("dispatch.transactionalEmail.trigger")}
|
|
258
|
+
</dt>
|
|
259
|
+
<dd className="mt-1 text-foreground">
|
|
260
|
+
{detail.email.trigger}
|
|
261
|
+
</dd>
|
|
262
|
+
</div>
|
|
263
|
+
<div>
|
|
264
|
+
<dt className="text-xs font-medium text-muted-foreground">
|
|
265
|
+
{t("dispatch.transactionalEmail.recipient")}
|
|
266
|
+
</dt>
|
|
267
|
+
<dd className="mt-1 text-foreground">
|
|
268
|
+
{detail.email.recipient}
|
|
269
|
+
</dd>
|
|
270
|
+
</div>
|
|
271
|
+
<div>
|
|
272
|
+
<dt className="text-xs font-medium text-muted-foreground">
|
|
273
|
+
{t("dispatch.transactionalEmail.sender")}
|
|
274
|
+
</dt>
|
|
275
|
+
<dd className="mt-1 text-foreground">
|
|
276
|
+
{detail.email.sender}
|
|
277
|
+
</dd>
|
|
278
|
+
</div>
|
|
279
|
+
</dl>
|
|
280
|
+
|
|
281
|
+
<div className="mt-4 flex flex-wrap gap-6 border-t pt-4 text-sm">
|
|
282
|
+
<div>
|
|
283
|
+
<div className="text-xs font-medium text-muted-foreground">
|
|
284
|
+
{t("dispatch.transactionalEmail.sends")}
|
|
285
|
+
</div>
|
|
286
|
+
<div className="mt-1">
|
|
287
|
+
<SendsCell
|
|
288
|
+
sent={detail.email.sent}
|
|
289
|
+
failed={detail.email.failed}
|
|
290
|
+
/>
|
|
291
|
+
</div>
|
|
292
|
+
</div>
|
|
293
|
+
<div>
|
|
294
|
+
<div className="text-xs font-medium text-muted-foreground">
|
|
295
|
+
{t("dispatch.transactionalEmail.openRate")}
|
|
296
|
+
</div>
|
|
297
|
+
<div className="mt-1">
|
|
298
|
+
<OpenRateCell
|
|
299
|
+
engagement={engagement}
|
|
300
|
+
unavailableReason={engagementUnavailable}
|
|
301
|
+
loading={engagementQuery.isLoading}
|
|
302
|
+
/>
|
|
303
|
+
</div>
|
|
304
|
+
</div>
|
|
305
|
+
<div>
|
|
306
|
+
<div className="text-xs font-medium text-muted-foreground">
|
|
307
|
+
{t("dispatch.transactionalEmail.lastSent")}
|
|
308
|
+
</div>
|
|
309
|
+
<div className="mt-1">
|
|
310
|
+
<LastSentCell
|
|
311
|
+
lastSentAt={detail.email.lastSentAt}
|
|
312
|
+
sent={detail.email.sent}
|
|
313
|
+
/>
|
|
314
|
+
</div>
|
|
315
|
+
</div>
|
|
316
|
+
</div>
|
|
317
|
+
</section>
|
|
318
|
+
|
|
319
|
+
<section className="rounded-2xl bg-card p-5">
|
|
320
|
+
<h2 className="text-sm font-medium text-foreground">
|
|
321
|
+
{t("dispatch.transactionalEmail.preview")}
|
|
322
|
+
</h2>
|
|
323
|
+
<p className="mt-1 text-xs text-muted-foreground">
|
|
324
|
+
{t("dispatch.transactionalEmail.previewDescription")}
|
|
325
|
+
</p>
|
|
326
|
+
<div className="mt-4">
|
|
327
|
+
<EmailPreviewPane
|
|
328
|
+
appId={appId}
|
|
329
|
+
appPath={detail.appPath}
|
|
330
|
+
id={detail.email.id}
|
|
331
|
+
name={detail.email.name}
|
|
332
|
+
/>
|
|
333
|
+
</div>
|
|
334
|
+
</section>
|
|
335
|
+
|
|
336
|
+
<section className="rounded-2xl bg-card p-5">
|
|
337
|
+
<h2 className="text-sm font-medium text-foreground">
|
|
338
|
+
{t("dispatch.transactionalEmail.activityLink")}
|
|
339
|
+
</h2>
|
|
340
|
+
<p className="mt-1 text-xs text-muted-foreground">
|
|
341
|
+
{t("dispatch.transactionalEmail.retentionNote")}
|
|
342
|
+
</p>
|
|
343
|
+
<div className="mt-4">
|
|
344
|
+
<ActivityTable
|
|
345
|
+
result={
|
|
346
|
+
engagementUnavailable
|
|
347
|
+
? { available: false, reason: engagementUnavailable }
|
|
348
|
+
: activityQuery.data
|
|
349
|
+
}
|
|
350
|
+
isLoading={activityQuery.isLoading}
|
|
351
|
+
isError={activityQuery.isError}
|
|
352
|
+
error={activityQuery.error}
|
|
353
|
+
onRetry={() => void activityQuery.refetch()}
|
|
354
|
+
/>
|
|
355
|
+
</div>
|
|
356
|
+
</section>
|
|
357
|
+
</>
|
|
358
|
+
)}
|
|
359
|
+
</div>
|
|
360
|
+
</DispatchShell>
|
|
361
|
+
);
|
|
362
|
+
}
|