@selfcommunity/react-ui
Version:
React UI Components to integrate a Community created with SelfCommunity Platform.
33 lines (32 loc) • 1.1 kB
JavaScript
import { SCCourseJoinStatusType } from '@selfcommunity/types';
export function isCourseNew(course) {
if (course && course.join_status === SCCourseJoinStatusType.JOINED) {
const createdAtDate = new Date(course.created_at);
const twoWeeksAgo = new Date();
twoWeeksAgo.setDate(twoWeeksAgo.getDate() - 14);
return createdAtDate >= twoWeeksAgo;
}
return false;
}
export function isCourseCompleted(course) {
return (course === null || course === void 0 ? void 0 : course.user_completion_rate) === 100;
}
var unitType;
(function (unitType) {
unitType["DAYS"] = "days";
unitType["WEEKS"] = "weeks";
})(unitType || (unitType = {}));
export function getDripDelayAndUnit(value) {
if (value > 7 && value % 7 === 0) {
return { delay: value / 7, _unit: unitType.WEEKS };
}
return { delay: value, _unit: unitType.DAYS };
}
export function getUrlLesson(course, lesson, section) {
return {
id: course.id,
slug: course.slug,
section_id: section ? section.id : lesson.section_id,
lesson_id: lesson.id
};
}