diff --git a/src/lib/components/Course/components/Lesson/Materials/index.svelte b/src/lib/components/Course/components/Lesson/Materials/index.svelte index 4562c24a..7eb74fd5 100644 --- a/src/lib/components/Course/components/Lesson/Materials/index.svelte +++ b/src/lib/components/Course/components/Lesson/Materials/index.svelte @@ -47,7 +47,7 @@ let openPopover = false; let player = null; let aiButtonClass = - 'flex items-center px-5 py-2 border border-gray-300 hover:bg-gray-200 rounded-md w-full mb-2'; + 'flex items-center px-5 py-2 border border-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700 rounded-md w-full mb-2'; const onChange = (tab = 0) => diff --git a/src/lib/components/Course/components/Settings/index.svelte b/src/lib/components/Course/components/Settings/index.svelte index 0bf445e4..3f718a21 100644 --- a/src/lib/components/Course/components/Settings/index.svelte +++ b/src/lib/components/Course/components/Settings/index.svelte @@ -10,6 +10,7 @@ import { settingsDialog } from './store'; import { course } from '$lib/components/Course/store'; import { updateCourse, deleteCourse } from '$lib/utils/services/courses'; + import { currentOrgPath } from '$lib/utils/store/org'; let shouldDelete = false; let avatar; @@ -41,7 +42,7 @@ async function handleDelete() { $settingsDialog.open = false; await deleteCourse($course.id); - goto('/courses'); + goto($currentOrgPath + '/courses'); } // function setAvatar(logo) { diff --git a/src/lib/components/Courses/components/Card/index.svelte b/src/lib/components/Courses/components/Card/index.svelte index 5a9ef452..308152ad 100644 --- a/src/lib/components/Courses/components/Card/index.svelte +++ b/src/lib/components/Courses/components/Card/index.svelte @@ -5,6 +5,7 @@ import getCurrencyFormatter from '$lib/utils/functions/getCurrencyFormatter'; import OverflowMenuHorizontalIcon from 'carbon-icons-svelte/lib/OverflowMenuHorizontal.svelte'; import ArrowRight from 'carbon-icons-svelte/lib/ArrowRight.svelte'; + // import { deleteCourse } from '$lib/utils/services/courses'; export let bannerImage: string | undefined; export let id = ''; @@ -17,6 +18,7 @@ export let totalLessons = 0; export let currency = 'NGN'; export let isOnLandingPage = false; + // export let onDelete = (id: string) => {}; let formatter = getCurrencyFormatter(currency); @@ -37,10 +39,15 @@ } // { // label: 'Delete', + // show: () => role_id === ROLE.TUTOR, // onClick() { - // console.log('Deleting'); - // }, - // }, + // (async () => { + // await deleteCourse(id); + // onDelete(id); + // console.log('Deleting'); + // })(); + // } + // } ].filter((option) => option.show()); } diff --git a/src/lib/components/Courses/index.svelte b/src/lib/components/Courses/index.svelte index 0627b91e..2ff5b159 100644 --- a/src/lib/components/Courses/index.svelte +++ b/src/lib/components/Courses/index.svelte @@ -1,11 +1,10 @@ - diff --git a/src/lib/components/Courses/store.js b/src/lib/components/Courses/store.ts similarity index 83% rename from src/lib/components/Courses/store.js rename to src/lib/components/Courses/store.ts index f30531e2..def11467 100644 --- a/src/lib/components/Courses/store.js +++ b/src/lib/components/Courses/store.ts @@ -1,6 +1,7 @@ import { writable } from 'svelte/store'; +import type { Course } from '$lib/utils/types'; -export const courses = writable([]); +export const courses = writable([]); export const courseMetaDeta = writable({ isLoading: true }); diff --git a/src/lib/utils/constants/course.ts b/src/lib/utils/constants/course.ts new file mode 100644 index 00000000..bd791835 --- /dev/null +++ b/src/lib/utils/constants/course.ts @@ -0,0 +1,5 @@ +export enum STATUS { + ACTIVE, + ARCHIVE, + DELETED +} diff --git a/src/lib/utils/services/courses/index.ts b/src/lib/utils/services/courses/index.ts index b980bee9..3f38a9bd 100644 --- a/src/lib/utils/services/courses/index.ts +++ b/src/lib/utils/services/courses/index.ts @@ -2,9 +2,10 @@ import { supabase } from '$lib/utils/functions/supabase'; import { isUUID } from '$lib/utils/functions/isUUID'; import { QUESTION_TYPE } from '$lib/components/Question/constants'; import type { Lesson, Course, Group, Groupmember, Exercise } from '$lib/utils/types'; +import { STATUS } from '$lib/utils/constants/course'; export async function fetchCourse(courseId?: Course['id'], slug?: Course['slug']) { - let match: { slug?: string; id?: string } = {}; + let match: { slug?: string; id?: string; status?: string } = {}; if (slug) { match.slug = slug; @@ -12,6 +13,8 @@ export async function fetchCourse(courseId?: Course['id'], slug?: Course['slug'] match.id = courseId; } + match.status = STATUS[STATUS.ACTIVE]; + const { data, error } = await supabase .from('course') .select( @@ -109,7 +112,7 @@ export async function updateCourse( avatar: string | undefined, course: Course ) { - if (avatar) { + if (avatar && courseId) { const filename = `course/${courseId + Date.now()}.webp`; const { data } = await supabase.storage.from('avatars').upload(filename, avatar, { @@ -132,7 +135,7 @@ export async function updateCourse( } export async function deleteCourse(courseId: Course['id']) { - return await supabase.from('course').delete().match({ id: courseId }); + return await supabase.from('course').update({ status: 'DELETED' }).match({ id: courseId }); } export function addGroupMember(member: any) { diff --git a/src/lib/utils/services/org/index.js b/src/lib/utils/services/org/index.js index 8c0c5402..e5bc4ba0 100644 --- a/src/lib/utils/services/org/index.js +++ b/src/lib/utils/services/org/index.js @@ -147,6 +147,7 @@ export async function getCourseBySiteName(siteName) { ` ) .eq('group.organization.siteName', siteName) + .eq('status', 'ACTIVE') .eq('is_published', true); if (error) { diff --git a/src/lib/utils/types/index.ts b/src/lib/utils/types/index.ts index ff0571ba..98cdc6ff 100644 --- a/src/lib/utils/types/index.ts +++ b/src/lib/utils/types/index.ts @@ -99,6 +99,7 @@ export interface Course { organization?: Organization; is_certificate_downloadable?: boolean; certificate_theme?: string; + status: string; } export interface Groupmember {