From f677b0d8409cc428819cde7aac32bc290a1f3342 Mon Sep 17 00:00:00 2001 From: Valentyna Dudchak Date: Sun, 24 Nov 2024 18:27:53 +0200 Subject: [PATCH] fixed conditional rendering & optimized using useMemo --- .../ProfessionalInfoTab.tsx | 2 +- .../AboutStudentAccordion.tsx | 26 +++++++------- .../AboutTutorAccordion.tsx | 36 ++++++++++--------- .../about-user-block.constants.ts | 2 ++ 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/containers/edit-profile/professional-info-tab/ProfessionalInfoTab.tsx b/src/containers/edit-profile/professional-info-tab/ProfessionalInfoTab.tsx index 87f482d08..27c213f4f 100644 --- a/src/containers/edit-profile/professional-info-tab/ProfessionalInfoTab.tsx +++ b/src/containers/edit-profile/professional-info-tab/ProfessionalInfoTab.tsx @@ -100,7 +100,7 @@ const ProfessionalInfoTab: FC = () => { }) } - const TutorInfo = userRole === UserRoleEnum.Tutor && ( + const TutorInfo = ( } -const AboutStudentAccordion: FC = ({ - data, - handleInputChange -}) => { +const AboutStudentAccordion: FC = ({ 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: ( = ({ 'editProfilePage.profile.professionalTab.accordionStudent.textareaLabel' )} maxLength={1000} - onChange={mockHandleInputChange} - value={data.education} + onChange={mockHandleStudentInputChange} + value={data[item]} /> ) - } - }) + })) + }, [t, data]) return ( = ({ toggle: true }) - const accordionItems: AccordionItem[] = aboutTutorKeys.map((item) => { - return { - title: `editProfilePage.profile.professionalTab.accordionTutor.${item}`, - content: ( - - ) - } - }) + const accordionItems: AccordionItem[] = useMemo(() => { + return aboutTutorKeys.map((item) => { + return { + title: `editProfilePage.profile.professionalTab.accordionTutor.${item}`, + content: ( + + ) + } + }) + }, [t, handleInputChange, data]) return ( = [ 'scientificActivities', 'awards' ] + +export const mockHandleStudentInputChange = () => null