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

[TAS-504] ✨ Add basic v2 template #39

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ <h2>Basic</h2>
</li>
</ul>

<h2>Basic V2</h2>
<ul>
<li>
<a href="/v2/basic?title=Lorem Ipsum&subtitle=Lorem Ipsum&content=<p>Lorem <b>Ipsum</b></p>">
Default
</a>
</li>
</ul>

<h2>New supporter</h2>
<ul>
<li>
Expand Down
6 changes: 6 additions & 0 deletions example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
getNFTNotificationTransferTemplate,
getNFTNotificationPurchaseTemplate,
getNFTNotificationPurchaseMultipleTemplate,
getBasicV2Template,
} from '../dist';

import {
Expand Down Expand Up @@ -55,6 +56,11 @@ handleRequest('/basic', (req, res) => {
res.send(body);
});

handleRequest('/v2/basic', (req, res) => {
const { body } = getBasicV2Template({ ...req.query, ...req.body });
res.send(body);
});

handleRequest('/basic/avatar', (req, res) => {
const { body } = getBasicWithAvatarTemplate({ ...req.query, ...req.body });
res.send(body);
Expand Down
2 changes: 1 addition & 1 deletion src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const ASSETS_ROOT =
process.env.NODE_ENV === 'production'
? 'https://static.like.co/edm'
: 'http://localhost:3000/static';
: `http://localhost:${process.env.PORT || '3000'}/static`;

export const DEFAULT_AVATAR_URL = `${ASSETS_ROOT}/default-avatar.jpg`;

Expand Down
13 changes: 13 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {
NFTNotificationPurchaseMultipleTemplate,
NFTNotificationPurchaseMultipleTemplateProps,
} from './templates/nft/notification/purchase-multiple';
import { BasicV2Template, BasicV2TemplateProps } from './templates/basic-v2';

export const getBasicTemplate = (
props: BasicTemplateProps,
Expand All @@ -73,6 +74,18 @@ export const getBasicTemplate = (
return { subject, body };
};

export const getBasicV2Template = (
props: BasicV2TemplateProps,
options?: Mjml2HtmlOptions
) => {
const { html: body } = render(<BasicV2Template {...props} />, {
minify: false,
...options,
});
const { subject } = props;
return { subject, body };
};

export const getBasicWithAvatarTemplate = (
props: BasicWithAvatarTemplateProps,
options?: Mjml2HtmlOptions
Expand Down
71 changes: 71 additions & 0 deletions src/templates/basic-v2.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import * as React from 'react';
import { MjmlColumn, MjmlText } from 'mjml-react';

import * as Colors from '../constants/colors';

import { ContentSection } from '../components/content';
import { CivicLikerCTASection } from '../components/cta-civic-liker';
import { WritingNFTCTASection } from '../components/cta-writing-nft';
import { FooterSection } from '../components/footer';
import { HeaderSection } from '../components/header';
import { BasicSection } from '../components/sections/basic';
import { TemplateBase } from '../components/template-base';

export interface BasicV2TemplateProps {
subject?: string;
title?: string;
titleTop?: React.ReactElement;
subtitle?: string;
subtitlePrepend?: React.ReactElement;
avatarURL?: string;
isCivicLiker?: boolean;
content?: string;
cta?: string;
unsubscribeLink?: string;
language?: string;
}

export const BasicV2Template = ({
subject,
title,
titleTop,
subtitle,
subtitlePrepend,
content,
cta = 'writing-nft',
unsubscribeLink,
language,
}: BasicV2TemplateProps) => {
return (
<TemplateBase language={language} subject={subject}>
<HeaderSection />
<BasicSection
backgroundColor={Colors.LikeGreen}
paddingTop={48}
paddingBottom={48}
>
<MjmlColumn>
{titleTop}
<MjmlText color="white" fontSize={36} fontWeight={600} align="left">
{title}
</MjmlText>
{subtitle && (
<MjmlText
color={Colors.LighterCyan}
fontSize={24}
align="left"
paddingTop={16}
>
{subtitlePrepend}
{subtitle}
</MjmlText>
)}
</MjmlColumn>
</BasicSection>
<ContentSection content={content} />
{cta === 'civic-liker' && <CivicLikerCTASection />}
{cta === 'writing-nft' && <WritingNFTCTASection />}
<FooterSection unsubscribeLink={unsubscribeLink} />
</TemplateBase>
);
};