Skip to content

Commit 2cc94cb

Browse files
authored
Merge pull request #2512 from tekdi/feat-lead-mapping-new
Feat lead mapping new to qa feat
2 parents 5ffd7b7 + 5f9389c commit 2cc94cb

File tree

3 files changed

+191
-55
lines changed

3 files changed

+191
-55
lines changed

apps/learner-web-app/src/components/UserProfileCard/UserProfileCard.tsx

Lines changed: 129 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import settingImage from '../../../public/images/settings.png';
1717
import Image from 'next/image';
1818
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
1919
import { useRouter } from 'next/navigation';
20-
import { getUserDetails } from '@learner/utils/API/userService';
20+
import { getUserDetails, getMentorList } from '@learner/utils/API/userService';
2121
import { Loader, useTranslation } from '@shared-lib';
2222
import { isUnderEighteen, toPascalCase } from '@learner/utils/helper';
2323
import { 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}>

apps/learner-web-app/src/utils/API/userService.ts

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,30 @@ export const userCheck = async ({
4646
function setLocalStorageFromCustomFields(fields: any) {
4747
const getFieldId = (labelKey: any) => {
4848
const field = fields?.find?.((f: any) => f.label === labelKey);
49-
console.log("statename",field?.selectedValues?.[0]?.value )
50-
// localStorage.setItem("stateName", field?.selectedValues?.[0]?.value)
51-
return field?.selectedValues?.[0]?.id ?? null;
49+
console.log('statename', field?.selectedValues?.[0]?.value);
50+
// localStorage.setItem("stateName", field?.selectedValues?.[0]?.value)
51+
return field?.selectedValues?.[0]?.id ?? null;
5252
};
53-
const getFieldLabel = (labelKey: any) => {
53+
const getFieldLabel = (labelKey: any) => {
5454
const field = fields?.find?.((f: any) => f.label === labelKey);
55-
console.log("statename",field?.selectedValues?.[0]?.value )
55+
console.log('statename', field?.selectedValues?.[0]?.value);
5656
// localStorage.setItem("stateName", field?.selectedValues?.[0]?.value)
57-
return field?.selectedValues?.[0]?.value ?? null;
57+
return field?.selectedValues?.[0]?.value ?? null;
5858
};
5959

6060
const stateId = getFieldId('STATE');
61-
const stateName=getFieldLabel('STATE')
61+
const stateName = getFieldLabel('STATE');
6262
const districtId = getFieldId('DISTRICT');
6363
const blockId = getFieldId('BLOCK');
6464

65-
if (stateId)
66-
{localStorage.setItem('mfe_state', String(stateId));
67-
localStorage.setItem('stateId', String(stateId));
68-
}
65+
if (stateId) {
66+
localStorage.setItem('mfe_state', String(stateId));
67+
localStorage.setItem('stateId', String(stateId));
68+
}
6969
if (districtId) localStorage.setItem('mfe_district', String(districtId));
70-
if(stateName) localStorage.setItem("stateName", stateName)
70+
if (stateName) localStorage.setItem('stateName', stateName);
7171
if (blockId) localStorage.setItem('mfe_block', String(blockId));
72-
localStorage.setItem('roleName' , "Learner")
73-
72+
localStorage.setItem('roleName', 'Learner');
7473
}
7574

7675
export const profileComplitionCheck = async (): Promise<any> => {
@@ -116,7 +115,8 @@ export const profileComplitionCheck = async (): Promise<any> => {
116115
console.log('result', result);
117116
delete result?.properties?.is_volunteer;
118117

119-
const isPropertiesEmpty = Object.keys(result?.properties || {}).length === 0;
118+
const isPropertiesEmpty =
119+
Object.keys(result?.properties || {}).length === 0;
120120
return isPropertiesEmpty;
121121
}
122122
} catch (error) {
@@ -132,7 +132,11 @@ export const updateUser = async (
132132
const apiUrl: string = API_ENDPOINTS.userUpdate(userId);
133133

134134
try {
135-
const response = await patch(apiUrl, { userData, customFields }, {tenantid: localStorage.getItem('tenantId')});
135+
const response = await patch(
136+
apiUrl,
137+
{ userData, customFields },
138+
{ tenantid: localStorage.getItem('tenantId') }
139+
);
136140
return response;
137141
} catch (error) {
138142
console.error('error in fetching user details', error);
@@ -147,7 +151,9 @@ export const getUserDetails = async (
147151
// apiUrl = fieldValue ? `${apiUrl}?fieldvalue=true` : apiUrl;
148152

149153
try {
150-
const response = await get(apiUrl, {tenantid: localStorage.getItem('tenantId')});
154+
const response = await get(apiUrl, {
155+
tenantid: localStorage.getItem('tenantId'),
156+
});
151157
return response?.data;
152158
} catch (error) {
153159
console.error('error in fetching user details', error);
@@ -164,3 +170,38 @@ export const userNameExist = async (userData: any): Promise<any> => {
164170
throw error;
165171
}
166172
};
173+
174+
export interface MentorListParams {
175+
limit?: number;
176+
filters?: {
177+
working_village?: string[];
178+
role?: string;
179+
};
180+
sort?: string[];
181+
offset?: number;
182+
}
183+
184+
export const getMentorList = async ({
185+
limit = 100,
186+
filters,
187+
sort = ['createdAt', 'asc'],
188+
offset = 0,
189+
}: MentorListParams): Promise<any> => {
190+
const apiUrl: string = API_ENDPOINTS.userList;
191+
try {
192+
const response = await post(
193+
apiUrl,
194+
{
195+
limit,
196+
filters,
197+
sort,
198+
offset,
199+
},
200+
{}
201+
);
202+
return response?.data?.result;
203+
} catch (error) {
204+
console.error('error in getting mentor list', error);
205+
throw error;
206+
}
207+
};

libs/shared-lib-v2/src/lib/context/locales/en.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,10 @@
355355
"GUARDIAN_NAME": "Guardian's Name",
356356
"GUARDIAN_DETAILS": "Guardian Details",
357357
"I_WANT_TO_BECOME": "I want to become {futureWork}",
358-
"PTM_NAME": "PTM Name"
358+
"PTM_NAME": "PTM Name",
359+
"MY_MENTOR_DETAILS": "My Mentor Details",
360+
"MENTOR_NAME": "Mentor Name",
361+
"MENTOR_EMAIL": "Mentor Email"
359362
},
360363
"USERNAME_SUGGESTION": {
361364
"USERNAME": "Username",

0 commit comments

Comments
 (0)