feat: forward org_id values for lectures

This commit is contained in:
swve 2023-03-22 22:54:28 +01:00
parent 98b470f2ab
commit 447ac93649
6 changed files with 75 additions and 67 deletions

View file

@ -13,6 +13,7 @@ import { useRouter } from "next/navigation";
import NewChapterModal from "@components/Modals/CourseEdit/NewChapter";
import NewLectureModal from "@components/Modals/CourseEdit/NewLecture";
import { createLecture, createFileLecture } from "@services/courses/lectures";
import { getOrganizationContextInfo } from "@services/orgs";
function CourseEdit(params: any) {
const router = useRouter();
@ -31,6 +32,8 @@ function CourseEdit(params: any) {
const courseid = params.params.courseid;
const orgslug = params.params.orgslug;
async function getCourseChapters() {
const courseChapters = await getCourseChaptersMetadata(courseid);
setData(courseChapters);
@ -75,8 +78,9 @@ function CourseEdit(params: any) {
// Submit new lecture
const submitLecture = async (lecture: any) => {
console.log("submitLecture", lecture);
let org = await getOrganizationContextInfo(orgslug);
await updateChaptersMetadata(courseid, data);
await createLecture(lecture, lecture.chapterId);
await createLecture(lecture, lecture.chapterId, org.org_id);
await getCourseChapters();
setNewLectureModal(false);
};
@ -226,63 +230,63 @@ function CourseEdit(params: any) {
return (
<>
<Page>
<Title>
Edit Course {" "}
<button
onClick={() => {
setNewChapterModal(true);
}}
>
Add chapter +
</button>
<button
onClick={() => {
updateChapters();
}}
>
Save
</button>
</Title>
{newChapterModal && <NewChapterModal closeModal={closeNewChapterModal} submitChapter={submitChapter}></NewChapterModal>}
{newLectureModal && (
<NewLectureModal
closeModal={closeNewLectureModal}
submitFileLecture={submitFileLecture}
submitLecture={submitLecture}
chapterId={newLectureModalData}
></NewLectureModal>
)}
<Page>
<Title>
Edit Course {" "}
<button
onClick={() => {
setNewChapterModal(true);
}}
>
Add chapter +
</button>
<button
onClick={() => {
updateChapters();
}}
>
Save
</button>
</Title>
{newChapterModal && <NewChapterModal closeModal={closeNewChapterModal} submitChapter={submitChapter}></NewChapterModal>}
{newLectureModal && (
<NewLectureModal
closeModal={closeNewLectureModal}
submitFileLecture={submitFileLecture}
submitLecture={submitLecture}
chapterId={newLectureModalData}
></NewLectureModal>
)}
<br />
{winReady && (
<ChapterlistWrapper>
<DragDropContext onDragEnd={onDragEnd}>
<Droppable key="chapters" droppableId="chapters" type="chapter">
{(provided) => (
<>
<div key={"chapters"} {...provided.droppableProps} ref={provided.innerRef}>
{getChapters().map((info: any, index: any) => (
<>
<Chapter
orgslug={orgslug}
courseid={courseid}
openNewLectureModal={openNewLectureModal}
deleteChapter={deleteChapterUI}
key={index}
info={info}
index={index}
></Chapter>
</>
))}
{provided.placeholder}
</div>
</>
)}
</Droppable>
</DragDropContext>
</ChapterlistWrapper>
)}
<br />
{winReady && (
<ChapterlistWrapper>
<DragDropContext onDragEnd={onDragEnd}>
<Droppable key="chapters" droppableId="chapters" type="chapter">
{(provided) => (
<>
<div key={"chapters"} {...provided.droppableProps} ref={provided.innerRef}>
{getChapters().map((info: any, index: any) => (
<>
<Chapter
orgslug={orgslug}
courseid={courseid}
openNewLectureModal={openNewLectureModal}
deleteChapter={deleteChapterUI}
key={index}
info={info}
index={index}
></Chapter>
</>
))}
{provided.placeholder}
</div>
</>
)}
</Droppable>
</DragDropContext>
</ChapterlistWrapper>
)}
</Page>
</>
);

View file

@ -6,6 +6,7 @@ import Layout from "@components/UI/Layout";
import { Title } from "@components/UI/Elements/Styles/Title";
import { createNewCourse } from "@services/courses/courses";
import { getOrganizationContextInfo } from "@services/orgs";
import { getUriWithOrg } from "@services/config";
const NewCoursePage = (params: any) => {
const router = useRouter();
@ -40,7 +41,7 @@ const NewCoursePage = (params: any) => {
// TODO : wow this is terrible - fix this
if (status.org_id == orgId) {
router.push(`/org/${orgslug}/courses`);
router.push(getUriWithOrg(orgslug, `/courses`));
} else {
alert("Error creating course, please see console logs");
console.log(status);

View file

@ -1,13 +1,13 @@
import { getAPIUrl } from "@services/config";
import { RequestBody, RequestBodyForm } from "@services/utils/requests";
export async function createLecture(data: any, chapter_id: any) {
export async function createLecture(data: any, chapter_id: any, org_id: any) {
data.content = {};
// remove chapter_id from data
delete data.chapterId;
const result: any = await fetch(`${getAPIUrl()}lectures/?coursechapter_id=${chapter_id}`, RequestBody("POST", data))
const result: any = await fetch(`${getAPIUrl()}lectures/?coursechapter_id=${chapter_id}&org_id=${org_id}`, RequestBody("POST", data))
.then((result) => result.json())
.catch((error) => console.log("error", error));