diff --git a/front/app/orgs/[orgslug]/(withmenu)/collections/admin.tsx b/front/app/orgs/[orgslug]/(withmenu)/collections/admin.tsx index 732c4068..d55e87c7 100644 --- a/front/app/orgs/[orgslug]/(withmenu)/collections/admin.tsx +++ b/front/app/orgs/[orgslug]/(withmenu)/collections/admin.tsx @@ -15,7 +15,7 @@ const CollectionAdminEditsArea = (props: any) => { const deleteCollectionUI = async (collectionId: number) => { await deleteCollection(collectionId); - revalidateTags(["collections"], props.orgslug); + await revalidateTags(["collections"], props.orgslug); // reload the page router.refresh(); router.push(getUriWithOrg(props.orgslug, "/collections")); diff --git a/front/app/orgs/[orgslug]/(withmenu)/collections/new/page.tsx b/front/app/orgs/[orgslug]/(withmenu)/collections/new/page.tsx index abee6674..e338f86e 100644 --- a/front/app/orgs/[orgslug]/(withmenu)/collections/new/page.tsx +++ b/front/app/orgs/[orgslug]/(withmenu)/collections/new/page.tsx @@ -44,11 +44,10 @@ function NewCollection(params: any) { org_id: org.org_id, }; await createCollection(collection); - revalidateTags(["collections"], orgslug); + await revalidateTags(["collections"], orgslug); + router.refresh(); router.prefetch(getUriWithOrg(orgslug, "/collections")); router.push(getUriWithOrg(orgslug, "/collections")); - router.refresh(); - }; diff --git a/front/app/orgs/[orgslug]/(withmenu)/collections/page.tsx b/front/app/orgs/[orgslug]/(withmenu)/collections/page.tsx index 0524577b..8bc03745 100644 --- a/front/app/orgs/[orgslug]/(withmenu)/collections/page.tsx +++ b/front/app/orgs/[orgslug]/(withmenu)/collections/page.tsx @@ -39,7 +39,7 @@ const CollectionsPage = async (params: any) => { const orgslug = params.params.orgslug; const org = await getOrganizationContextInfo(orgslug, { revalidate: 1800, tags: ['organizations'] }); const org_id = org.org_id; - const collections = await getOrgCollectionsWithAuthHeader(org_id, access_token_cookie ? access_token_cookie.value : null); + const collections = await getOrgCollectionsWithAuthHeader(org_id, access_token_cookie ? access_token_cookie.value : null, { revalidate: 0, tags: ['collections'] }); return ( diff --git a/front/app/orgs/[orgslug]/(withmenu)/course/[courseid]/course.tsx b/front/app/orgs/[orgslug]/(withmenu)/course/[courseid]/course.tsx index 95d1149c..a39c6865 100644 --- a/front/app/orgs/[orgslug]/(withmenu)/course/[courseid]/course.tsx +++ b/front/app/orgs/[orgslug]/(withmenu)/course/[courseid]/course.tsx @@ -23,7 +23,7 @@ const CourseClient = (props: any) => { async function startCourseUI() { // Create activity await startCourse("course_" + courseid, orgslug); - revalidateTags(['courses'], orgslug); + await revalidateTags(['courses'], orgslug); router.refresh(); // refresh page (FIX for Next.js BUG) @@ -34,7 +34,7 @@ const CourseClient = (props: any) => { // Close activity let activity = await removeCourse("course_" + courseid, orgslug); // Mutate course - revalidateTags(['courses'], orgslug); + await revalidateTags(['courses'], orgslug); router.refresh(); // refresh page (FIX for Next.js BUG) diff --git a/front/app/orgs/[orgslug]/(withmenu)/course/[courseid]/edit/[[...subpage]]/edit.tsx b/front/app/orgs/[orgslug]/(withmenu)/course/[courseid]/edit/[[...subpage]]/edit.tsx index c290d344..d4b95bd1 100644 --- a/front/app/orgs/[orgslug]/(withmenu)/course/[courseid]/edit/[[...subpage]]/edit.tsx +++ b/front/app/orgs/[orgslug]/(withmenu)/course/[courseid]/edit/[[...subpage]]/edit.tsx @@ -1,6 +1,6 @@ "use client"; import React, { FC, use, useEffect, useReducer } from 'react' -import { swrFetcher } from "@services/utils/ts/requests"; +import { revalidateTags, swrFetcher } from "@services/utils/ts/requests"; import { getAPIUrl, getUriWithOrg } from '@services/config/config'; import useSWR, { mutate } from 'swr'; import { getCourseThumbnailMediaDirectory } from '@services/media/media'; @@ -12,6 +12,7 @@ import { updateChaptersMetadata } from '@services/courses/chapters'; import { Check, SaveAllIcon, Timer } from 'lucide-react'; import Loading from '../../loading'; import { updateCourse } from '@services/courses/courses'; +import { useRouter } from 'next/navigation'; function CourseEditClient({ courseid, subpage, params }: { courseid: string, subpage: string, params: any }) { const { data: chapters_meta, error: chapters_meta_error, isLoading: chapters_meta_isloading } = useSWR(`${getAPIUrl()}chapters/meta/course_${courseid}`, swrFetcher); @@ -19,6 +20,7 @@ function CourseEditClient({ courseid, subpage, params }: { courseid: string, sub const [courseChaptersMetadata, dispatchCourseChaptersMetadata] = useReducer(courseChaptersReducer, {}); const [courseState, dispatchCourseMetadata] = useReducer(courseReducer, {}); const [savedContent, dispatchSavedContent] = useReducer(savedContentReducer, true); + const router = useRouter(); @@ -58,11 +60,15 @@ function CourseEditClient({ courseid, subpage, params }: { courseid: string, sub await updateChaptersMetadata(courseid, courseChaptersMetadata) dispatchSavedContent({ type: 'saved_content' }) await mutate(`${getAPIUrl()}chapters/meta/course_${courseid}`) + await revalidateTags(['courses'], course.org_slug) + router.refresh() } else if (subpage.toString() === 'general') { await updateCourse(courseid, courseState) dispatchSavedContent({ type: 'saved_content' }) await mutate(`${getAPIUrl()}courses/course_${courseid}`) + await revalidateTags(['courses'], course.org_slug) + router.refresh() } } diff --git a/front/app/orgs/[orgslug]/(withmenu)/course/[courseid]/edit/subpages/CourseContentEdition.tsx b/front/app/orgs/[orgslug]/(withmenu)/course/[courseid]/edit/subpages/CourseContentEdition.tsx index 41c1f27f..81b3adb9 100644 --- a/front/app/orgs/[orgslug]/(withmenu)/course/[courseid]/edit/subpages/CourseContentEdition.tsx +++ b/front/app/orgs/[orgslug]/(withmenu)/course/[courseid]/edit/subpages/CourseContentEdition.tsx @@ -64,7 +64,7 @@ function CourseContentEdition(props: any) { await createChapter(chapter, courseid); mutate(`${getAPIUrl()}chapters/meta/course_${courseid}`); // await getCourseChapters(); - revalidateTags(['courses'], orgslug); + await revalidateTags(['courses'], orgslug); router.refresh(); setNewChapterModal(false); }; @@ -77,7 +77,7 @@ function CourseContentEdition(props: any) { mutate(`${getAPIUrl()}chapters/meta/course_${courseid}`); // await getCourseChapters(); setNewActivityModal(false); - revalidateTags(['courses'], orgslug); + await revalidateTags(['courses'], orgslug); router.refresh(); }; @@ -88,7 +88,7 @@ function CourseContentEdition(props: any) { mutate(`${getAPIUrl()}chapters/meta/course_${courseid}`); // await getCourseChapters(); setNewActivityModal(false); - revalidateTags(['courses'], orgslug); + await revalidateTags(['courses'], orgslug); router.refresh(); }; @@ -99,7 +99,7 @@ function CourseContentEdition(props: any) { mutate(`${getAPIUrl()}chapters/meta/course_${courseid}`); // await getCourseChapters(); setNewActivityModal(false); - revalidateTags(['courses'], orgslug); + await revalidateTags(['courses'], orgslug); router.refresh(); }; @@ -108,7 +108,7 @@ function CourseContentEdition(props: any) { await deleteChapter(chapterId); mutate(`${getAPIUrl()}chapters/meta/course_${courseid}`); // await getCourseChapters(); - revalidateTags(['courses'], orgslug); + await revalidateTags(['courses'], orgslug); router.refresh(); }; diff --git a/front/app/orgs/[orgslug]/(withmenu)/courses/courses.tsx b/front/app/orgs/[orgslug]/(withmenu)/courses/courses.tsx index 58385d6e..8484aece 100644 --- a/front/app/orgs/[orgslug]/(withmenu)/courses/courses.tsx +++ b/front/app/orgs/[orgslug]/(withmenu)/courses/courses.tsx @@ -36,7 +36,7 @@ function Courses(props: CourseProps) { async function deleteCourses(course_id: any) { await deleteCourseFromBackend(course_id); - revalidateTags(['courses'], orgslug); + await revalidateTags(['courses'], orgslug); router.refresh(); } diff --git a/front/app/orgs/[orgslug]/(withmenu)/page.tsx b/front/app/orgs/[orgslug]/(withmenu)/page.tsx index 897513e8..45af8588 100644 --- a/front/app/orgs/[orgslug]/(withmenu)/page.tsx +++ b/front/app/orgs/[orgslug]/(withmenu)/page.tsx @@ -38,7 +38,7 @@ const OrgHomePage = async (params: any) => { const courses = await getOrgCoursesWithAuthHeader(orgslug, { revalidate: 0, tags: ['courses'] }, access_token_cookie ? access_token_cookie.value : null); const org = await getOrganizationContextInfo(orgslug, { revalidate: 1800, tags: ['organizations'] }); - const collections = await getOrgCollectionsWithAuthHeader(org.org_id, access_token_cookie ? access_token_cookie.value : null); + const collections = await getOrgCollectionsWithAuthHeader(org.org_id, access_token_cookie ? access_token_cookie.value : null, { revalidate: 0, tags: ['courses'] }); // function to remove "course_" from the course_id diff --git a/front/app/orgs/[orgslug]/settings/organization/general/organization.tsx b/front/app/orgs/[orgslug]/settings/organization/general/organization.tsx index 116c919b..695a6a9c 100644 --- a/front/app/orgs/[orgslug]/settings/organization/general/organization.tsx +++ b/front/app/orgs/[orgslug]/settings/organization/general/organization.tsx @@ -33,7 +33,7 @@ function OrganizationClient(props: any) { let org_id = org.org_id; await uploadOrganizationLogo(org_id, selectedFile); setSelectedFile(null); // Reset the selected file - revalidateTags(['organizations'], org.slug); + await revalidateTags(['organizations'], org.slug); router.refresh(); } @@ -54,7 +54,7 @@ function OrganizationClient(props: any) { await updateOrganization(org_id, values); // Mutate the org - revalidateTags(['organizations'], org.slug); + await revalidateTags(['organizations'], org.slug); router.refresh(); } diff --git a/front/components/Objects/Modals/Course/Create/CreateCourse.tsx b/front/components/Objects/Modals/Course/Create/CreateCourse.tsx index dd92a7d1..d1bc7b63 100644 --- a/front/components/Objects/Modals/Course/Create/CreateCourse.tsx +++ b/front/components/Objects/Modals/Course/Create/CreateCourse.tsx @@ -43,13 +43,13 @@ function CreateCourseModal({ closeModal, orgslug }: any) { e.preventDefault(); setIsSubmitting(true); let status = await createNewCourse(orgId, { name, description }, thumbnail); - revalidateTags(['courses'], orgslug); + await revalidateTags(['courses'], orgslug); setIsSubmitting(false); if (status.org_id == orgId) { closeModal(); router.refresh(); - revalidateTags(['courses'], orgslug); + await revalidateTags(['courses'], orgslug); // refresh page (FIX for Next.js BUG) // window.location.reload(); diff --git a/front/components/Pages/Trail/TrailCourseElement.tsx b/front/components/Pages/Trail/TrailCourseElement.tsx index 67332711..253f2e87 100644 --- a/front/components/Pages/Trail/TrailCourseElement.tsx +++ b/front/components/Pages/Trail/TrailCourseElement.tsx @@ -21,7 +21,7 @@ function TrailCourseElement(props: TrailCourseElementProps) { // Close activity let activity = await removeCourse(course_id, props.orgslug); // Mutate course - revalidateTags(['courses'], props.orgslug); + await revalidateTags(['courses'], props.orgslug); router.refresh(); // Mutate diff --git a/front/services/courses/collections.ts b/front/services/courses/collections.ts index 26ba6f92..d1f9e29c 100644 --- a/front/services/courses/collections.ts +++ b/front/services/courses/collections.ts @@ -40,8 +40,8 @@ export async function getOrgCollections() { return res; } -export async function getOrgCollectionsWithAuthHeader(org_id: string, access_token: string) { - const result: any = await fetch(`${getAPIUrl()}collections/org_id/${org_id}/page/1/limit/10`, RequestBodyWithAuthHeader("GET", null, { revalidate: 3 }, access_token)); +export async function getOrgCollectionsWithAuthHeader(org_id: string, access_token: string, next: any) { + const result: any = await fetch(`${getAPIUrl()}collections/org_id/${org_id}/page/1/limit/10`, RequestBodyWithAuthHeader("GET", null, next, access_token)); const res = await errorHandling(result); return res; } diff --git a/front/services/utils/ts/requests.ts b/front/services/utils/ts/requests.ts index b0b49390..fc4e66c7 100644 --- a/front/services/utils/ts/requests.ts +++ b/front/services/utils/ts/requests.ts @@ -85,7 +85,7 @@ export const errorHandling = (res: any) => { return res.json(); }; -export const revalidateTags = (tags: string[], orgslug: string) => { +export const revalidateTags = async (tags: string[], orgslug: string) => { const url = getUriWithOrg(orgslug, ""); tags.forEach((tag) => { fetch(`${url}/api/revalidate?tag=${tag}`);