feat: Add loading toasts

This commit is contained in:
swve 2024-08-13 18:13:58 +02:00
parent 0f2b8689c4
commit c68fa66ff8
7 changed files with 34 additions and 4 deletions

View file

@ -14,6 +14,7 @@ import { useLHSession } from '@components/Contexts/LHSessionContext'
import { useRouter } from 'next/navigation'
import React, { useEffect } from 'react'
import { mutate } from 'swr'
import toast from 'react-hot-toast'
type NewActivityButtonProps = {
chapterId: string
@ -41,8 +42,11 @@ function NewActivityButton(props: NewActivityButtonProps) {
props.orgslug,
{ revalidate: 1800 }
)
const toast_loading = toast.loading('Creating activity...')
await createActivity(activity, props.chapterId, org.org_id, access_token)
mutate(`${getAPIUrl()}courses/${course.courseStructure.course_uuid}/meta`)
toast.dismiss(toast_loading)
toast.success('Activity created successfully')
setNewActivityModal(false)
await revalidateTags(['courses'], props.orgslug)
router.refresh()
@ -55,9 +59,13 @@ function NewActivityButton(props: NewActivityButtonProps) {
activity: any,
chapterId: string
) => {
toast.loading('Uploading file and creating activity...')
await createFileActivity(file, type, activity, chapterId, access_token)
mutate(`${getAPIUrl()}courses/${course.courseStructure.course_uuid}/meta`)
setNewActivityModal(false)
toast.dismiss()
toast.success('File uploaded successfully')
toast.success('Activity created successfully')
await revalidateTags(['courses'], props.orgslug)
router.refresh()
}
@ -68,6 +76,7 @@ function NewActivityButton(props: NewActivityButtonProps) {
activity: any,
chapterId: string
) => {
const toast_loading = toast.loading('Creating activity and uploading file...')
await createExternalVideoActivity(
external_video_data,
activity,
@ -75,6 +84,8 @@ function NewActivityButton(props: NewActivityButtonProps) {
)
mutate(`${getAPIUrl()}courses/${course.courseStructure.course_uuid}/meta`)
setNewActivityModal(false)
toast.dismiss(toast_loading)
toast.success('Activity created successfully')
await revalidateTags(['courses'], props.orgslug)
router.refresh()
}

View file

@ -25,6 +25,7 @@ import { mutate } from 'swr'
import { deleteAssignmentUsingActivityUUID, getAssignmentFromActivityUUID } from '@services/courses/assignments'
import { useOrg } from '@components/Contexts/OrgContext'
import { useCourse } from '@components/Contexts/CourseContext'
import toast from 'react-hot-toast'
type ActivitiyElementProps = {
orgslug: string
@ -51,6 +52,7 @@ function ActivityElement(props: ActivitiyElementProps) {
const activityUUID = props.activity.activity_uuid
async function deleteActivityUI() {
const toast_loading = toast.loading('Deleting activity...')
// Assignments
if (props.activity.activity_type === 'TYPE_ASSIGNMENT') {
await deleteAssignmentUsingActivityUUID(props.activity.activity_uuid, access_token)
@ -59,10 +61,13 @@ function ActivityElement(props: ActivitiyElementProps) {
await deleteActivity(props.activity.activity_uuid, access_token)
mutate(`${getAPIUrl()}courses/${props.course_uuid}/meta`)
await revalidateTags(['courses'], props.orgslug)
toast.dismiss(toast_loading)
toast.success('Activity deleted successfully')
router.refresh()
}
async function changePublicStatus() {
const toast_loading = toast.loading('Updating assignment...')
await updateActivity(
{
...props.activity,
@ -72,6 +77,8 @@ function ActivityElement(props: ActivitiyElementProps) {
access_token
)
mutate(`${getAPIUrl()}courses/${props.course_uuid}/meta`)
toast.dismiss(toast_loading)
toast.success('The activity has been updated successfully')
await revalidateTags(['courses'], props.orgslug)
router.refresh()
}
@ -158,8 +165,8 @@ function ActivityElement(props: ActivitiyElementProps) {
{/* Publishing */}
<div
className={`hover:cursor-pointer p-1 px-3 border shadow-lg rounded-md font-bold text-xs flex items-center space-x-1 ${!props.activity.published
? 'bg-gradient-to-bl text-green-800 from-green-400/50 to-lime-200/80 border-green-600/10 shadow-green-900/10'
: 'bg-gradient-to-bl text-gray-800 from-gray-400/50 to-gray-200/80 border-gray-600/10 shadow-gray-900/10'
? 'bg-gradient-to-bl text-green-800 from-green-400/50 to-lime-200/80 border-green-600/10 shadow-green-900/10'
: 'bg-gradient-to-bl text-gray-800 from-gray-400/50 to-gray-200/80 border-gray-600/10 shadow-gray-900/10'
}`}
rel="noopener noreferrer"
onClick={() => changePublicStatus()}