Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #966 from egovernments/ISTE-474
Browse files Browse the repository at this point in the history
Iste 474: Resolved "The system is displaying each division twice under jurisdictions"
  • Loading branch information
pradeepkumarcm-egov authored Oct 4, 2024
2 parents 0ac0432 + 1ccd223 commit 33f5ea8
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,20 @@ const Jurisdictions = ({ t, config, onSelect, userType, formData }) => {
}
return res;
});

if (isEdit && STATE_ADMIN) {
let divisionData = [];
let divisionDataSet = new Set();
if (isEdit && jurisdictionData.length > 0) {
jurisdictionData?.map((jurisdiction) => {
if (jurisdiction?.divisionBoundary && jurisdiction?.divisionBoundary?.length > 0 && divisionData.length === 0) {
divisionData.push(jurisdiction);
} else if (divisionData.length > 0) {
if (divisionData[divisionData.length - 1]?.division?.code !== jurisdiction?.division?.code) {
divisionData.push(jurisdiction);
jurisdictionData?.forEach((jurisdiction) => {
if (jurisdiction?.divisionBoundary && jurisdiction?.divisionBoundary?.length > 0) {
// If divisionData set doesn't already have this division, add it
if (!Array.from(divisionDataSet).some((item) => item.division?.code === jurisdiction?.division?.code)) {
divisionDataSet.add(jurisdiction);
}
}
});
}
let divisionData = Array.from(divisionDataSet);

let finalData = [];
divisionData &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ const EditForm = ({ tenantId, data }) => {
}
}, [mobileNumber]);


let defaultValues = {
tenantId: tenantId,
employeeStatus: "EMPLOYED",
Expand All @@ -73,10 +72,9 @@ const EditForm = ({ tenantId, data }) => {
},
SelectUserTypeAndDesignation: {
department: data?.assignments[0]?.department,
designation: data?.assignments[0]?.designation
designation: data?.assignments[0]?.designation,
},


SelectDateofBirthEmployment: { dob: convertEpochToDate(data?.user?.dob) },
Jurisdictions: data?.jurisdictions?.map((ele, index) => {
let obj = {
Expand Down Expand Up @@ -118,7 +116,6 @@ const EditForm = ({ tenantId, data }) => {
return validEmail && name.match(Digit.Utils.getPattern("Name"));
};


function hasUniqueTenantIds(items) {
// Create a Set to efficiently store unique tenantIds
const uniqueTenantIds = new Set();
Expand All @@ -137,6 +134,18 @@ const EditForm = ({ tenantId, data }) => {
return true;
}

function hasUniqueDivisions(items) {
const uniqueDivisions = new Set();
for (const item of items) {
const divisionCode = item?.division?.code;
if (divisionCode && uniqueDivisions.has(divisionCode)) {
return false;
}
uniqueDivisions.add(divisionCode);
}
return true;
}

const onFormValueChange = (setValue = true, formData) => {
let isValid = false;
if (formData?.SelectEmployeePhoneNumber?.mobileNumber) {
Expand All @@ -153,10 +162,13 @@ const EditForm = ({ tenantId, data }) => {
} else {
if (!STATE_ADMIN) {
key?.roles?.length > 0 && setcheck(true);
if (formData?.SelectUserTypeAndDesignation[0] && formData?.SelectUserTypeAndDesignation[0]?.department != undefined && formData?.SelectUserTypeAndDesignation[0]?.designation != undefined) {
if (
formData?.SelectUserTypeAndDesignation[0] &&
formData?.SelectUserTypeAndDesignation[0]?.department != undefined &&
formData?.SelectUserTypeAndDesignation[0]?.designation != undefined
) {
isValid = true;
}
else {
} else {
isValid = false;
}
} else if (STATE_ADMIN) {
Expand All @@ -168,17 +180,20 @@ const EditForm = ({ tenantId, data }) => {

if (
formData?.SelectEmployeeGender?.gender.code &&
formData?.SelectEmployeeName?.employeeName &&
formData?.SelectEmployeePhoneNumber?.mobileNumber &&
STATE_ADMIN ?
(formData?.Jurisdictions?.length && !formData?.Jurisdictions.some(juris => juris?.division == undefined || juris?.divisionBoundary?.length === 0))
: formData?.Jurisdictions?.length && formData?.Jurisdictions.length && !formData?.Jurisdictions.some(juris => juris?.roles?.length === 0)
&&
isValid &&
checkfield &&
phonecheck &&
checkMailNameNum(formData) &&
hasUniqueTenantIds(formData?.Jurisdictions)
formData?.SelectEmployeeName?.employeeName &&
formData?.SelectEmployeePhoneNumber?.mobileNumber &&
STATE_ADMIN
? formData?.Jurisdictions?.length &&
!formData?.Jurisdictions.some((juris) => juris?.division == undefined || juris?.divisionBoundary?.length === 0) &&
hasUniqueDivisions(formData?.Jurisdictions)
: formData?.Jurisdictions?.length &&
formData?.Jurisdictions.length &&
!formData?.Jurisdictions.some((juris) => juris?.roles?.length === 0) &&
isValid &&
checkfield &&
phonecheck &&
checkMailNameNum(formData) &&
hasUniqueTenantIds(formData?.Jurisdictions)
) {
setSubmitValve(true);
} else {
Expand Down Expand Up @@ -309,7 +324,6 @@ const EditForm = ({ tenantId, data }) => {
dataAssignments[0].department = input.SelectUserTypeAndDesignation[0]?.department?.code;
dataAssignments[0].designation = input.SelectUserTypeAndDesignation[0]?.designation?.code;


requestdata.assignments = input?.Assignments ? input?.Assignments : dataAssignments;
requestdata.dateOfAppointment = Date.parse(input?.SelectDateofEmployment?.dateOfAppointment);
requestdata.code = input?.SelectEmployeeId?.code ? input?.SelectEmployeeId?.code : data?.code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ const CreateEmployee = () => {
return true;
}

function hasUniqueDivisions(items) {
const uniqueDivisions = new Set();
for (const item of items) {
const divisionCode = item?.division?.code;
if (divisionCode && uniqueDivisions.has(divisionCode)) {
return false;
}
uniqueDivisions.add(divisionCode);
}
return true;
}

const onFormValueChange = (setValue = true, formData) => {
let isValid = false;
if (!_.isEqual(sessionFormData, formData)) {
Expand All @@ -120,10 +132,13 @@ const CreateEmployee = () => {
break;
} else {
if (!STATE_ADMIN) {
if (formData?.SelectUserTypeAndDesignation[0] && formData?.SelectUserTypeAndDesignation[0]?.department != undefined && formData?.SelectUserTypeAndDesignation[0]?.designation != undefined) {
if (
formData?.SelectUserTypeAndDesignation[0] &&
formData?.SelectUserTypeAndDesignation[0]?.department != undefined &&
formData?.SelectUserTypeAndDesignation[0]?.designation != undefined
) {
isValid = true;
}
else {
} else {
isValid = false;
}

Expand All @@ -142,26 +157,23 @@ const CreateEmployee = () => {
// , "formData");
console.log(isValid, "isValid");


if (


formData?.SelectEmployeeGender?.gender.code &&
formData?.SelectEmployeeName?.employeeName &&
formData?.SelectEmployeePhoneNumber?.mobileNumber &&
formData?.Jurisdictions?.length &&
STATE_ADMIN ?
(formData?.Jurisdictions.length && !formData?.Jurisdictions.some(juris => juris?.division == undefined || juris?.divisionBoundary?.length === 0))

: formData?.Jurisdictions?.length && formData?.Jurisdictions.length && !formData?.Jurisdictions.some(juris => juris?.roles?.length === 0) &&

isValid &&

checkfield &&
phonecheck &&
checkMailNameNum(formData) &&
hasUniqueTenantIds(formData?.Jurisdictions)

formData?.SelectEmployeeName?.employeeName &&
formData?.SelectEmployeePhoneNumber?.mobileNumber &&
formData?.Jurisdictions?.length &&
STATE_ADMIN
? formData?.Jurisdictions.length &&
hasUniqueDivisions(formData?.Jurisdictions) &&
!formData?.Jurisdictions.some((juris) => juris?.division == undefined || juris?.divisionBoundary?.length === 0)
: formData?.Jurisdictions?.length &&
formData?.Jurisdictions.length &&
!formData?.Jurisdictions.some((juris) => juris?.roles?.length === 0) &&
isValid &&
checkfield &&
phonecheck &&
checkMailNameNum(formData) &&
hasUniqueTenantIds(formData?.Jurisdictions)
) {
setSubmitValve(true);
} else {
Expand All @@ -174,7 +186,6 @@ const CreateEmployee = () => {
};

const onSubmit = (data) => {

if (!STATE_ADMIN && data.Jurisdictions?.filter((juris) => juris.tenantId == tenantId).length == 0) {
setShowToast({ key: true, label: "ERR_BASE_TENANT_MANDATORY" });
closeToast();
Expand Down Expand Up @@ -299,8 +310,7 @@ const CreateEmployee = () => {
{
fromDate: new Date().getTime(),
isCurrentAssignment: hrmsData?.["egov-hrms"]?.HRMSConfig[0]?.isCurrentAssignment,
department: !STATE_ADMIN ? data?.SelectUserTypeAndDesignation[0]?.department?.code :
hrmsData?.["egov-hrms"]?.HRMSConfig[0]?.department,
department: !STATE_ADMIN ? data?.SelectUserTypeAndDesignation[0]?.department?.code : hrmsData?.["egov-hrms"]?.HRMSConfig[0]?.department,
designation: STATE_ADMIN
? hrmsData?.["egov-hrms"]?.HRMSConfig[0]?.designation?.filter((x) => x?.isStateUser)[0]?.code
: data?.SelectUserTypeAndDesignation[0]?.designation?.code,
Expand Down

0 comments on commit 33f5ea8

Please sign in to comment.