Skip to content

Commit

Permalink
Merge pull request #80 from Rushikesh-Sonawane99/release-1.0.0
Browse files Browse the repository at this point in the history
Issue #PS-1275 chore: Modified state, district and block mapping logic for user profile
  • Loading branch information
itsvick authored Aug 2, 2024
2 parents d0ea9f8 + 59f2fb5 commit 7f39c95
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/pages/user-profile/[userId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ const TeacherProfile = () => {
const [loading, setLoading] = useState(false);
const [image, setImage] = useState(user_placeholder_img);
const [isAuthenticated, setIsAuthenticated] = React.useState(false);
const [unitName, setUnitName] = useState('');
const [stateName, setStateName] = useState('');
const [districtName, setDistrictName] = useState('');
const [blockName, setBlockName] = useState('');
const [isError, setIsError] = React.useState<boolean>(false);
const [isData, setIsData] = React.useState<boolean>(false);
Expand Down Expand Up @@ -193,7 +194,7 @@ const TeacherProfile = () => {
// find Address
const getFieldValue = (data: any, label: string) => {
const field = data.find((item: any) => item.label === label);
return field ? field?.value[0] : null;
return field ? field?.value : null;
};

const { data, error, isLoading } = useProfileInfo(userId ?? '', true, reload);
Expand All @@ -213,6 +214,14 @@ const TeacherProfile = () => {
const coreFieldData = data?.result?.userData;
setUserName(toPascalCase(coreFieldData?.name));
const fields: CustomField[] = data?.result?.userData?.customFields;
if (fields?.length > 0) {
const stateName = getFieldValue(fields, 'State');
setStateName(toPascalCase(stateName));
const districtName = getFieldValue(fields, 'District');
setDistrictName(toPascalCase(districtName));
const blockName = getFieldValue(fields, 'Block');
setBlockName(toPascalCase(blockName));
}
const fieldIdToValueMap: { [key: string]: string } =
mapFieldIdToValue(fields);
console.log(`coreFieldData`, coreFieldData);
Expand Down Expand Up @@ -264,11 +273,6 @@ const TeacherProfile = () => {

if (customDataFields?.length > 0) {
setCustomFieldsData(customDataFields);

const unitName = getFieldValue(customDataFields, 'Unit Name');
setUnitName(unitName);
const blockName = getFieldValue(customDataFields, 'Block Name');
setBlockName(blockName);
}
}
} else {
Expand Down Expand Up @@ -339,7 +343,7 @@ const TeacherProfile = () => {
};

// address find
const address = [unitName, blockName, userData?.district, userData?.state]
const address = [stateName, districtName, blockName]
?.filter(Boolean)
?.join(', ');

Expand Down

0 comments on commit 7f39c95

Please sign in to comment.