Skip to content

Commit

Permalink
feat: add notion link to email get a quote
Browse files Browse the repository at this point in the history
  • Loading branch information
kaaps committed Jan 15, 2024
1 parent c519eec commit 2571a80
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 28 deletions.
7 changes: 5 additions & 2 deletions src/lib/mail/sendEmail.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ export const sendEmailNotification = async ({
name,
email,
message,
formType
formType,
notionLink
}: {
name: string;
email: string;
message: string;
formType: FormType;
notionLink?: string;
}) => {
name = escapeHTML(name);
email = escapeHTML(email);
Expand Down Expand Up @@ -107,7 +109,8 @@ export const sendEmailNotification = async ({
`New website submission.\n`,
`name: ${name}`,
`email: ${email}`,
`message: ${message}`
`message: ${message}`,
formType === 'quote' && notionLink && `Notion Link: ${notionLink}`
].join('\n')
}
},
Expand Down
59 changes: 33 additions & 26 deletions src/routes/form/[type=formType]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const actions = {
default: async (event) => {
const data = await event.request.formData();
const formType = event.params.type;
let notionLink = '';

if (!isFormType(formType)) {
return fail(500, {
Expand All @@ -56,37 +57,27 @@ export const actions = {
});
}

try {
sendEmailNotification({
name,
email,
message,
formType
});
} catch (error) {
return fail(500, {
error: {
message: 'Failed to send internal email notification'
}
});
}

try {
switch (event.params.type) {
case 'quote':
await notion.pages.create({
parent: { database_id: env.NOTION_DB_LEADS },
properties: {
Name: { title: [{ text: { content: name } }] },
Email: { email: email },
Budget: { select: { name: fields.budget || 'n/a' } },
Message: { rich_text: [{ text: { content: message || '' } }] },
Status: { select: { name: 'To triage' } },
Attachments: {
files: getNotionAttachments(fields.attachments || '')
{
const response = await notion.pages.create({
parent: { database_id: env.NOTION_DB_LEADS },
properties: {
Name: { title: [{ text: { content: name } }] },
Email: { email: email },
Budget: { select: { name: fields.budget || 'n/a' } },
Message: { rich_text: [{ text: { content: message || '' } }] },
Status: { select: { name: 'To triage' } },
Attachments: {
files: getNotionAttachments(fields.attachments || '')
}
}
});
if ('url' in response) {
notionLink = response.url;
}
});
}
break;
case 'career':
await notion.pages.create({
Expand Down Expand Up @@ -123,6 +114,22 @@ export const actions = {
});
}

try {
sendEmailNotification({
name,
email,
message,
formType,
notionLink
});
} catch (error) {
return fail(500, {
error: {
message: 'Failed to send internal email notification'
}
});
}

try {
const subject = t('form.subject');
await sendTransactionalEmail({
Expand Down

0 comments on commit 2571a80

Please sign in to comment.