Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api-service): Usage insights email #7346

Draft
wants to merge 34 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9f7b9dc
feat: insights
scopsy Dec 4, 2024
5728669
feat: wip
scopsy Dec 4, 2024
6eb853e
fix: hello world
scopsy Dec 4, 2024
099fea9
fix: email
scopsy Dec 4, 2024
8fb84e3
fix: email style
scopsy Dec 4, 2024
60a85a3
fix: add marketing section
scopsy Dec 4, 2024
a49b625
fix: upload
scopsy Dec 4, 2024
d56c811
fix: logo
scopsy Dec 4, 2024
8a89c1b
Merge branch 'next' into insights-email
scopsy Dec 22, 2024
747dffd
fix: items
scopsy Dec 22, 2024
5ee4ad9
fix: workflows
scopsy Dec 22, 2024
6d7c867
fix: items
scopsy Dec 22, 2024
63ef939
fix: items
scopsy Dec 22, 2024
836c44f
fix: items
scopsy Dec 22, 2024
0dd5361
fix: refactor
scopsy Dec 22, 2024
9570eff
fix: review
scopsy Dec 22, 2024
2be2bf1
fix: items
scopsy Dec 22, 2024
5464b96
fix: items
scopsy Dec 22, 2024
2945749
fix: bugs
scopsy Dec 22, 2024
4c9bd12
fix: working state
scopsy Dec 22, 2024
3b4e5a9
feat: add controller
scopsy Dec 22, 2024
4a4f6bc
feat: add insights tester
scopsy Dec 22, 2024
88f0530
fix: mixpanel
scopsy Dec 22, 2024
510860a
fix: remove cache
scopsy Dec 22, 2024
efc2df7
fix: remove unused import
scopsy Dec 22, 2024
bd7e05f
fix: trigger
scopsy Dec 22, 2024
65c3d67
fix: empty state
scopsy Dec 22, 2024
9ea8c3c
fix: refactpr
scopsy Dec 22, 2024
69a10f8
fix: r emov unused
scopsy Dec 22, 2024
3173273
fix: validation
scopsy Dec 22, 2024
465427d
fix: remove pr info
scopsy Dec 22, 2024
2c39098
Merge branch 'next' into insights-email
scopsy Dec 22, 2024
ed1d443
Merge branch 'next' into insights-email
scopsy Dec 22, 2024
325762b
fix: import
scopsy Dec 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: add marketing section
  • Loading branch information
scopsy committed Dec 4, 2024
commit 60a85a34263aeb67579966dd674be2b214738b7a
71 changes: 57 additions & 14 deletions libs/notifications/src/workflows/usage-insights/email.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
Img,
Row,
Column,
Link,
Hr,
} from '@react-email/components';
import { IUsageEmailData } from './types';

Expand Down Expand Up @@ -125,7 +127,56 @@ function WorkflowStats({ workflows }: { workflows: IUsageEmailData['workflowStat
);
}

export default function UsageInsightsEmail(props: IUsageEmailData) {
interface IMarketingLink {
href: string;
text: string;
emoji: string;
}

interface IMarketingConfig {
title: string;
links: IMarketingLink[];
cta: {
text: string;
buttonText: string;
buttonUrl: string;
};
}

function MarketingSection({ config }: { config: IMarketingConfig }) {
return (
<Section className="mt-8">
<Hr className="mb-6 border-t border-gray-200" />
<div className="mb-6">
<Heading className="mb-4 text-base font-semibold text-gray-900">{config.title}</Heading>
<div className="flex flex-col space-y-3">
{config.links.map((link, index) => (
<Link
key={index}
href={link.href}
className="flex items-center rounded-lg border border-gray-200 bg-white p-3 text-xs font-medium text-gray-700 hover:underline"
>
<span className="mr-2">{link.emoji}</span>
{link.text}
</Link>
))}
</div>
</div>

<div className="rounded-lg border border-indigo-100 bg-indigo-50/50 p-4 text-center">
<Text className="mb-2 text-sm font-medium text-indigo-900">{config.cta.text}</Text>
<Link
href={config.cta.buttonUrl}
className="inline-block rounded-lg bg-indigo-600 px-4 py-2 text-xs font-medium text-white hover:underline"
>
{config.cta.buttonText}
</Link>
</div>
</Section>
);
}

export default function UsageInsightsEmail(props: IUsageEmailData & { marketingConfig: IMarketingConfig }) {
return (
<Html>
<Head />
Expand All @@ -135,18 +186,8 @@ export default function UsageInsightsEmail(props: IUsageEmailData) {
<Tailwind>
<Body className="bg-gray-50 font-sans">
<Container className="mx-auto w-full">
<Section>
<Img
src={`https://dashboard.novu.co/static/images/novu-colored-text.png`}
width="119"
height="37"
alt="Novu"
className="mx-auto my-[32px]"
/>
</Section>

<Section className="rounded-t-lg bg-[#000000] px-6 py-8">
<Heading className="text-center text-2xl font-bold text-white">Novu Insights Report</Heading>
<Section className="rounded-t-lg bg-indigo-600 px-6 py-8">
<Heading className="text-center text-2xl font-bold text-white">Usage Insights Report</Heading>
<Text className="text-center text-sm text-indigo-100">{props.organizationName}</Text>
</Section>

Expand Down Expand Up @@ -174,7 +215,9 @@ export default function UsageInsightsEmail(props: IUsageEmailData) {
<InboxMetrics metrics={props.inboxMetrics} />
<WorkflowStats workflows={props.workflowStats} />

<Section className="mt-8 border-t border-gray-100 pt-6">
<MarketingSection config={props.marketingConfig} />

<Section className="mt-6 border-t border-gray-100 pt-6">
<Text className="text-center text-xs text-gray-400">Generated with ❤️ by Novu</Text>
</Section>
</Container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@ import UsageInsightsEmail from './email';
import { IUsageEmailData } from './types';
import { sampleUsageData } from './sample-data';

const marketingLinkSchema = z
.object({
href: z.string(),
text: z.string(),
emoji: z.string(),
})
.required();

async function renderUsageInsightsEmail(payload: IUsageEmailData, controls: any) {
const html = await renderAsync(UsageInsightsEmail(payload));
const html = await renderAsync(UsageInsightsEmail({ ...payload, marketingConfig: controls.marketingConfig }));

return html;
}
Expand Down Expand Up @@ -34,6 +42,52 @@ export const usageInsightsWorkflow = workflow(
controlSchema: z.object({
subject: z.string().default('Your Monthly Usage Insights'),
previewText: z.string().default('Here are your usage insights for {{payload.organizationName}}'),
marketingConfig: z
.object({
title: z.string().default('Discover More with Novu'),
links: z.array(marketingLinkSchema).default([
{
href: 'https://docs.novu.co',
text: 'Read our Documentation',
emoji: '📚',
},
{
href: 'https://discord.novu.co',
text: 'Join our Discord Community',
emoji: '💬',
},
{
href: 'https://github.com/novuhq/novu',
text: 'Star us on GitHub',
emoji: '⭐',
},
{
href: 'https://novu.co/blog',
text: 'Check out our Blog',
emoji: '📝',
},
]),
cta: z.object({
text: z.string().default('Ready to take your notifications to the next level?'),
buttonText: z.string().default('Upgrade Your Plan →'),
buttonUrl: z.string().default('https://novu.co/pricing'),
}),
})
.default({
cta: {
text: 'Ready to take your notifications to the next level?',
buttonText: 'Upgrade Your Plan →',
buttonUrl: 'https://novu.co/pricing',
},
links: [
{
href: 'https://docs.novu.co',
text: 'Read our Documentation',
emoji: '📚',
},
],
title: 'Discover More with Novu',
}),
}),
}
);
Expand Down
Loading