mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: working UI with the database
This commit is contained in:
parent
b0d492a116
commit
306230174e
4 changed files with 417 additions and 173 deletions
|
|
@ -11,6 +11,7 @@ import { useRouter } from 'next/navigation'
|
|||
import React, { useEffect, useState } from 'react'
|
||||
import { mutate } from 'swr'
|
||||
import { updateCourse } from '@services/courses/courses'
|
||||
import { updateCertification } from '@services/courses/certifications'
|
||||
import { useLHSession } from '@components/Contexts/LHSessionContext'
|
||||
|
||||
function SaveState(props: { orgslug: string }) {
|
||||
|
|
@ -32,6 +33,8 @@ function SaveState(props: { orgslug: string }) {
|
|||
// Course metadata
|
||||
await changeMetadataBackend()
|
||||
mutate(`${getAPIUrl()}courses/${course.courseStructure.course_uuid}/meta?with_unpublished_activities=${withUnpublishedActivities}`)
|
||||
// Certification data (if present)
|
||||
await saveCertificationData()
|
||||
await revalidateTags(['courses'], props.orgslug)
|
||||
dispatchCourse({ type: 'setIsSaved' })
|
||||
} finally {
|
||||
|
|
@ -66,6 +69,24 @@ function SaveState(props: { orgslug: string }) {
|
|||
dispatchCourse({ type: 'setIsSaved' })
|
||||
}
|
||||
|
||||
// Certification data
|
||||
const saveCertificationData = async () => {
|
||||
if (course.courseStructure._certificationData) {
|
||||
const certData = course.courseStructure._certificationData;
|
||||
try {
|
||||
await updateCertification(
|
||||
certData.certification_uuid,
|
||||
certData.config,
|
||||
session.data?.tokens?.access_token
|
||||
);
|
||||
console.log('Certification data saved successfully');
|
||||
} catch (error) {
|
||||
console.error('Failed to save certification data:', error);
|
||||
// Don't throw error to prevent breaking the main save flow
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleCourseOrder = (course_structure: any) => {
|
||||
const chapters = course_structure.chapters
|
||||
const chapter_order_by_ids = chapters.map((chapter: any) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue