Skip to content

Commit

Permalink
email notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
potts99 committed Dec 1, 2023
1 parent 5c21f81 commit 4d92010
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 49 deletions.
17 changes: 13 additions & 4 deletions apps/api/src/controllers/ticket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ export function ticketRoutes(fastify: FastifyInstance) {

await sendTicketCreate(ticket);

if (engineer && engineer.name !== "Unassigned") {
const assgined = await prisma.user.findUnique({
where: {
id: ticket.userId,
},
});

await sendAssignedEmail(assgined!.email);
}

for (let i = 0; i < webhook.length; i++) {
if (webhook[i].active === true) {
console.log(webhook[i].url);
Expand Down Expand Up @@ -315,7 +325,7 @@ export function ticketRoutes(fastify: FastifyInstance) {
const { user, id }: any = request.body;

if (token) {
const ticket = await prisma.user.update({
const assigned = await prisma.user.update({
where: { id: user },
data: {
tickets: {
Expand All @@ -326,10 +336,9 @@ export function ticketRoutes(fastify: FastifyInstance) {
},
});

// Send email to user that has been assigned the ticket
// Saying that they have been assigned a ticket
const { email } = assigned;

await sendAssignedEmail(ticket);
await sendAssignedEmail(email);

reply.send({
success: true,
Expand Down
76 changes: 37 additions & 39 deletions apps/api/src/lib/nodemailer/ticket/assigned.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import nodeMailer from "nodemailer";
import { prisma } from "../../../prisma";

export async function sendAssignedEmail(ticket: any) {
export async function sendAssignedEmail(email: any) {
try {
let mail;

const emails = await prisma.email.findMany();

if (emails.length > 0) {
if (emails.length === 0) {
if (process.env.ENVIRONMENT === "development") {
let testAccount = await nodeMailer.createTestAccount();
mail = nodeMailer.createTransport({
Expand All @@ -32,52 +32,50 @@ export async function sendAssignedEmail(ticket: any) {
});
}

console.log("Sending email to: ", ticket.email);
console.log("Sending email to: ", email);

let info = await mail.sendMail({
from: '"No reply 👻" [email protected]', // sender address
to: ticket.email,
subject: `Ticket ${ticket.id} has just been created & logged`, // Subject line
text: `Hello there, Ticket ${ticket.id}, which you reported on ${ticket.createdAt}, has now been created and logged`, // plain text body
to: email, // list of receivers
subject: `A new ticket has been assigned to you`, // Subject line
text: `Hello there, a ticket has been assigned to you`, // plain text body
html: `
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html charset=UTF-8" />
</head>
<div id="" style="display:none;overflow:hidden;line-height:1px;opacity:0;max-height:0;max-width:0">Ticket Created<div></div>
</div>
<head>
<meta http-equiv="Content-Type" content="text/html charset=UTF-8" />
</head>
<div id="" style="display:none;overflow:hidden;line-height:1px;opacity:0;max-height:0;max-width:0">Ticket Created<div></div>
</div>
<body style="background-color:#ffffff;margin:0 auto;font-family:-apple-system, BlinkMacSystemFont, &#x27;Segoe UI&#x27;, &#x27;Roboto&#x27;, &#x27;Oxygen&#x27;, &#x27;Ubuntu&#x27;, &#x27;Cantarell&#x27;, &#x27;Fira Sans&#x27;, &#x27;Droid Sans&#x27;, &#x27;Helvetica Neue&#x27;, sans-serif">
<table align="center" role="presentation" cellSpacing="0" cellPadding="0" border="0" width="100%" style="max-width:600px;margin:0 auto">
<tr style="width:100%">
<td>
<table style="margin-top:8px" align="center" border="0" cellPadding="0" cellSpacing="0" role="presentation" width="100%">
</table>
<h1 style="color:#1d1c1d;font-size:16px;font-weight:700;margin:10px 0;padding:0;line-height:42px">Ticket Created: ${ticket.id}</h1>
<p style="font-size:20px;line-height:28px;margin:4px 0">
<p>Hello, <br>Your ticket has now been created and logged.</p>
<p style="font-size:14px;margin:16px 0;color:#000">
Kind regards,
<table align="center" border="0" cellPadding="0" cellSpacing="0" role="presentation" width="100%">
<tbody>
<tr>
<body style="background-color:#ffffff;margin:0 auto;font-family:-apple-system, BlinkMacSystemFont, &#x27;Segoe UI&#x27;, &#x27;Roboto&#x27;, &#x27;Oxygen&#x27;, &#x27;Ubuntu&#x27;, &#x27;Cantarell&#x27;, &#x27;Fira Sans&#x27;, &#x27;Droid Sans&#x27;, &#x27;Helvetica Neue&#x27;, sans-serif">
<table align="center" role="presentation" cellSpacing="0" cellPadding="0" border="0" width="100%" style="max-width:600px;margin:0 auto">
<tr style="width:100%">
<td>
<a target="_blank" style="color:#b7b7b7;text-decoration:underline" href="https://slackhq.com" rel="noopener noreferrer">Our blog</a> | <a target="_blank" style="color:#b7b7b7;text-decoration:underline" href="https://slack.com/legal" rel="noopener noreferrer">Documentation</a> | <a target="_blank" style="color:#b7b7b7;text-decoration:underline" href="https://slack.com/help" rel="noopener noreferrer">Discord</a> </a>
<p style="font-size:12px;line-height:15px;margin:16px 0;color:#b7b7b7;text-align:left">This was an automated message sent by peppermint.sh -> An open source helpdesk solution</p>
<p style="font-size:12px;line-height:15px;margin:16px 0;color:#b7b7b7;text-align:left;margin-bottom:50px">©2022 Peppermint Ticket Management, a Peppermint Labs product.<br />All rights reserved.</p>
<table style="margin-top:8px" align="center" border="0" cellPadding="0" cellSpacing="0" role="presentation" width="100%">
</table>
<h1 style="color:#1d1c1d;font-size:16px;font-weight:700;margin:10px 0;padding:0;line-height:42px">Ticket Created</h1>
<p style="font-size:20px;line-height:28px;margin:4px 0">
<p>Hello, <br>Your ticket has now been created and logged.</p>
<p style="font-size:14px;margin:16px 0;color:#000">
Kind regards,
<table align="center" border="0" cellPadding="0" cellSpacing="0" role="presentation" width="100%">
<tbody>
<tr>
<td>
<a target="_blank" style="color:#b7b7b7;text-decoration:underline" href="https://slackhq.com" rel="noopener noreferrer">Our blog</a> | <a target="_blank" style="color:#b7b7b7;text-decoration:underline" href="https://slack.com/legal" rel="noopener noreferrer">Documentation</a> | <a target="_blank" style="color:#b7b7b7;text-decoration:underline" href="https://slack.com/help" rel="noopener noreferrer">Discord</a> </a>
<p style="font-size:12px;line-height:15px;margin:16px 0;color:#b7b7b7;text-align:left">This was an automated message sent by peppermint.sh -> An open source helpdesk solution</p>
<p style="font-size:12px;line-height:15px;margin:16px 0;color:#b7b7b7;text-align:left;margin-bottom:50px">©2022 Peppermint Ticket Management, a Peppermint Labs product.<br />All rights reserved.</p>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</body>
</html>
</table>
</body>
</html>
`,
});

Expand Down
2 changes: 1 addition & 1 deletion apps/client/layouts/adminLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default function AdminLayout({ children }: any) {
))}
</nav>
</div>
<div className="flex-1 px-6 xl:w-[800px]">{children}</div>
<div className="flex-1 px-6 xl:w-[800px] ">{children}</div>
</div>
</div>
);
Expand Down
7 changes: 3 additions & 4 deletions apps/client/layouts/newLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Link from "next/link";
import { useRouter } from "next/router";
import { Fragment, useCallback, useEffect, useState } from "react";

import { spotlight } from "@mantine/spotlight";
import useTranslation from "next-translate/useTranslation";
import { useUser } from "../store/session";

Expand Down Expand Up @@ -496,7 +495,7 @@ export default function NewLayout({ children }: any) {
/>

<div className="flex flex-1 gap-x-4 self-stretch lg:gap-x-6 pb-2">
<div
{/* <div
className="relative mt-2 hidden sm:flex items-center w-full min-w-[320px] max-w-[360px] hover:cursor-pointer"
onClick={() => {
spotlight.open();
Expand All @@ -518,7 +517,7 @@ export default function NewLayout({ children }: any) {
/
</kbd>
</div>
</div>
</div> */}
<div className="flex w-full justify-end items-center gap-x-4 lg:gap-x-6">
<button
type="button"
Expand Down Expand Up @@ -590,7 +589,7 @@ export default function NewLayout({ children }: any) {
</div>

<main className="py-2">
<div className="px-2 py-2 sm:px-4">{children}</div>
<div className="p-4 sm:p-8">{children}</div>
</main>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion apps/client/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default function Home() {
}, []);

return (
<div className="flex flex-col xl:flex-row min-h-[85vh] m-6">
<div className="flex flex-col xl:flex-row min-h-[85vh]">
<div className="w-full xl:w-[70%]">
<div className="bg-white shadow rounded-lg">
<div className="px-4 sm:px-6 lg:w-full lg:mx-auto lg:px-8">
Expand Down

0 comments on commit 4d92010

Please sign in to comment.