Skip to content

Commit

Permalink
Merge branch 'main' into redesign-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
iampearceman authored Oct 16, 2024
2 parents 682eaf0 + 4c13348 commit a7dec5e
Show file tree
Hide file tree
Showing 32 changed files with 322 additions and 1,105 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@next/third-parties": "^14.2.9",
"@novu/framework": "^2.1.0",
"@novu/node": "^2.0.1",
"@novu/react": "^2.3.0",
"@novu/react": "^2.5.0",
"@paralleldrive/cuid2": "^2.2.2",
"@react-email/components": "0.0.22",
"axios": "^1.7.4",
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/trigger/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function POST(request: Request) {
controls: {
steps: controls,
},
// bridgeUrl,
bridgeUrl,
},
{
headers: {
Expand Down
18 changes: 17 additions & 1 deletion src/app/contexts/ThemeContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,23 @@ const themes: Theme[] = [
id: "default-theme",
title: "Default Theme",
icon: <PenIcon />,
workflows: [{ id: "custom-workflow", title: "Custom Workflow" }],
workflows: [
{
id: "default-notification",
title: "Custom Workflow",
data: {
inAppSubject: `In-App Notification Subject!`, //Main notification text (subject)
inAppBody: `In-App Notification Body!`, //page name
enablePrimaryAction: true,
inAppPrimaryActionLabel: "Reply",
inAppPrimaryActionUrl: "https://google.com",
enableSecondaryAction: false,
inAppSecondaryActionLabel: "Dismiss",
inAppSecondaryActionUrl: "https://google.com",
showInAppAvatar: true,
inAppAvatar: "https://avatars.githubusercontent.com/u/77433905?s=200&v=4",
},
}],
appearance: {
variables: {},
elements: {},
Expand Down
6 changes: 6 additions & 0 deletions src/app/workflows/default-usecase/Default/payloadSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { z } from "zod";

export const payloadSchema = z.object({
firstName: z.string().default("John"),
lastName: z.string().default("Doe"),
});
15 changes: 15 additions & 0 deletions src/app/workflows/default-usecase/Default/stepsControlSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { z } from "zod";

export const inAppControlSchema = z.object({
useControls: z.boolean().default(false),
inAppSubject: z.string().default("In-App Notification Subject!"),
inAppBody: z.string().default("In-App Notification Body!"),
inAppAvatar: z.string().default("https://avatars.githubusercontent.com/u/63902456?v=4"),
showInAppAvatar: z.boolean().default(true),
inAppPrimaryActionLabel: z.string().default("Reply"),
enablePrimaryAction: z.boolean().default(true),
inAppPrimaryActionUrl: z.string().default("https://novu.com"),
inAppSecondaryActionLabel: z.string().default("Dismiss"),
enableSecondaryAction: z.boolean().default(false),
inAppSecondaryActionUrl: z.string().default("https://novu.com"),
});
45 changes: 45 additions & 0 deletions src/app/workflows/default-usecase/Default/workflow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { workflow } from "@novu/framework";
import { payloadSchema } from "./payloadSchema";
import { inAppControlSchema } from "./stepsControlSchema";

const workflowName = "default-notification";

export const defaultNotification = workflow(
workflowName,
async ({ step, payload, subscriber }) => {
await step.inApp(
"in-app-step",
async (controls) => {
const result: any = {
subject: controls.inAppSubject,
body: controls.inAppBody,
};

if (controls.showInAppAvatar) {
result.avatar = controls.inAppAvatar;
}

if (controls.enablePrimaryAction) {
result.primaryAction = {
label: controls.inAppPrimaryActionLabel,
url: controls.inAppPrimaryActionUrl,
};
}

if (controls.enableSecondaryAction) {
result.secondaryAction = {
label: controls.inAppSecondaryActionLabel,
url: controls.inAppSecondaryActionUrl,
};
}
return result;
},
{
controlSchema: inAppControlSchema,
}
);
},
{
payloadSchema: payloadSchema,
}
);

This file was deleted.

6 changes: 6 additions & 0 deletions src/app/workflows/notion-usecases/Comment/payloadSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { z } from "zod";

export const payloadSchema = z.object({
firstName: z.string().default("John"),
lastName: z.string().default("Doe"),
});
88 changes: 14 additions & 74 deletions src/app/workflows/notion-usecases/Comment/stepsControlSchema.ts
Original file line number Diff line number Diff line change
@@ -1,82 +1,22 @@
import { z } from "zod";
import { CronExpression } from "@novu/framework";

export const emailControlSchema = z.object({
subject: z.string().default("A Successful Test on Novu!"),
showHeader: z.boolean().default(true),
components: z
.array(
z.object({
type: z.enum(["heading", "text", "button", "code", "users"]),
text: z.string().default(""),
align: z.enum(["left", "center", "right"]).default("left"),
}),
)
.default([
{
type: "heading",
text: "Welcome to Novu",
align: "center",
},
{
type: "text",
text: "Congratulations on receiving your first notification email from Novu! Join the hundreds of thousands of developers worldwide who use Novu to build notification platforms for their products.",
align: "left",
},
{
type: "users",
align: "center",
text: "",
},
{
type: "text",
text: "Ready to get started? Click on the button below, and you will see first-hand how easily you can edit this email content.",
align: "left",
},
{
type: "button",
text: "Edit Email",
align: "center",
},
]),
});

export const inAppControlSchema = z.object({
inAppSubject: z.string().default("In-App Notification Subject!"),
pageName: z.string().default("Very Intresting Page"),
inAppAvatar: z.string().default("https://avatars.githubusercontent.com/u/63902456?v=4"),
subscriberFirstName: z.string().default("John"),
subscriberLastName: z.string().default("Doe"),
inAppSubject: z
.string()
.default(
`{{subscriber.firstName | capitalize}} {{subscriber.lastName | capitalize}} commented in`
),
inAppBody: z.string().default("Important Page"),
inAppAvatar: z
.string()
.default("https://avatars.githubusercontent.com/u/63902456?v=4"),
showInAppAvatar: z.boolean().default(true),
inAppPrimaryActionLabel: z.string().default("Reply"),
enablePrimaryAction: z.boolean().default(true),
inAppPrimaryActionUrl: z.string().default("https://novu.com"),
});

export const smsControlSchema = z.object({
smsBody: z.string().default("SMS Notification Subject"),
});

export const pushControlSchema = z.object({
pushSubject: z.string().default("Push Notification Subject"),
pushBody: z.string().default("Push Notification Body"),
});

export const chatControlSchema = z.object({
chatBody: z.string().default("Chat Notification Body"),
});

export const delayControlSchema = z.object({
unit: z.enum(["seconds", "minutes", "hours", "days", "weeks", "months"]).default("days"),
amount: z.number().default(2),
});

export const digestControlSchema = z.object({
strategy: z.enum(["Regular", "Scheduled"]).default("Regular"),
lookBackWindow: z.boolean().default(false),
digestKey: z.string().default("digestKey"),
unit: z.enum(["seconds", "minutes", "hours", "days", "weeks", "months"]).default("days"),
amount: z.number().default(3),
cron: z.string().default(CronExpression.EVERY_DAY_AT_8AM), // visit https://crontab.guru/ to set the cron expression.
});

export const customControlSchema = z.object({
inAppSecondaryActionLabel: z.string().default("Dismiss"),
enableSecondaryAction: z.boolean().default(false),
inAppSecondaryActionUrl: z.string().default("https://novu.com"),
});
Loading

0 comments on commit a7dec5e

Please sign in to comment.