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, 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) => (
{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)} />

Delete Chapter

} functionToExecute={() => props.deleteChapter(props.info.list.chapter.id)} status='warning' > {(provided) => (
{props.info.list.activities.map((activity: any, index: any) => ( ))} {provided.placeholder}
{ props.openNewActivityModal(props.info.list.chapter.id); }} className="flex space-x-2 items-center py-2 my-3 rounded-md justify-center text-white bg-black hover:cursor-pointer">
Add Activity +
)}
)}
); } const ChapterWrapper = styled.div` margin-bottom: 20px; padding: 12px; font-size: 15px; display: block; border-radius: 9px; border: 1px solid rgba(255, 255, 255, 0.19); box-shadow: 0px 13px 33px -13px rgb(0 0 0 / 12%); transition: all 0.2s ease; h3{ padding-left: 20px; padding-right: 20px; } `; const ActivitiesList = styled.div` padding: 10px; `; export default Chapter;