feat(dashboard): add view course site actions and publish flow (#690)
Add View course site and Publish course options to org course context menus. Replace the course header View as student button with View Course Site and a companion overflow menu that includes View as student plus list actions. Show a publish prompt modal for unpublished courses and support #publish deep links in course settings.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { generateSlug } from '@cio/utils/functions';
|
||||
import { isObject } from '$lib/utils/functions/isObject';
|
||||
import { courseApi } from '$features/course/api';
|
||||
import type { Course } from '$features/course/utils/types';
|
||||
|
||||
export async function publishCourse(course: Course): Promise<boolean> {
|
||||
if (!course?.id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let slug = course.slug?.trim() ? course.slug : undefined;
|
||||
if (!slug) {
|
||||
slug = generateSlug(course.title, { appendTimestamp: true });
|
||||
}
|
||||
|
||||
const metadataPayload = {
|
||||
...(isObject(course.metadata) ? course.metadata : {}),
|
||||
allowNewStudent: true
|
||||
};
|
||||
|
||||
const result = await courseApi.update(
|
||||
course.id,
|
||||
{
|
||||
isPublished: true,
|
||||
slug,
|
||||
metadata: metadataPayload
|
||||
},
|
||||
{ showSuccessToast: true }
|
||||
);
|
||||
|
||||
return !!result;
|
||||
}
|
||||
Reference in New Issue
Block a user