Skip to content

Commit

Permalink
Merge pull request #57 from Rushikesh-Sonawane99/release-1.0.0
Browse files Browse the repository at this point in the history
Issue #PS-1255 chore: View TL and facilitator profile and learner's profile based on new form API
  • Loading branch information
itsvick authored Jul 30, 2024
2 parents 2efc60d + a03be76 commit 7769ac6
Show file tree
Hide file tree
Showing 6 changed files with 347 additions and 123 deletions.
8 changes: 4 additions & 4 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@

"FIELDS": {
"DESIGNATION": "Designation",
"NO_OF_CLUSTERS": "Number of Clusters I Teach",
"NUMBER_OF_CLUSTERS_I_TEACH": "Number of Clusters I Teach",
"YEAR_OF_JOINING_SCP": "Year of joining SCP",
"MAIN_SUBJECT": "My Main Subjects",
"SUBJECT_TAUGHT": "Subjects I Teach",
"SUBJECTS_I_TEACH": "Subjects I Teach",
"GENDER": "Gender",
"UNIT_NAME": "Unit Name",
"UNIT_CODE": "Unit Code",
Expand Down Expand Up @@ -390,10 +390,10 @@
"REASON_FOR_DROP_OUT_FROM_SCHOOL": "Reason for drop out from School",
"EMAIL": "Email",
"DESIGNATION": "Designation",
"NO_OF_CLUSTERS": "Number of Clusters I Teach",
"NUMBER_OF_CLUSTERS_I_TEACH": "Number of Clusters I Teach",
"YEAR_OF_JOINING_SCP": "Year of joining SCP",
"MAIN_SUBJECT": "My Main Subjects",
"SUBJECT_TAUGHT": "Subjects I Teach",
"SUBJECTS_I_TEACH": "Subjects I Teach",
"GENDER": "Gender",
"UNIT_NAME": "Unit Name",
"UNIT_CODE": "Unit Code",
Expand Down
148 changes: 111 additions & 37 deletions src/pages/learner/[userId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
useMediaQuery,
} from '@mui/material';
import {
CustomField,
LearnerData,
UserData,
CohortAttendancePercentParam,
Expand All @@ -44,7 +45,12 @@ import {
getCohortAttendance,
} from '@/services/AttendanceService';
import { editEditUser, getUserDetails } from '@/services/ProfileService';
import { formatSelectedDate, getTodayDate, toPascalCase } from '@/utils/Helper';
import {
formatSelectedDate,
getTodayDate,
mapFieldIdToValue,
toPascalCase,
} from '@/utils/Helper';

import CloseIcon from '@mui/icons-material/Close';
import CreateOutlinedIcon from '@mui/icons-material/CreateOutlined';
Expand All @@ -67,6 +73,8 @@ import { useRouter } from 'next/router';
import { useTranslation } from 'next-i18next';
import withAccessControl from '@/utils/hoc/withAccessControl';
import { accessControl } from '../../../app.config';
import { getFormRead } from '@/services/CreateUserService';
import { FormContext, FormContextType } from '@/utils/app.constant';

// import { UserData, UpdateCustomField } from '../utils/Interfaces';

Expand Down Expand Up @@ -258,24 +266,89 @@ const LearnerProfile: React.FC = () => {
const response = await getUserDetails(user, true);

if (response?.responseCode === 200) {
const data = response?.result;
const data = response;
if (data) {
const userData = data?.userData;

setUserData(userData);

const customDataFields = userData?.customFields;
if (customDataFields?.length > 0) {
setCustomFieldsData(customDataFields);
const unitName = getFieldValue(customDataFields, 'Unit Name');
setUnitName(unitName);

const blockName = getFieldValue(customDataFields, 'Block Name');
setBlockName(blockName);

setUserName(userData?.name);
setContactNumber(userData?.mobile);
setLoading(false);
if (data) {
const coreFieldData = data?.result?.userData;
setUserName(coreFieldData?.name);
const fields: CustomField[] =
data?.result?.userData?.customFields;
const fieldIdToValueMap: { [key: string]: string } =
mapFieldIdToValue(fields);
console.log(`coreFieldData`, coreFieldData);

const fetchFormData = async () => {
try {
const response: FormData = await getFormRead(
FormContext.USERS,
FormContextType.STUDENT
);
console.log('response', response);
if (response) {
const mergeData = (
fieldIdToValueMap: { [key: string]: string },
response: any
): any => {
response.fields.forEach(
(field: {
name: any;
fieldId: string | number;
value: string;
coreField: number;
}) => {
if (
field.fieldId &&
fieldIdToValueMap[field.fieldId]
) {
// Update field value from fieldIdToValueMap if fieldId is available
field.value =
fieldIdToValueMap[field.fieldId] || '-';
} else if (field.coreField === 1) {
// Set field value from fieldIdToValueMap if coreField is 1 and fieldId is not in the map
field.value = coreFieldData[field.name] || '-';
}
}
);
return response;
};

const mergedProfileData = mergeData(
fieldIdToValueMap,
response
);
console.log(`mergedProfileData`, mergedProfileData);
if (mergedProfileData) {
setUserData(mergedProfileData?.fields);
const nameField = mergedProfileData.fields.find(
(field: { name: string }) => field.name === 'name'
);
const customDataFields = mergedProfileData?.fields;
// setIsData(true);

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

const unitName = getFieldValue(
customDataFields,
'Unit Name'
);
setUnitName(unitName);
const blockName = getFieldValue(
customDataFields,
'Block Name'
);
setBlockName(blockName);
}
}
} else {
// setIsData(false);
console.log('No data Found');
}
} catch (error) {
console.error('Error fetching form data:', error);
}
};
fetchFormData();
}
} else {
setLoading(false);
Expand Down Expand Up @@ -305,22 +378,29 @@ const LearnerProfile: React.FC = () => {
?.sort((a, b) => a.order - b.order)
?.filter((field) => field.order <= 12)
?.map((field) => {
const getSelectedOption = (field: any) => {
return (
field?.options?.find(
(option: any) => option?.value === field?.value?.[0]
) || '-'
);
};

if (
field.type === 'drop_down' ||
field.type === 'radio' ||
field.type === 'dropdown' ||
(field.type === 'Radio' && field.options && field.value.length)
) {
const selectedOption = field?.options?.find(
(option: any) => option.value === field.value[0]
);
const selectedOption = getSelectedOption(field);
return {
...field,
displayValue: selectedOption
? selectedOption.label
: field.value
? toPascalCase(field.value)
: '-',
displayValue:
selectedOption !== '-'
? selectedOption.label
: field.value
? toPascalCase(field.value)
: '-',
};
}
return {
Expand Down Expand Up @@ -791,7 +871,7 @@ const LearnerProfile: React.FC = () => {
filteredSortedForEdit?.forEach((field) => {
const value =
formData?.customFields?.find((f) => f.fieldId === field.fieldId)
?.value[0] || '';
?.value?.[0] || '';

if (field.type === 'text') {
newErrors[field.fieldId] = !value.trim() || /^\s/.test(value);
Expand Down Expand Up @@ -878,9 +958,9 @@ const LearnerProfile: React.FC = () => {
lineHeight={'28px'}
color={theme.palette.warning['A200']}
>
{userData?.name?.length > 18
? `${userData?.name?.substring(0, 18)}...`
: userData?.name}
{userName?.length > 18
? `${userName?.substring(0, 18)}...`
: userName}
</Typography>
<Typography
variant="h5"
Expand Down Expand Up @@ -1138,12 +1218,6 @@ const LearnerProfile: React.FC = () => {
padding="15px"
>
<Grid container spacing={4}>
<FieldComponent
size={12}
label={t('PROFILE.FULL_NAME')}
data={userName}
/>

{learnerDetailsByOrder &&
learnerDetailsByOrder.map((item: any, i: number) => (
<React.Fragment key={i}>
Expand Down Expand Up @@ -1420,7 +1494,7 @@ const LearnerProfile: React.FC = () => {
{filteredSortedForEdit?.map((field) => {
const fieldValue =
formData?.customFields?.find((f) => f.fieldId === field.fieldId)
?.value[0] || '';
?.value?.[0] || '';
const isError: any = errors[field.fieldId];

return (
Expand Down
5 changes: 5 additions & 0 deletions src/pages/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ import appLogo from '../../public/images/appLogo.png';
import Loader from '../components/Loader';
import { login } from '../services/LoginService';
import { getUserId } from '../services/ProfileService';
import manageUserStore from '@/store/manageUserStore';

const LoginPage = () => {
const { t } = useTranslation();
const store = useStore();
const userStore = manageUserStore();
const setUserId = manageUserStore((state) => state.setUserId);
const setUserRole = useStore(
(state: { setUserRole: any }) => state.setUserRole
);
Expand Down Expand Up @@ -122,6 +126,7 @@ const LoginPage = () => {

const userResponse = await getUserId();
localStorage.setItem('userId', userResponse?.userId);
setUserId(userResponse?.userId);
localStorage.setItem('state', userResponse?.state);
localStorage.setItem('district', userResponse?.district);
localStorage.setItem('role', userResponse?.tenantData[0]?.roleName);
Expand Down
Loading

0 comments on commit 7769ac6

Please sign in to comment.