@selfcommunity/react-ui
Version:
React UI Components to integrate a Community created with SelfCommunity Platform.
40 lines (39 loc) • 1.56 kB
JavaScript
import { SCCourseEditTabType } from '../../../types/course';
import { SCNotificationTypologyType } from '@selfcommunity/types';
import { SCRoutes } from '@selfcommunity/react-core';
function formatLessonUrl(notificationObject) {
return {
id: notificationObject.course.id,
slug: notificationObject.course.slug,
section_id: notificationObject.comment.section_id,
lesson_id: notificationObject.comment.lesson_id
};
}
function formatCourseRequestsUrl(notificationObject) {
return {
id: notificationObject.course.id,
slug: notificationObject.course.slug,
tab: SCCourseEditTabType.REQUESTS
};
}
const getRouteName = (notificationObject) => {
switch (notificationObject.type) {
case SCNotificationTypologyType.USER_COMMENTED_A_COURSE_LESSON:
return SCRoutes.COURSE_LESSON_COMMENTS_ROUTE_NAME;
case SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_COURSE:
return SCRoutes.COURSE_EDIT_ROUTE_NAME;
default:
return SCRoutes.COURSE_ROUTE_NAME;
}
};
const getRouteParams = (notificationObject) => {
switch (notificationObject.type) {
case SCNotificationTypologyType.USER_COMMENTED_A_COURSE_LESSON:
return formatLessonUrl(notificationObject);
case SCNotificationTypologyType.USER_REQUESTED_TO_JOIN_COURSE:
return formatCourseRequestsUrl(notificationObject);
default:
return notificationObject.course;
}
};
export { getRouteName, getRouteParams, formatLessonUrl };