Skip to content

Commit

Permalink
Added currency symbol & format the email template
Browse files Browse the repository at this point in the history
  • Loading branch information
ravirajput10 committed Nov 25, 2024
1 parent 3ae1b11 commit 4139416
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
6 changes: 5 additions & 1 deletion apps/web/lib/finalize-purchase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { send } from "@/services/mail";
import { formattedLocaleDate } from "@ui-lib/utils";
import { error } from "@/services/logger";
import { responses } from "@/config/strings";
import getSymbolFromCurrency from "currency-symbol-map";

const finalizePurchase = async (
userId: string,
Expand Down Expand Up @@ -103,10 +104,13 @@ async function sendSaleNotificationToAdmins({
(x) => x.email,
);

const currencySymbol = getSymbolFromCurrency(
domain?.settings?.currencyISOCode,
);
const emailBody = pug.render(saleEmailTemplate, {
order: purchase?.orderId,
courseName: course.title,
coursePrice: course.cost,
coursePrice: `${currencySymbol}${course.cost}`,
date: formattedLocaleDate(purchase!.purchasedOn),
email: user?.email,
hideCourseLitBranding: domain?.settings.hideCourseLitBranding,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/services/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const info = async (
metadata,
});
} else {
console.error(severityError, message, metadata);
console.error(severityInfo, message, metadata);

Check warning

Code scanning / CodeQL

Log injection Medium

Log entry depends on a
user-provided value
.
}
};

Expand Down
39 changes: 28 additions & 11 deletions apps/web/templates/sale-email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ doctype html
html
head
style(type='text/css').
.email-container {
max-width: 960px;
}
.cta-container {
margin: 32px 0px;
text-align: center;
Expand Down Expand Up @@ -31,26 +34,40 @@ html
border-radius: 6px;
text-align: center;
}
.signature {
padding-top: 20px;
.sale-notification-heading {
padding-bottom: 5px;
}
.sale-details {
padding-bottom: 10px;
}
.course-name-and-price {
display: flex;
justify-content: space-between;
align-items: center;
font-weight: bold;
padding-bottom: 20px;
}
body
p Yay! You have made a sale!
p Order: #{order}
p Date: #{date}
p Email: #{email}
p Course Title: #{courseName}
p Course Price: #{coursePrice}
div(class="email-container")
div(class="sale-notification-heading")
p Yay! You have made a sale!
div(class="sale-details")
p <strong>Order</strong>: #{order}
p <strong>Date</strong>: #{date}
p <strong>Email</strong>: #{email}
div(class="course-name-and-price")
span #{courseName}
span #{coursePrice}
p(class="signature")
| Best,
p #[a(href="https://x.com/courselit") @CourseLit]
| Best,
p #[a(href="https://x.com/courselit") @CourseLit]
if !hideCourseLitBranding
div(class="courselit-branding-container")
a(
href="https://courselit.app"
target="_blank"
class="courselit-branding-cta"
) Powered by <strong> CourseLit </strong>
) Powered by <strong>CourseLit</strong>
`;

export default saleEmailTemplate;

0 comments on commit 4139416

Please sign in to comment.