diff --git a/package-lock.json b/package-lock.json index 99f350c0b..11ebb8021 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22156,9 +22156,15 @@ "optional": true }, "node_modules/nanoid": { - "version": "3.3.4", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.4.tgz", - "integrity": "sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==", + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz", + "integrity": "sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], "bin": { "nanoid": "bin/nanoid.cjs" }, diff --git a/src/components/file-editor/FileEditor.tsx b/src/components/file-editor/FileEditor.tsx index 273738da3..34e707958 100644 --- a/src/components/file-editor/FileEditor.tsx +++ b/src/components/file-editor/FileEditor.tsx @@ -1,12 +1,14 @@ +import { FC } from 'react' import { Editor } from '@tinymce/tinymce-react' import { initialFileValue } from '~/components/file-editor/FileEditor.constants' -const FileEditor = () => { - const handleSave = (content: string) => { - console.log('Saved content:', content) - } +interface FileEditorProps { + onEdit: (content: string) => void + value: string +} +const FileEditor: FC = ({ onEdit, value }) => { return ( { toolbar: 'undo redo | blocks fontsize | bold italic underline strikethrough | ltr rtl | link image media table mergetags | align lineheight | tinycomments | checklist numlist bullist indent outdent accordion | removeformat', content_style: - 'body { font-family:Helvetica,Arial,sans-serif; font-size:14px }', - save_onsavecallback: handleSave + 'body { font-family:Helvetica,Arial,sans-serif; font-size:14px }' }} initialValue={initialFileValue} + onEditorChange={onEdit} + value={value} /> ) } diff --git a/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx b/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx index 06cfa7e5f..5f69046e7 100644 --- a/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx +++ b/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx @@ -50,6 +50,7 @@ const CreateOrEditLesson = () => { const { openModal } = useModalContext() const navigate = useNavigate() const [attachments, setAttachments] = useState([]) + const [content, setContent] = useState('') const { id } = useParams() const handleResponseError = (error: ErrorResponse) => { @@ -92,9 +93,14 @@ const CreateOrEditLesson = () => { ) } + const handleEdit = (content: string) => { + setContent(content) + } + const addLesson = (): Promise => { const lesson = { ...data, + content, attachments: attachments.map((attachment) => attachment._id) } return ResourceService.addLesson(lesson) @@ -156,11 +162,8 @@ const CreateOrEditLesson = () => { }) useEffect(() => { - if (id) { - void fetchDataLesson(id) - } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []) + if (id) void fetchDataLesson(id) + }, [id, fetchDataLesson]) if (getLessonLoading) { return @@ -214,7 +217,7 @@ const CreateOrEditLesson = () => { > {t('lesson.labels.attachments')} - + {attachmentsList} diff --git a/src/pages/lesson-details/LessonDetails.constants.tsx b/src/pages/lesson-details/LessonDetails.constants.tsx index e0eb77d16..f69df509d 100644 --- a/src/pages/lesson-details/LessonDetails.constants.tsx +++ b/src/pages/lesson-details/LessonDetails.constants.tsx @@ -3,6 +3,7 @@ export const defaultResponse = { author: '', createdAt: '', description: '', + content: '', title: '', updatedAt: '', _id: '' diff --git a/src/pages/lesson-details/LessonDetails.tsx b/src/pages/lesson-details/LessonDetails.tsx index 13f30f023..76fd65e45 100644 --- a/src/pages/lesson-details/LessonDetails.tsx +++ b/src/pages/lesson-details/LessonDetails.tsx @@ -11,7 +11,6 @@ import useAxios from '~/hooks/use-axios' import { ResourceService } from '~/services/resource-service' import { attachmentsMock, - contentMock, defaultResponse } from '~/pages/lesson-details/LessonDetails.constants' import Accordions from '~/components/accordion/Accordions' @@ -70,7 +69,7 @@ const LessonDetails = () => { const items = [ { title: 'lesson.content', - content: contentMock + content:
}, { title: 'lesson.attachments', diff --git a/src/services/resource-service.ts b/src/services/resource-service.ts index a6594c3d1..ba91420b5 100644 --- a/src/services/resource-service.ts +++ b/src/services/resource-service.ts @@ -9,6 +9,7 @@ import { ItemsWithCount, LessonData, Lesson, + NewLesson, UpdateAttachmentParams } from '~/types' import { createUrlPath } from '~/utils/helper-functions' @@ -22,7 +23,7 @@ export const ResourceService = { await axiosClient.get(createUrlPath(URLs.resources.lessons.get, id)), deleteLesson: async (id: string): Promise> => await axiosClient.delete(createUrlPath(URLs.resources.lessons.delete, id)), - addLesson: async (data: LessonData): Promise => + addLesson: async (data: NewLesson): Promise => await axiosClient.post(URLs.resources.lessons.add, data), editLesson: async (data: LessonData, id?: string): Promise => await axiosClient.patch( diff --git a/src/types/lesson/interfaces/lesson.interfaces.ts b/src/types/lesson/interfaces/lesson.interfaces.ts index ca66d156b..c3dd0278b 100644 --- a/src/types/lesson/interfaces/lesson.interfaces.ts +++ b/src/types/lesson/interfaces/lesson.interfaces.ts @@ -3,3 +3,7 @@ export interface LessonData { description: string attachments: string[] } + +export interface NewLesson extends LessonData { + content: string +} diff --git a/src/types/my-resources/interfaces/myResources.interface.ts b/src/types/my-resources/interfaces/myResources.interface.ts index 5eb0f55a5..5fa646b31 100644 --- a/src/types/my-resources/interfaces/myResources.interface.ts +++ b/src/types/my-resources/interfaces/myResources.interface.ts @@ -3,6 +3,7 @@ import { CommonEntityFields, RequestParams } from '~/types' export interface Lesson extends CommonEntityFields { title: string author: string + content: string description: string attachments: string[] }