diff --git a/front/app/api/revalidate/route.ts b/front/app/api/revalidate/route.ts new file mode 100644 index 00000000..c3d0aa71 --- /dev/null +++ b/front/app/api/revalidate/route.ts @@ -0,0 +1,19 @@ +import { NextRequest, NextResponse } from "next/server"; +import { revalidateTag } from "next/cache"; + +export async function GET(request: NextRequest) { + const tag: any = request.nextUrl.searchParams.get("tag"); + revalidateTag(tag); + + return NextResponse.json( + { revalidated: true, now: Date.now() }, + { + status: 200, + headers: { + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", + "Access-Control-Allow-Headers": "Content-Type, Authorization", + }, + } + ); +} diff --git a/front/app/orgs/[orgslug]/(withmenu)/collections/new/page.tsx b/front/app/orgs/[orgslug]/(withmenu)/collections/new/page.tsx index 28185a44..e1de0cb6 100644 --- a/front/app/orgs/[orgslug]/(withmenu)/collections/new/page.tsx +++ b/front/app/orgs/[orgslug]/(withmenu)/collections/new/page.tsx @@ -20,7 +20,7 @@ function NewCollection(params: any) { React.useEffect(() => { async function getOrg() { - const org = await getOrganizationContextInfo(orgslug); + const org = await getOrganizationContextInfo(orgslug, { revalidate: 1800 }); setOrg(org); } getOrg(); diff --git a/front/app/orgs/[orgslug]/(withmenu)/course/[courseid]/edit/page.tsx b/front/app/orgs/[orgslug]/(withmenu)/course/[courseid]/edit/page.tsx index bbb0b04f..0dda558b 100644 --- a/front/app/orgs/[orgslug]/(withmenu)/course/[courseid]/edit/page.tsx +++ b/front/app/orgs/[orgslug]/(withmenu)/course/[courseid]/edit/page.tsx @@ -35,7 +35,7 @@ function CourseEdit(params: any) { async function getCourseChapters() { try { - const courseChapters = await getCourseChaptersMetadata(courseid); + const courseChapters = await getCourseChaptersMetadata(courseid, { revalidate: 120 }); setData(courseChapters); } catch (error: any) { denyAccessToUser(error, router) @@ -80,7 +80,7 @@ function CourseEdit(params: any) { // Submit new activity const submitActivity = async (activity: any) => { console.log("submitActivity", activity); - let org = await getOrganizationContextInfo(orgslug); + let org = await getOrganizationContextInfo(orgslug, { revalidate: 1800 }); await updateChaptersMetadata(courseid, data); await createActivity(activity, activity.chapterId, org.org_id); await getCourseChapters(); diff --git a/front/app/orgs/[orgslug]/(withmenu)/courses/courses.tsx b/front/app/orgs/[orgslug]/(withmenu)/courses/courses.tsx index a37f2010..079cc54a 100644 --- a/front/app/orgs/[orgslug]/(withmenu)/courses/courses.tsx +++ b/front/app/orgs/[orgslug]/(withmenu)/courses/courses.tsx @@ -10,6 +10,7 @@ import Link from 'next/link'; import React from 'react' import Image from 'next/image'; import { AuthContext } from '@components/Security/AuthProvider'; +import { revalidateTags } from '@services/utils/ts/requests'; interface CourseProps { orgslug: string; @@ -28,13 +29,14 @@ function Courses(props: CourseProps) { async function deleteCourses(course_id: any) { await deleteCourseFromBackend(course_id); + revalidateTags(['courses']); } async function closeNewCourseModal() { setNewCourseModal(false); } - + return ( @@ -103,7 +105,7 @@ const AdminEditsArea = (props: any) => { // this is amazingly terrible code, but gotta release that MVP // TODO: fix this - + function isAuthorized() { const org_id = props.course.org_id; const org_roles = auth.userInfo.user_object.orgs; diff --git a/front/app/orgs/[orgslug]/(withmenu)/courses/page.tsx b/front/app/orgs/[orgslug]/(withmenu)/courses/page.tsx index 831dc15e..17dd3580 100644 --- a/front/app/orgs/[orgslug]/(withmenu)/courses/page.tsx +++ b/front/app/orgs/[orgslug]/(withmenu)/courses/page.tsx @@ -3,19 +3,32 @@ import React from "react"; import Courses from "./courses"; import { getOrgCourses } from "@services/courses/courses"; import { Metadata } from "next"; +import { getOrganizationContextInfo } from "@services/organizations/orgs"; -export const metadata: Metadata = { - title: 'LearnHouse - Courses', - description: 'courses', +type MetadataProps = { + params: { orgslug: string }; + searchParams: { [key: string]: string | string[] | undefined }; }; +export async function generateMetadata( + { params }: MetadataProps, +): Promise { + + // Get Org context information + const org = await getOrganizationContextInfo(params.orgslug, { revalidate: 1800, tags: ['organizations'] }); + return { + title: org.name + " — Courses", + description: org.description, + }; +} + const CoursesPage = async (params: any) => { const orgslug = params.params.orgslug; - const courses = await getOrgCourses(orgslug); + const courses = await getOrgCourses(orgslug, { revalidate: 360, tags: ['courses'] }); return (
- +
); }; diff --git a/front/app/orgs/[orgslug]/(withmenu)/page.tsx b/front/app/orgs/[orgslug]/(withmenu)/page.tsx index 94b1c30d..ee1d2d7f 100644 --- a/front/app/orgs/[orgslug]/(withmenu)/page.tsx +++ b/front/app/orgs/[orgslug]/(withmenu)/page.tsx @@ -1,5 +1,5 @@ export const dynamic = 'force-dynamic'; - +import { Metadata, ResolvingMetadata } from 'next'; import { Menu } from "@components/UI/Elements/Menu"; import { getBackendUrl, getUriWithOrg } from "@services/config/config"; import { getOrgCourses } from "@services/courses/courses"; @@ -10,13 +10,28 @@ import Image from "next/image"; import { log } from "console"; import AuthProvider from "@components/Security/AuthProvider"; import { getOrgCollections } from "@services/courses/collections"; +import { getOrganizationContextInfo } from '@services/organizations/orgs'; + +type MetadataProps = { + params: { orgslug: string }; + searchParams: { [key: string]: string | string[] | undefined }; +}; + +export async function generateMetadata( + { params }: MetadataProps, +): Promise { + + // Get Org context information + const org = await getOrganizationContextInfo(params.orgslug, { revalidate: 1800, tags: ['organizations'] }); + return { + title: org.name + " — Home", + description: org.description, + }; +} const OrgHomePage = async (params: any) => { const orgslug = params.params.orgslug; - // timeout to simulate a slow connection - // await new Promise((resolve) => setTimeout(resolve, 12000)); - - const courses = await getOrgCourses(orgslug); + const courses = await getOrgCourses(orgslug, { revalidate: 360 , tags: ['courses'] }); const collections = await getOrgCollections(); // function to remove "course_" from the course_id @@ -26,9 +41,6 @@ const OrgHomePage = async (params: any) => { return (
- - -
{/* Collections */} diff --git a/front/components/Modals/Course/Create/CreateCourse.tsx b/front/components/Modals/Course/Create/CreateCourse.tsx index f182bb38..96a7456e 100644 --- a/front/components/Modals/Course/Create/CreateCourse.tsx +++ b/front/components/Modals/Course/Create/CreateCourse.tsx @@ -1,4 +1,4 @@ -import FormLayout, { ButtonBlack, Flex, FormField, FormLabel, Input, Textarea } from '@components/UI/Form/Form' +import FormLayout, { ButtonBlack, Flex, FormField, FormLabel, Input, Textarea } from '@components/UI/Form/Form' import * as Form from '@radix-ui/react-form' import { getAPIUrl, getUriWithOrg } from '@services/config/config'; import { FormMessage } from "@radix-ui/react-form"; @@ -7,6 +7,7 @@ import { getOrganizationContextInfo } from '@services/organizations/orgs'; import React, { useState } from 'react' import { BarLoader } from 'react-spinners' import { mutate } from 'swr'; +import { revalidateTags } from '@services/utils/ts/requests'; function CreateCourseModal({ closeModal, orgslug }: any) { const [isSubmitting, setIsSubmitting] = useState(false); @@ -19,7 +20,7 @@ function CreateCourseModal({ closeModal, orgslug }: any) { const getOrgMetadata = async () => { - const org = await getOrganizationContextInfo(orgslug); + const org = await getOrganizationContextInfo(orgslug, { revalidate: 360, tags: ['organizations'] }); setOrgId(org.org_id); } @@ -40,7 +41,7 @@ function CreateCourseModal({ closeModal, orgslug }: any) { e.preventDefault(); setIsSubmitting(true); let status = await createNewCourse(orgId, { name, description }, thumbnail); - mutate(`${getAPIUrl()}courses/org_slug/${orgslug}/page/1/limit/10`); + revalidateTags(['courses']); setIsSubmitting(false); if (status.org_id == orgId) { diff --git a/front/public/favicon.ico b/front/public/favicon.ico index 718d6fea..a3082559 100644 Binary files a/front/public/favicon.ico and b/front/public/favicon.ico differ diff --git a/front/public/vercel.svg b/front/public/vercel.svg deleted file mode 100644 index fbf0e25a..00000000 --- a/front/public/vercel.svg +++ /dev/null @@ -1,4 +0,0 @@ -<svg width="283" height="64" viewBox="0 0 283 64" fill="none" - xmlns="http://www.w3.org/2000/svg"> - <path d="M141.04 16c-11.04 0-19 7.2-19 18s8.96 18 20 18c6.67 0 12.55-2.64 16.19-7.09l-7.65-4.42c-2.02 2.21-5.09 3.5-8.54 3.5-4.79 0-8.86-2.5-10.37-6.5h28.02c.22-1.12.35-2.28.35-3.5 0-10.79-7.96-17.99-19-17.99zm-9.46 14.5c1.25-3.99 4.67-6.5 9.45-6.5 4.79 0 8.21 2.51 9.45 6.5h-18.9zM248.72 16c-11.04 0-19 7.2-19 18s8.96 18 20 18c6.67 0 12.55-2.64 16.19-7.09l-7.65-4.42c-2.02 2.21-5.09 3.5-8.54 3.5-4.79 0-8.86-2.5-10.37-6.5h28.02c.22-1.12.35-2.28.35-3.5 0-10.79-7.96-17.99-19-17.99zm-9.45 14.5c1.25-3.99 4.67-6.5 9.45-6.5 4.79 0 8.21 2.51 9.45 6.5h-18.9zM200.24 34c0 6 3.92 10 10 10 4.12 0 7.21-1.87 8.8-4.92l7.68 4.43c-3.18 5.3-9.14 8.49-16.48 8.49-11.05 0-19-7.2-19-18s7.96-18 19-18c7.34 0 13.29 3.19 16.48 8.49l-7.68 4.43c-1.59-3.05-4.68-4.92-8.8-4.92-6.07 0-10 4-10 10zm82.48-29v46h-9V5h9zM36.95 0L73.9 64H0L36.95 0zm92.38 5l-27.71 48L73.91 5H84.3l17.32 30 17.32-30h10.39zm58.91 12v9.69c-1-.29-2.06-.49-3.2-.49-5.81 0-10 4-10 10V51h-9V17h9v9.2c0-5.08 5.91-9.2 13.2-9.2z" fill="#000"/> -</svg> \ No newline at end of file diff --git a/front/services/blocks/Image/images.ts b/front/services/blocks/Image/images.ts index 0429b6dd..8a1ab1c2 100644 --- a/front/services/blocks/Image/images.ts +++ b/front/services/blocks/Image/images.ts @@ -7,14 +7,14 @@ export async function uploadNewImageFile(file: any, activity_id: string) { formData.append("file_object", file); formData.append("activity_id", activity_id); - return fetch(`${getAPIUrl()}blocks/image`, RequestBodyForm("POST", formData)) + return fetch(`${getAPIUrl()}blocks/image`, RequestBodyForm("POST", formData, null)) .then((result) => result.json()) .catch((error) => console.log("error", error)); } export async function getImageFile(file_id: string) { // todo : add course id to url - return fetch(`${getAPIUrl()}blocks/image?file_id=${file_id}`, RequestBody("GET", null)) + return fetch(`${getAPIUrl()}blocks/image?file_id=${file_id}`, RequestBody("GET", null, null)) .then((result) => result.json()) .catch((error) => console.log("error", error)); } diff --git a/front/services/blocks/Pdf/pdf.ts b/front/services/blocks/Pdf/pdf.ts index fc9b4e5e..89b520f1 100644 --- a/front/services/blocks/Pdf/pdf.ts +++ b/front/services/blocks/Pdf/pdf.ts @@ -7,14 +7,14 @@ export async function uploadNewPDFFile(file: any, activity_id: string) { formData.append("file_object", file); formData.append("activity_id", activity_id); - return fetch(`${getAPIUrl()}blocks/pdf`, RequestBodyForm("POST", formData)) + return fetch(`${getAPIUrl()}blocks/pdf`, RequestBodyForm("POST", formData, null)) .then((result) => result.json()) .catch((error) => console.log("error", error)); } export async function getPDFFile(file_id: string) { // todo : add course id to url - return fetch(`${getAPIUrl()}blocks/pdf?file_id=${file_id}`, RequestBody("GET", null)) + return fetch(`${getAPIUrl()}blocks/pdf?file_id=${file_id}`, RequestBody("GET", null, null)) .then((result) => result.json()) .catch((error) => console.log("error", error)); } diff --git a/front/services/blocks/Quiz/quiz.ts b/front/services/blocks/Quiz/quiz.ts index 0adb85dd..60e921ed 100644 --- a/front/services/blocks/Quiz/quiz.ts +++ b/front/services/blocks/Quiz/quiz.ts @@ -3,7 +3,7 @@ import { RequestBody, RequestBodyForm } from "@services/utils/ts/requests"; export async function submitQuizBlock(activity_id: string, data: any) { - const result: any = await fetch(`${getAPIUrl()}blocks/quiz/${activity_id}"`, RequestBody("POST", data)) + const result: any = await fetch(`${getAPIUrl()}blocks/quiz/${activity_id}"`, RequestBody("POST", data, null)) .then((result) => result.json()) .catch((error) => console.log("error", error)); return result; diff --git a/front/services/blocks/Video/video.ts b/front/services/blocks/Video/video.ts index bf7142b4..714a2fc3 100644 --- a/front/services/blocks/Video/video.ts +++ b/front/services/blocks/Video/video.ts @@ -7,13 +7,13 @@ export async function uploadNewVideoFile(file: any, activity_id: string) { formData.append("file_object", file); formData.append("activity_id", activity_id); - return fetch(`${getAPIUrl()}blocks/video`, RequestBodyForm("POST", formData)) + return fetch(`${getAPIUrl()}blocks/video`, RequestBodyForm("POST", formData, null)) .then((result) => result.json()) .catch((error) => console.log("error", error)); } export async function getVideoFile(file_id: string) { - return fetch(`${getAPIUrl()}blocks/video?file_id=${file_id}`, RequestBody("GET", null)) + return fetch(`${getAPIUrl()}blocks/video?file_id=${file_id}`, RequestBody("GET", null, null)) .then((result) => result.json()) .catch((error) => console.log("error", error)); } diff --git a/front/services/config/config.ts b/front/services/config/config.ts index fd674bf0..4fca83ce 100644 --- a/front/services/config/config.ts +++ b/front/services/config/config.ts @@ -1,4 +1,4 @@ -const LEARNHOUSE_HTTP_PROTOCOL = process.env.NEXT_PUBLIC_LEARNHOUSE_HTTPS === "true" ? "https://" : "http://"; +export const LEARNHOUSE_HTTP_PROTOCOL = process.env.NEXT_PUBLIC_LEARNHOUSE_HTTPS === "true" ? "https://" : "http://"; const LEARNHOUSE_API_URL = `${process.env.NEXT_PUBLIC_LEARNHOUSE_API_URL}`; const LEARNHOUSE_BACKEND_URL = `${process.env.NEXT_PUBLIC_LEARNHOUSE_BACKEND_URL}`; export const LEARNHOUSE_DOMAIN = process.env.NEXT_PUBLIC_LEARNHOUSE_DOMAIN; diff --git a/front/services/courses/activities.ts b/front/services/courses/activities.ts index a7976e05..a87b398e 100644 --- a/front/services/courses/activities.ts +++ b/front/services/courses/activities.ts @@ -6,7 +6,7 @@ export async function createActivity(data: any, chapter_id: any, org_id: any) { // remove chapter_id from data delete data.chapterId; - const result = await fetch(`${getAPIUrl()}activities/?coursechapter_id=${chapter_id}&org_id=${org_id}`, RequestBody("POST", data)); + const result = await fetch(`${getAPIUrl()}activities/?coursechapter_id=${chapter_id}&org_id=${org_id}`, RequestBody("POST", data, null)); const res = await result.json(); return res; } @@ -31,7 +31,7 @@ export async function createFileActivity(file: File, type: string, data: any, ch // Handle other file types here } - const result: any = await fetch(endpoint, RequestBodyForm("POST", formData)); + const result: any = await fetch(endpoint, RequestBodyForm("POST", formData, null)); const res = await result.json(); return res; } @@ -41,19 +41,19 @@ export async function createExternalVideoActivity(data: any, activity: any, chap data.coursechapter_id = chapter_id; data.activity_id = activity.id; - const result = await fetch(`${getAPIUrl()}activities/external_video?coursechapter_id=${chapter_id}`, RequestBody("POST", data)); + const result = await fetch(`${getAPIUrl()}activities/external_video?coursechapter_id=${chapter_id}`, RequestBody("POST", data, null)); const res = await result.json(); return res; } -export async function getActivity(activity_id: any) { - const result = await fetch(`${getAPIUrl()}activities/${activity_id}`, RequestBody("GET", null)); +export async function getActivity(activity_id: any, next: any) { + const result = await fetch(`${getAPIUrl()}activities/${activity_id}`, RequestBody("GET", null,next)); const res = await result.json(); return res; } export async function updateActivity(data: any, activity_id: any) { - const result = await fetch(`${getAPIUrl()}activities/${activity_id}`, RequestBody("PUT", data)); + const result = await fetch(`${getAPIUrl()}activities/${activity_id}`, RequestBody("PUT", data, null)); const res = await result.json(); return res; } diff --git a/front/services/courses/activity.ts b/front/services/courses/activity.ts index aec4ec45..9ac90450 100644 --- a/front/services/courses/activity.ts +++ b/front/services/courses/activity.ts @@ -7,19 +7,19 @@ import { getAPIUrl } from "@services/config/config"; */ export async function startCourse(course_id: string, org_slug: string) { - const result: any = await fetch(`${getAPIUrl()}trail/org_slug/${org_slug}/add_course/${course_id}`, RequestBody("POST", null)) + const result: any = await fetch(`${getAPIUrl()}trail/org_slug/${org_slug}/add_course/${course_id}`, RequestBody("POST", null, null)) const res = await errorHandling(result); return res; } export async function removeCourse(course_id: string, org_slug: string) { - const result: any = await fetch(`${getAPIUrl()}trail/org_slug/${org_slug}/remove_course/${course_id}`, RequestBody("POST", null)) + const result: any = await fetch(`${getAPIUrl()}trail/org_slug/${org_slug}/remove_course/${course_id}`, RequestBody("POST", null, null)) const res = await errorHandling(result); return res; } export async function markActivityAsComplete(org_slug: string, course_id: string, activity_id: string) { - const result: any = await fetch(`${getAPIUrl()}trail/org_slug/${org_slug}/add_activity/course_id/${course_id}/activity_id/${activity_id}`, RequestBody("POST", null)) + const result: any = await fetch(`${getAPIUrl()}trail/org_slug/${org_slug}/add_activity/course_id/${course_id}/activity_id/${activity_id}`, RequestBody("POST", null, null)) const res = await errorHandling(result); return res; } diff --git a/front/services/courses/chapters.ts b/front/services/courses/chapters.ts index ddf2c521..eecaca41 100644 --- a/front/services/courses/chapters.ts +++ b/front/services/courses/chapters.ts @@ -7,27 +7,27 @@ import { RequestBody, errorHandling } from "@services/utils/ts/requests"; */ //TODO : depreciate this function -export async function getCourseChaptersMetadata(course_id: any) { - const result = await fetch(`${getAPIUrl()}chapters/meta/course_${course_id}`, RequestBody("GET", null)); +export async function getCourseChaptersMetadata(course_id: any, next: any) { + const result = await fetch(`${getAPIUrl()}chapters/meta/course_${course_id}`, RequestBody("GET", null,next)); const res = await errorHandling(result); return res; } export async function updateChaptersMetadata(course_id: any, data: any) { - const result: any = await fetch(`${getAPIUrl()}chapters/meta/course_${course_id}`, RequestBody("PUT", data)); + const result: any = await fetch(`${getAPIUrl()}chapters/meta/course_${course_id}`, RequestBody("PUT", data, null)); const res = await errorHandling(result); return res; } export async function createChapter(data: any, course_id: any) { - const result: any = await fetch(`${getAPIUrl()}chapters/?course_id=course_${course_id}`, RequestBody("POST", data)); + const result: any = await fetch(`${getAPIUrl()}chapters/?course_id=course_${course_id}`, RequestBody("POST", data, null)); const res = await errorHandling(result); return res; } export async function deleteChapter(coursechapter_id: any) { - const result: any = await fetch(`${getAPIUrl()}chapters/${coursechapter_id}`, RequestBody("DELETE", null)); + const result: any = await fetch(`${getAPIUrl()}chapters/${coursechapter_id}`, RequestBody("DELETE", null, null)); const res = await errorHandling(result); return res; } diff --git a/front/services/courses/collections.ts b/front/services/courses/collections.ts index 9228fbc2..b3e4c027 100644 --- a/front/services/courses/collections.ts +++ b/front/services/courses/collections.ts @@ -7,14 +7,14 @@ import { RequestBody, errorHandling } from "@services/utils/ts/requests"; */ export async function deleteCollection(collection_id: any) { - const result: any = await fetch(`${getAPIUrl()}collections/${collection_id}`, RequestBody("DELETE", null)); + const result: any = await fetch(`${getAPIUrl()}collections/${collection_id}`, RequestBody("DELETE", null, null)); const res = await errorHandling(result); return res; } // Create a new collection export async function createCollection(collection: any) { - const result: any = await fetch(`${getAPIUrl()}collections/`, RequestBody("POST", collection)); + const result: any = await fetch(`${getAPIUrl()}collections/`, RequestBody("POST", collection, null)); const res = await errorHandling(result); return res; } @@ -22,7 +22,7 @@ export async function createCollection(collection: any) { // Get collections // TODO : add per org filter export async function getOrgCollections() { - const result: any = await fetch(`${getAPIUrl()}collections/page/1/limit/10`); + const result: any = await fetch(`${getAPIUrl()}collections/page/1/limit/10`, { next: { revalidate: 10 } }); const res = await errorHandling(result); return res; } diff --git a/front/services/courses/courses.ts b/front/services/courses/courses.ts index f200f46b..ea1b4941 100644 --- a/front/services/courses/courses.ts +++ b/front/services/courses/courses.ts @@ -6,15 +6,15 @@ import { RequestBody, RequestBodyForm, errorHandling } from "@services/utils/ts/ GET requests are called from the frontend using SWR (https://swr.vercel.app/) */ -export async function getOrgCourses(org_id: number) { - const result: any = await fetch(`${getAPIUrl()}courses/org_slug/${org_id}/page/1/limit/10`, RequestBody("GET", null)); +export async function getOrgCourses(org_id: number, next: any) { + const result: any = await fetch(`${getAPIUrl()}courses/org_slug/${org_id}/page/1/limit/10`, RequestBody("GET", null, next)); const res = await errorHandling(result); return res; } -export async function getCourse(course_id: string) { - const result: any = await fetch(`${getAPIUrl()}courses/${course_id}`, RequestBody("GET", null)); +export async function getCourse(course_id: string, next: any) { + const result: any = await fetch(`${getAPIUrl()}courses/${course_id}`, RequestBody("GET", null, next)); const res = await errorHandling(result); return res; } @@ -28,13 +28,13 @@ export async function createNewCourse(org_id: string, course_body: any, thumbnai formData.append("mini_description", "course_body.mini_description"); formData.append("public", "true"); - const result = await fetch(`${getAPIUrl()}courses/?org_id=${org_id}`, RequestBodyForm("POST", formData)); + const result = await fetch(`${getAPIUrl()}courses/?org_id=${org_id}`, RequestBodyForm("POST", formData, null)); const res = await errorHandling(result); return res; } export async function deleteCourseFromBackend(course_id: any) { - const result: any = await fetch(`${getAPIUrl()}courses/${course_id}`, RequestBody("DELETE", null)); + const result: any = await fetch(`${getAPIUrl()}courses/${course_id}`, RequestBody("DELETE", null, null)); const res = await errorHandling(result); return res; } diff --git a/front/services/organizations/orgs.ts b/front/services/organizations/orgs.ts index 2718df70..56a11a94 100644 --- a/front/services/organizations/orgs.ts +++ b/front/services/organizations/orgs.ts @@ -7,19 +7,19 @@ import { RequestBody, errorHandling } from "@services/utils/ts/requests"; */ export async function createNewOrganization(body: any) { - const result = await fetch(`${getAPIUrl()}orgs/`, RequestBody("POST", body)); + const result = await fetch(`${getAPIUrl()}orgs/`, RequestBody("POST", body, null)); const res = await errorHandling(result); return res; } export async function deleteOrganizationFromBackend(org_id: any) { - const result = await fetch(`${getAPIUrl()}orgs/${org_id}`, RequestBody("DELETE", null)); + const result = await fetch(`${getAPIUrl()}orgs/${org_id}`, RequestBody("DELETE", null, null)); const res = await errorHandling(result); return res; } -export async function getOrganizationContextInfo(org_slug: any) { - const result = await fetch(`${getAPIUrl()}orgs/slug/${org_slug}`, RequestBody("GET", null)); +export async function getOrganizationContextInfo(org_slug: any, next: any) { + const result = await fetch(`${getAPIUrl()}orgs/slug/${org_slug}`, RequestBody("GET", null,next)); const res = await errorHandling(result); return res; } diff --git a/front/services/settings/org.ts b/front/services/settings/org.ts index 1f4a0fd8..786eb56a 100644 --- a/front/services/settings/org.ts +++ b/front/services/settings/org.ts @@ -7,7 +7,7 @@ import { RequestBody, errorHandling } from "@services/utils/ts/requests"; */ export async function updateOrganization(org_id: string, data: any) { - const result: any = await fetch(`${getAPIUrl()}orgs/` + org_id, RequestBody("PUT", data)); + const result: any = await fetch(`${getAPIUrl()}orgs/` + org_id, RequestBody("PUT", data, null)); const res = await errorHandling(result); return res; } diff --git a/front/services/settings/password.ts b/front/services/settings/password.ts index a93483f3..86d4a659 100644 --- a/front/services/settings/password.ts +++ b/front/services/settings/password.ts @@ -7,7 +7,7 @@ import { RequestBody, errorHandling } from "@services/utils/ts/requests"; */ export async function updatePassword(user_id : string, data: any) { - const result: any = await fetch(`${getAPIUrl()}users/password/user_id/` + user_id, RequestBody("PUT", data)) + const result: any = await fetch(`${getAPIUrl()}users/password/user_id/` + user_id, RequestBody("PUT", data, null)) const res = await errorHandling(result); return res; } diff --git a/front/services/settings/profile.ts b/front/services/settings/profile.ts index 06f0667e..adfb3045 100644 --- a/front/services/settings/profile.ts +++ b/front/services/settings/profile.ts @@ -7,7 +7,7 @@ import { RequestBody, errorHandling } from "@services/utils/ts/requests"; */ export async function updateProfile(data: any) { - const result: any = await fetch(`${getAPIUrl()}users/user_id/` + data.user_id, RequestBody("PUT", data)) + const result: any = await fetch(`${getAPIUrl()}users/user_id/` + data.user_id, RequestBody("PUT", data, null)) const res = await errorHandling(result); return res; } diff --git a/front/services/utils/ts/requests.ts b/front/services/utils/ts/requests.ts index 3df81e89..07ba1142 100644 --- a/front/services/utils/ts/requests.ts +++ b/front/services/utils/ts/requests.ts @@ -1,15 +1,16 @@ import { AppRouterInstance } from "next/dist/shared/lib/app-router-context"; import { denyAccessToUser } from "../react/middlewares/views"; +import { LEARNHOUSE_DOMAIN, LEARNHOUSE_HTTP_PROTOCOL } from "@services/config/config"; -export const RequestBody = (method: string, data: any) => { +export const RequestBody = (method: string, data: any, next: any) => { let HeadersConfig = new Headers({ "Content-Type": "application/json" }); let options: any = { method: method, headers: HeadersConfig, redirect: "follow", credentials: "include", - // Next.js - cache: 'no-store' + // Next.js + next: next, }; if (data) { options.body = JSON.stringify(data); @@ -17,7 +18,7 @@ export const RequestBody = (method: string, data: any) => { return options; }; -export const RequestBodyForm = (method: string, data: any) => { +export const RequestBodyForm = (method: string, data: any, next: any) => { let HeadersConfig = new Headers({}); let options: any = { method: method, @@ -25,6 +26,8 @@ export const RequestBodyForm = (method: string, data: any) => { redirect: "follow", credentials: "include", body: data, + // Next.js + next: next, }; return options; }; @@ -67,3 +70,9 @@ export const errorHandling = (res: any) => { } return res.json(); }; + +export const revalidateTags = (tags: string[]) => { + tags.forEach((tag) => { + fetch(`${LEARNHOUSE_HTTP_PROTOCOL}${LEARNHOUSE_DOMAIN}/api/revalidate?tag=${tag}`); + }); +};