Skip to content

Commit

Permalink
✨ Add NFT 2 content with message & button template (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwingt authored Jun 19, 2024
1 parent c9a9ccc commit 3e56f3d
Show file tree
Hide file tree
Showing 16 changed files with 1,067 additions and 863 deletions.
9 changes: 9 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ <h2>Notification</h2>
</a>
</li>
</ul>

<h2>NFT</h2>
<ul>
<li>
<a href="/nft/2-content-with-message-n-button">
NFT Two Content With Message And Button
</a>
</li>
</ul>

</body>
</html>
11 changes: 11 additions & 0 deletions example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
getNFTNotificationPurchaseTemplate,
getNFTNotificationPurchaseMultipleTemplate,
getBasicV2Template,
getNFTTwoContentWithMessageAndButtonTemplate,
} from '../dist';

import {
Expand All @@ -34,6 +35,7 @@ import {
import {
CreatorFollowConfirmationSampleData,
CreatorFollowPublishNewSampleData,
NFTTwoContentWithMessageAndButtonTemplateSampleData,
NFTNotificationPurchaseMultipleSampleData,
NFTNotificationPurchaseSampleData,
NFTNotificationTransferSampleData,
Expand Down Expand Up @@ -185,6 +187,15 @@ handleRequest('/nft/notification/purchase-multiple', (req, res) => {
res.send(subject.concat(body));
});

handleRequest('/nft/2-content-with-message-n-button', (req, res) => {
const { body } = getNFTTwoContentWithMessageAndButtonTemplate({
...NFTTwoContentWithMessageAndButtonTemplateSampleData,
...req.query,
...req.body,
});
res.send(body);
});

app.get('/', (_, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "8.0.0-beta.4",
"version": "8.2.0-beta.0",
"license": "GPL-3.0-or-later",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down Expand Up @@ -71,7 +71,7 @@
"dependencies": {
"@types/mjml-react": "^2.0.6",
"canvas": "^2.8.0",
"mjml": "^4.13.0",
"mjml": "^4.15.3",
"mjml-react": "^2.0.8",
"react-intl": "^5.10.16"
}
Expand Down
8 changes: 5 additions & 3 deletions src/components/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ export const FooterSection = ({
<MjmlText align="center" padding={4}>
<HelpCenterLink />
</MjmlText>
<MjmlText align="center" padding={4}>
<UnsubscribeLink link={unsubscribeLink} />
</MjmlText>
{!!unsubscribeLink && (
<MjmlText align="center" padding={4}>
<UnsubscribeLink link={unsubscribeLink} />
</MjmlText>
)}
</MjmlColumn>
</BasicSection>
</>
Expand Down
1 change: 1 addition & 0 deletions src/constants/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export const GreyD8 = '#d8d8d8';
export const GreyEB = '#ebebeb';
export const GreyF7 = '#f7f7f7';

export const White = '#ffffff';
export const Green = '#36de00';
export const Red = '#ff0000';
18 changes: 18 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ import {
NFTNotificationPurchaseMultipleTemplateProps,
} from './templates/nft/notification/purchase-multiple';
import { BasicV2Template, BasicV2TemplateProps } from './templates/basic-v2';
import {
NFTTwoContentWithMessageAndButtonTemplate,
NFTTwoContentWithMessageAndButtonTemplateProps,
} from './templates/nft/two-content-with-message-and-button';

export const getBasicTemplate = (
props: BasicTemplateProps,
Expand Down Expand Up @@ -353,3 +357,17 @@ export const getNFTNotificationPurchaseMultipleTemplate = (
);
return { subject, body };
};

export const getNFTTwoContentWithMessageAndButtonTemplate = (
props: NFTTwoContentWithMessageAndButtonTemplateProps,
options?: Mjml2HtmlOptions
) => {
const { html: body } = render(
<NFTTwoContentWithMessageAndButtonTemplate {...props} />,
{
minify: false,
...options,
}
);
return { body };
};
234 changes: 234 additions & 0 deletions src/templates/nft/two-content-with-message-and-button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
import * as React from 'react';
import {
MjmlButton,
MjmlColumn,
MjmlDivider,
MjmlRaw,
MjmlText,
} from 'mjml-react';

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

import { Avatar } from '../../components/avatar';
import { FooterSection } from '../../components/footer';
import { HeaderSection } from '../../components/header';
import { TemplateBase } from '../../components/template-base';
import { BasicSection } from '../../components/sections/basic';

interface NFTMessageBoxProps {
title?: string;
content?: string;
avatarSrc?: string;
style?: React.CSSProperties;
}

const NFTMessageBox = (props: NFTMessageBoxProps) => (
<MjmlRaw>
<table
style={{
marginTop: 16,
marginBottom: 16,

fontSize: '1rem',
fontFamily: 'Arial, sans-serif',

backgroundColor: Colors.White,

borderWidth: 1,
borderColor: Colors.GreyEB,
borderStyle: 'solid',
borderCollapse: 'separate',
borderRadius: 16,
borderTopLeftRadius: 24,

boxShadow: '0px 20px 20px 0px rgba(0, 0, 0, 0.04)',

...props.style,
}}
>
{!!(props.avatarSrc || props.title) && (
<tr>
{!!props.avatarSrc && (
<td style={{ paddingLeft: 24, width: 48 }}>
<Avatar
src={props.avatarSrc}
size={40}
style={{ marginTop: -16, marginLeft: -4 }}
/>
</td>
)}
{!!props.title && (
<td
style={{
paddingTop: props.avatarSrc ? 8 : 16,
paddingRight: 16,
paddingLeft: props.avatarSrc ? 8 : 24,
fontWeight: 'bold',
lineHeight: 1.5,
}}
>
{props.title}
</td>
)}
</tr>
)}
<tr>
<td
colSpan={2}
style={{
paddingTop: props.avatarSrc || props.title ? 4 : 16,
paddingBottom: 16,
paddingRight: 16,
paddingLeft: 24,
lineHeight: 1.5,
}}
>
{props.content}
</td>
</tr>
</table>
</MjmlRaw>
);

export interface NFTContentWithMessageAndButtonSectionProps {
content?: string;
messageAvatarSrc?: string;
messageTitle?: string;
messageContent?: string;
buttonText?: string;
buttonHref?: string;
append?: string;
}

export const NFTContentWithMessageAndButtonSection = (
props: NFTContentWithMessageAndButtonSectionProps
) => {
return (
<BasicSection
paddingLeft={40}
paddingRight={40}
paddingTop={16}
paddingBottom={16}
>
<MjmlColumn>
{!!props.content && (
<MjmlText>
<div dangerouslySetInnerHTML={{ __html: props.content }} />
</MjmlText>
)}

{!!(props.messageTitle || props.messageContent) && (
<NFTMessageBox
avatarSrc={props.messageAvatarSrc}
content={props.messageContent}
title={props.messageTitle}
style={{ marginTop: 32 }}
/>
)}

{!!props.buttonText && (
<MjmlButton
color={Colors.White}
align="left"
fontWeight={600}
backgroundColor={Colors.LikeGreen}
paddingTop={32}
paddingBottom={16}
inner-padding="16px 64px"
borderRadius={12}
href={props.buttonHref}
rel="noopener noreferrer"
>
{props.buttonText}
</MjmlButton>
)}

{!!props.append && (
<MjmlText paddingTop={24}>
<div dangerouslySetInnerHTML={{ __html: props.append }} />
</MjmlText>
)}
</MjmlColumn>
</BasicSection>
);
};

export interface NFTTwoContentWithMessageAndButtonTemplateProps {
subject?: string;
title1?: string;
title2?: string;
content1?: string;
content2?: string;
messageAvatarSrc1?: string;
messageAvatarSrc2?: string;
messageTitle1?: string;
messageTitle2?: string;
messageContent1?: string;
messageContent2?: string;
buttonText1?: string;
buttonText2?: string;
buttonHref1?: string;
buttonHref2?: string;
append1?: string;
append2?: string;
unsubscribeLink?: string;
}

export const NFTTwoContentWithMessageAndButtonTemplate = (
props: NFTTwoContentWithMessageAndButtonTemplateProps
) => {
return (
<TemplateBase subject={props.subject}>
<HeaderSection />

<BasicSection
backgroundColor={Colors.LikeGreen}
paddingLeft={40}
paddingRight={40}
paddingTop={60}
paddingBottom={60}
>
<MjmlColumn>
<MjmlText color="white" fontSize={36} fontWeight={600} align="left">
{props.title1}
<br />
{props.title2}
</MjmlText>
</MjmlColumn>
</BasicSection>

<NFTContentWithMessageAndButtonSection
content={props.content1}
append={props.append1}
messageAvatarSrc={props.messageAvatarSrc1}
messageTitle={props.messageTitle1}
messageContent={props.messageContent1}
buttonHref={props.buttonHref1}
buttonText={props.buttonText1}
/>

<BasicSection
paddingLeft={40}
paddingRight={40}
paddingTop={24}
paddingBottom={24}
>
<MjmlColumn>
<MjmlDivider borderColor={Colors.Grey4A} borderWidth={1} />
</MjmlColumn>
</BasicSection>

<NFTContentWithMessageAndButtonSection
content={props.content2}
append={props.append2}
messageAvatarSrc={props.messageAvatarSrc2}
messageTitle={props.messageTitle2}
messageContent={props.messageContent2}
buttonHref={props.buttonHref2}
buttonText={props.buttonText2}
/>

<FooterSection unsubscribeLink={props.unsubscribeLink} />
</TemplateBase>
);
};
Loading

0 comments on commit 3e56f3d

Please sign in to comment.