Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Dec 11, 2024
1 parent 84bf5e4 commit 2f04ef2
Show file tree
Hide file tree
Showing 13 changed files with 211 additions and 269 deletions.
12 changes: 7 additions & 5 deletions expose/api/src/Consumer/Handler/ZippyDownloadRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace App\Consumer\Handler;

use Alchemy\CoreBundle\Util\DoctrineUtil;
use Alchemy\NotifyBundle\src\NotifierInterface;
use Alchemy\NotifyBundle\Notification\NotifierInterface;
use App\Entity\DownloadRequest;
use App\Security\Authentication\JWTManager;
use App\ZippyManager;
Expand All @@ -32,20 +32,22 @@ public function __invoke(ZippyDownloadRequest $message): void
// Trigger ZIP preparation
$this->zippyManager->getDownloadUrl($downloadRequest->getPublication());

$daysAvailable = 3;
$uri = $this->urlGenerator->generate('archive_download', [
'id' => $downloadRequest->getPublication()->getId(),
], UrlGeneratorInterface::ABSOLUTE_URL);
$downloadUrl = $this->JWTManager->signUri(
$uri,
259200 // 3 days
$daysAvailable * 3600 * 24,
);

$this->notifier->sendEmail(
$downloadRequest->getEmail(),
'expose/zippy_download_link',
$downloadRequest->getLocale(),
'expose-zippy-download-link',
[
'download_url' => $downloadUrl,
'locale' => $downloadRequest->getLocale(),
'downloadUrl' => $downloadUrl,
'daysAvailable' => $daysAvailable,
]
);
}
Expand Down
9 changes: 7 additions & 2 deletions novu/bridge/app/api/novu/route.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { serve } from "@novu/framework/next";
import {uploaderCommitAcknowledged, welcomeOnboardingEmail} from "../../novu/workflows";
import {
exposeDownloadLink,
exposeZippyDownloadLink,
uploaderCommitAcknowledged,
} from "../../novu/workflows";

// the workflows collection can hold as many workflow definitions as you need
export const { GET, POST, OPTIONS } = serve({
workflows: [
welcomeOnboardingEmail,
uploaderCommitAcknowledged,
exposeZippyDownloadLink,
exposeDownloadLink,
],
});
68 changes: 68 additions & 0 deletions novu/bridge/app/novu/emails/CTAEmail.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {Button, Section, Text} from "@react-email/components";
import React from "react";
import DefaultEmail, {
createEmailControlSchema,
CreateEmailControlSchemaProps,
styles
} from "@/app/novu/emails/DefaultEmail";
import {z, ZodDefault, ZodOptional, ZodString} from "zod";

type Props = {
introText?: string;
outroText?: string;
linkUrl: string;
linkText: string;
};

export default function CTAEmail({
linkUrl,
linkText,
introText,
outroText,
}: Props) {
return (
<DefaultEmail>
<Section>
{introText ? <Text>
{introText}
</Text> : null}

<Button style={styles.button} href={linkUrl}>{linkText}</Button>

<Text>
<a href={linkUrl}>{linkUrl}</a>
</Text>

{outroText ? <Text>
{outroText}
</Text> : null}
</Section>
</DefaultEmail>
);
}

export type CreateCTAEEmailControlSchemaProps = {
defaultIntroText?: string | undefined;
defaultOutroText?: string | undefined;
} & CreateEmailControlSchemaProps;

export function createCTAEmailControlSchema({
defaultIntroText,
defaultOutroText,
...rest
}: CreateCTAEEmailControlSchemaProps) {
return createEmailControlSchema({
...rest,
introText: createOptionalOrNotString(defaultIntroText),
outroText: createOptionalOrNotString(defaultOutroText),
});
}

function createOptionalOrNotString(defaultValue: string | undefined): ZodOptional<ZodString> | ZodDefault<ZodString> {
const string = z.string();
if (defaultValue) {
return string.default(defaultValue);
} else {
return string.optional();
}
}
80 changes: 80 additions & 0 deletions novu/bridge/app/novu/emails/DefaultEmail.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import {Body, Container, Head, Html, Preview} from "@react-email/components";
import React, {CSSProperties, PropsWithChildren} from "react";
import {z} from "zod";
import {ZodRawShape} from "zod/lib/types";

type Props = PropsWithChildren<{}>;

export default function DefaultEmail({
children,
}: Props) {
return (
<Html>
<Head/>
<Preview>Dropbox reset your password</Preview>
<Body style={main}>
<Container style={container}>
{children}
</Container>
</Body>
</Html>
);
}

const main: CSSProperties = {
backgroundColor: "#abc5ff",
padding: "8px 0",
};

const container: CSSProperties = {
backgroundColor: "#ffffff",
border: "1px solid #f0f0f0",
padding: "45px",
};

export const text: CSSProperties = {
fontSize: "16px",
fontWeight: "300",
color: "#404040",
lineHeight: "26px",
};
const headingText: CSSProperties = {
fontWeight: "300",
lineHeight: "30px",
}
const button: CSSProperties = {
backgroundColor: "#007ee6",
borderRadius: "4px",
color: "#fff",
fontSize: "15px",
textDecoration: "none",
textAlign: "center" as const,
display: "block",
width: "210px",
padding: "14px 7px",
};

const anchor: CSSProperties = {
textDecoration: "underline",
};

export const styles: Record<string, CSSProperties> = {
text,
headingText: headingText,
button,
anchor,
}

export type CreateEmailControlSchemaProps = {
defaultEmailSubject: string;
} & ZodRawShape;

export function createEmailControlSchema({
defaultEmailSubject,
...rest
}: CreateEmailControlSchemaProps) {
return z.object({
emailSubject: z.string().default(defaultEmailSubject),
...rest,
});
}
157 changes: 0 additions & 157 deletions novu/bridge/app/novu/emails/novu-onboarding-email.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import {workflow} from "@novu/framework";
import {z} from "zod";
import {render} from "@react-email/components";
import CTAEmail from "@/app/novu/emails/CTAEmail";

export const exposeDownloadLink = workflow(
"expose-download-link",
async ({step, payload}) => {
await step.email("Email", async () => {
return {
subject: `Your download link is ready!`,
body: `You can download your file from the following link: ${payload.downloadUrl}`,
body: render(<CTAEmail
introText={`You can download your file from the following link:`}
linkUrl={payload.downloadUrl}
linkText={'Download'}
/>
),
};
});
},
Expand Down
2 changes: 2 additions & 0 deletions novu/bridge/app/novu/workflows/expose/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./zippy-download-link";
export * from "./download-link";
Loading

0 comments on commit 2f04ef2

Please sign in to comment.