@@ -17,7 +17,7 @@ import settingImage from '../../../public/images/settings.png';
1717import Image from 'next/image' ;
1818import ChevronRightIcon from '@mui/icons-material/ChevronRight' ;
1919import { useRouter } from 'next/navigation' ;
20- import { getUserDetails } from '@learner/utils/API/userService' ;
20+ import { getUserDetails , getMentorList } from '@learner/utils/API/userService' ;
2121import { Loader , useTranslation } from '@shared-lib' ;
2222import { isUnderEighteen , toPascalCase } from '@learner/utils/helper' ;
2323import { isUndefined } from 'lodash' ;
@@ -43,6 +43,8 @@ const UserProfileCard = ({ maxWidth = '600px' }) => {
4343 const { t } = useTranslation ( ) ;
4444 const [ selectedOption , setSelectedOption ] = useState ( '' ) ;
4545 const [ anchorEl , setAnchorEl ] = useState < null | HTMLElement > ( null ) ;
46+ const [ villageId , setVillageId ] = useState < number | null > ( null ) ;
47+ const [ mentorData , setMentorData ] = useState < any > ( null ) ;
4648 const tenantName =
4749 typeof window !== 'undefined'
4850 ? localStorage . getItem ( 'userProgram' ) || ''
@@ -65,8 +67,7 @@ const UserProfileCard = ({ maxWidth = '600px' }) => {
6567 if ( storedConfig ?. isEditProfile ) {
6668 options . push ( t ( 'LEARNER_APP.USER_PROFILE_CARD.EDIT_PROFILE' ) ) ;
6769 }
68- if ( ! storedConfig ?. restrictChangePassword )
69- {
70+ if ( ! storedConfig ?. restrictChangePassword ) {
7071 options . push ( t ( 'LEARNER_APP.USER_PROFILE_CARD.CHANGE_PASSWORD' ) ) ;
7172 }
7273 const isBelow18 = ( dob : string ) : boolean => {
@@ -91,6 +92,12 @@ const UserProfileCard = ({ maxWidth = '600px' }) => {
9192 const userId = localStorage . getItem ( 'userId' ) ;
9293 if ( userId ) {
9394 const useInfo = await getUserDetails ( userId , true ) ;
95+ const extractedVillageId =
96+ useInfo ?. result ?. userData ?. customFields ?. find (
97+ ( f : any ) => f . label === 'VILLAGE'
98+ ) ?. selectedValues ?. [ 0 ] ?. id ?? null ;
99+ setVillageId ( extractedVillageId ) ;
100+ // console.log('villageId!!!!!!!!', extractedVillageId);
94101 console . log ( 'useInfo' , useInfo ?. result ?. userData ) ;
95102 setUserData ( useInfo ?. result ?. userData ) ;
96103 }
@@ -102,6 +109,43 @@ const UserProfileCard = ({ maxWidth = '600px' }) => {
102109 fetchUserData ( ) ;
103110 } , [ ] ) ;
104111
112+ useEffect ( ( ) => {
113+ const fetchMentorData = async ( ) => {
114+ try {
115+ if ( villageId ) {
116+ const mentorResponse = await getMentorList ( {
117+ limit : 100 ,
118+ filters : {
119+ working_village : [ String ( villageId ) ] ,
120+ role : 'Mobilizer' ,
121+ } ,
122+ sort : [ 'createdAt' , 'asc' ] ,
123+ offset : 0 ,
124+ } ) ;
125+
126+ // Handle different possible response structures
127+ const mentorList =
128+ mentorResponse ?. getUserDetails ||
129+ mentorResponse ?. userDetails ||
130+ mentorResponse ?. results ||
131+ [ ] ;
132+
133+ // Get the first mentor from the list if available
134+ if ( Array . isArray ( mentorList ) && mentorList . length > 0 ) {
135+ setMentorData ( mentorList [ 0 ] ) ;
136+ } else {
137+ setMentorData ( null ) ;
138+ }
139+ }
140+ } catch ( error ) {
141+ console . error ( 'Error fetching mentor data:' , error ) ;
142+ setMentorData ( null ) ;
143+ }
144+ } ;
145+
146+ fetchMentorData ( ) ;
147+ } , [ villageId ] ) ;
148+
105149 const handleSettingsClick = ( event : React . MouseEvent < HTMLElement > ) => {
106150 setAnchorEl ( event . currentTarget ) ;
107151 } ;
@@ -335,42 +379,46 @@ const UserProfileCard = ({ maxWidth = '600px' }) => {
335379 maxWidth : { maxWidth } ,
336380 } }
337381 >
338- { ! isUnderEighteen ( dob ) ? (
339- ( ( mobile !== '-' && mobile ) || ( phoneOwnership !== '-' && tenantName !== TenantName . CAMP_TO_CLUB && phoneOwnership !== 'No' ) ) &&
340- < >
341- < Typography sx = { sectionTitleStyle } >
342- { t ( 'LEARNER_APP.USER_PROFILE_CARD.CONTACT_INFORMATION' ) }
343- </ Typography >
344- < Box sx = { sectionCardStyle } >
345- { /* <Box sx={{ mb: 1.5 }}>
382+ { ! isUnderEighteen ( dob ) ? (
383+ ( ( mobile !== '-' && mobile ) ||
384+ ( phoneOwnership !== '-' &&
385+ tenantName !== TenantName . CAMP_TO_CLUB &&
386+ phoneOwnership !== 'No' ) ) && (
387+ < >
388+ < Typography sx = { sectionTitleStyle } >
389+ { t ( 'LEARNER_APP.USER_PROFILE_CARD.CONTACT_INFORMATION' ) }
390+ </ Typography >
391+ < Box sx = { sectionCardStyle } >
392+ { /* <Box sx={{ mb: 1.5 }}>
346393 <Typography sx={labelStyle}>
347394 {t('LEARNER_APP.USER_PROFILE_CARD.EMAIL_ADDRESS')}
348395 </Typography>
349396 <Typography sx={valueStyle}>{email || '-'}</Typography>
350397 </Box> */ }
351398
352- < Grid container spacing = { 1.5 } >
399+ < Grid container spacing = { 1.5 } >
353400 { mobile !== '-' && mobile && (
354- < Grid item xs = { 6 } >
355- < Typography sx = { labelStyle } >
356- { t ( 'LEARNER_APP.USER_PROFILE_CARD.PHONE_NUMBER' ) }
357- </ Typography >
358- < Typography sx = { valueStyle } > { mobile } </ Typography >
359- </ Grid >
360- ) }
401+ < Grid item xs = { 6 } >
402+ < Typography sx = { labelStyle } >
403+ { t ( 'LEARNER_APP.USER_PROFILE_CARD.PHONE_NUMBER' ) }
404+ </ Typography >
405+ < Typography sx = { valueStyle } > { mobile } </ Typography >
406+ </ Grid >
407+ ) }
361408 { phoneOwnership !== '-' && tenantName !== TenantName . CAMP_TO_CLUB && (
362- < Grid item xs = { 6 } >
363- < Typography sx = { labelStyle } >
409+ < Grid item xs = { 6 } >
410+ < Typography sx = { labelStyle } >
364411 { t ( 'LEARNER_APP.USER_PROFILE_CARD.PHONE_BELONGS_TO_YOU' ) }
365- </ Typography >
366- < Typography sx = { valueStyle } >
367- { toPascalCase ( phoneOwnership ) }
368- </ Typography >
369- </ Grid >
370- ) }
371- </ Grid >
372- </ Box >
373- </ >
412+ </ Typography >
413+ < Typography sx = { valueStyle } >
414+ { toPascalCase ( phoneOwnership ) }
415+ </ Typography >
416+ </ Grid >
417+ ) }
418+ </ Grid >
419+ </ Box >
420+ </ >
421+ )
374422 ) : (
375423 < >
376424 < Typography sx = { sectionTitleStyle } >
@@ -510,15 +558,15 @@ const UserProfileCard = ({ maxWidth = '600px' }) => {
510558 ) }
511559
512560 { qualification !== '-' && tenantName !== TenantName . CAMP_TO_CLUB && (
513- < Grid item xs = { 6 } >
514- < Typography sx = { labelStyle } >
561+ < Grid item xs = { 6 } >
562+ < Typography sx = { labelStyle } >
515563 { t ( 'LEARNER_APP.USER_PROFILE_CARD.HIGHEST_QUALIFICATION' ) }
516- </ Typography >
517- < Typography sx = { valueStyle } >
564+ </ Typography >
565+ < Typography sx = { valueStyle } >
518566 { t ( `FORM.${ qualification } ` , { defaultValue : qualification } ) }
519- </ Typography >
520- </ Grid >
521- ) }
567+ </ Typography >
568+ </ Grid >
569+ ) }
522570 { [ state , district , block , village ] . filter ( Boolean ) . join ( ', ' ) !==
523571 '-, -, -, -' && (
524572 < Grid item xs = { 12 } >
@@ -535,6 +583,50 @@ const UserProfileCard = ({ maxWidth = '600px' }) => {
535583 </ >
536584 ) }
537585
586+ { /* TODO: Add condition based on smart classroom show mentor details */ }
587+ { /* My Mentor Details */ }
588+ { mentorData && (
589+ < >
590+ < Typography sx = { sectionTitleStyle } >
591+ { t ( 'LEARNER_APP.USER_PROFILE_CARD.MY_MENTOR_DETAILS' ) }
592+ </ Typography >
593+ < Box sx = { sectionCardStyle } >
594+ < Grid container spacing = { 1.5 } >
595+ { mentorData . firstName || mentorData . lastName ? (
596+ < Grid item xs = { 6 } >
597+ < Typography sx = { labelStyle } >
598+ { t ( 'LEARNER_APP.USER_PROFILE_CARD.MENTOR_NAME' ) }
599+ </ Typography >
600+ < Typography sx = { valueStyle } >
601+ { toPascalCase (
602+ [ mentorData . firstName , mentorData . lastName ]
603+ . filter ( Boolean )
604+ . join ( ' ' )
605+ ) }
606+ </ Typography >
607+ </ Grid >
608+ ) : null }
609+ { mentorData . email && (
610+ < Grid item xs = { 6 } >
611+ < Typography sx = { labelStyle } >
612+ { t ( 'LEARNER_APP.USER_PROFILE_CARD.MENTOR_EMAIL' ) }
613+ </ Typography >
614+ < Typography sx = { valueStyle } > { mentorData . email } </ Typography >
615+ </ Grid >
616+ ) }
617+ { mentorData . mobile && (
618+ < Grid item xs = { 6 } >
619+ < Typography sx = { labelStyle } >
620+ { t ( 'LEARNER_APP.USER_PROFILE_CARD.PHONE_NUMBER' ) }
621+ </ Typography >
622+ < Typography sx = { valueStyle } > { mentorData . mobile } </ Typography >
623+ </ Grid >
624+ ) }
625+ </ Grid >
626+ </ Box >
627+ </ >
628+ ) }
629+
538630 { priorTraining !== '-' && currentWork !== '-' && futureWork !== '-' && (
539631 < >
540632 < Typography sx = { sectionTitleStyle } >
0 commit comments