mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
Merge pull request #88 from learnhouse/swve/eng-35-optimize-some-pages-for-seo
Optimize some pages for SEO + use Next.js caching
This commit is contained in:
commit
3457b57c58
24 changed files with 119 additions and 67 deletions
19
front/app/api/revalidate/route.ts
Normal file
19
front/app/api/revalidate/route.ts
Normal file
|
|
@ -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",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -20,7 +20,7 @@ function NewCollection(params: any) {
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
async function getOrg() {
|
async function getOrg() {
|
||||||
const org = await getOrganizationContextInfo(orgslug);
|
const org = await getOrganizationContextInfo(orgslug, { revalidate: 1800 });
|
||||||
setOrg(org);
|
setOrg(org);
|
||||||
}
|
}
|
||||||
getOrg();
|
getOrg();
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ function CourseEdit(params: any) {
|
||||||
|
|
||||||
async function getCourseChapters() {
|
async function getCourseChapters() {
|
||||||
try {
|
try {
|
||||||
const courseChapters = await getCourseChaptersMetadata(courseid);
|
const courseChapters = await getCourseChaptersMetadata(courseid, { revalidate: 120 });
|
||||||
setData(courseChapters);
|
setData(courseChapters);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
denyAccessToUser(error, router)
|
denyAccessToUser(error, router)
|
||||||
|
|
@ -80,7 +80,7 @@ function CourseEdit(params: any) {
|
||||||
// Submit new activity
|
// Submit new activity
|
||||||
const submitActivity = async (activity: any) => {
|
const submitActivity = async (activity: any) => {
|
||||||
console.log("submitActivity", activity);
|
console.log("submitActivity", activity);
|
||||||
let org = await getOrganizationContextInfo(orgslug);
|
let org = await getOrganizationContextInfo(orgslug, { revalidate: 1800 });
|
||||||
await updateChaptersMetadata(courseid, data);
|
await updateChaptersMetadata(courseid, data);
|
||||||
await createActivity(activity, activity.chapterId, org.org_id);
|
await createActivity(activity, activity.chapterId, org.org_id);
|
||||||
await getCourseChapters();
|
await getCourseChapters();
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import Link from 'next/link';
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import Image from 'next/image';
|
import Image from 'next/image';
|
||||||
import { AuthContext } from '@components/Security/AuthProvider';
|
import { AuthContext } from '@components/Security/AuthProvider';
|
||||||
|
import { revalidateTags } from '@services/utils/ts/requests';
|
||||||
|
|
||||||
interface CourseProps {
|
interface CourseProps {
|
||||||
orgslug: string;
|
orgslug: string;
|
||||||
|
|
@ -28,6 +29,7 @@ function Courses(props: CourseProps) {
|
||||||
|
|
||||||
async function deleteCourses(course_id: any) {
|
async function deleteCourses(course_id: any) {
|
||||||
await deleteCourseFromBackend(course_id);
|
await deleteCourseFromBackend(course_id);
|
||||||
|
revalidateTags(['courses']);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function closeNewCourseModal() {
|
async function closeNewCourseModal() {
|
||||||
|
|
|
||||||
|
|
@ -3,19 +3,32 @@ import React from "react";
|
||||||
import Courses from "./courses";
|
import Courses from "./courses";
|
||||||
import { getOrgCourses } from "@services/courses/courses";
|
import { getOrgCourses } from "@services/courses/courses";
|
||||||
import { Metadata } from "next";
|
import { Metadata } from "next";
|
||||||
|
import { getOrganizationContextInfo } from "@services/organizations/orgs";
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
type MetadataProps = {
|
||||||
title: 'LearnHouse - Courses',
|
params: { orgslug: string };
|
||||||
description: 'courses',
|
searchParams: { [key: string]: string | string[] | undefined };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export async function generateMetadata(
|
||||||
|
{ params }: MetadataProps,
|
||||||
|
): Promise<Metadata> {
|
||||||
|
|
||||||
|
// 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 CoursesPage = async (params: any) => {
|
||||||
const orgslug = params.params.orgslug;
|
const orgslug = params.params.orgslug;
|
||||||
const courses = await getOrgCourses(orgslug);
|
const courses = await getOrgCourses(orgslug, { revalidate: 360, tags: ['courses'] });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Courses orgslug={orgslug} courses={courses}/>
|
<Courses orgslug={orgslug} courses={courses} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
export const dynamic = 'force-dynamic';
|
export const dynamic = 'force-dynamic';
|
||||||
|
import { Metadata, ResolvingMetadata } from 'next';
|
||||||
import { Menu } from "@components/UI/Elements/Menu";
|
import { Menu } from "@components/UI/Elements/Menu";
|
||||||
import { getBackendUrl, getUriWithOrg } from "@services/config/config";
|
import { getBackendUrl, getUriWithOrg } from "@services/config/config";
|
||||||
import { getOrgCourses } from "@services/courses/courses";
|
import { getOrgCourses } from "@services/courses/courses";
|
||||||
|
|
@ -10,13 +10,28 @@ import Image from "next/image";
|
||||||
import { log } from "console";
|
import { log } from "console";
|
||||||
import AuthProvider from "@components/Security/AuthProvider";
|
import AuthProvider from "@components/Security/AuthProvider";
|
||||||
import { getOrgCollections } from "@services/courses/collections";
|
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<Metadata> {
|
||||||
|
|
||||||
|
// 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 OrgHomePage = async (params: any) => {
|
||||||
const orgslug = params.params.orgslug;
|
const orgslug = params.params.orgslug;
|
||||||
// timeout to simulate a slow connection
|
const courses = await getOrgCourses(orgslug, { revalidate: 360 , tags: ['courses'] });
|
||||||
// await new Promise((resolve) => setTimeout(resolve, 12000));
|
|
||||||
|
|
||||||
const courses = await getOrgCourses(orgslug);
|
|
||||||
const collections = await getOrgCollections();
|
const collections = await getOrgCollections();
|
||||||
|
|
||||||
// function to remove "course_" from the course_id
|
// function to remove "course_" from the course_id
|
||||||
|
|
@ -26,9 +41,6 @@ const OrgHomePage = async (params: any) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div className="max-w-7xl mx-auto px-4 py-10">
|
<div className="max-w-7xl mx-auto px-4 py-10">
|
||||||
{/* Collections */}
|
{/* Collections */}
|
||||||
<Title title="Collections" type="col" />
|
<Title title="Collections" type="col" />
|
||||||
|
|
|
||||||
|
|
@ -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 * as Form from '@radix-ui/react-form'
|
||||||
import { getAPIUrl, getUriWithOrg } from '@services/config/config';
|
import { getAPIUrl, getUriWithOrg } from '@services/config/config';
|
||||||
import { FormMessage } from "@radix-ui/react-form";
|
import { FormMessage } from "@radix-ui/react-form";
|
||||||
|
|
@ -7,6 +7,7 @@ import { getOrganizationContextInfo } from '@services/organizations/orgs';
|
||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
import { BarLoader } from 'react-spinners'
|
import { BarLoader } from 'react-spinners'
|
||||||
import { mutate } from 'swr';
|
import { mutate } from 'swr';
|
||||||
|
import { revalidateTags } from '@services/utils/ts/requests';
|
||||||
|
|
||||||
function CreateCourseModal({ closeModal, orgslug }: any) {
|
function CreateCourseModal({ closeModal, orgslug }: any) {
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
|
|
@ -19,7 +20,7 @@ function CreateCourseModal({ closeModal, orgslug }: any) {
|
||||||
|
|
||||||
|
|
||||||
const getOrgMetadata = async () => {
|
const getOrgMetadata = async () => {
|
||||||
const org = await getOrganizationContextInfo(orgslug);
|
const org = await getOrganizationContextInfo(orgslug, { revalidate: 360, tags: ['organizations'] });
|
||||||
setOrgId(org.org_id);
|
setOrgId(org.org_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,7 +41,7 @@ function CreateCourseModal({ closeModal, orgslug }: any) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setIsSubmitting(true);
|
setIsSubmitting(true);
|
||||||
let status = await createNewCourse(orgId, { name, description }, thumbnail);
|
let status = await createNewCourse(orgId, { name, description }, thumbnail);
|
||||||
mutate(`${getAPIUrl()}courses/org_slug/${orgslug}/page/1/limit/10`);
|
revalidateTags(['courses']);
|
||||||
setIsSubmitting(false);
|
setIsSubmitting(false);
|
||||||
|
|
||||||
if (status.org_id == orgId) {
|
if (status.org_id == orgId) {
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 15 KiB |
|
|
@ -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>
|
|
||||||
|
Before Width: | Height: | Size: 1.1 KiB |
|
|
@ -7,14 +7,14 @@ export async function uploadNewImageFile(file: any, activity_id: string) {
|
||||||
formData.append("file_object", file);
|
formData.append("file_object", file);
|
||||||
formData.append("activity_id", activity_id);
|
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())
|
.then((result) => result.json())
|
||||||
.catch((error) => console.log("error", error));
|
.catch((error) => console.log("error", error));
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getImageFile(file_id: string) {
|
export async function getImageFile(file_id: string) {
|
||||||
// todo : add course id to url
|
// 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())
|
.then((result) => result.json())
|
||||||
.catch((error) => console.log("error", error));
|
.catch((error) => console.log("error", error));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,14 @@ export async function uploadNewPDFFile(file: any, activity_id: string) {
|
||||||
formData.append("file_object", file);
|
formData.append("file_object", file);
|
||||||
formData.append("activity_id", activity_id);
|
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())
|
.then((result) => result.json())
|
||||||
.catch((error) => console.log("error", error));
|
.catch((error) => console.log("error", error));
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getPDFFile(file_id: string) {
|
export async function getPDFFile(file_id: string) {
|
||||||
// todo : add course id to url
|
// 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())
|
.then((result) => result.json())
|
||||||
.catch((error) => console.log("error", error));
|
.catch((error) => console.log("error", error));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { RequestBody, RequestBodyForm } from "@services/utils/ts/requests";
|
||||||
|
|
||||||
|
|
||||||
export async function submitQuizBlock(activity_id: string, data: any) {
|
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())
|
.then((result) => result.json())
|
||||||
.catch((error) => console.log("error", error));
|
.catch((error) => console.log("error", error));
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,13 @@ export async function uploadNewVideoFile(file: any, activity_id: string) {
|
||||||
formData.append("file_object", file);
|
formData.append("file_object", file);
|
||||||
formData.append("activity_id", activity_id);
|
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())
|
.then((result) => result.json())
|
||||||
.catch((error) => console.log("error", error));
|
.catch((error) => console.log("error", error));
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getVideoFile(file_id: string) {
|
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())
|
.then((result) => result.json())
|
||||||
.catch((error) => console.log("error", error));
|
.catch((error) => console.log("error", error));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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_API_URL = `${process.env.NEXT_PUBLIC_LEARNHOUSE_API_URL}`;
|
||||||
const LEARNHOUSE_BACKEND_URL = `${process.env.NEXT_PUBLIC_LEARNHOUSE_BACKEND_URL}`;
|
const LEARNHOUSE_BACKEND_URL = `${process.env.NEXT_PUBLIC_LEARNHOUSE_BACKEND_URL}`;
|
||||||
export const LEARNHOUSE_DOMAIN = process.env.NEXT_PUBLIC_LEARNHOUSE_DOMAIN;
|
export const LEARNHOUSE_DOMAIN = process.env.NEXT_PUBLIC_LEARNHOUSE_DOMAIN;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ export async function createActivity(data: any, chapter_id: any, org_id: any) {
|
||||||
// remove chapter_id from data
|
// remove chapter_id from data
|
||||||
delete data.chapterId;
|
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();
|
const res = await result.json();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
@ -31,7 +31,7 @@ export async function createFileActivity(file: File, type: string, data: any, ch
|
||||||
// Handle other file types here
|
// 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();
|
const res = await result.json();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
@ -41,19 +41,19 @@ export async function createExternalVideoActivity(data: any, activity: any, chap
|
||||||
data.coursechapter_id = chapter_id;
|
data.coursechapter_id = chapter_id;
|
||||||
data.activity_id = activity.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();
|
const res = await result.json();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getActivity(activity_id: any) {
|
export async function getActivity(activity_id: any, next: any) {
|
||||||
const result = await fetch(`${getAPIUrl()}activities/${activity_id}`, RequestBody("GET", null));
|
const result = await fetch(`${getAPIUrl()}activities/${activity_id}`, RequestBody("GET", null,next));
|
||||||
const res = await result.json();
|
const res = await result.json();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateActivity(data: any, activity_id: any) {
|
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();
|
const res = await result.json();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,19 +7,19 @@ import { getAPIUrl } from "@services/config/config";
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export async function startCourse(course_id: string, org_slug: string) {
|
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);
|
const res = await errorHandling(result);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function removeCourse(course_id: string, org_slug: string) {
|
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);
|
const res = await errorHandling(result);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function markActivityAsComplete(org_slug: string, course_id: string, activity_id: string) {
|
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);
|
const res = await errorHandling(result);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,27 +7,27 @@ import { RequestBody, errorHandling } from "@services/utils/ts/requests";
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//TODO : depreciate this function
|
//TODO : depreciate this function
|
||||||
export async function getCourseChaptersMetadata(course_id: any) {
|
export async function getCourseChaptersMetadata(course_id: any, next: any) {
|
||||||
const result = await fetch(`${getAPIUrl()}chapters/meta/course_${course_id}`, RequestBody("GET", null));
|
const result = await fetch(`${getAPIUrl()}chapters/meta/course_${course_id}`, RequestBody("GET", null,next));
|
||||||
const res = await errorHandling(result);
|
const res = await errorHandling(result);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateChaptersMetadata(course_id: any, data: any) {
|
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);
|
const res = await errorHandling(result);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createChapter(data: any, course_id: any) {
|
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);
|
const res = await errorHandling(result);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteChapter(coursechapter_id: any) {
|
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);
|
const res = await errorHandling(result);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,14 @@ import { RequestBody, errorHandling } from "@services/utils/ts/requests";
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export async function deleteCollection(collection_id: any) {
|
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);
|
const res = await errorHandling(result);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new collection
|
// Create a new collection
|
||||||
export async function createCollection(collection: any) {
|
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);
|
const res = await errorHandling(result);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
@ -22,7 +22,7 @@ export async function createCollection(collection: any) {
|
||||||
// Get collections
|
// Get collections
|
||||||
// TODO : add per org filter
|
// TODO : add per org filter
|
||||||
export async function getOrgCollections() {
|
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);
|
const res = await errorHandling(result);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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/)
|
GET requests are called from the frontend using SWR (https://swr.vercel.app/)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export async function getOrgCourses(org_id: number) {
|
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));
|
const result: any = await fetch(`${getAPIUrl()}courses/org_slug/${org_id}/page/1/limit/10`, RequestBody("GET", null, next));
|
||||||
const res = await errorHandling(result);
|
const res = await errorHandling(result);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getCourse(course_id: string) {
|
export async function getCourse(course_id: string, next: any) {
|
||||||
const result: any = await fetch(`${getAPIUrl()}courses/${course_id}`, RequestBody("GET", null));
|
const result: any = await fetch(`${getAPIUrl()}courses/${course_id}`, RequestBody("GET", null, next));
|
||||||
const res = await errorHandling(result);
|
const res = await errorHandling(result);
|
||||||
return res;
|
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("mini_description", "course_body.mini_description");
|
||||||
formData.append("public", "true");
|
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);
|
const res = await errorHandling(result);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteCourseFromBackend(course_id: any) {
|
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);
|
const res = await errorHandling(result);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,19 +7,19 @@ import { RequestBody, errorHandling } from "@services/utils/ts/requests";
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export async function createNewOrganization(body: any) {
|
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);
|
const res = await errorHandling(result);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteOrganizationFromBackend(org_id: any) {
|
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);
|
const res = await errorHandling(result);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getOrganizationContextInfo(org_slug: any) {
|
export async function getOrganizationContextInfo(org_slug: any, next: any) {
|
||||||
const result = await fetch(`${getAPIUrl()}orgs/slug/${org_slug}`, RequestBody("GET", null));
|
const result = await fetch(`${getAPIUrl()}orgs/slug/${org_slug}`, RequestBody("GET", null,next));
|
||||||
const res = await errorHandling(result);
|
const res = await errorHandling(result);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import { RequestBody, errorHandling } from "@services/utils/ts/requests";
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export async function updateOrganization(org_id: string, data: any) {
|
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);
|
const res = await errorHandling(result);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import { RequestBody, errorHandling } from "@services/utils/ts/requests";
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export async function updatePassword(user_id : string, data: any) {
|
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);
|
const res = await errorHandling(result);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import { RequestBody, errorHandling } from "@services/utils/ts/requests";
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export async function updateProfile(data: any) {
|
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);
|
const res = await errorHandling(result);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context";
|
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context";
|
||||||
import { denyAccessToUser } from "../react/middlewares/views";
|
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 HeadersConfig = new Headers({ "Content-Type": "application/json" });
|
||||||
let options: any = {
|
let options: any = {
|
||||||
method: method,
|
method: method,
|
||||||
|
|
@ -9,7 +10,7 @@ export const RequestBody = (method: string, data: any) => {
|
||||||
redirect: "follow",
|
redirect: "follow",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
// Next.js
|
// Next.js
|
||||||
cache: 'no-store'
|
next: next,
|
||||||
};
|
};
|
||||||
if (data) {
|
if (data) {
|
||||||
options.body = JSON.stringify(data);
|
options.body = JSON.stringify(data);
|
||||||
|
|
@ -17,7 +18,7 @@ export const RequestBody = (method: string, data: any) => {
|
||||||
return options;
|
return options;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const RequestBodyForm = (method: string, data: any) => {
|
export const RequestBodyForm = (method: string, data: any, next: any) => {
|
||||||
let HeadersConfig = new Headers({});
|
let HeadersConfig = new Headers({});
|
||||||
let options: any = {
|
let options: any = {
|
||||||
method: method,
|
method: method,
|
||||||
|
|
@ -25,6 +26,8 @@ export const RequestBodyForm = (method: string, data: any) => {
|
||||||
redirect: "follow",
|
redirect: "follow",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
body: data,
|
body: data,
|
||||||
|
// Next.js
|
||||||
|
next: next,
|
||||||
};
|
};
|
||||||
return options;
|
return options;
|
||||||
};
|
};
|
||||||
|
|
@ -67,3 +70,9 @@ export const errorHandling = (res: any) => {
|
||||||
}
|
}
|
||||||
return res.json();
|
return res.json();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const revalidateTags = (tags: string[]) => {
|
||||||
|
tags.forEach((tag) => {
|
||||||
|
fetch(`${LEARNHOUSE_HTTP_PROTOCOL}${LEARNHOUSE_DOMAIN}/api/revalidate?tag=${tag}`);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue