Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue feat PS-3574:Add firstname , lastname gender changes of learner and facilitator #627

Merged
merged 5 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/components/AddFacilitator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
RoleId,
Status,
Telemetry,
fieldKeys,
} from '@/utils/app.constant';
import React, { useEffect } from 'react';
import ReactGA from 'react-ga4';
Expand Down Expand Up @@ -221,7 +222,7 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
const fieldSchema = schemaProperties[fieldKey];
const fieldId = fieldSchema?.fieldId;

if (fieldId === null || fieldId === 'null') {
if (fieldId === null || fieldId === 'null' || fieldKey===fieldKeys.GENDER) {
if (typeof fieldValue !== 'object') {
apiBody[fieldKey] = fieldValue;
if (fieldKey === 'name') {
Expand Down Expand Up @@ -355,7 +356,7 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
telemetryFactory.interact(telemetryInteract);

await sendEmail(
apiBody['name'],
apiBody['firstName'],
formData?.email,
password,
formData?.email
Expand Down
9 changes: 6 additions & 3 deletions src/components/AddLeanerModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,19 @@ const AddLearnerModal: React.FC<AddLearnerModalProps> = ({
username,
password,
userEmail,
apiBody['name']
apiBody['firstName']
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Critical: Accessing undefined field firstName

The code attempts to use apiBody['firstName'] but this field is not set anywhere in the code. The form processing only sets apiBody['name'] without splitting it into first/last name components.

Apply this fix to properly handle the name fields:

- apiBody['firstName']
+ apiBody['name']?.split(' ')?.[0] || apiBody['name']

Additionally, consider refactoring the name handling logic:

  1. Add proper name splitting when processing form data:
if (fieldKey === 'name') {
  const nameParts = fieldValue.split(' ');
  apiBody['firstName'] = nameParts[0];
  apiBody['lastName'] = nameParts.slice(1).join(' ');
  setFullname(fieldValue);
}
  1. Add validation to ensure name fields are properly set:
if (!apiBody['firstName']) {
  showToastMessage(t('COMMON.INVALID_NAME_FORMAT'), 'error');
  return;
}

);
} else {
showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error');
}
}
}
} catch (error: any) {
if (error?.response?.data?.params?.err === 'User already exist.') {
showToastMessage(error?.response?.data?.params?.err, 'error');
if (error?.response?.data?.params?.err === "User already exist.") {
showToastMessage(error?.response?.data?.params?.err, "error");
}
else if (error?.response?.data?.params?.errmsg === "Email already exists") {
showToastMessage(error?.response?.data?.params?.errmsg, "error");
} else {
showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error');
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/CohortFacilitatorList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const CohortLearnerList: React.FC<CohortLearnerListProp> = ({
(field: { label: string }) => field.label === 'AGE'
);
return {
name: toPascalCase(user?.name),
name: toPascalCase(user?.firstName || '') + ' ' + (user?.lastName ? toPascalCase(user.lastName) : ""),
userId: user?.userId,
memberStatus: user?.status,
statusReason: user?.statusReason,
Expand Down
2 changes: 1 addition & 1 deletion src/components/CohortLearnerList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const CohortLearnerList: React.FC<CohortLearnerListProp> = ({
(field: { label: string }) => field.label === 'AGE'
);
return {
name: toPascalCase(user?.name),
name: toPascalCase(user?.firstName || '') + ' ' + (user?.lastName ? toPascalCase(user.lastName) : ""),
userId: user?.userId,
memberStatus: user?.status,
statusReason: user?.statusReason,
Expand Down
5 changes: 5 additions & 0 deletions src/components/GeneratedSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ export const GenerateSchemaAndUiSchema = (
}));
fieldUiSchema['ui:widget'] = 'CustomRadioWidget';
break;
case 'date':
fieldSchema.type = 'string';
fieldSchema.format = 'date';
fieldUiSchema['ui:widget'] = 'date';
break;
default:
break;
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/LearnersListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -408,15 +408,15 @@ const LearnersListItem: React.FC<LearnerListProps> = ({
const stringAvatar = (name: string) => {
if (name) {
const nameParts = name.split(' ');

return {
children:
nameParts.length === 1
? nameParts[0][0]
: `${nameParts[0][0]}${nameParts[1][0]}`,
: `${nameParts[0][0]}${nameParts[1]?.[0] || ''}`,
};
}

return '';
};

Expand Down
3 changes: 1 addition & 2 deletions src/pages/assessments/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ const Assessments = () => {
if (resp) {
const userDetails = resp.map((user: any) => ({
...user,
name: toPascalCase(user.name),
userId: user.userId,
name: toPascalCase(user?.firstName || '') + ' ' + (user?.lastName ? toPascalCase(user.lastName) : ""), userId: user.userId,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AkshataKatwal16 add proper formatting

}));
setCohortMembers(userDetails);
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/attendance-history.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ const UserAttendanceHistory = () => {
const nameUserIdArray = resp
?.map((entry: any) => ({
userId: entry.userId,
name: toPascalCase(entry.name),
name: toPascalCase(entry?.firstName || '') + ' ' + (entry?.lastName ? toPascalCase(entry.lastName) : ""),
memberStatus: entry.status,
createdAt: entry.createdAt,
updatedAt: entry.updatedAt,
Expand Down
3 changes: 2 additions & 1 deletion src/pages/attendance-overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ const AttendanceOverview: React.FC<AttendanceOverviewProps> = () => {
if (resp) {
const nameUserIdArray = resp?.map((entry: any) => ({
userId: entry.userId,
name: toPascalCase(entry.name),
name: toPascalCase(entry?.firstName || '') + ' ' + (entry?.lastName ? toPascalCase(entry.lastName) : ""),

memberStatus: entry.status,
}));
if (nameUserIdArray) {
Expand Down
4 changes: 3 additions & 1 deletion src/pages/board-enrollment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ const BoardEnrollment = () => {
return members.map((entry: any) => ({
userId: entry.userId,
cohortMembershipId: entry.cohortMembershipId,
name: toPascalCase(entry.name),
name: toPascalCase(entry?.firstName || '') + ' ' + (entry?.lastName ? toPascalCase(entry.lastName) : ""),


memberStatus: entry.status,
statusReason: entry.statusReason,
customField: entry.customField,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/observation/[observationId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ setFilteredEntityData(result)
const filters = {
cohortId: selectedCohort,
} as CohortMemberList['filters'];
if (searchInput !== '') filters.name = searchInput;
if (searchInput !== '') filters.firstName = searchInput;
//const limit=limit;
let response;
if (entity === ObservationEntityType?.LEARNER) {
Expand All @@ -338,7 +338,7 @@ setFilteredEntityData(result)
(field: { label: string }) => field.label === 'AGE'
);
return {
name: toPascalCase(user?.name),
name: toPascalCase(user?.firstName || '') + ' ' + (user?.lastName ? toPascalCase(user.lastName) : ""),
userId: user?.userId,
memberStatus: user?.status,
statusReason: user?.statusReason,
Expand Down
3 changes: 2 additions & 1 deletion src/utils/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export interface CohortMemberList {
role?: string;
status?: string[];
name?: string | undefined;
firstName?:string
};
includeArchived?: boolean;
}
Expand Down Expand Up @@ -432,7 +433,7 @@ export interface FieldOption {

export interface Field {
name: string;
type: 'text' | 'numeric' | 'drop_down' | 'checkbox' | 'radio' | 'email';
type: 'text' | 'numeric' | 'drop_down' | 'checkbox' | 'radio' | 'email' | 'date';
label: string;
order: string;
coreField: number;
Expand Down
3 changes: 3 additions & 0 deletions src/utils/app.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,6 @@ export enum sessionType {
PLANNED = 'planned',
EXTRA = 'extra',
}
export enum fieldKeys {
GENDER="gender"
}