import ConfirmationModal from '@components/StyledElements/ConfirmationModal/ConfirmationModal' import { Hexagon, MoreHorizontal, MoreVertical, Pencil, Save, X, } from 'lucide-react' import React from 'react' import { Draggable, Droppable } from 'react-beautiful-dnd' import ActivityElement from './ActivityElement' import NewActivityButton from '../Buttons/NewActivityButton' import { deleteChapter, updateChapter } from '@services/courses/chapters' import { revalidateTags } from '@services/utils/ts/requests' import { useRouter } from 'next/navigation' import { getAPIUrl } from '@services/config/config' import { mutate } from 'swr' type ChapterElementProps = { chapter: any chapterIndex: number orgslug: string course_uuid: string } interface ModifiedChapterInterface { chapterId: string chapterName: string } function ChapterElement(props: ChapterElementProps) { const activities = props.chapter.activities || [] const [modifiedChapter, setModifiedChapter] = React.useState< ModifiedChapterInterface | undefined >(undefined) const [selectedChapter, setSelectedChapter] = React.useState< string | undefined >(undefined) const router = useRouter() const deleteChapterUI = async () => { await deleteChapter(props.chapter.id) mutate(`${getAPIUrl()}courses/${props.course_uuid}/meta`) await revalidateTags(['courses'], props.orgslug) router.refresh() } async function updateChapterName(chapterId: string) { if (modifiedChapter?.chapterId === chapterId) { setSelectedChapter(undefined) let modifiedChapterCopy = { name: modifiedChapter.chapterName, } await updateChapter(chapterId, modifiedChapterCopy) mutate(`${getAPIUrl()}courses/${props.course_uuid}/meta`) await revalidateTags(['courses'], props.orgslug) router.refresh() } } return ( {(provided, snapshot) => (
{selectedChapter === props.chapter.id ? (
setModifiedChapter({ chapterId: props.chapter.id, chapterName: e.target.value, }) } />
) : (

{props.chapter.name}

)} setSelectedChapter(props.chapter.id)} className="text-neutral-600 hover:cursor-pointer" />

Delete Chapter

} functionToExecute={() => deleteChapterUI()} status="warning" >
{(provided) => (
{activities.map((activity: any, index: any) => { return (
) })} {provided.placeholder}
)}
)}
) } export default ChapterElement