Skip to content

Commit

Permalink
fix: undo reminder 😢
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Lilleby authored and Anton Lilleby committed Jan 15, 2025
1 parent 9213c0a commit 58eb4e8
Show file tree
Hide file tree
Showing 13 changed files with 8 additions and 344 deletions.
1 change: 0 additions & 1 deletion app/src/lib/actions/external/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ export const submitRegistrationExternal: Actions["submitRegistrationExternal"] =
organiser: eventContent.organisers,
subject: eventContent.emailTemplate.registrationSubject,
message: eventContent.emailTemplate.registrationMessage,
reminder: eventContent.emailReminder,
};

if (process.env.NODE_ENV !== "development") {
Expand Down
1 change: 0 additions & 1 deletion app/src/lib/actions/internal/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ export const submitRegistrationInternal: Actions["submitRegistrationInternal"] =
organiser: eventContent.organisers,
subject: eventContent.emailTemplate.registrationSubject,
message: eventContent.emailTemplate.registrationMessage,
reminder: eventContent.emailReminder,
};

if (process.env.NODE_ENV !== "development") {
Expand Down
33 changes: 2 additions & 31 deletions app/src/lib/email/event/accepted.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import ical, {
ICalAlarmType,
ICalAttendeeRole,
ICalAttendeeStatus,
ICalCalendarMethod,
} from "ical-generator";
import { toHTML } from "@portabletext/to-html";
import { composeEmail, sendEmail, wrapWithStyles } from "../nodemailer";
import ical, { ICalAttendeeRole, ICalAttendeeStatus, ICalCalendarMethod } from "ical-generator";
import { composeEmail, sendEmail } from "../nodemailer";
import { PUBLIC_APP_BASE_URL } from "$env/static/public";
import type { EventUpdatedProps } from "../../../routes/api/send-event-updated/+server";

Expand Down Expand Up @@ -35,31 +29,9 @@ const createIcsFile = ({
end,
location,
organiser,
reminder,
}: EmailAcceptedProps) => {
const url = `${PUBLIC_APP_BASE_URL}/event/${id}`;
const calendar = ical({ name: organiser, method: ICalCalendarMethod.REQUEST });
const alarms = [];

if (reminder.hasThreeDaysBefore) {
alarms.push({
type: ICalAlarmType.email,
summary: reminder.threeDaysSubject,
description: reminder.threeDaysMessage
? wrapWithStyles(toHTML(reminder.threeDaysMessage))
: "",
trigger: 259200, // ->3 days before event starts
});
}

if (reminder.hasOneHourBefore) {
alarms.push({
type: ICalAlarmType.email,
summary: reminder.oneHourSubject,
description: reminder.oneHourMessage ? wrapWithStyles(toHTML(reminder.oneHourMessage)) : "",
trigger: 3600, // -> 1 hour before event starts
});
}

calendar.createEvent({
id,
Expand All @@ -80,7 +52,6 @@ const createIcsFile = ({
name: organiser === "Alle" ? "Capra Gruppen" : organiser,
email: "[email protected]",
},
alarms,
});

return Buffer.from(calendar.toString());
Expand Down
11 changes: 0 additions & 11 deletions app/src/models/sanity.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ export type Event = {
fieldType: "radio" | "checkbox" | "input";
_key: string;
}>;
emailReminder: EmailReminder;
emailTemplate: EmailTemplate;
};

Expand All @@ -145,16 +144,6 @@ export type EmailTemplate = {
cancelMessage: BlockContent;
};

export type EmailReminder = {
_type: "emailReminder";
hasThreeDaysBefore: boolean;
threeDaysSubject: string;
threeDaysMessage?: BlockContent;
hasOneHourBefore: boolean;
oneHourSubject: string;
oneHourMessage?: BlockContent;
};

export type BlogPost = {
_id: string;
_type: "blogPost";
Expand Down
3 changes: 1 addition & 2 deletions app/src/routes/api/send-event-updated/+server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { APP_API_TOKEN } from "$env/static/private";
import { sendEmailAccepted } from "$lib/email/event/accepted";
import { getAttendingParticipants } from "$lib/server/supabase/queries";
import type { Event, BlockContent, EmailReminder } from "$models/sanity.model";
import type { Event, BlockContent } from "$models/sanity.model";
import { json, type RequestHandler } from "@sveltejs/kit";

export interface EventUpdatedProps {
Expand All @@ -14,7 +14,6 @@ export interface EventUpdatedProps {
organiser: Event["organisers"];
subject: string;
message: BlockContent;
reminder: EmailReminder;
}

export const POST: RequestHandler = async ({ request }) => {
Expand Down
1 change: 0 additions & 1 deletion studio/actions/publish-event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export function createExtendedEventPublishAction(originalPublishAction: Document
organiser: draftEvent.organisers,
subject: draftEvent.emailTemplate.updateSubject,
message: draftEvent.emailTemplate.updateMessage,
reminder: draftEvent.emailReminder,
};

const result = await sendEmailEventUpdated(emailProps);
Expand Down
9 changes: 3 additions & 6 deletions studio/lib/event-email.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BlockContent, EmailReminder } from "../models/sanity.model";
import { BlockContent } from "../models/sanity.model";

interface EventProps {
id: string;
Expand All @@ -10,12 +10,9 @@ interface EventProps {
organiser: string;
subject: string;
message: BlockContent;
reminder: EmailReminder;
}
interface EventUpdatedProps extends EventProps {}
interface EventCanceledProps extends Omit<EventProps, "reminder"> {}

export const sendEmailEventUpdated = async (props: EventUpdatedProps) => {
export const sendEmailEventUpdated = async (props: EventProps) => {
if (process.env.MODE === "development") return;

const url = process.env.SANITY_STUDIO_APP_BASE_URL;
Expand All @@ -37,7 +34,7 @@ export const sendEmailEventUpdated = async (props: EventUpdatedProps) => {
}
};

export const sendEmailEventCanceled = async (props: EventCanceledProps) => {
export const sendEmailEventCanceled = async (props: EventProps) => {
if (process.env.MODE === "development") return true;

const url = process.env.SANITY_STUDIO_APP_BASE_URL;
Expand Down
11 changes: 0 additions & 11 deletions studio/models/sanity.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ export type Event = {
fieldType: "radio" | "checkbox" | "input";
_key: string;
}>;
emailReminder: EmailReminder;
emailTemplate: EmailTemplate;
};

Expand All @@ -145,16 +144,6 @@ export type EmailTemplate = {
cancelMessage: BlockContent;
};

export type EmailReminder = {
_type: "emailReminder";
hasThreeDaysBefore: boolean;
threeDaysSubject: string;
threeDaysMessage?: BlockContent;
hasOneHourBefore: boolean;
oneHourSubject: string;
oneHourMessage?: BlockContent;
};

export type BlogPost = {
_id: string;
_type: "blogPost";
Expand Down
2 changes: 1 addition & 1 deletion studio/sanity.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const enivornment = process.env.MODE;

export default defineConfig({
name: "capra-web",
title: "Capra Web",
title: "Skjer",
projectId,
dataset,
icon: StudioIcon,
Expand Down
68 changes: 0 additions & 68 deletions studio/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -791,14 +791,6 @@
},
"optional": true
},
"emailReminder": {
"type": "objectAttribute",
"value": {
"type": "inline",
"name": "emailReminder"
},
"optional": false
},
"emailTemplate": {
"type": "objectAttribute",
"value": {
Expand Down Expand Up @@ -885,66 +877,6 @@
}
}
},
{
"name": "emailReminder",
"type": "type",
"value": {
"type": "object",
"attributes": {
"_type": {
"type": "objectAttribute",
"value": {
"type": "string",
"value": "emailReminder"
}
},
"hasThreeDaysBefore": {
"type": "objectAttribute",
"value": {
"type": "boolean"
},
"optional": false
},
"threeDaysSubject": {
"type": "objectAttribute",
"value": {
"type": "string"
},
"optional": false
},
"threeDaysMessage": {
"type": "objectAttribute",
"value": {
"type": "inline",
"name": "blockContent"
},
"optional": true
},
"hasOneHourBefore": {
"type": "objectAttribute",
"value": {
"type": "boolean"
},
"optional": false
},
"oneHourSubject": {
"type": "objectAttribute",
"value": {
"type": "string"
},
"optional": false
},
"oneHourMessage": {
"type": "objectAttribute",
"value": {
"type": "inline",
"name": "blockContent"
},
"optional": true
}
}
}
},
{
"name": "blogPost",
"type": "document",
Expand Down
Loading

0 comments on commit 58eb4e8

Please sign in to comment.