Skip to content

Commit

Permalink
added second menu and section delete
Browse files Browse the repository at this point in the history
  • Loading branch information
OlyaKorchan committed Oct 30, 2023
1 parent 5c59b56 commit dd4b6b7
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 17 deletions.
3 changes: 3 additions & 0 deletions src/constants/translations/en/course.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"lessonMenuItem": "Lesson",
"quizMenuItem": "Quiz",
"attachmentMenuItem": "Attachment"
},
"sectionMenu": {
"deleteSection": "Delete"
}
},
"errorMessages": {
Expand Down
5 changes: 4 additions & 1 deletion src/constants/translations/ua/course.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
"courseSection": {
"defaultNewTitle": "Розділ 1",
"defaultNewDescription": "Опис ...",
"adddResourceBtn": "Додати матеріал",
"addResourceBtn": "Додати матеріал",
"resourcesMenu": {
"lessonMenuItem": "Урок",
"quizMenuItem": "Тест",
"attachmentMenuItem": "Вкладення"
},
"sectionMenu": {
"deleteSection": "Видалити"
}
},
"errorMessages": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const menuTypes = {
resourcesMenu: 'resources',
sectionMenu: 'section'
}
61 changes: 45 additions & 16 deletions src/containers/course-section/CourseSectionContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import AppButton from '~/components/app-button/AppButton'
import useMenu from '~/hooks/use-menu'

import { styles } from '~/containers/course-section/CourseSectionContainer.styles'
import { menuTypes } from '~/containers/course-section/CourseSectionContainer.constants'
import {
TextFieldVariantEnum,
SizeEnum,
Expand All @@ -30,10 +31,14 @@ interface SectionProps {

type openModalFunc = () => void

const CourseSectionContainer: FC<SectionProps> = ({ sectionData }) => {
const CourseSectionContainer: FC<SectionProps> = ({
sectionData,
setSectionsItems
}) => {
const { t } = useTranslation()
const { openMenu, renderMenu, closeMenu } = useMenu()

const [activeMenu, setActiveMenu] = useState<string>('')
const [isVisible, setIsVisible] = useState<boolean>(true)
const [titleInput, setTitleInput] = useState<string>(sectionData.title)
const [descriptionInput, setDescriptionInput] = useState(
Expand All @@ -44,6 +49,10 @@ const CourseSectionContainer: FC<SectionProps> = ({ sectionData }) => {
setIsVisible((isVisible) => !isVisible)
}

const onAction = (actionFunc: openModalFunc) => {
actionFunc()
}

const onTitleInputChange = (event: ChangeEvent<HTMLInputElement>) => {
setTitleInput(event.target.value)
}
Expand All @@ -52,39 +61,49 @@ const CourseSectionContainer: FC<SectionProps> = ({ sectionData }) => {
setDescriptionInput(event.target.value)
}

const onAction = (actionFunc: openModalFunc) => {
actionFunc()
const onDeleteSection = () => {
setSectionsItems((prev) => {
return prev.filter((item) => item.section_id !== sectionData.section_id)
})
}

const sectionActions = [
{
id: 1,
label: <Box>{t('course.courseSection.sectionMenu.deleteSection')}</Box>,
func: onDeleteSection
}
]

const sectionMenuItems = sectionActions.map(({ label, func, id }) => (
<MenuItem key={id} onClick={func}>
{label}
</MenuItem>
))

const addResourceActions = [
{
id: 1,
label: (
<Box>
{` ${t('course.courseSection.resourcesMenu.lessonMenuItem')}`}
</Box>
<Box>{t('course.courseSection.resourcesMenu.lessonMenuItem')}</Box>
),
func: closeMenu
},
{
id: 2,
label: (
<Box>{` ${t('course.courseSection.resourcesMenu.quizMenuItem')}`}</Box>
),
label: <Box>{t('course.courseSection.resourcesMenu.quizMenuItem')}</Box>,
func: closeMenu
},
{
id: 3,
label: (
<Box>
{` ${t('course.courseSection.resourcesMenu.attachmentMenuItem')}`}
</Box>
<Box>{t('course.courseSection.resourcesMenu.attachmentMenuItem')}</Box>
),
func: closeMenu
}
]

const menuItems = addResourceActions.map(({ label, func, id }) => (
const resourcesMenuItems = addResourceActions.map(({ label, func, id }) => (
<MenuItem key={id} onClick={() => onAction(func)} sx={styles.menuItem}>
{label}
</MenuItem>
Expand Down Expand Up @@ -119,9 +138,15 @@ const CourseSectionContainer: FC<SectionProps> = ({ sectionData }) => {
value={titleInput}
variant={TextFieldVariantEnum.Standard}
/>
<IconButton>
<IconButton
onClick={(event) => {
setActiveMenu(menuTypes.sectionMenu)
openMenu(event)
}}
>
<MoreVertIcon color={ColorEnum.Primary} sx={styles.headerIcon} />
</IconButton>
{activeMenu === menuTypes.sectionMenu && renderMenu(sectionMenuItems)}
</Box>
{isVisible && (
<Box>
Expand All @@ -141,14 +166,18 @@ const CourseSectionContainer: FC<SectionProps> = ({ sectionData }) => {
/>
<AppButton
endIcon={<KeyboardArrowDownIcon fontSize={SizeEnum.Small} />}
onClick={openMenu}
onClick={(event) => {
setActiveMenu(menuTypes.resourcesMenu)
openMenu(event)
}}
size={SizeEnum.Large}
startIcon={<AddIcon fontSize={SizeEnum.Small} />}
variant={ButtonVariantEnum.Contained}
>
{t('course.courseSection.addResourceBtn')}
</AppButton>
{renderMenu(menuItems)}
{activeMenu === menuTypes.resourcesMenu &&
renderMenu(resourcesMenuItems)}
</Box>
)}
</Box>
Expand Down

0 comments on commit dd4b6b7

Please sign in to comment.