Files
classroomio/apps/dashboard/src/lib/utils/functions/course.ts
T
Rotimi Best 8ab51095a7 fix: course and org landing page improvements (#468)
* make gift section HTML rendered

* hide classroomio branding on landing page

* improve section expanding

* feat: toggle show sections on course landing page

* fix: show discount on landing page course card
2024-09-09 01:14:55 +01:00

39 lines
963 B
TypeScript

import type { Course } from '../types';
export const isCourseFree = (cost: number) => !(Number(cost) > 0);
export const getStudentInviteLink = (_course: Course, orgSiteName: string, origin: string) => {
const hash = encodeURIComponent(
btoa(
JSON.stringify({
id: _course.id,
name: _course.title,
description: _course.description,
orgSiteName
})
)
);
return `${origin}/invite/s/${hash}`;
};
const tagsToReplace: { [k: string]: string } = {
'&': '&',
'<': '&lt;',
'>': '&gt;'
};
export function replaceHTMLTag(text: string) {
return text
.split('')
.map((char) => tagsToReplace[char] || char)
.join('');
}
export function calcCourseDiscount(percent = 0, cost: number, showDiscount: boolean) {
if (!percent || !showDiscount) return cost;
const discountAmount = (percent / 100) * cost;
const discountedPrice = cost - discountAmount;
return Math.round(discountedPrice);
}