Skip to content

Commit

Permalink
ticket ui
Browse files Browse the repository at this point in the history
  • Loading branch information
potts99 committed Dec 4, 2023
1 parent f967658 commit e0668ee
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 168 deletions.
24 changes: 17 additions & 7 deletions apps/api/src/controllers/ticket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ import { sendTicketStatus } from "../lib/nodemailer/ticket/status";
import { checkSession } from "../lib/session";
import { prisma } from "../prisma";

const validateEmail = (email: string) => {
return String(email)
.toLowerCase()
.match(
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|.(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
);
};

export function ticketRoutes(fastify: FastifyInstance) {
// Create a new ticket
fastify.post(
Expand Down Expand Up @@ -54,13 +62,9 @@ export function ticketRoutes(fastify: FastifyInstance) {
},
});

const webhook = await prisma.webhooks.findMany({
where: {
type: "ticket_created",
},
});

await sendTicketCreate(ticket);
if (!email && !validateEmail(email)) {
await sendTicketCreate(ticket);
}

if (engineer && engineer.name !== "Unassigned") {
const assgined = await prisma.user.findUnique({
Expand All @@ -72,6 +76,12 @@ export function ticketRoutes(fastify: FastifyInstance) {
await sendAssignedEmail(assgined!.email);
}

const webhook = await prisma.webhooks.findMany({
where: {
type: "ticket_created",
},
});

for (let i = 0; i < webhook.length; i++) {
if (webhook[i].active === true) {
const url = webhook[i].url;
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/lib/imap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const getEmails = async () => {

const parsedData = parseEmailContent(textAsHtml);

if (subject.includes("Re:")) {
if (subject !== undefined && subject.includes("Re:")) {
return await client.comment.create({
data: {
text: text ? text : "No Body",
Expand Down
92 changes: 46 additions & 46 deletions apps/api/src/lib/nodemailer/ticket/assigned.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,55 +34,55 @@ export async function sendAssignedEmail(email: any) {

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

let info = await mail.sendMail({
from: '"No reply 👻" [email protected]', // sender address
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">
<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>
await mail
.sendMail({
from: "[email protected]", // sender address
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">
<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</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,
<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 Assigned</h1>
<p style="font-size:20px;line-height:28px;margin:4px 0">
<p>Hello, <br>A new ticket has been assigned to you.</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 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://docs.peppermint.sh" rel="noopener noreferrer">Documentation</a> | <a target="_blank" style="color:#b7b7b7;text-decoration:underline" href="https://discord.gg/8XFkbgKmgv" 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>
</table>
</td>
</tr>
</table>
</body>
</html>
`,
});

console.log("Message sent: %s", info.messageId);

// Preview only available when sending through an Ethereal account
console.log("Preview URL: %s", nodeMailer.getTestMessageUrl(info));
</body>
</html>
`,
})
.then((info) => {
console.log("Message sent: %s", info.messageId);
})
.catch((err) => console.log(err));
}
} catch (error) {
console.log(error);
Expand Down
94 changes: 46 additions & 48 deletions apps/api/src/lib/nodemailer/ticket/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,59 +38,57 @@ export async function sendComment(
});
}

console.log("Sending email to: ", email);
await mail
.sendMail({
from: '"No reply 👻" [email protected]', // sender address
to: email,
subject: `New comment on a ticket`, // Subject line
text: `Hello there, Ticket: ${title}, has had an update with a comment of ${comment}`, // 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">
let info = await mail.sendMail({
from: '"No reply 👻" [email protected]', // sender address
to: email,
subject: `New comment on a ticket`, // Subject line
text: `Hello there, Ticket ${title}, has had an update with a comment of ${comment}`, // 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">
<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 Update for: ${title}</h1>
<p style="font-size:20px;line-height:28px;margin:4px 0">
<p>${comment}</p>
<p style="font-size:14px;margin:16px 0;color:#000">
Kind regards,
<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 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://docs.peppermint.sh" rel="noopener noreferrer">Documentation</a> | <a target="_blank" style="color:#b7b7b7;text-decoration:underline" href="https://discord.gg/8XFkbgKmgv" 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>
</table>
<h1 style="color:#1d1c1d;font-size:16px;font-weight:700;margin:10px 0;padding:0;line-height:42px">Ticket Update:</h1>
<p style="font-size:20px;line-height:28px;margin:4px 0">
<p>${comment}</p>
<p style="font-size:14px;margin:16px 0;color:#000">
Kind regards,
</body>
<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>
</table>
</body>
</html>
`,
});

console.log("Message sent: %s", info.messageId);

// Preview only available when sending through an Ethereal account
console.log("Preview URL: %s", nodeMailer.getTestMessageUrl(info));
</html>
`,
})
.then((info) => {
console.log("Message sent: %s", info.messageId);
})
.catch((err) => console.log(err));
}
} catch (error) {
console.log(error);
Expand Down
Loading

0 comments on commit e0668ee

Please sign in to comment.