Skip to content

Commit

Permalink
Merge pull request #497 from AkshataKatwal16/master-data
Browse files Browse the repository at this point in the history
Issue #3723 #3719 #3720 bugs: Resolved Bugs
  • Loading branch information
itsvick authored Jan 30, 2025
2 parents b819e4d + 6b08978 commit e37f31a
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 79 deletions.
131 changes: 65 additions & 66 deletions src/components/CommonUserModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
RoleId,
TelemetryEventType,
apiCatchingDuration,
fieldKeys
fieldKeys,
} from "@/utils/app.constant";
import { telemetryFactory } from "@/utils/telemetry";
import { useLocationState } from "@/utils/useLocationState";
Expand Down Expand Up @@ -58,8 +58,8 @@ interface UserModalProps {
onSubmit: (submitValue: boolean) => void;
userType: string;
userName?: string;
emailFieldValue?:string
userNameFieldValue?:string
emailFieldValue?: string;
userNameFieldValue?: string;
}

const CommonUserModal: React.FC<UserModalProps> = ({
Expand All @@ -72,11 +72,8 @@ const CommonUserModal: React.FC<UserModalProps> = ({
userType,
userName,
emailFieldValue,
userNameFieldValue
}) => {



userNameFieldValue,
}) => {
const [schema, setSchema] = React.useState<any>();
const [uiSchema, setUiSchema] = React.useState<any>();
const [openModal, setOpenModal] = React.useState(false);
Expand Down Expand Up @@ -212,7 +209,7 @@ const CommonUserModal: React.FC<UserModalProps> = ({
assignedTeamLeader,
assignedTeamLeaderNames,
selectedStateCohortId,
} = useLocationState(open, onClose, roleType);
} = useLocationState(open, onClose, roleType);

useEffect(() => {
const getAddUserFormData = () => {
Expand All @@ -224,7 +221,7 @@ const CommonUserModal: React.FC<UserModalProps> = ({
// const response2= await getFormRead(
// FormContext.USERS,
// userType
// );
// );
const response: FormData =
userType === FormContextType.TEACHER
? teacherFormData
Expand All @@ -233,7 +230,6 @@ const CommonUserModal: React.FC<UserModalProps> = ({
: userType === FormContextType.CONTENT_CREATOR
? contentCreatorFormData
: teamLeaderFormData;


if (response) {
if (userType === FormContextType.TEACHER) {
Expand All @@ -247,19 +243,19 @@ const CommonUserModal: React.FC<UserModalProps> = ({
);
setFormValue(formValues);
setSchema(schema);
setUiSchema(uiSchema);
setUiSchema(uiSchema);
} else if (userType === FormContextType.TEAM_LEADER) {
const { schema, uiSchema, formValues } = GenerateSchemaAndUiSchema(
response,
t
);
setFormValue(formValues);
setSchema(schema);
setSchema(schema);
setUiSchema(uiSchema);
} else {
console.log("response---------", response);
const { schema, uiSchema } = GenerateSchemaAndUiSchema(response, t);
setSchema(schema);
setSchema(schema);
setUiSchema(uiSchema);
}
}
Expand All @@ -280,14 +276,12 @@ const CommonUserModal: React.FC<UserModalProps> = ({
const handleSubmit = async (
data: IChangeEvent<any, RJSFSchema, any>,
event: React.FormEvent<any>
) => {
) => {
const target = event?.target as HTMLFormElement;



const formData = data.formData;
const formData = data.formData;
const schemaProperties = schema.properties;

let result;
if (formData["year of joining scp"]) {
result = generateUsernameAndPassword(
Expand All @@ -302,7 +296,8 @@ const CommonUserModal: React.FC<UserModalProps> = ({
const { username, password } = result;

const apiBody: any = {
username: userType === FormContextType.STUDENT ? username : formData.email,
username:
userType === FormContextType.STUDENT ? username : formData.email,
password: password,
tenantCohortRoleMapping: [
{
Expand All @@ -326,11 +321,15 @@ const CommonUserModal: React.FC<UserModalProps> = ({
customFields: [],
};

Object.entries(formData).forEach(([fieldKey, fieldValue]) => {
Object.entries(formData).forEach(([fieldKey, fieldValue]) => {
const fieldSchema = schemaProperties[fieldKey];
const fieldId = fieldSchema?.fieldId;
const fieldId = fieldSchema?.fieldId;

if (fieldId === null || fieldId === "null" || fieldKey===fieldKeys.GENDER) {
if (
fieldId === null ||
fieldId === "null" ||
fieldKey === fieldKeys.GENDER
) {
if (typeof fieldValue !== "object") {
apiBody[fieldKey] = fieldValue;
}
Expand All @@ -355,7 +354,7 @@ const CommonUserModal: React.FC<UserModalProps> = ({
if (fieldId) {
apiBody.customFields.push({
fieldId: fieldId,
value: String(fieldValue),
value: fieldValue ? String(fieldValue) : "",
});
}
}
Expand Down Expand Up @@ -383,29 +382,34 @@ const CommonUserModal: React.FC<UserModalProps> = ({
}

try {
if (isEditModal && userId) {
if (isEditModal && userId) {
const userData = {
name: apiBody?.name,
mobile: String(apiBody?.phone_number),
mobile: apiBody?.mobile
? apiBody?.mobile
: String(apiBody?.phone_number),
father_name: apiBody?.father_name,
email: apiBody?.email,
updatedBy: localStorage.getItem("userId"),
username: apiBody?.username,
firstName:apiBody?.firstName,
middleName:apiBody?.middleName,
lastName:apiBody?.lastName,
dob:apiBody?.dob,
gender:apiBody?.gender,
firstName: apiBody?.firstName,
middleName: apiBody?.middleName,
lastName: apiBody?.lastName,
dob: apiBody?.dob,
gender: apiBody?.gender,
};

const customFields = apiBody?.customFields;
if(emailFieldValue===userData.email)
{
const customFields = apiBody?.customFields;
if (emailFieldValue === userData.email) {
delete userData.email;

}
if(userNameFieldValue===userData.username)
delete userData.username;
console.log(
"userNameFieldValue",
userNameFieldValue,
userData.username
);
if (userNameFieldValue === userData.username)
delete userData.username;

const object = {
userData: userData,
Expand Down Expand Up @@ -460,19 +464,16 @@ const CommonUserModal: React.FC<UserModalProps> = ({
};
telemetryFactory.interact(telemetryInteract);
} else {
if(apiBody?.name)
{
if (apiBody?.name) {
apiBody.name = apiBody?.name.trim();
}
if(apiBody?.father_name)
{
if (apiBody?.father_name) {
apiBody.father_name = apiBody?.father_name.trim();
}
if(apiBody?.phone_number)
{
if (apiBody?.phone_number) {
apiBody.mobile = apiBody?.phone_number;
}
const response = await createUser(apiBody);
const response = await createUser(apiBody);
if (response) {
const messageKey = messageKeyMap[userType];

Expand Down Expand Up @@ -513,14 +514,16 @@ const CommonUserModal: React.FC<UserModalProps> = ({
creatorName = getUserFullName();
}
let replacements: { [key: string]: string };
replacements = {};
replacements = {};
if (creatorName) {
if (userType === FormContextType.STUDENT) {
replacements = {
"{FirstName}": firstLetterInUpperCase(creatorName),
"{UserName}": apiBody["username"],
"{LearnerName}": firstLetterInUpperCase(apiBody["firstName"]),
"{Password}": apiBody["username"],
"{LearnerName}": firstLetterInUpperCase(
apiBody["firstName"]
),
"{Password}": apiBody["username"],
};
} else {
replacements = {
Expand Down Expand Up @@ -583,14 +586,14 @@ const CommonUserModal: React.FC<UserModalProps> = ({
onClose();
onCloseModal();
} catch (error: any) {
// onClose();
// onClose();
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") {
} else if (
error?.response?.data?.params?.errmsg === "Email already exists"
) {
showToastMessage(error?.response?.data?.params?.errmsg, "error");
}
else {
} else {
showToastMessage(t("COMMON.SOMETHING_WENT_WRONG"), "error");
}
}
Expand All @@ -602,9 +605,9 @@ const CommonUserModal: React.FC<UserModalProps> = ({

if (!isEditModal) {
const { firstName, lastName, username } = formData;
if (firstName && lastName ) {
setFormValue(formData);
}
if (firstName && lastName) {
setFormValue(formData);
}
// else {
// //setFormValue({ ...event.formData });
// }
Expand Down Expand Up @@ -648,11 +651,9 @@ const CommonUserModal: React.FC<UserModalProps> = ({
}
}, [dynamicForm, dynamicFormForBlock, open]);
useEffect(() => {

if(!open)
{
setFormValue({});
}
if (!open) {
setFormValue({});
}
}, [open]);
const handleChangeCheckBox = (event: React.ChangeEvent<HTMLInputElement>) => {
setCheckedConfirmation(event.target.checked);
Expand Down Expand Up @@ -688,7 +689,7 @@ const CommonUserModal: React.FC<UserModalProps> = ({
useEffect(() => {
if (typeof window !== "undefined" && window.localStorage) {
const admin = localStorage.getItem("adminInfo");
if (admin) setAdminInfo(JSON.parse(admin));
if (admin) setAdminInfo(JSON.parse(admin));
}
}, []);
return (
Expand Down Expand Up @@ -732,13 +733,13 @@ const CommonUserModal: React.FC<UserModalProps> = ({
color="primary"
disabled={!submitButtonEnable}
onClick={() => {
setSubmittedButtonStatus(true);
setSubmittedButtonStatus(true);
if (
userType !== FormContextType.STUDENT &&
!isEditModal &&
noError
) {
// setOpenModal(true);
// setOpenModal(true);
if (
assignedTeamLeaderNames.length !== 0 &&
userType === FormContextType.TEAM_LEADER
Expand All @@ -749,7 +750,7 @@ const CommonUserModal: React.FC<UserModalProps> = ({
//onClose();
setOpenModal(true);
}
}
}
}}
>
{!isEditModal ? t("COMMON.CREATE") : t("COMMON.UPDATE")}
Expand Down Expand Up @@ -804,7 +805,6 @@ const CommonUserModal: React.FC<UserModalProps> = ({
formData={formData}
role={userType}
isEdit={isEditModal}

>
{/* <CustomSubmitButton onClose={primaryActionHandler} /> */}
</DynamicForm>
Expand All @@ -826,7 +826,6 @@ const CommonUserModal: React.FC<UserModalProps> = ({
formData={formValue}
role={userType}
isEdit={isEditModal}

>
{/* <CustomSubmitButton onClose={primaryActionHandler} /> */}
</DynamicForm>
Expand Down
6 changes: 2 additions & 4 deletions src/components/UserTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -952,9 +952,7 @@ const UserTable: React.FC<UserTableProps> = ({
userId: user?.userId,
username: user?.username,
status: user?.status,
name:
user?.firstName?.charAt(0).toUpperCase() +
user?.firstName?.slice(1).toLowerCase(),
name: getUserFullName(user) ?? "-",
role: user.role,
// gender: user.gender,
mobile: user.mobile === "NaN" ? "-" : user.mobile,
Expand Down Expand Up @@ -1696,4 +1694,4 @@ const UserTable: React.FC<UserTableProps> = ({
);
};

export default UserTable;
export default UserTable;
24 changes: 15 additions & 9 deletions src/components/layouts/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const Header = ({
}
}, []);
const handleSelectChange = (event: SelectChangeEvent) => {
setSelectedSessionId(event.target.value);
setSelectedSessionId(event.target.value);
localStorage.setItem("academicYearId", event.target.value);
// Check if the selected academic year is active
const selectedYear = academicYearList?.find(
Expand All @@ -108,12 +108,21 @@ const Header = ({
else router.push("/course-planner");
} else {
if (locale) {
if (storedUserData?.role === Role.CENTRAL_ADMIN)
router.push("/programs", undefined, { locale: locale });
else router.push("/centers", undefined, { locale: locale });
if (storedUserData?.role === Role.CENTRAL_ADMIN) {
if (router.pathname === "/programs") window.location.reload();
else router.push("/programs", undefined, { locale: locale });
} else {
if (router.pathname === "/centers") window.location.reload();
else router.push("/centers", undefined, { locale: locale });
}
} else {
if (storedUserData?.role === Role.CENTRAL_ADMIN) router.push("/programs");
else router.push("/centers");
if (storedUserData?.role === Role.CENTRAL_ADMIN) {
if (router.pathname === "/programs") window.location.reload();
else router.push("/programs");
} else {
if (router.pathname === "/centers") window.location.reload();
else router.push("/centers");
}
}
}
};
Expand All @@ -127,15 +136,12 @@ const Header = ({
}
};
const handleClick = (event: React.MouseEvent<HTMLElement>) => {

setAnchorEl(event.currentTarget);

};
const handleClose = () => {
setAnchorEl(null);
};
const handleMenuItemClick = (newLocale: any) => {

setLanguage(newLocale);
if (typeof window !== "undefined" && window.localStorage) {
localStorage.setItem("preferredLanguage", newLocale);
Expand Down

0 comments on commit e37f31a

Please sign in to comment.