diff --git a/front/components/Pages/CourseEdit/Draggables/Activity.tsx b/front/components/Pages/CourseEdit/Draggables/Activity.tsx index 18a0cb4b..9d92bc21 100644 --- a/front/components/Pages/CourseEdit/Draggables/Activity.tsx +++ b/front/components/Pages/CourseEdit/Draggables/Activity.tsx @@ -1,16 +1,23 @@ +import React from "react"; import Link from "next/link"; import { Draggable } from "react-beautiful-dnd"; -import { EyeOpenIcon, Pencil2Icon, TrashIcon } from '@radix-ui/react-icons' import { getAPIUrl, getUriWithOrg } from "@services/config/config"; -import { FileText, Video, Sparkles, XSquare, X, Pencil, MoreVertical, Eye } from "lucide-react"; +import { FileText, Video, Sparkles, X, Pencil, MoreVertical, Eye, Save, File } from "lucide-react"; import { mutate } from "swr"; import { revalidateTags } from "@services/utils/ts/requests"; import { useRouter } from "next/navigation"; import ConfirmationModal from "@components/StyledElements/ConfirmationModal/ConfirmationModal"; -import { deleteActivity } from "@services/courses/activities"; +import { deleteActivity, updateActivity } from "@services/courses/activities"; + +interface ModifiedActivityInterface { + activityId: string; + activityName: string; +} function Activity(props: any) { const router = useRouter(); + const [modifiedActivity, setModifiedActivity] = React.useState(undefined); + const [selectedActivity, setSelectedActivity] = React.useState(undefined); async function removeActivity() { await deleteActivity(props.activity.id); @@ -19,6 +26,22 @@ function Activity(props: any) { router.refresh(); } + async function updateActivityName(activityId: string) { + if ((modifiedActivity?.activityId === activityId) && selectedActivity !== undefined) { + setSelectedActivity(undefined); + let modifiedActivityCopy = { + name: modifiedActivity.activityName, + description: '', + type: props.activity.type, + content: props.activity.content, + } + + await updateActivity(modifiedActivityCopy, activityId) + await mutate(`${getAPIUrl()}chapters/meta/course_${props.courseid}`) + await revalidateTags(['courses'], props.orgslug) + router.refresh(); + } + } return ( @@ -26,17 +49,27 @@ function Activity(props: any) {
- {props.activity.type === "video" && <>
} - {props.activity.type === "documentpdf" && <>
Document
} + {props.activity.type === "video" && <> +
} + {props.activity.type === "documentpdf" && <>
Document
} {props.activity.type === "dynamic" && <>
Dynamic
}
-
-

{props.activity.name}

+
+ + {selectedActivity === props.activity.id ? + (
+ setModifiedActivity({ activityId: props.activity.id, activityName: e.target.value })} /> + +
) : (

{props.activity.name}

)} + setSelectedActivity(props.activity.id)} + size={12} className="text-neutral-400 hover:cursor-pointer" />
- {props.activity.type === "dynamic" && <> + {props.activity.type === "dynamic" && <> - +
diff --git a/front/components/Pages/CourseEdit/Draggables/Chapter.tsx b/front/components/Pages/CourseEdit/Draggables/Chapter.tsx index 6bd4787f..ba6e7f2f 100644 --- a/front/components/Pages/CourseEdit/Draggables/Chapter.tsx +++ b/front/components/Pages/CourseEdit/Draggables/Chapter.tsx @@ -2,10 +2,39 @@ import React from "react"; import styled from "styled-components"; import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd"; import Activity from "./Activity"; -import { Folders, Hexagon, MoreVertical, PlusSquare, Sparkle, Sparkles, Trash, Trash2, X } from "lucide-react"; +import { Folders, Hexagon, MoreVertical, Pencil, PlusSquare, Save, Sparkle, Sparkles, Trash, Trash2, X } from "lucide-react"; import ConfirmationModal from "@components/StyledElements/ConfirmationModal/ConfirmationModal"; +import { useRouter } from "next/navigation"; +import { updateChapter } from "@services/courses/chapters"; +import { mutate } from "swr"; +import { getAPIUrl } from "@services/config/config"; +import { revalidateTags } from "@services/utils/ts/requests"; + +interface ModifiedChapterInterface { + chapterId: string; + chapterName: string; +} function Chapter(props: any) { + const router = useRouter(); + const [modifiedChapter, setModifiedChapter] = React.useState(undefined); + const [selectedChapter, setSelectedChapter] = React.useState(undefined); + + async function updateChapterName(chapterId: string) { + if (modifiedChapter?.chapterId === chapterId) { + setSelectedChapter(undefined); + let modifiedChapterCopy = { + name: modifiedChapter.chapterName, + description: '', + activities: props.info.list.chapter.activityIds, + } + await updateChapter(chapterId, modifiedChapterCopy) + await mutate(`${getAPIUrl()}chapters/meta/course_${props.courseid}`) + await revalidateTags(['courses'], props.orgslug) + router.refresh(); + } + } + return ( {(provided, snapshot) => ( @@ -23,7 +52,17 @@ function Chapter(props: any) {
-

{props.info.list.chapter.name}

+
+ + {selectedChapter === props.info.list.chapter.id ? + (
+ setModifiedChapter({ chapterId: props.info.list.chapter.id, chapterName: e.target.value })} /> + +
) : (

{props.info.list.chapter.name}

)} + setSelectedChapter(props.info.list.chapter.id)} /> +
{ async function checkRefreshToken() { - deleteCookie("access_token_cookie"); + //deleteCookie("access_token_cookie"); let data = await getNewAccessTokenUsingRefreshToken(); if (data) { return data.access_token; diff --git a/front/package-lock.json b/front/package-lock.json index b9cd040d..66508099 100644 --- a/front/package-lock.json +++ b/front/package-lock.json @@ -28,7 +28,7 @@ "framer-motion": "^10.16.1", "lowlight": "^3.0.0", "lucide-react": "^0.268.0", - "next": "^13.5.2", + "next": "^13.5.4", "re-resizable": "^6.9.9", "react": "^18.2.0", "react-beautiful-dnd": "^13.1.1", diff --git a/front/package.json b/front/package.json index 2279d92e..353749ad 100644 --- a/front/package.json +++ b/front/package.json @@ -29,7 +29,7 @@ "framer-motion": "^10.16.1", "lowlight": "^3.0.0", "lucide-react": "^0.268.0", - "next": "^13.5.2", + "next": "^13.5.4", "re-resizable": "^6.9.9", "react": "^18.2.0", "react-beautiful-dnd": "^13.1.1", diff --git a/front/services/courses/chapters.ts b/front/services/courses/chapters.ts index 35a8887c..0049cf08 100644 --- a/front/services/courses/chapters.ts +++ b/front/services/courses/chapters.ts @@ -21,6 +21,12 @@ export async function updateChaptersMetadata(course_id: any, data: any) { return res; } +export async function updateChapter(coursechapter_id: any, data: any) { + const result: any = await fetch(`${getAPIUrl()}chapters/${coursechapter_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, null)); const res = await errorHandling(result);