From 3d3f5da9105a2023c19a45caa53da69506049d03 Mon Sep 17 00:00:00 2001 From: Rushikesh-Sonawane99 Date: Mon, 5 Aug 2024 16:46:38 +0530 Subject: [PATCH] Issue #PS-1275 chore: Resolved runtime error and optimised code --- src/pages/user-profile/[userId].tsx | 82 ++++++++++++++++------------- 1 file changed, 46 insertions(+), 36 deletions(-) diff --git a/src/pages/user-profile/[userId].tsx b/src/pages/user-profile/[userId].tsx index 000387e8..9b04923e 100644 --- a/src/pages/user-profile/[userId].tsx +++ b/src/pages/user-profile/[userId].tsx @@ -293,10 +293,10 @@ const TeacherProfile = () => { // Find fields for "Subjects I Teach" and "My Main Subjects" const teachSubjectsField = customFieldsData?.find( - (field) => field.name === 'subject_taught' + (field) => field?.name === 'subject_taught' ); const mainSubjectsField: any = customFieldsData?.find( - (field) => field.name === 'main_subject' + (field) => field?.name === 'main_subject' ); const teachSubjects: string[] = teachSubjectsField @@ -308,13 +308,23 @@ const TeacherProfile = () => { : []; // Find mutual and remaining subjects - const mutualSubjects = teachSubjects?.filter((subject) => - mainSubjects?.includes(subject) - ); + // const mutualSubjects = teachSubjects?.filter((subject) => + // mainSubjects?.includes(subject) + // ); - const remainingSubjects = teachSubjects?.filter( - (subject) => !mainSubjects?.includes(subject) - ); + // const remainingSubjects = teachSubjects?.filter( + // (subject) => !mainSubjects?.includes(subject) + // ); + + const mutualSubjects = + teachSubjects && mainSubjects + ? teachSubjects.filter((subject) => mainSubjects.includes(subject)) + : []; + + const remainingSubjects = + teachSubjects && mainSubjects + ? teachSubjects.filter((subject) => !mainSubjects.includes(subject)) + : []; let orderedSubjects: any; if (remainingSubjects?.length) { @@ -635,34 +645,34 @@ const TeacherProfile = () => { }} > {orderedSubjects && - orderedSubjects?.map( - (subject: any, index: number) => ( - - ) + orderedSubjects.length > 0 && + orderedSubjects.map( + (subject: any, index: number) => { + const isMutualSubject = + mutualSubjects?.includes(subject); + return ( + + ); + } )}