feat: init CS + SS course chapter deletion

This commit is contained in:
swve 2022-11-04 23:46:55 +01:00
parent 5331e4db90
commit 0572368a32
4 changed files with 37 additions and 6 deletions

View file

@ -22,7 +22,7 @@ function Chapter(props: any) {
<Draggable key={props.info.list.chapter.id} draggableId={props.info.list.chapter.id} index={props.index}>
{(provided, snapshot) => (
<ChapterWrapper {...provided.dragHandleProps} {...provided.draggableProps} ref={provided.innerRef} isDragging={snapshot.isDragging} key={props.info.list.chapter.id}>
<h3>{props.info.list.chapter.name}</h3>
<h3>{props.info.list.chapter.name} <button onClick={() => {props.deleteChapter(props.info.list.chapter.id)}}>X</button></h3>
<Droppable droppableId={props.info.list.chapter.id} type="element">
{(provided) => (
<ElementsList {...provided.droppableProps} ref={provided.innerRef}>

View file

@ -7,7 +7,7 @@ import { Title } from "../../../../../../components/ui/styles/title";
import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd";
import { initialData, initialData2 } from "../../../../../../components/drags/data";
import Chapter from "../../../../../../components/drags/chapter";
import { createChapter, getCourseChaptersMetadata } from "../../../../../../services/chapters";
import { createChapter, deleteChapter, getCourseChaptersMetadata } from "../../../../../../services/chapters";
import { useRouter } from "next/router";
import NewChapterModal from "../../../../../../components/modals/chapters/new";
@ -59,6 +59,15 @@ function CourseEdit() {
setNewChapterModal(false);
};
const deleteChapterUI = async (chapterId: any) => {
console.log("deleteChapter", chapterId);
await deleteChapter(chapterId);
getCourseChapters();
};
// Close new chapter modal
const closeModal = () => {
setNewChapterModal(false);
@ -177,7 +186,7 @@ function CourseEdit() {
{(provided) => (
<div key={"chapters"} {...provided.droppableProps} ref={provided.innerRef}>
{getChapters().map((info: any, index: any) => (
<Chapter key={index} info={info} index={index}></Chapter>
<Chapter deleteChapter={deleteChapterUI} key={index} info={info} index={index}></Chapter>
))}
{provided.placeholder}
</div>

View file

@ -41,3 +41,22 @@ export async function createChapter(data: any, course_id: any) {
return result;
}
export async function deleteChapter (coursechapter_id: any) {
const HeadersConfig = new Headers({ "Content-Type": "application/json" });
const requestOptions: any = {
method: "DELETE",
headers: HeadersConfig,
redirect: "follow",
credentials: "include",
};
const result: any = await fetch(`${getAPIUrl()}chapters/${coursechapter_id}`, requestOptions)
.then((result) => result.json())
.catch((error) => console.log("error", error));
console.log("result", result);
return result;
}