Skip to content

Commit

Permalink
Email template
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan-Papa committed Oct 14, 2024
1 parent b8f7cdb commit d0215ca
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 8 deletions.
120 changes: 120 additions & 0 deletions backend/server/utils/emails/create/html.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
doctype html
html(dir="ltr" xmlns="http://www.w3.org/1999/xhtml" xmlns:o="urn:schemas-microsoft-com:office:office" lang="en")
head
meta(charset="UTF-8")
meta(name="viewport" content="width=device-width, initial-scale=1")
meta(name="x-apple-disable-message-reformatting")
meta(http-equiv="X-UA-Compatible" content="IE=edge")
meta(name="format-detection" content="telephone=no")
title New Message
//[if (mso 16)]
style.
a { text-decoration: none; }
//[endif]
//[if gte mso 9]
style.
sup { font-size: 100% !important; }
//[endif]
//[if gte mso 9]
noscript
xml
o:OfficeDocumentSettings
o:AllowPNG
o:PixelsPerInch 96
style.
.rollover:hover .rollover-first { max-height: 0px !important; display: none !important; }
.rollover:hover .rollover-second { max-height: none !important; display: block !important; }
.rollover span { font-size: 0px; }
u + .body img ~ div div { display: none; }
#outlook a { padding: 0; }
span.MsoHyperlink, span.MsoHyperlinkFollowed { color: inherit; mso-style-priority: 99; }
a.es-button { mso-style-priority: 100 !important; text-decoration: none !important; }
a[x-apple-data-detectors], #MessageViewBody a {
color: inherit !important;
text-decoration: none !important;
font-size: inherit !important;
font-family: inherit !important;
font-weight: inherit !important;
line-height: inherit !important;
}
.es-desk-hidden {
display: none;
float: left;
overflow: hidden;
width: 0;
max-height: 0;
line-height: 0;
mso-hide: all;
}
@media only screen and (max-width: 600px) {
.es-m-p20b { padding-bottom: 20px !important; }
.es-p-default { }
*[class="gmail-fix"] { display: none !important; }
p, a { line-height: 150% !important; }
h1, h1 a, h2, h2 a, h3, h3 a, h4, h4 a, h5, h5 a, h6, h6 a { line-height: 120% !important; }
h1 { font-size: 30px !important; text-align: left; }
h2 { font-size: 24px !important; text-align: left; }
h3 { font-size: 20px !important; text-align: left; }
h4 { font-size: 24px !important; text-align: left; }
h5 { font-size: 20px !important; text-align: left; }
h6 { font-size: 16px !important; text-align: left; }
.es-menu td a { font-size: 14px !important; }
.es-m-txt-c { text-align: center !important; }
.es-m-txt-r { text-align: right !important; }
.es-m-txt-j { text-align: justify !important; }
.es-m-txt-l { text-align: left !important; }
.adapt-img { width: 100% !important; height: auto !important; }
}
@media screen and (max-width: 384px) {
.mail-message-content { width: 414px !important; }
}
body.body(style="width:100%;height:100%;padding:0;Margin:0")
.es-wrapper-color(dir="ltr" lang="en" style="background-color:#F6F6F6")
table.es-wrapper(role="none" style="border-collapse:collapse;border-spacing:0px;padding:0;Margin:0;width:100%;height:100%;background-repeat:repeat;background-position:center top;background-color:#F6F6F6")
tr
td(valign="top" style="padding:0;Margin:0")
table.es-header(role="none" style="width:100%;table-layout:fixed !important;background-color:transparent;background-repeat:repeat;background-position:center top")
tr
td(align="center" style="padding:0;Margin:0")
table.es-header-body(role="none" bgcolor="#ffffff" align="center" style="background-color:#FFFFFF;width:600px")
tr
td(align="left" style="padding-top:20px;padding-right:150px;padding-left:150px")
table.es-right(role="none" align="right" style="float:right")
tr
td(align="left" style="width:300px")
table(role="presentation" style="width:100%")
tr
td(align="center" style="font-size:0")
img.adapt-img(src="https://epiujlr.stripocdn.email/content/guids/CABINET_7549fef78daf44f7e4239172940d77c4be0d1029babaaeba34ec276d15a5ae69/images/h4hlogo.png" width="150" alt="" style="display:block;font-size:14px;border:0;outline:none;text-decoration:none")
table.es-content(role="none" align="center" style="width:100%;table-layout:fixed !important")
tr
td(align="center" style="padding:0;Margin:0")
table.es-content-body(role="none" bgcolor="#ffffff" align="center" style="background-color:#FFFFFF;width:600px")
tr
td(align="left" style="padding-top:20px;padding-right:20px;padding-left:20px")
table(role="none" style="width:100%")
tr
td(align="center" valign="top" style="width:560px")
table(role="presentation" style="width:100%")
tr
td(align="left")
p(style="Margin:0;font-family:arial, 'helvetica neue', helvetica, sans-serif;line-height:21px;letter-spacing:0;color:#333333;font-size:14px")
| Hello #{firstName} #{lastName}! This email was sent to you because an account was made with the email (#{email}) and the address #{address}.
table.es-footer(role="none" align="center" style="width:100%;table-layout:fixed !important;background-color:transparent;background-repeat:repeat;background-position:center top")
tr
td(align="center" style="padding:0;Margin:0")
table.es-footer-body(role="none" bgcolor="#ffffff" align="center" style="background-color:#FFFFFF;width:600px")
tr
td(align="left" style="padding-top:20px;padding-right:20px;padding-left:20px;padding-bottom:20px")
table.es-left(role="none" align="left" style="float:left;width:270px")
tr
td(align="left" class="es-m-p20b")
table(role="none" style="width:100%")
tr
td(align="center" style="display:none")
table.es-right(role="none" align="right" style="float:right;width:270px")
tr
td(align="left")
table(role="none" style="width:100%")
tr
td(align="center" style="display:none")
19 changes: 15 additions & 4 deletions backend/src/pages/api/user/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import {
import APIWrapper from "server/utils/APIWrapper";
import { getUser } from "server/utils/Authentication";
import { HandlerType, Role } from "src/utils/types";
import { sendEmail } from "server/utils/Authentication";
import { EmailSubject } from "src/utils/types";
import { EmailTemplate } from "src/utils/types";

export default APIWrapper({
GET: {
Expand All @@ -32,7 +35,6 @@ export default APIWrapper({
requireEmailVerified: false,
},
handler: async (req) => {
console.log("POST /api/user/user");
const email: string = req.body.email as string;
const birthday: Date = req.body.birthday as Date;
const firebaseUid: string = req.body.firebaseUid as string;
Expand All @@ -42,15 +44,12 @@ export default APIWrapper({
const profileImage: string = req.body.profileImage as string;
const address: string = req.body.address as string;
const annualPetVisitDay: Date = req.body.annualPetVisitDay as Date;
console.log("email", email);

const dbUser = await findUserByFirebaseUid(firebaseUid);
if (dbUser) {
throw new Error("User already exists in database!");
}

console.log("dbUser passed");

const roles = [Role.NONPROFIT_USER];
const isAdmin = email.endsWith("@healing4heroes.org");
if (isAdmin) {
Expand All @@ -72,6 +71,18 @@ export default APIWrapper({
);
if (!user) {
throw new Error("Failed to create user!");
} else {
let emailData = {
email: email,
address: address ? address : "N/A",
firstName: firstName ? firstName : "N/A",
lastName: lastName ? lastName : "N/A",
}
if (process.env.NODE_ENV === "production") {
await sendEmail("[email protected]", EmailSubject.ACCOUNT_CREATED, EmailTemplate.ACCOUNT_CREATED, emailData);
} else if (process.env.NODE_ENV === "development") {
await sendEmail("[email protected]", EmailSubject.ACCOUNT_CREATED, EmailTemplate.ACCOUNT_CREATED, emailData);
}
}

return user;
Expand Down
2 changes: 2 additions & 0 deletions backend/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,13 @@ export interface UploadedPart {
export enum EmailSubject {
EMAIL_VERIFICATION = "Verify Your Email for Healing4Heroes",
PASSWORD_RESET = "Reset Your Password for Healing4Heroes",
ACCOUNT_CREATED = "Account Created on Healing4Heroes",
}

export enum EmailTemplate {
EMAIL_VERIFICATION = "verify",
PASSWORD_RESET = "reset",
ACCOUNT_CREATED = "create",
}

/* User Retrieval */
Expand Down
3 changes: 0 additions & 3 deletions mobile/screens/Onboarding/SignUpScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export default function SignUpScreen(props: any) {

const handleSignUp = async () => {
try {
console.log("handleSignUp");
await auth.signOut().then().catch();
const userCredential = await ErrorWrapper({
functionToExecute: createUserWithEmailAndPassword,
Expand All @@ -65,8 +64,6 @@ export default function SignUpScreen(props: any) {
});
const user = userCredential.user;
const firebaseUid = user.uid;
console.log("user");
console.log(user);
const createdUser = await ErrorWrapper({
functionToExecute: userCreateUser,
errorHandler: setErrorMessage,
Expand Down
1 change: 0 additions & 1 deletion mobile/screens/User/UserDashboardScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ export default function UserDashboardScreen(props: any) {
</View>

{/* animal cards */}
<Text>{JSON.stringify(userInfo)}</Text>
<HealthCard
handlerName={userInfo?.firstName + " " + userInfo?.lastName}
animalName={animalInfo?.name as string}
Expand Down

0 comments on commit d0215ca

Please sign in to comment.