'use client';
import CreateCourseModal from '@components/Modals/Course/Create/CreateCourse';
import Modal from '@components/UI/Modal/Modal';
import { Edit2, Trash } from "lucide-react";
import { getAPIUrl, getBackendUrl, getUriWithOrg } from '@services/config/config';
import CoursesLogo from "public/svg/courses.svg";
import CollectionsLogo from "public/svg/collections.svg";
import { deleteCourseFromBackend } from '@services/courses/courses';
import Link from 'next/link';
import React from 'react'
import Image from 'next/image';
import { AuthContext } from '@components/Security/AuthProvider';
interface CourseProps {
orgslug: string;
courses: any;
}
// function to remove "course_" from the course_id
function removeCoursePrefix(course_id: string) {
return course_id.replace("course_", "");
}
function Courses(props: CourseProps) {
const orgslug = props.orgslug;
const courses = props.courses;
const [newCourseModal, setNewCourseModal] = React.useState(false);
async function deleteCourses(course_id: any) {
await deleteCourseFromBackend(course_id);
}
async function closeNewCourseModal() {
setNewCourseModal(false);
}
return (
}
dialogTitle="Create Course"
dialogDescription="Create a new course"
dialogTrigger={
}
/>
{courses.map((course: any) => (
))}
)
}
export const Title = (props: any) => {
return (
)
}
const AdminEditsArea = (props: any) => {
const org_roles_values = ["admin", "owner"];
const user_roles_values = ["role_admin"];
const auth: any = React.useContext(AuthContext);
console.log("auth: ", auth);
// this is amazingly terrible code, but gotta release that MVP
// TODO: fix this
function isAuthorized() {
const org_id = props.course.org_id;
const org_roles = auth.userInfo.user_object.orgs;
const user_roles = auth.userInfo.user_object.roles;
const org_role = org_roles.find((org: any) => org.org_id == org_id);
const user_role = user_roles.find((role: any) => role.org_id == org_id);
if (org_role && user_role) {
if (org_roles_values.includes(org_role.org_role) && user_roles_values.includes(user_role.role_id)) {
return true;
}
else {
return false;
}
} else {
return false;
}
}
// this is amazingly terrible code, but gotta release that MVP
// TODO: fix this
if (auth.isAuthenticated) {
if (isAuthorized()) {
return (
)
} else {
return (
)
}
}
else {
return (
)
}
}
export default Courses