mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: implement usage limits across the app
This commit is contained in:
parent
85ffb44d93
commit
a5fbf49304
15 changed files with 281 additions and 160 deletions
|
|
@ -15,7 +15,8 @@ import { getAPIUrl } from '@services/config/config'
|
|||
import { mutate } from 'swr'
|
||||
import { createAssignment } from '@services/courses/assignments'
|
||||
import { useLHSession } from '@components/Contexts/LHSessionContext'
|
||||
import { createActivity } from '@services/courses/activities'
|
||||
import { createActivity, deleteActivity } from '@services/courses/activities'
|
||||
import toast from 'react-hot-toast'
|
||||
|
||||
function NewAssignment({ submitActivity, chapterId, course, closeModal }: any) {
|
||||
const org = useOrg() as any;
|
||||
|
|
@ -55,7 +56,7 @@ function NewAssignment({ submitActivity, chapterId, course, closeModal }: any) {
|
|||
}
|
||||
|
||||
const activity_res = await createActivity(activity, chapterId, org?.id, session.data?.tokens?.access_token)
|
||||
await createAssignment({
|
||||
const res = await createAssignment({
|
||||
title: activityName,
|
||||
description: activityDescription,
|
||||
due_date: dueDate,
|
||||
|
|
@ -66,6 +67,14 @@ function NewAssignment({ submitActivity, chapterId, course, closeModal }: any) {
|
|||
activity_id: activity_res?.id,
|
||||
}, session.data?.tokens?.access_token)
|
||||
|
||||
if (res.success) {
|
||||
toast.success('Assignment created successfully')
|
||||
} else {
|
||||
toast.error(res.data.detail)
|
||||
await deleteActivity(activity_res.activity_uuid, session.data?.tokens?.access_token)
|
||||
|
||||
}
|
||||
|
||||
mutate(`${getAPIUrl()}courses/${course.courseStructure.course_uuid}/meta`)
|
||||
setIsSubmitting(false)
|
||||
closeModal()
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import { BarLoader } from 'react-spinners'
|
|||
import { revalidateTags } from '@services/utils/ts/requests'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { useLHSession } from '@components/Contexts/LHSessionContext'
|
||||
import toast from 'react-hot-toast'
|
||||
|
||||
function CreateCourseModal({ closeModal, orgslug }: any) {
|
||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||
|
|
@ -69,21 +70,27 @@ function CreateCourseModal({ closeModal, orgslug }: any) {
|
|||
e.preventDefault()
|
||||
setIsSubmitting(true)
|
||||
|
||||
let status = await createNewCourse(
|
||||
let res = await createNewCourse(
|
||||
orgId,
|
||||
{ name, description, tags, visibility },
|
||||
thumbnail,
|
||||
session.data?.tokens?.access_token
|
||||
)
|
||||
await revalidateTags(['courses'], orgslug)
|
||||
setIsSubmitting(false)
|
||||
|
||||
if (status.org_id == orgId) {
|
||||
closeModal()
|
||||
router.refresh()
|
||||
if (res.success) {
|
||||
await revalidateTags(['courses'], orgslug)
|
||||
} else {
|
||||
alert('Error creating course, please see console logs')
|
||||
setIsSubmitting(false)
|
||||
toast.success('Course created successfully')
|
||||
|
||||
if (res.data.org_id == orgId) {
|
||||
closeModal()
|
||||
router.refresh()
|
||||
await revalidateTags(['courses'], orgslug)
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
setIsSubmitting(false)
|
||||
toast.error(res.data.detail)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -99,9 +99,9 @@ export async function getActivityByID(
|
|||
return res
|
||||
}
|
||||
|
||||
export async function deleteActivity(activity_id: any, access_token: string) {
|
||||
export async function deleteActivity(activity_uuid: any, access_token: string) {
|
||||
const result = await fetch(
|
||||
`${getAPIUrl()}activities/${activity_id}`,
|
||||
`${getAPIUrl()}activities/${activity_uuid}`,
|
||||
RequestBodyWithAuthHeader('DELETE', null, null, access_token)
|
||||
)
|
||||
const res = await result.json()
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ export async function createNewCourse(
|
|||
`${getAPIUrl()}courses/?org_id=${org_id}`,
|
||||
RequestBodyFormWithAuthHeader('POST', formData, null, access_token)
|
||||
)
|
||||
const res = await errorHandling(result)
|
||||
const res = await getResponseMetadata(result)
|
||||
return res
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue