From 60138df6a5811fc2cd8b0548d868a04e4827d5b9 Mon Sep 17 00:00:00 2001 From: Yura Didenko Date: Sun, 13 Aug 2023 19:36:45 +0300 Subject: [PATCH 01/25] Inplemented uploading files --- src/components/file-uploader/FileUploader.tsx | 10 +++--- src/constants/translations/en/common.json | 1 + src/containers/add-documents/AddDocuments.tsx | 1 + .../CreateOrEditLesson.tsx | 34 +++++++++++++++++-- src/services/attachment-service.ts | 17 ++++++++++ 5 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 src/services/attachment-service.ts diff --git a/src/components/file-uploader/FileUploader.tsx b/src/components/file-uploader/FileUploader.tsx index c7fcc0870..7178f270a 100644 --- a/src/components/file-uploader/FileUploader.tsx +++ b/src/components/file-uploader/FileUploader.tsx @@ -29,9 +29,9 @@ interface FileUploaderProps { initialError: string validationData: AddDocuments isImages?: boolean - sx?: { - root?: SxProps - button?: SxProps + sx: { + root?: SxProps + button?: SxProps } variant?: ButtonVariantEnum icon?: ReactElement @@ -90,9 +90,7 @@ const FileUploader: FC = ({ {isImages && ( <> - {`${t('constant.fileSize', { size: '10' })} ${t( - 'common.megabytes' - )}`} + {t('constant.fileSize', { size: '10 Mb' })} {initialError && ( {t(initialError)} diff --git a/src/constants/translations/en/common.json b/src/constants/translations/en/common.json index 5bc8cd83b..6495e2c88 100644 --- a/src/constants/translations/en/common.json +++ b/src/constants/translations/en/common.json @@ -31,6 +31,7 @@ "bytes": "B", "kilobytes": "KB", "megabytes": "MB", + "plusSign": "+", "uploadNewFile": "Upload new file", "typeError": "Wrong file type. Only .pdf/.jpg/.jpeg files are allowed.", "allFilesSizeError": "All files size error", diff --git a/src/containers/add-documents/AddDocuments.tsx b/src/containers/add-documents/AddDocuments.tsx index 909fe88d0..68853efd9 100644 --- a/src/containers/add-documents/AddDocuments.tsx +++ b/src/containers/add-documents/AddDocuments.tsx @@ -11,6 +11,7 @@ import { snackbarVariants } from '~/constants' import { ButtonVariantEnum, Emitter } from '~/types' import { spliceSx } from '~/utils/helper-functions' + interface AddDocumentsProps { fetchData: (formData: FormData) => Promise formData: FormData diff --git a/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx b/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx index 5f69046e7..a461bf64c 100644 --- a/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx +++ b/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx @@ -1,4 +1,4 @@ -import { useState, useEffect } from 'react' +import { useState, useEffect, useCallback } from 'react' import { useTranslation } from 'react-i18next' import { Link, useNavigate, useParams } from 'react-router-dom' import { AxiosResponse } from 'axios' @@ -11,8 +11,7 @@ import IconButton from '@mui/material/IconButton' import Loader from '~/components/loader/Loader' import AddAttachments from '~/containers/add-attachments/AddAttachments' import IconExtensionWithTitle from '~/components/icon-extension-with-title/IconExtensionWithTitle' - -import { useModalContext } from '~/context/modal-context' +import { attachmentService } from '~/services/attachment-service' import AppButton from '~/components/app-button/AppButton' import AppTextField from '~/components/app-text-field/AppTextField' import FileEditor from '~/components/file-editor/FileEditor' @@ -21,6 +20,8 @@ import { useSnackBarContext } from '~/context/snackbar-context' import useAxios from '~/hooks/use-axios' import useForm from '~/hooks/use-form' import { ResourceService } from '~/services/resource-service' +import { useModalContext } from '~/context/modal-context' +import AddDocuments from '~/containers/add-documents/AddDocuments' import { snackbarVariants } from '~/constants' import { @@ -49,10 +50,18 @@ const CreateOrEditLesson = () => { const { openModal } = useModalContext() const navigate = useNavigate() + const [attachments, setAttachments] = useState([]) const [content, setContent] = useState('') const { id } = useParams() + const formData = new FormData() + + const createAttachments = useCallback( + (data?: FormData) => attachmentService.createAttachments(data), + [] + ) + const handleResponseError = (error: ErrorResponse) => { setAlert({ severity: snackbarVariants.error, @@ -169,6 +178,20 @@ const CreateOrEditLesson = () => { return } + const onCreateAttachmentsError = (error: ErrorResponse) => { + setAlert({ + severity: snackbarVariants.error, + message: error ? `errors.${error.code}` : '' + }) + } + const { fetchData: fetchDataAttachments } = useAxios({ + service: createAttachments, + fetchOnMount: false, + defaultResponse: null, + onResponseError: onCreateAttachmentsError + }) + + const attachmentsList = attachments.map((attachment) => ( { value={data.description} variant={TextFieldVariantEnum.Standard} /> + => + await axiosClient.get(URLs.resources.attachments.get, { params }), + + createAttachments: (data?: FormData): Promise => { + return axiosClient.post(URLs.attachments.post, data, { + headers: { 'Content-Type': 'multipart/form-data' } + }) + } +} From b5882a185ce4d19480b48fab2a5bb374941d7336 Mon Sep 17 00:00:00 2001 From: Yura Didenko Date: Mon, 14 Aug 2023 12:08:56 +0300 Subject: [PATCH 02/25] Small fix --- src/containers/add-documents/AddDocuments.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/containers/add-documents/AddDocuments.tsx b/src/containers/add-documents/AddDocuments.tsx index 68853efd9..909fe88d0 100644 --- a/src/containers/add-documents/AddDocuments.tsx +++ b/src/containers/add-documents/AddDocuments.tsx @@ -11,7 +11,6 @@ import { snackbarVariants } from '~/constants' import { ButtonVariantEnum, Emitter } from '~/types' import { spliceSx } from '~/utils/helper-functions' - interface AddDocumentsProps { fetchData: (formData: FormData) => Promise formData: FormData From 45bca8a7c34b17c2c7db65009e92738430ae8914 Mon Sep 17 00:00:00 2001 From: Yura Didenko Date: Mon, 14 Aug 2023 14:01:44 +0300 Subject: [PATCH 03/25] Added type --- src/types/attachments/attachments.index.ts | 1 + src/types/attachments/types/attachments.types.ts | 1 + 2 files changed, 2 insertions(+) create mode 100644 src/types/attachments/attachments.index.ts create mode 100644 src/types/attachments/types/attachments.types.ts diff --git a/src/types/attachments/attachments.index.ts b/src/types/attachments/attachments.index.ts new file mode 100644 index 000000000..b803b9be9 --- /dev/null +++ b/src/types/attachments/attachments.index.ts @@ -0,0 +1 @@ +export * from '~/types/attachments/types/attachments.types' diff --git a/src/types/attachments/types/attachments.types.ts b/src/types/attachments/types/attachments.types.ts new file mode 100644 index 000000000..4db01e9d4 --- /dev/null +++ b/src/types/attachments/types/attachments.types.ts @@ -0,0 +1 @@ +export type Emitter = { files: File[]; error: string } From 26bcfbea0b978c430c0f4357922ccb8086f87b65 Mon Sep 17 00:00:00 2001 From: Yura Didenko Date: Wed, 16 Aug 2023 15:04:50 +0300 Subject: [PATCH 04/25] Move uploadin to modal window --- .../AttachmentsContainer.tsx | 1 + .../CreateOrEditLesson.styles.ts | 1 + .../CreateOrEditLesson.tsx | 20 ++++++++++++------- src/types/attachments/attachments.index.ts | 1 - .../attachments/types/attachments.types.ts | 1 - 5 files changed, 15 insertions(+), 9 deletions(-) delete mode 100644 src/types/attachments/attachments.index.ts delete mode 100644 src/types/attachments/types/attachments.types.ts diff --git a/src/containers/my-resources/attachments-container/AttachmentsContainer.tsx b/src/containers/my-resources/attachments-container/AttachmentsContainer.tsx index cd0f2b812..24fb268b5 100644 --- a/src/containers/my-resources/attachments-container/AttachmentsContainer.tsx +++ b/src/containers/my-resources/attachments-container/AttachmentsContainer.tsx @@ -32,6 +32,7 @@ import { } from '~/types' import { ajustColumns, getScreenBasedLimit } from '~/utils/helper-functions' import { styles } from '~/containers/my-resources/attachments-container/AttachmentsContainer.styles' +import { ItemsWithCount, Attachment, ErrorResponse } from '~/types' const AttachmentsContainer = () => { const { t } = useTranslation() diff --git a/src/pages/create-or-edit-lesson/CreateOrEditLesson.styles.ts b/src/pages/create-or-edit-lesson/CreateOrEditLesson.styles.ts index 113c992f7..817c6c03b 100644 --- a/src/pages/create-or-edit-lesson/CreateOrEditLesson.styles.ts +++ b/src/pages/create-or-edit-lesson/CreateOrEditLesson.styles.ts @@ -43,6 +43,7 @@ export const styles = { gap: { xs: '24px', sm: '30px' }, justifyContent: 'space-between' }, + attachmentList: { container: { background: palette.basic.grey, diff --git a/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx b/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx index a461bf64c..b2cd56c7b 100644 --- a/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx +++ b/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx @@ -7,11 +7,13 @@ import Divider from '@mui/material/Divider' import AddIcon from '@mui/icons-material/Add' import CloseIcon from '@mui/icons-material/Close' import IconButton from '@mui/material/IconButton' +import Typography from '@mui/material/Typography' import Loader from '~/components/loader/Loader' import AddAttachments from '~/containers/add-attachments/AddAttachments' import IconExtensionWithTitle from '~/components/icon-extension-with-title/IconExtensionWithTitle' import { attachmentService } from '~/services/attachment-service' +import { useModalContext } from '~/context/modal-context' import AppButton from '~/components/app-button/AppButton' import AppTextField from '~/components/app-text-field/AppTextField' import FileEditor from '~/components/file-editor/FileEditor' @@ -20,7 +22,7 @@ import { useSnackBarContext } from '~/context/snackbar-context' import useAxios from '~/hooks/use-axios' import useForm from '~/hooks/use-form' import { ResourceService } from '~/services/resource-service' -import { useModalContext } from '~/context/modal-context' + import AddDocuments from '~/containers/add-documents/AddDocuments' import { snackbarVariants } from '~/constants' @@ -50,7 +52,6 @@ const CreateOrEditLesson = () => { const { openModal } = useModalContext() const navigate = useNavigate() - const [attachments, setAttachments] = useState([]) const [content, setContent] = useState('') const { id } = useParams() @@ -190,6 +191,7 @@ const CreateOrEditLesson = () => { defaultResponse: null, onResponseError: onCreateAttachmentsError }) + const handleOpenModal = () => openModal({ component: }) const attachmentsList = attachments.map((attachment) => ( @@ -233,11 +235,15 @@ const CreateOrEditLesson = () => { value={data.description} variant={TextFieldVariantEnum.Standard} /> - + + {t('myResourcesPage.attachments.addAttachment')} + + {t('common.plusSign')} + + Date: Wed, 16 Aug 2023 20:57:39 +0300 Subject: [PATCH 05/25] Small fix --- .../CreateOrEditLesson.tsx | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx b/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx index b2cd56c7b..25313201a 100644 --- a/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx +++ b/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx @@ -1,4 +1,8 @@ +<<<<<<< HEAD:src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx import { useState, useEffect, useCallback } from 'react' +======= +import { useState, useCallback } from 'react' +>>>>>>> 4bf6336 (Small fix):src/pages/new-lesson/NewLesson.tsx import { useTranslation } from 'react-i18next' import { Link, useNavigate, useParams } from 'react-router-dom' import { AxiosResponse } from 'axios' @@ -49,6 +53,10 @@ import { const CreateOrEditLesson = () => { const { t } = useTranslation() const { setAlert } = useSnackBarContext() +<<<<<<< HEAD:src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx +======= + const navigate = useNavigate() +>>>>>>> 4bf6336 (Small fix):src/pages/new-lesson/NewLesson.tsx const { openModal } = useModalContext() const navigate = useNavigate() @@ -63,6 +71,8 @@ const CreateOrEditLesson = () => { [] ) + const handleOpenModal = () => openModal({ component: }) + const handleResponseError = (error: ErrorResponse) => { setAlert({ severity: snackbarVariants.error, @@ -136,6 +146,7 @@ const CreateOrEditLesson = () => { onResponseError: handleResponseError }) +<<<<<<< HEAD:src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx const { data, errors, @@ -193,6 +204,15 @@ const CreateOrEditLesson = () => { }) const handleOpenModal = () => openModal({ component: }) +======= + const { data, errors, handleInputChange, handleSubmit } = + useForm({ + initialValues, + validations, + onSubmit: fetchData, + submitWithData: true + }) +>>>>>>> 4bf6336 (Small fix):src/pages/new-lesson/NewLesson.tsx const attachmentsList = attachments.map((attachment) => ( @@ -235,6 +255,7 @@ const CreateOrEditLesson = () => { value={data.description} variant={TextFieldVariantEnum.Standard} /> + {t('myResourcesPage.attachments.addAttachment')} Date: Thu, 17 Aug 2023 16:20:47 +0300 Subject: [PATCH 06/25] Fixed buttons --- .../attachments-container/AttachmentsContainer.tsx | 1 + .../create-or-edit-lesson/CreateOrEditLesson.styles.ts | 1 - src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx | 10 ++-------- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/containers/my-resources/attachments-container/AttachmentsContainer.tsx b/src/containers/my-resources/attachments-container/AttachmentsContainer.tsx index 24fb268b5..a4cc67094 100644 --- a/src/containers/my-resources/attachments-container/AttachmentsContainer.tsx +++ b/src/containers/my-resources/attachments-container/AttachmentsContainer.tsx @@ -15,6 +15,7 @@ import usePagination from '~/hooks/table/use-pagination' import AddDocuments from '~/containers/add-documents/AddDocuments' import { defaultResponses, snackbarVariants } from '~/constants' + import { columns, initialSort, diff --git a/src/pages/create-or-edit-lesson/CreateOrEditLesson.styles.ts b/src/pages/create-or-edit-lesson/CreateOrEditLesson.styles.ts index 817c6c03b..113c992f7 100644 --- a/src/pages/create-or-edit-lesson/CreateOrEditLesson.styles.ts +++ b/src/pages/create-or-edit-lesson/CreateOrEditLesson.styles.ts @@ -43,7 +43,6 @@ export const styles = { gap: { xs: '24px', sm: '30px' }, justifyContent: 'space-between' }, - attachmentList: { container: { background: palette.basic.grey, diff --git a/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx b/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx index 25313201a..bb159059e 100644 --- a/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx +++ b/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx @@ -11,7 +11,6 @@ import Divider from '@mui/material/Divider' import AddIcon from '@mui/icons-material/Add' import CloseIcon from '@mui/icons-material/Close' import IconButton from '@mui/material/IconButton' -import Typography from '@mui/material/Typography' import Loader from '~/components/loader/Loader' import AddAttachments from '~/containers/add-attachments/AddAttachments' @@ -256,14 +255,9 @@ const CreateOrEditLesson = () => { variant={TextFieldVariantEnum.Standard} /> - + {t('myResourcesPage.attachments.addAttachment')} - - {t('common.plusSign')} - + Date: Thu, 17 Aug 2023 16:26:29 +0300 Subject: [PATCH 07/25] Fixed buttons --- src/constants/translations/en/common.json | 1 - 1 file changed, 1 deletion(-) diff --git a/src/constants/translations/en/common.json b/src/constants/translations/en/common.json index 6495e2c88..5bc8cd83b 100644 --- a/src/constants/translations/en/common.json +++ b/src/constants/translations/en/common.json @@ -31,7 +31,6 @@ "bytes": "B", "kilobytes": "KB", "megabytes": "MB", - "plusSign": "+", "uploadNewFile": "Upload new file", "typeError": "Wrong file type. Only .pdf/.jpg/.jpeg files are allowed.", "allFilesSizeError": "All files size error", From 2f994e7275c0c9274fd9f37d547fd6931286a813 Mon Sep 17 00:00:00 2001 From: Yura Didenko Date: Wed, 23 Aug 2023 09:19:49 +0300 Subject: [PATCH 08/25] Fixed comments --- src/components/file-uploader/FileUploader.tsx | 4 +++- src/services/attachment-service.ts | 2 +- src/types/common/enums/common.enums.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/file-uploader/FileUploader.tsx b/src/components/file-uploader/FileUploader.tsx index 7178f270a..7fed61aeb 100644 --- a/src/components/file-uploader/FileUploader.tsx +++ b/src/components/file-uploader/FileUploader.tsx @@ -90,7 +90,9 @@ const FileUploader: FC = ({ {isImages && ( <> - {t('constant.fileSize', { size: '10 Mb' })} + {`${t('constant.fileSize', { size: '10' })} ${t( + 'common.megabytes' + )}`} {initialError && ( {t(initialError)} diff --git a/src/services/attachment-service.ts b/src/services/attachment-service.ts index 732c038e0..a4f086eee 100644 --- a/src/services/attachment-service.ts +++ b/src/services/attachment-service.ts @@ -8,7 +8,7 @@ export const attachmentService = { params: GetAttachmentsParams ): Promise => await axiosClient.get(URLs.resources.attachments.get, { params }), - + createAttachments: (data?: FormData): Promise => { return axiosClient.post(URLs.attachments.post, data, { headers: { 'Content-Type': 'multipart/form-data' } diff --git a/src/types/common/enums/common.enums.ts b/src/types/common/enums/common.enums.ts index 338c241d4..588c31418 100644 --- a/src/types/common/enums/common.enums.ts +++ b/src/types/common/enums/common.enums.ts @@ -100,4 +100,4 @@ export enum InputEnum { export enum OverlapEnum { Circular = 'circular', Rectangular = 'rectangular' -} +} \ No newline at end of file From c7fd0ffcf2b96b9f8d2de91c991e28c016daeaba Mon Sep 17 00:00:00 2001 From: Yura Didenko Date: Fri, 25 Aug 2023 14:33:43 +0300 Subject: [PATCH 09/25] Fixed comment --- src/components/file-uploader/FileUploader.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/file-uploader/FileUploader.tsx b/src/components/file-uploader/FileUploader.tsx index 7fed61aeb..c7fcc0870 100644 --- a/src/components/file-uploader/FileUploader.tsx +++ b/src/components/file-uploader/FileUploader.tsx @@ -29,9 +29,9 @@ interface FileUploaderProps { initialError: string validationData: AddDocuments isImages?: boolean - sx: { - root?: SxProps - button?: SxProps + sx?: { + root?: SxProps + button?: SxProps } variant?: ButtonVariantEnum icon?: ReactElement From 7cbfd3d9baeee5db889f70fe95d93a31d9a7d6f5 Mon Sep 17 00:00:00 2001 From: Taras Chaika <45912519+TSlashDreamy@users.noreply.github.com> Date: Fri, 25 Aug 2023 15:39:29 +0300 Subject: [PATCH 10/25] Added sorting to quizzes tab (#1043) * added sorting to quizzes tab * removed redundant destructured variable * renamed variable * fixed code smell --- src/containers/my-quizzes/QuizzesContainer.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/containers/my-quizzes/QuizzesContainer.tsx b/src/containers/my-quizzes/QuizzesContainer.tsx index 2c2cd850b..39fbb4d2f 100644 --- a/src/containers/my-quizzes/QuizzesContainer.tsx +++ b/src/containers/my-quizzes/QuizzesContainer.tsx @@ -19,7 +19,6 @@ import { itemsLoadLimit, removeColumnRules } from '~/containers/my-quizzes/QuizzesContainer.constants' - import { ItemsWithCount, GetResourcesParams, From cb916250ba713979b76fa09e13523d808bb37c25 Mon Sep 17 00:00:00 2001 From: Artur Bekh <102412173+ArturBekhDEV@users.noreply.github.com> Date: Sat, 26 Aug 2023 13:33:13 +0300 Subject: [PATCH 11/25] Add sort to attachments on myResources (#1059) * fix conflicts * fix conflicts 3 --- .../AttachmentsContainer.tsx | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/containers/my-resources/attachments-container/AttachmentsContainer.tsx b/src/containers/my-resources/attachments-container/AttachmentsContainer.tsx index a4cc67094..46dc21258 100644 --- a/src/containers/my-resources/attachments-container/AttachmentsContainer.tsx +++ b/src/containers/my-resources/attachments-container/AttachmentsContainer.tsx @@ -22,6 +22,8 @@ import { itemsLoadLimit, removeColumnRules } from '~/containers/my-resources/attachments-container/AttachmentsContainer.constants' +import { ajustColumns, getScreenBasedLimit } from '~/utils/helper-functions' +import { styles } from '~/containers/my-resources/attachments-container/AttachmentsContainer.styles' import { ItemsWithCount, GetResourcesParams, @@ -31,9 +33,6 @@ import { ResourcesTabsEnum, ButtonVariantEnum } from '~/types' -import { ajustColumns, getScreenBasedLimit } from '~/utils/helper-functions' -import { styles } from '~/containers/my-resources/attachments-container/AttachmentsContainer.styles' -import { ItemsWithCount, Attachment, ErrorResponse } from '~/types' const AttachmentsContainer = () => { const { t } = useTranslation() @@ -144,6 +143,34 @@ const AttachmentsContainer = () => { removeColumnRules ) + const openDeletionConfirmDialog = (id: string) => { + openDialog({ + message: 'myResourcesPage.confirmDeletionMessage', + sendConfirm: (isConfirmed: boolean) => + void handleDeleteAttachment(id, isConfirmed), + title: 'myResourcesPage.attachments.confirmAttachmentDeletionTitle' + }) + } + + const rowActions = [ + { + label: t('common.edit'), + func: () => console.log(t('common.edit')) + }, + { + label: t('common.delete'), + func: openDeletionConfirmDialog + } + ] + const addAttachmentBlock = ( + + ) + const props = { columns: columnsToShow, data: { response, getData: fetchAttachments }, From 6fea027e6acd1c0cc2c1a971cc534cd44506070b Mon Sep 17 00:00:00 2001 From: mxrcury Date: Tue, 29 Aug 2023 14:50:39 +0300 Subject: [PATCH 12/25] init --- .../AttachmentsContainer.tsx | 33 ++----------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/src/containers/my-resources/attachments-container/AttachmentsContainer.tsx b/src/containers/my-resources/attachments-container/AttachmentsContainer.tsx index 46dc21258..cd0f2b812 100644 --- a/src/containers/my-resources/attachments-container/AttachmentsContainer.tsx +++ b/src/containers/my-resources/attachments-container/AttachmentsContainer.tsx @@ -15,15 +15,12 @@ import usePagination from '~/hooks/table/use-pagination' import AddDocuments from '~/containers/add-documents/AddDocuments' import { defaultResponses, snackbarVariants } from '~/constants' - import { columns, initialSort, itemsLoadLimit, removeColumnRules } from '~/containers/my-resources/attachments-container/AttachmentsContainer.constants' -import { ajustColumns, getScreenBasedLimit } from '~/utils/helper-functions' -import { styles } from '~/containers/my-resources/attachments-container/AttachmentsContainer.styles' import { ItemsWithCount, GetResourcesParams, @@ -33,6 +30,8 @@ import { ResourcesTabsEnum, ButtonVariantEnum } from '~/types' +import { ajustColumns, getScreenBasedLimit } from '~/utils/helper-functions' +import { styles } from '~/containers/my-resources/attachments-container/AttachmentsContainer.styles' const AttachmentsContainer = () => { const { t } = useTranslation() @@ -143,34 +142,6 @@ const AttachmentsContainer = () => { removeColumnRules ) - const openDeletionConfirmDialog = (id: string) => { - openDialog({ - message: 'myResourcesPage.confirmDeletionMessage', - sendConfirm: (isConfirmed: boolean) => - void handleDeleteAttachment(id, isConfirmed), - title: 'myResourcesPage.attachments.confirmAttachmentDeletionTitle' - }) - } - - const rowActions = [ - { - label: t('common.edit'), - func: () => console.log(t('common.edit')) - }, - { - label: t('common.delete'), - func: openDeletionConfirmDialog - } - ] - const addAttachmentBlock = ( - - ) - const props = { columns: columnsToShow, data: { response, getData: fetchAttachments }, From 00023296f29e29fb8742fdcbaf022e95e681e11e Mon Sep 17 00:00:00 2001 From: mxrcury Date: Tue, 29 Aug 2023 16:04:47 +0300 Subject: [PATCH 13/25] finished --- src/components/file-uploader/FileUploader.tsx | 2 +- src/containers/add-documents/AddDocuments.tsx | 1 + .../add-resource-with-input/AddResourceWithInput.tsx | 2 +- .../my-resources/attachments-container/AttachmentsContainer.tsx | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/file-uploader/FileUploader.tsx b/src/components/file-uploader/FileUploader.tsx index c7fcc0870..eea95dc0f 100644 --- a/src/components/file-uploader/FileUploader.tsx +++ b/src/components/file-uploader/FileUploader.tsx @@ -103,4 +103,4 @@ const FileUploader: FC = ({ ) } -export default FileUploader +export default FileUploader \ No newline at end of file diff --git a/src/containers/add-documents/AddDocuments.tsx b/src/containers/add-documents/AddDocuments.tsx index 909fe88d0..69a896763 100644 --- a/src/containers/add-documents/AddDocuments.tsx +++ b/src/containers/add-documents/AddDocuments.tsx @@ -55,6 +55,7 @@ const AddDocuments: FC = ({ !error && void fetchData(formData) } + spliceSx return ( diff --git a/src/containers/my-resources/add-resource-with-input/AddResourceWithInput.tsx b/src/containers/my-resources/add-resource-with-input/AddResourceWithInput.tsx index 8b04587e3..92e48d865 100644 --- a/src/containers/my-resources/add-resource-with-input/AddResourceWithInput.tsx +++ b/src/containers/my-resources/add-resource-with-input/AddResourceWithInput.tsx @@ -74,4 +74,4 @@ const AddResourceWithInput: FC = ({ ) } -export default AddResourceWithInput +export default AddResourceWithInput \ No newline at end of file diff --git a/src/containers/my-resources/attachments-container/AttachmentsContainer.tsx b/src/containers/my-resources/attachments-container/AttachmentsContainer.tsx index cd0f2b812..28bbb326d 100644 --- a/src/containers/my-resources/attachments-container/AttachmentsContainer.tsx +++ b/src/containers/my-resources/attachments-container/AttachmentsContainer.tsx @@ -183,4 +183,4 @@ const AttachmentsContainer = () => { ) } -export default AttachmentsContainer +export default AttachmentsContainer \ No newline at end of file From 84baff7af5eaa3bb0ca711b0b9ae5701f2f3f1fe Mon Sep 17 00:00:00 2001 From: mxrcury Date: Tue, 29 Aug 2023 16:25:27 +0300 Subject: [PATCH 14/25] fix --- .../CreateOrEditLesson.tsx | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx b/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx index bb159059e..3076b6770 100644 --- a/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx +++ b/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx @@ -1,8 +1,12 @@ <<<<<<< HEAD:src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx +<<<<<<< HEAD:src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx import { useState, useEffect, useCallback } from 'react' ======= import { useState, useCallback } from 'react' >>>>>>> 4bf6336 (Small fix):src/pages/new-lesson/NewLesson.tsx +======= +import { useState, useCallback } from 'react' +>>>>>>> 8e16e12 (fix):src/pages/new-lesson/NewLesson.tsx import { useTranslation } from 'react-i18next' import { Link, useNavigate, useParams } from 'react-router-dom' import { AxiosResponse } from 'axios' @@ -53,9 +57,12 @@ const CreateOrEditLesson = () => { const { t } = useTranslation() const { setAlert } = useSnackBarContext() <<<<<<< HEAD:src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx +<<<<<<< HEAD:src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx ======= const navigate = useNavigate() >>>>>>> 4bf6336 (Small fix):src/pages/new-lesson/NewLesson.tsx +======= +>>>>>>> 8e16e12 (fix):src/pages/new-lesson/NewLesson.tsx const { openModal } = useModalContext() const navigate = useNavigate() @@ -65,12 +72,24 @@ const CreateOrEditLesson = () => { const formData = new FormData() +<<<<<<< HEAD:src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx const createAttachments = useCallback( (data?: FormData) => attachmentService.createAttachments(data), [] ) const handleOpenModal = () => openModal({ component: }) +======= + const handleOpenModal = () => + openModal({ + component: ( + + ) + }) +>>>>>>> 8e16e12 (fix):src/pages/new-lesson/NewLesson.tsx const handleResponseError = (error: ErrorResponse) => { setAlert({ @@ -255,11 +274,6 @@ const CreateOrEditLesson = () => { variant={TextFieldVariantEnum.Standard} /> - - {t('myResourcesPage.attachments.addAttachment')} - - - Date: Tue, 5 Sep 2023 19:03:42 +0300 Subject: [PATCH 15/25] fix --- src/containers/add-documents/AddDocuments.tsx | 1 - src/types/common/enums/common.enums.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/containers/add-documents/AddDocuments.tsx b/src/containers/add-documents/AddDocuments.tsx index 69a896763..909fe88d0 100644 --- a/src/containers/add-documents/AddDocuments.tsx +++ b/src/containers/add-documents/AddDocuments.tsx @@ -55,7 +55,6 @@ const AddDocuments: FC = ({ !error && void fetchData(formData) } - spliceSx return ( diff --git a/src/types/common/enums/common.enums.ts b/src/types/common/enums/common.enums.ts index 588c31418..338c241d4 100644 --- a/src/types/common/enums/common.enums.ts +++ b/src/types/common/enums/common.enums.ts @@ -100,4 +100,4 @@ export enum InputEnum { export enum OverlapEnum { Circular = 'circular', Rectangular = 'rectangular' -} \ No newline at end of file +} From c245a0fe0b3624ffd4d2899433451d2f93184a58 Mon Sep 17 00:00:00 2001 From: mxrcury Date: Tue, 5 Sep 2023 19:09:44 +0300 Subject: [PATCH 16/25] fix --- .../CreateOrEditLesson.tsx | 67 +------------------ 1 file changed, 2 insertions(+), 65 deletions(-) diff --git a/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx b/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx index 3076b6770..5f69046e7 100644 --- a/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx +++ b/src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx @@ -1,12 +1,4 @@ -<<<<<<< HEAD:src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx -<<<<<<< HEAD:src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx -import { useState, useEffect, useCallback } from 'react' -======= -import { useState, useCallback } from 'react' ->>>>>>> 4bf6336 (Small fix):src/pages/new-lesson/NewLesson.tsx -======= -import { useState, useCallback } from 'react' ->>>>>>> 8e16e12 (fix):src/pages/new-lesson/NewLesson.tsx +import { useState, useEffect } from 'react' import { useTranslation } from 'react-i18next' import { Link, useNavigate, useParams } from 'react-router-dom' import { AxiosResponse } from 'axios' @@ -19,7 +11,7 @@ import IconButton from '@mui/material/IconButton' import Loader from '~/components/loader/Loader' import AddAttachments from '~/containers/add-attachments/AddAttachments' import IconExtensionWithTitle from '~/components/icon-extension-with-title/IconExtensionWithTitle' -import { attachmentService } from '~/services/attachment-service' + import { useModalContext } from '~/context/modal-context' import AppButton from '~/components/app-button/AppButton' import AppTextField from '~/components/app-text-field/AppTextField' @@ -30,8 +22,6 @@ import useAxios from '~/hooks/use-axios' import useForm from '~/hooks/use-form' import { ResourceService } from '~/services/resource-service' -import AddDocuments from '~/containers/add-documents/AddDocuments' - import { snackbarVariants } from '~/constants' import { initialValues, @@ -56,13 +46,6 @@ import { const CreateOrEditLesson = () => { const { t } = useTranslation() const { setAlert } = useSnackBarContext() -<<<<<<< HEAD:src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx -<<<<<<< HEAD:src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx -======= - const navigate = useNavigate() ->>>>>>> 4bf6336 (Small fix):src/pages/new-lesson/NewLesson.tsx -======= ->>>>>>> 8e16e12 (fix):src/pages/new-lesson/NewLesson.tsx const { openModal } = useModalContext() const navigate = useNavigate() @@ -70,27 +53,6 @@ const CreateOrEditLesson = () => { const [content, setContent] = useState('') const { id } = useParams() - const formData = new FormData() - -<<<<<<< HEAD:src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx - const createAttachments = useCallback( - (data?: FormData) => attachmentService.createAttachments(data), - [] - ) - - const handleOpenModal = () => openModal({ component: }) -======= - const handleOpenModal = () => - openModal({ - component: ( - - ) - }) ->>>>>>> 8e16e12 (fix):src/pages/new-lesson/NewLesson.tsx - const handleResponseError = (error: ErrorResponse) => { setAlert({ severity: snackbarVariants.error, @@ -164,7 +126,6 @@ const CreateOrEditLesson = () => { onResponseError: handleResponseError }) -<<<<<<< HEAD:src/pages/create-or-edit-lesson/CreateOrEditLesson.tsx const { data, errors, @@ -208,30 +169,6 @@ const CreateOrEditLesson = () => { return } - const onCreateAttachmentsError = (error: ErrorResponse) => { - setAlert({ - severity: snackbarVariants.error, - message: error ? `errors.${error.code}` : '' - }) - } - const { fetchData: fetchDataAttachments } = useAxios({ - service: createAttachments, - fetchOnMount: false, - defaultResponse: null, - onResponseError: onCreateAttachmentsError - }) - const handleOpenModal = () => openModal({ component: }) - -======= - const { data, errors, handleInputChange, handleSubmit } = - useForm({ - initialValues, - validations, - onSubmit: fetchData, - submitWithData: true - }) ->>>>>>> 4bf6336 (Small fix):src/pages/new-lesson/NewLesson.tsx - const attachmentsList = attachments.map((attachment) => ( Date: Mon, 11 Sep 2023 16:29:56 +0300 Subject: [PATCH 17/25] fixed conflicts --- src/containers/my-quizzes/QuizzesContainer.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/containers/my-quizzes/QuizzesContainer.tsx b/src/containers/my-quizzes/QuizzesContainer.tsx index 39fbb4d2f..faf627f9e 100644 --- a/src/containers/my-quizzes/QuizzesContainer.tsx +++ b/src/containers/my-quizzes/QuizzesContainer.tsx @@ -19,6 +19,7 @@ import { itemsLoadLimit, removeColumnRules } from '~/containers/my-quizzes/QuizzesContainer.constants' + import { ItemsWithCount, GetResourcesParams, @@ -106,4 +107,4 @@ const QuizzesContainer = () => { ) } -export default QuizzesContainer +export default QuizzesContainer \ No newline at end of file From 18ef6bac67cefadf10ffb97ed6bc2db924c9326b Mon Sep 17 00:00:00 2001 From: mxrcury Date: Thu, 14 Sep 2023 12:10:30 +0300 Subject: [PATCH 18/25] added question component --- src/components/question/Question.styles.ts | 95 ++++++++++++++ src/components/question/Question.tsx | 118 ++++++++++++++++++ .../QuestionsContainer.tsx | 2 +- src/types/common/enums/common.enums.ts | 4 + .../interfaces/questions.interface.ts | 6 +- 5 files changed, 223 insertions(+), 2 deletions(-) create mode 100644 src/components/question/Question.styles.ts create mode 100644 src/components/question/Question.tsx diff --git a/src/components/question/Question.styles.ts b/src/components/question/Question.styles.ts new file mode 100644 index 000000000..c49f55cc0 --- /dev/null +++ b/src/components/question/Question.styles.ts @@ -0,0 +1,95 @@ +import palette from '~/styles/app-theme/app.pallete' +import { TypographyVariantEnum } from '~/types' + +const actionIconWrapper = { + display: 'flex', + alignItems: 'center' +} + +const actionIcon = { + fontSize: '18px', + mr: '10px' +} + +export const styles = { + root: { + width: '60%', + background: palette.basic.white, + borderRadius: '6px', + p: '24px' + }, + header: { + display: 'flex', + justifyContent: 'space-between', + alignItems: 'center' + }, + iconTitleDescription: { + container: { display: 'flex', columnGap: '16px', alignItems: 'center' }, + icon: { + svg: { width: '16px', height: '16px', color: 'primary.600' } + }, + titleWithDescription: { + wrapper: { display: 'flex', flexDirection: 'column', rowGap: '3px' }, + title: { + typography: TypographyVariantEnum.Subtitle2, + color: 'primary.900' + }, + description: { + typography: TypographyVariantEnum.Caption, + color: 'primary.400' + } + } + }, + iconWrapper: { + backgroundColor: 'basic.grey', + borderRadius: '4px', + p: '8px' + }, + categoryChip: { + backgroundColor: 'inherit', + border: `2px solid ${palette.basic.turquoiseDark}`, + borderRadius: '50px', + '& .MuiChip-label': { p: '0px 8px' }, + my: '12px' + }, + categoryChipLabel: { + typography: TypographyVariantEnum.Caption, + fontWeight: 500, + color: 'basic.turquoiseDark' + }, + questionBody: { + my: '24px' + }, + questionText: { + typography: TypographyVariantEnum.MidTitle + }, + answers: { + display: 'flex', + flexDirection: 'column' + }, + answer: { + display: 'flex', + justifyContent: 'space-between', + alignItems: 'center' + }, + moreIcon: { + fontSize: '20px' + }, + dragIconWrapper: { + display: 'flex', + justifyContent: 'center' + }, + dragIcon: { + fontSize: '30px', + transform: 'rotate(90deg)', + color: 'primary.400', + cursor: 'pointer' + }, + editIconWrapper: actionIconWrapper, + deleteIconWrapper: { ...actionIconWrapper, color: 'error.700' }, + editIcon: actionIcon, + deleteIcon: { + ...actionIcon, + color: 'error.700' + } +} diff --git a/src/components/question/Question.tsx b/src/components/question/Question.tsx new file mode 100644 index 000000000..75b52a0e1 --- /dev/null +++ b/src/components/question/Question.tsx @@ -0,0 +1,118 @@ +import { FC } from 'react' + +import Box from '@mui/material/Box' +import Divider from '@mui/material/Divider' +import Typography from '@mui/material/Typography' +import FormControlLabel from '@mui/material/FormControlLabel' +import Checkbox from '@mui/material/Checkbox' +import CheckIcon from '@mui/icons-material/Check' +import appPallete from '~/styles/app-theme/app.pallete' +import DragIndicatorIcon from '@mui/icons-material/DragIndicator' +import IconButton from '@mui/material/IconButton' +import MoreVertIcon from '@mui/icons-material/MoreVert' +import EditIcon from '@mui/icons-material/Edit' +import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline' +import LibraryAddCheckOutlinedIcon from '@mui/icons-material/LibraryAddCheckOutlined' + +import IconTitleDescription from '~/components/icon-title-description/IconTitleDescription' +import AppChip from '~/components/app-chip/AppChip' + +import { ColorEnum, Answer, TableActionFunc, QuestionCategory } from '~/types' +import { styles } from '~/components/question/Question.styles' +import useMenu from '~/hooks/use-menu' +import { MenuItem } from '@mui/material' +import { useTranslation } from 'react-i18next' + +interface QuestionProps { + title: string + answers: Answer[] + text: string + category: QuestionCategory +} + +const Question: FC = ({ title, answers, text, category }) => { + const { t } = useTranslation() + const { openMenu, renderMenu, closeMenu } = useMenu() + + const onAction = async (actionFunc: TableActionFunc) => { + closeMenu() + await actionFunc('dw') + } + const rowActions = [ + { + label: ( + + + {` ${t('common.edit')}`} + + ), + func: (id: string) => { + console.log('Edit', id) + } + }, + { + label: ( + + + {` ${t('common.delete')}`} + + ), + func: (id: string) => { + console.log('delete', id) + } + } + ] + const menuItems = rowActions.map(({ label, func }) => ( + void onAction(func)}> + {label} + + )) + + const answersList = answers.map((answer, i) => ( + + } + label={answer.text} + /> + + {answer.isCorrect ? ( + + ) : null} + + )) + + return ( + + + + + + + + + } + sx={styles.iconTitleDescription} + title={title} + /> + + + + {renderMenu(menuItems)} + + + {category.name} + + + + + {text} + {answersList} + + + ) +} + +export default Question diff --git a/src/containers/my-resources/questions-container/QuestionsContainer.tsx b/src/containers/my-resources/questions-container/QuestionsContainer.tsx index e7a316709..9c98eae1f 100644 --- a/src/containers/my-resources/questions-container/QuestionsContainer.tsx +++ b/src/containers/my-resources/questions-container/QuestionsContainer.tsx @@ -98,4 +98,4 @@ const QuestionsContainer = () => { ) } -export default QuestionsContainer +export default QuestionsContainer \ No newline at end of file diff --git a/src/types/common/enums/common.enums.ts b/src/types/common/enums/common.enums.ts index 338c241d4..53fbc4d6c 100644 --- a/src/types/common/enums/common.enums.ts +++ b/src/types/common/enums/common.enums.ts @@ -101,3 +101,7 @@ export enum OverlapEnum { Circular = 'circular', Rectangular = 'rectangular' } + +export enum ColorEnum { + Primary = 'primary' +} diff --git a/src/types/questions/interfaces/questions.interface.ts b/src/types/questions/interfaces/questions.interface.ts index fa6284d30..e8fcaa0b8 100644 --- a/src/types/questions/interfaces/questions.interface.ts +++ b/src/types/questions/interfaces/questions.interface.ts @@ -1,6 +1,6 @@ import { CommonEntityFields, UserResponse } from '~/types' export interface Answer { - id: number + id: string text: string isCorrect: boolean } @@ -10,3 +10,7 @@ export interface Question extends CommonEntityFields { items: Omit[] author: Pick } +export interface QuestionCategory { + name: string + _id: string +} From 716ab3f75c2acc37c3b4b5051c260e317ccc8c78 Mon Sep 17 00:00:00 2001 From: mxrcury Date: Thu, 14 Sep 2023 12:42:28 +0300 Subject: [PATCH 19/25] fix eslint --- src/containers/my-quizzes/QuizzesContainer.tsx | 2 +- .../add-resource-with-input/AddResourceWithInput.tsx | 2 +- .../my-resources/attachments-container/AttachmentsContainer.tsx | 2 +- .../my-resources/questions-container/QuestionsContainer.tsx | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/containers/my-quizzes/QuizzesContainer.tsx b/src/containers/my-quizzes/QuizzesContainer.tsx index faf627f9e..2c2cd850b 100644 --- a/src/containers/my-quizzes/QuizzesContainer.tsx +++ b/src/containers/my-quizzes/QuizzesContainer.tsx @@ -107,4 +107,4 @@ const QuizzesContainer = () => { ) } -export default QuizzesContainer \ No newline at end of file +export default QuizzesContainer diff --git a/src/containers/my-resources/add-resource-with-input/AddResourceWithInput.tsx b/src/containers/my-resources/add-resource-with-input/AddResourceWithInput.tsx index 92e48d865..8b04587e3 100644 --- a/src/containers/my-resources/add-resource-with-input/AddResourceWithInput.tsx +++ b/src/containers/my-resources/add-resource-with-input/AddResourceWithInput.tsx @@ -74,4 +74,4 @@ const AddResourceWithInput: FC = ({ ) } -export default AddResourceWithInput \ No newline at end of file +export default AddResourceWithInput diff --git a/src/containers/my-resources/attachments-container/AttachmentsContainer.tsx b/src/containers/my-resources/attachments-container/AttachmentsContainer.tsx index 28bbb326d..cd0f2b812 100644 --- a/src/containers/my-resources/attachments-container/AttachmentsContainer.tsx +++ b/src/containers/my-resources/attachments-container/AttachmentsContainer.tsx @@ -183,4 +183,4 @@ const AttachmentsContainer = () => { ) } -export default AttachmentsContainer \ No newline at end of file +export default AttachmentsContainer diff --git a/src/containers/my-resources/questions-container/QuestionsContainer.tsx b/src/containers/my-resources/questions-container/QuestionsContainer.tsx index 9c98eae1f..e7a316709 100644 --- a/src/containers/my-resources/questions-container/QuestionsContainer.tsx +++ b/src/containers/my-resources/questions-container/QuestionsContainer.tsx @@ -98,4 +98,4 @@ const QuestionsContainer = () => { ) } -export default QuestionsContainer \ No newline at end of file +export default QuestionsContainer From 38ef22aae78656adb6e331595688a9ba4a50ebca Mon Sep 17 00:00:00 2001 From: mxrcury Date: Thu, 14 Sep 2023 12:44:27 +0300 Subject: [PATCH 20/25] fix --- src/services/attachment-service.ts | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 src/services/attachment-service.ts diff --git a/src/services/attachment-service.ts b/src/services/attachment-service.ts deleted file mode 100644 index a4f086eee..000000000 --- a/src/services/attachment-service.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { AxiosResponse } from 'axios' -import { URLs } from '~/constants/request' -import { axiosClient } from '~/plugins/axiosClient' -import { GetAttachmentsParams } from '~/types' - -export const attachmentService = { - getAttachments: async ( - params: GetAttachmentsParams - ): Promise => - await axiosClient.get(URLs.resources.attachments.get, { params }), - - createAttachments: (data?: FormData): Promise => { - return axiosClient.post(URLs.attachments.post, data, { - headers: { 'Content-Type': 'multipart/form-data' } - }) - } -} From 446088bc6fd7b2e94125a08cca8210548308f380 Mon Sep 17 00:00:00 2001 From: mxrcury Date: Thu, 14 Sep 2023 13:07:20 +0300 Subject: [PATCH 21/25] fix eslint --- src/components/file-uploader/FileUploader.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/file-uploader/FileUploader.tsx b/src/components/file-uploader/FileUploader.tsx index eea95dc0f..c7fcc0870 100644 --- a/src/components/file-uploader/FileUploader.tsx +++ b/src/components/file-uploader/FileUploader.tsx @@ -103,4 +103,4 @@ const FileUploader: FC = ({ ) } -export default FileUploader \ No newline at end of file +export default FileUploader From db06576ecf371476435ac8994dd4185f8cacfd48 Mon Sep 17 00:00:00 2001 From: mxrcury Date: Thu, 14 Sep 2023 13:10:28 +0300 Subject: [PATCH 22/25] import fix --- src/components/question/Question.tsx | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/components/question/Question.tsx b/src/components/question/Question.tsx index 75b52a0e1..0d9c75de5 100644 --- a/src/components/question/Question.tsx +++ b/src/components/question/Question.tsx @@ -1,5 +1,6 @@ import { FC } from 'react' - +import { useTranslation } from 'react-i18next' +import { MenuItem } from '@mui/material' import Box from '@mui/material/Box' import Divider from '@mui/material/Divider' import Typography from '@mui/material/Typography' @@ -14,29 +15,34 @@ import EditIcon from '@mui/icons-material/Edit' import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline' import LibraryAddCheckOutlinedIcon from '@mui/icons-material/LibraryAddCheckOutlined' +import useMenu from '~/hooks/use-menu' import IconTitleDescription from '~/components/icon-title-description/IconTitleDescription' import AppChip from '~/components/app-chip/AppChip' import { ColorEnum, Answer, TableActionFunc, QuestionCategory } from '~/types' import { styles } from '~/components/question/Question.styles' -import useMenu from '~/hooks/use-menu' -import { MenuItem } from '@mui/material' -import { useTranslation } from 'react-i18next' interface QuestionProps { title: string answers: Answer[] text: string category: QuestionCategory + id: string } -const Question: FC = ({ title, answers, text, category }) => { +const Question: FC = ({ + title, + answers, + text, + category, + id +}) => { const { t } = useTranslation() const { openMenu, renderMenu, closeMenu } = useMenu() const onAction = async (actionFunc: TableActionFunc) => { closeMenu() - await actionFunc('dw') + await actionFunc(id) } const rowActions = [ { @@ -58,7 +64,7 @@ const Question: FC = ({ title, answers, text, category }) => { ), func: (id: string) => { - console.log('delete', id) + console.log('Delete', id) } } ] From 92971da0fbdbee2abac1fe1427fa24e9dd951394 Mon Sep 17 00:00:00 2001 From: mxrcury Date: Mon, 18 Sep 2023 14:55:39 +0300 Subject: [PATCH 23/25] small fixes, added unit test --- src/components/question/Question.tsx | 4 +- .../components/question/Question.spec.jsx | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 tests/unit/components/question/Question.spec.jsx diff --git a/src/components/question/Question.tsx b/src/components/question/Question.tsx index 0d9c75de5..189d3ec20 100644 --- a/src/components/question/Question.tsx +++ b/src/components/question/Question.tsx @@ -82,9 +82,9 @@ const Question: FC = ({ label={answer.text} /> - {answer.isCorrect ? ( + {answer.isCorrect && ( - ) : null} + )} )) diff --git a/tests/unit/components/question/Question.spec.jsx b/tests/unit/components/question/Question.spec.jsx new file mode 100644 index 000000000..bc33afc3e --- /dev/null +++ b/tests/unit/components/question/Question.spec.jsx @@ -0,0 +1,42 @@ +import { screen, render } from '@testing-library/react' +import Question from '~/components/question/Question' + +const mockedQuestion = { + title: 'Philosophy', + answers: [ + { + id: '1', + text: 'Buddha Shakyamuni', + isCorrect: true + }, + { + id: '2', + text: 'Jordan Belfort', + isCorrect: false + } + ], + text: 'Who created buddhism?', + category: { + _id: 'some-text-id-123', + name: 'Philosophy' + }, + id: '1' +} + +describe('Question', () => { + beforeEach(() => { + render() + }) + + it('render question text', () => { + const questionText = screen.getByText(mockedQuestion.text) + + expect(questionText).toBeInTheDocument() + }) + + it('render question category', () => { + const category = screen.getByText(mockedQuestion.category.name) + + expect(category).toBeInTheDocument() + }) +}) From 86bf5b32d75c996de2eec3f659f40fb22fba9230 Mon Sep 17 00:00:00 2001 From: mxrcury Date: Mon, 18 Sep 2023 15:04:25 +0300 Subject: [PATCH 24/25] fix --- src/components/question/Question.styles.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/question/Question.styles.ts b/src/components/question/Question.styles.ts index c49f55cc0..ff8932c50 100644 --- a/src/components/question/Question.styles.ts +++ b/src/components/question/Question.styles.ts @@ -14,7 +14,7 @@ const actionIcon = { export const styles = { root: { width: '60%', - background: palette.basic.white, + background: 'basic.white', borderRadius: '6px', p: '24px' }, From f8c13f7ff2af5162e93055156d27f29778fdc750 Mon Sep 17 00:00:00 2001 From: mxrcury Date: Mon, 18 Sep 2023 15:07:52 +0300 Subject: [PATCH 25/25] fixed styles --- src/components/question/Question.styles.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/question/Question.styles.ts b/src/components/question/Question.styles.ts index ff8932c50..0d7643a08 100644 --- a/src/components/question/Question.styles.ts +++ b/src/components/question/Question.styles.ts @@ -91,5 +91,6 @@ export const styles = { deleteIcon: { ...actionIcon, color: 'error.700' - } + }, + checkIcon: { color: 'basic.orientalHerbs' } }