Skip to content

Commit

Permalink
✨ Add NFT 2 content with message & button template
Browse files Browse the repository at this point in the history
  • Loading branch information
nwingt committed Jun 6, 2024
1 parent c9a9ccc commit 105af56
Show file tree
Hide file tree
Showing 9 changed files with 834 additions and 475 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
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 };
};
222 changes: 222 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,222 @@
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;
}

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)',
}}
>
<tr>
<td style={{ paddingLeft: 24, width: 48 }}>
<Avatar
src={props.avatarSrc}
size={40}
style={{ marginTop: -16, marginLeft: -4 }}
/>
</td>
<td
style={{
paddingTop: 8,
paddingRight: 16,
paddingLeft: 8,
fontWeight: 'bold',
lineHeight: 1.5,
}}
>
{props.title}
</td>
</tr>
<tr>
<td
colSpan={2}
style={{
paddingTop: 4,
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={32}
paddingBottom={32}
>
<MjmlColumn>
{!!props.content && (
<MjmlText paddingBottom={24}>
<div dangerouslySetInnerHTML={{ __html: props.content }} />
</MjmlText>
)}

<NFTMessageBox
avatarSrc={props.messageAvatarSrc}
content={props.messageContent}
title={props.messageTitle}
/>

{!!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>
);
};
23 changes: 23 additions & 0 deletions test/stub/nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { NFTNotificationPurchaseTemplateProps } from '../../dist/templates/nft/n
import { NFTNotificationPurchaseMultipleTemplateProps } from '../../dist/templates/nft/notification/purchase-multiple';
import { CreatorFollowConfirmationTemplateProps } from '../../dist/templates/nft/creator-follow/confirmation';
import { CreatorFollowPublishNewTemplateProps } from '../../dist/templates/nft/creator-follow/publish-new';
import { NFTTwoContentWithMessageAndButtonTemplateProps } from '../../dist/templates/nft/two-content-with-message-and-button';

import {
SAMPLE_IMAGE_URL,
Expand Down Expand Up @@ -106,3 +107,25 @@ export const NFTNotificationPurchaseMultipleSampleData: NFTNotificationPurchaseM
],
totalPriceInLIKE: 3192,
};

export const NFTTwoContentWithMessageAndButtonTemplateSampleData: NFTTwoContentWithMessageAndButtonTemplateProps = {
title1: '領取你的電子書',
title2: 'Claim your ebook',
content1: `<p>親愛的讀者:</p>
<p>恭喜你,你已成功領取你的電子書《XXX》。你可到 <a href="#">Liker Land 個人主頁</a>查看你的收藏,及閱讀內容。</p>`,
content2: `<p>Dear reader,</p>
<p>Congratulations! You have successfully claimed your ebook "<a href="#">XXX</a>". You can view your collection and read the content on your <a href="#">Liker Land profile</a>.</p>`,
append1: `<p>如有任何疑問,歡迎<a href="#">聯絡客服</a>查詢。<br>感謝珍藏此書,願你享受閱讀的樂趣。</p>
<p>Liker Land</p>`,
append2: `<p>If you have any questions, please feel free to contact our <a href="#">Customer Service</a> for assistance.<br>
Thank you for cherishing this book, and may you enjoy the pleasure of reading.</p>
<p>Liker Land</p>`,
messageTitle1: '突破出版的留言:',
messageTitle2: 'Message from the publisher:',
messageContent1: '感謝支持,2024 散步去!',
messageContent2: 'Thank you for your support, 2024 to the moon!',
buttonText1: '查看收藏',
buttonText2: 'View Collection',
buttonHref1: SAMPLE_URL,
buttonHref2: SAMPLE_URL,
};
Loading

0 comments on commit 105af56

Please sign in to comment.