feat: init routes protection

This commit is contained in:
swve 2023-04-10 19:59:50 +02:00
parent 49b6d1dfe7
commit 1ad8ee12b1
25 changed files with 82 additions and 64 deletions

View file

@ -9,7 +9,7 @@ import AuthProvider from "@components/Security/AuthProvider";
import EditorWrapper from "@components/Editor/EditorWrapper";
import useSWR, { mutate } from "swr";
import { getAPIUrl } from "@services/config/config";
import { swrFetcher } from "@services/utils/requests";
import { swrFetcher } from "@services/utils/ts/requests";
function EditActivity(params: any) {

View file

@ -5,7 +5,7 @@ import { Title } from "@components/UI/Elements/Styles/Title";
import { createCollection } from "@services/courses/collections";
import useSWR from "swr";
import { getAPIUrl } from "@services/config/config";
import { swrFetcher } from "@services/utils/requests";
import { swrFetcher } from "@services/utils/ts/requests";
import { getOrganizationContextInfo } from "@services/organizations/orgs";
function NewCollection(params : any) {

View file

@ -5,7 +5,7 @@ import styled from "styled-components";
import { Title } from "@components/UI/Elements/Styles/Title";
import { deleteCollection } from "@services/courses/collections";
import { getAPIUrl, getBackendUrl, getUriWithOrg } from "@services/config/config";
import { swrFetcher } from "@services/utils/requests";
import { swrFetcher } from "@services/utils/ts/requests";
import useSWR, { mutate } from "swr";
function Collections(params: any) {

View file

@ -10,7 +10,7 @@ import { getCourse } from "@services/courses/courses";
import VideoActivity from "@components/Pages/Activities/Video/Video";
import useSWR, { mutate } from "swr";
import { Check } from "lucide-react";
import { swrFetcher } from "@services/utils/requests";
import { swrFetcher } from "@services/utils/ts/requests";
import { markActivityAsComplete } from "@services/courses/activity";
function ActivityPage(params: any) {

View file

@ -15,6 +15,7 @@ import { createActivity, createFileActivity } from "@services/courses/activities
import { getOrganizationContextInfo } from "@services/organizations/orgs";
import Modal from "@components/UI/Modal/Modal";
import AuthProvider from "@components/Security/AuthProvider";
import { denyAccessToUser } from "@services/utils/react/middlewares/views";
function CourseEdit(params: any) {
@ -38,9 +39,7 @@ function CourseEdit(params: any) {
const courseChapters = await getCourseChaptersMetadata(courseid);
setData(courseChapters);
} catch (error: any) {
if (error.status === 401) {
router.push("/login");
}
denyAccessToUser(error, router)
}
}

View file

@ -1,21 +1,26 @@
"use client";
import { EyeOpenIcon, Pencil2Icon } from "@radix-ui/react-icons";
import { removeCourse, startCourse } from "@services/courses/activity";
import { removeCourse, startCourse } from "@services/courses/activity";
import Link from "next/link";
import React from "react";
import styled from "styled-components";
import { getAPIUrl, getBackendUrl, getUriWithOrg } from "@services/config/config";
import useSWR, { mutate } from "swr";
import { swrFetcher } from "@services/utils/requests";
import { swrFetcher } from "@services/utils/ts/requests";
import { useRouter } from "next/navigation";
const CourseIdPage = (params: any) => {
const courseid = params.params.courseid;
const orgslug = params.params.orgslug;
const { data: course, error: error } = useSWR(`${getAPIUrl()}courses/meta/course_${courseid}`, swrFetcher);
const router = useRouter();
const { data: course, error: error } = useSWR(`${getAPIUrl()}courses/meta/course_${courseid}`,
(url: string, body: any) => swrFetcher(url, body, router)
);
async function startCourseUI() {
// Create activity
await startCourse("course_" + courseid, orgslug);
await startCourse("course_" + courseid, orgslug);
// Mutate course
mutate(`${getAPIUrl()}courses/meta/course_${courseid}`);
@ -24,7 +29,7 @@ const CourseIdPage = (params: any) => {
async function quitCourse() {
// Close activity
let activity = await removeCourse("course_" + courseid, orgslug);
let activity = await removeCourse("course_" + courseid, orgslug);
console.log(activity);
// Mutate course
@ -42,7 +47,7 @@ const CourseIdPage = (params: any) => {
<p>Course</p>
<h1>
{course.course.name}{" "}
<Link href={getUriWithOrg(orgslug,"") +`/course/${courseid}/edit`} rel="noopener noreferrer">
<Link href={getUriWithOrg(orgslug, "") + `/course/${courseid}/edit`} rel="noopener noreferrer">
<Pencil2Icon />
</Link>{" "}
</h1>
@ -53,7 +58,7 @@ const CourseIdPage = (params: any) => {
{chapter.activities.map((activity: any) => {
return (
<>
<Link href={getUriWithOrg(orgslug,"") +`/course/${courseid}/activity/${activity.id.replace("activity_", "")}`}>
<Link href={getUriWithOrg(orgslug, "") + `/course/${courseid}/activity/${activity.id.replace("activity_", "")}`}>
<ChapterIndicator />
</Link>{" "}
</>
@ -94,7 +99,7 @@ const CourseIdPage = (params: any) => {
<>
<p>
Activity {activity.name}
<Link href={getUriWithOrg(orgslug,"") +`/course/${courseid}/activity/${activity.id.replace("activity_", "")}`} rel="noopener noreferrer">
<Link href={getUriWithOrg(orgslug, "") + `/course/${courseid}/activity/${activity.id.replace("activity_", "")}`} rel="noopener noreferrer">
<EyeOpenIcon />
</Link>{" "}
</p>

View file

@ -7,7 +7,7 @@ import { Title } from "@components/UI/Elements/Styles/Title";
import { getAPIUrl, getBackendUrl, getSelfHostedOption, getUriWithOrg } from "@services/config/config";
import { deleteCourseFromBackend } from "@services/courses/courses";
import useSWR, { mutate } from "swr";
import { swrFetcher } from "@services/utils/requests";
import { swrFetcher } from "@services/utils/ts/requests";
import { Edit2, Trash } from "lucide-react";
const CoursesIndexPage = (params: any) => {

View file

@ -1,6 +1,6 @@
"use client";
import { getAPIUrl, getBackendUrl } from "@services/config/config";
import { swrFetcher } from "@services/utils/requests";
import { swrFetcher } from "@services/utils/ts/requests";
import React from "react";
import { styled } from "styled-components";
import useSWR from "swr";

View file

@ -1,7 +1,7 @@
"use client";
import React from 'react'
import useSWR, { mutate } from "swr";
import { swrFetcher } from "@services/utils/requests";
import { swrFetcher } from "@services/utils/ts/requests";
import { getAPIUrl } from '@services/config/config';
import { Field, Form, Formik } from 'formik';
import { updateOrganization } from '@services/settings/org';

View file

@ -4,7 +4,7 @@ import React from "react";
import { Title } from "../../components/UI/Elements/Styles/Title";
import { deleteOrganizationFromBackend } from "@services/organizations/orgs";
import useSWR, { mutate } from "swr";
import { swrFetcher } from "@services/utils/requests";
import { swrFetcher } from "@services/utils/ts/requests";
import { getAPIUrl, getUriWithOrg } from "@services/config/config";
import AuthProvider from "@components/Security/AuthProvider";