Delete a course functionality

This commit is contained in:
Rotimi Best
2023-09-10 07:24:06 +01:00
parent 7e74568e74
commit bd2f647ca1
9 changed files with 29 additions and 11 deletions
@@ -47,7 +47,7 @@
let openPopover = false; let openPopover = false;
let player = null; let player = null;
let aiButtonClass = 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 = const onChange =
(tab = 0) => (tab = 0) =>
@@ -10,6 +10,7 @@
import { settingsDialog } from './store'; import { settingsDialog } from './store';
import { course } from '$lib/components/Course/store'; import { course } from '$lib/components/Course/store';
import { updateCourse, deleteCourse } from '$lib/utils/services/courses'; import { updateCourse, deleteCourse } from '$lib/utils/services/courses';
import { currentOrgPath } from '$lib/utils/store/org';
let shouldDelete = false; let shouldDelete = false;
let avatar; let avatar;
@@ -41,7 +42,7 @@
async function handleDelete() { async function handleDelete() {
$settingsDialog.open = false; $settingsDialog.open = false;
await deleteCourse($course.id); await deleteCourse($course.id);
goto('/courses'); goto($currentOrgPath + '/courses');
} }
// function setAvatar(logo) { // function setAvatar(logo) {
@@ -5,6 +5,7 @@
import getCurrencyFormatter from '$lib/utils/functions/getCurrencyFormatter'; import getCurrencyFormatter from '$lib/utils/functions/getCurrencyFormatter';
import OverflowMenuHorizontalIcon from 'carbon-icons-svelte/lib/OverflowMenuHorizontal.svelte'; import OverflowMenuHorizontalIcon from 'carbon-icons-svelte/lib/OverflowMenuHorizontal.svelte';
import ArrowRight from 'carbon-icons-svelte/lib/ArrowRight.svelte'; import ArrowRight from 'carbon-icons-svelte/lib/ArrowRight.svelte';
// import { deleteCourse } from '$lib/utils/services/courses';
export let bannerImage: string | undefined; export let bannerImage: string | undefined;
export let id = ''; export let id = '';
@@ -17,6 +18,7 @@
export let totalLessons = 0; export let totalLessons = 0;
export let currency = 'NGN'; export let currency = 'NGN';
export let isOnLandingPage = false; export let isOnLandingPage = false;
// export let onDelete = (id: string) => {};
let formatter = getCurrencyFormatter(currency); let formatter = getCurrencyFormatter(currency);
@@ -37,10 +39,15 @@
} }
// { // {
// label: 'Delete', // label: 'Delete',
// show: () => role_id === ROLE.TUTOR,
// onClick() { // onClick() {
// console.log('Deleting'); // (async () => {
// }, // await deleteCourse(id);
// }, // onDelete(id);
// console.log('Deleting');
// })();
// }
// }
].filter((option) => option.show()); ].filter((option) => option.show());
} }
</script> </script>
+1 -2
View File
@@ -1,11 +1,10 @@
<script> <script lang="ts">
import Box from '../Box/index.svelte'; import Box from '../Box/index.svelte';
import Card from './components/Card/index.svelte'; import Card from './components/Card/index.svelte';
import CardLoader from './components/Card/Loader.svelte'; import CardLoader from './components/Card/Loader.svelte';
import CoursesEmptyIcon from '../Icons/CoursesEmptyIcon.svelte'; import CoursesEmptyIcon from '../Icons/CoursesEmptyIcon.svelte';
import CopyCourseModal from './components/CopyCourseModal/index.svelte'; import CopyCourseModal from './components/CopyCourseModal/index.svelte';
import { courses, courseMetaDeta } from './store'; import { courses, courseMetaDeta } from './store';
import { isMobile } from '$lib/utils/store/useMobile';
</script> </script>
<CopyCourseModal /> <CopyCourseModal />
@@ -1,6 +1,7 @@
import { writable } from 'svelte/store'; import { writable } from 'svelte/store';
import type { Course } from '$lib/utils/types';
export const courses = writable([]); export const courses = writable<Course[]>([]);
export const courseMetaDeta = writable({ export const courseMetaDeta = writable({
isLoading: true isLoading: true
}); });
+5
View File
@@ -0,0 +1,5 @@
export enum STATUS {
ACTIVE,
ARCHIVE,
DELETED
}
+6 -3
View File
@@ -2,9 +2,10 @@ import { supabase } from '$lib/utils/functions/supabase';
import { isUUID } from '$lib/utils/functions/isUUID'; import { isUUID } from '$lib/utils/functions/isUUID';
import { QUESTION_TYPE } from '$lib/components/Question/constants'; import { QUESTION_TYPE } from '$lib/components/Question/constants';
import type { Lesson, Course, Group, Groupmember, Exercise } from '$lib/utils/types'; 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']) { 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) { if (slug) {
match.slug = slug; match.slug = slug;
@@ -12,6 +13,8 @@ export async function fetchCourse(courseId?: Course['id'], slug?: Course['slug']
match.id = courseId; match.id = courseId;
} }
match.status = STATUS[STATUS.ACTIVE];
const { data, error } = await supabase const { data, error } = await supabase
.from('course') .from('course')
.select( .select(
@@ -109,7 +112,7 @@ export async function updateCourse(
avatar: string | undefined, avatar: string | undefined,
course: Course course: Course
) { ) {
if (avatar) { if (avatar && courseId) {
const filename = `course/${courseId + Date.now()}.webp`; const filename = `course/${courseId + Date.now()}.webp`;
const { data } = await supabase.storage.from('avatars').upload(filename, avatar, { 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']) { 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) { export function addGroupMember(member: any) {
+1
View File
@@ -147,6 +147,7 @@ export async function getCourseBySiteName(siteName) {
` `
) )
.eq('group.organization.siteName', siteName) .eq('group.organization.siteName', siteName)
.eq('status', 'ACTIVE')
.eq('is_published', true); .eq('is_published', true);
if (error) { if (error) {
+1
View File
@@ -99,6 +99,7 @@ export interface Course {
organization?: Organization; organization?: Organization;
is_certificate_downloadable?: boolean; is_certificate_downloadable?: boolean;
certificate_theme?: string; certificate_theme?: string;
status: string;
} }
export interface Groupmember { export interface Groupmember {