Skip to content

Commit

Permalink
fixed conditional rendering & optimized using useMemo
Browse files Browse the repository at this point in the history
  • Loading branch information
dudchakk committed Nov 24, 2024
1 parent 527ad57 commit f677b0d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const ProfessionalInfoTab: FC = () => {
})
}

const TutorInfo = userRole === UserRoleEnum.Tutor && (
const TutorInfo = (
<Box component='section' id='education'>
<Box sx={highlightElem}></Box>
<TitleWithDescription
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC } from 'react'
import { FC, useMemo } from 'react'
import { useTranslation } from 'react-i18next'

import {
Expand All @@ -15,7 +15,10 @@ import Accordions from '~/components/accordion/Accordions'
import AppTextArea from '~/components/app-text-area/AppTextArea'

import { styles } from '~/containers/edit-profile/professional-info-tab/about-tutor-accordion/AboutTutorAccordion.styles'
import { aboutStudentKeys } from '~/containers/user-profile/about-user-block/about-user-block.constants'
import {
aboutStudentKeys,
mockHandleStudentInputChange
} from '~/containers/user-profile/about-user-block/about-user-block.constants'

interface AboutStudentAccordionProps {
data: AboutStudentData
Expand All @@ -25,20 +28,15 @@ interface AboutStudentAccordionProps {
>
}

const AboutStudentAccordion: FC<AboutStudentAccordionProps> = ({
data,
handleInputChange
}) => {
const AboutStudentAccordion: FC<AboutStudentAccordionProps> = ({ data }) => {
const { t } = useTranslation()
const [expandedItem, handleAccordionChange] = useAccordions({
initialState: 0,
toggle: true
})

const mockHandleInputChange = () => null

const accordionItems: AccordionItem[] = aboutStudentKeys.map((item) => {
return {
const accordionItems: AccordionItem[] = useMemo(() => {
return aboutStudentKeys.map((item) => ({
title: `editProfilePage.profile.professionalTab.accordionStudent.${item}`,
content: (
<AppTextArea
Expand All @@ -47,12 +45,12 @@ const AboutStudentAccordion: FC<AboutStudentAccordionProps> = ({
'editProfilePage.profile.professionalTab.accordionStudent.textareaLabel'
)}
maxLength={1000}
onChange={mockHandleInputChange}
value={data.education}
onChange={mockHandleStudentInputChange}
value={data[item]}
/>
)
}
})
}))
}, [t, data])

return (
<Accordions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC } from 'react'
import { FC, useMemo } from 'react'
import { useTranslation } from 'react-i18next'

import {
Expand Down Expand Up @@ -35,22 +35,24 @@ const AboutTutorAccordion: FC<AboutTutorAccordionProps> = ({
toggle: true
})

const accordionItems: AccordionItem[] = aboutTutorKeys.map((item) => {
return {
title: `editProfilePage.profile.professionalTab.accordionTutor.${item}`,
content: (
<AppTextArea
fullWidth
label={t(
'editProfilePage.profile.professionalTab.accordionTutor.textareaLabel'
)}
maxLength={1000}
onChange={handleInputChange(item)}
value={data.education}
/>
)
}
})
const accordionItems: AccordionItem[] = useMemo(() => {
return aboutTutorKeys.map((item) => {
return {
title: `editProfilePage.profile.professionalTab.accordionTutor.${item}`,
content: (
<AppTextArea
fullWidth
label={t(
'editProfilePage.profile.professionalTab.accordionTutor.textareaLabel'
)}
maxLength={1000}
onChange={handleInputChange(item)}
value={data[item]}
/>
)
}
})
}, [t, handleInputChange, data])

return (
<Accordions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ export const aboutTutorKeys: Array<keyof ProfessionalBlock> = [
'scientificActivities',
'awards'
]

export const mockHandleStudentInputChange = () => null

0 comments on commit f677b0d

Please sign in to comment.