Skip to content

Commit

Permalink
fixed validation logic (#846)
Browse files Browse the repository at this point in the history
* fixed validation logic

* Update micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/UploadData.js

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: Jagankumar <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jun 12, 2024
1 parent 666cfa9 commit b3a0b33
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,16 @@ const UploadData = ({ formData, onSelect, ...props }) => {
}
}
enrichSchema(data, properties, required, columns);
const newData=JSON.parse(JSON.stringify(data))
const newData = JSON.parse(JSON.stringify(data));
delete newData.campaignType;
return newData;
}

useEffect(()=>{
if(uploadedFile.length == 0){
useEffect(() => {
if (uploadedFile.length == 0) {
setErrorsType({});
}
},[uploadedFile])
}, [uploadedFile]);

useEffect(async () => {
if (Schemas?.["HCM-ADMIN-CONSOLE"]?.adminSchema) {
Expand All @@ -184,9 +184,9 @@ const UploadData = ({ formData, onSelect, ...props }) => {
}
}, [Schemas?.["HCM-ADMIN-CONSOLE"]?.adminSchema]);

useEffect(async() =>{
if(convertedSchema && Object.keys(convertedSchema).length > 0){
const newFacilitySchema = await translateSchema(convertedSchema?.facilityWithBoundary);
useEffect(async () => {
if (convertedSchema && Object.keys(convertedSchema).length > 0) {
const newFacilitySchema = await translateSchema(convertedSchema?.facilityWithBoundary);
const newBoundarySchema = await translateSchema(convertedSchema?.boundary);
const newUserSchema = await translateSchema(convertedSchema?.userWithBoundary);
const headers = {
Expand All @@ -204,7 +204,7 @@ const UploadData = ({ formData, onSelect, ...props }) => {
setSheetHeaders(headers);
setTranslatedSchema(schema);
}
}, [convertedSchema])
}, [convertedSchema]);

useEffect(async () => {
if (readMe?.["HCM-ADMIN-CONSOLE"]) {
Expand Down Expand Up @@ -234,7 +234,7 @@ const UploadData = ({ formData, onSelect, ...props }) => {
} else if (type === "facilityWithBoundary") {
uploadType = "uploadFacility";
}
onSelect(uploadType, { uploadedFile });
onSelect(uploadType, { uploadedFile, isError, isValidation: false, apiError: false, isSuccess: uploadedFile?.length > 0 });
setExecutionCount((prevCount) => prevCount + 1);
}
});
Expand Down Expand Up @@ -462,22 +462,57 @@ const UploadData = ({ formData, onSelect, ...props }) => {

const jsonData = XLSX.utils.sheet_to_json(sheet, { blankrows: true });

// const boundaryCodeIndex = headersToValidate.indexOf(t("HCM_ADMIN_CONSOLE_BOUNDARY_CODE"));
// const headersBeforeBoundaryCode = headersToValidate.slice(0, boundaryCodeIndex);

// const columnBeforeBoundaryCode = jsonData.map((row) => row[headersBeforeBoundaryCode[headersBeforeBoundaryCode.length - 1]]);

// // Getting the length of data in the column before the boundary code
// const lengthOfColumnBeforeBoundaryCode = columnBeforeBoundaryCode.filter((value) => value !== undefined && value !== "").length;

// const filteredData = jsonData
// .filter((e) => e[headersBeforeBoundaryCode[headersBeforeBoundaryCode?.length - 1]])
// .filter((e) => e[t("HCM_ADMIN_CONSOLE_TARGET_AT_THE_SELECTED_BOUNDARY_LEVEL")]);
// if (filteredData?.length == 0 || filteredData?.length != lengthOfColumnBeforeBoundaryCode) {
// const errorMessage = t("HCM_MISSING_TARGET");
// setErrorsType((prevErrors) => ({
// ...prevErrors,
// [type]: errorMessage,
// }));
// setIsError(true);
// isValid = false;
// break;
// }

// const targetValue = filteredData?.[0][t("HCM_ADMIN_CONSOLE_TARGET_AT_THE_SELECTED_BOUNDARY_LEVEL")];

// if (targetValue <= 0 || targetValue >= 100000000) {
// const errorMessage = t("HCM_TARGET_VALIDATION_ERROR");
// setErrorsType((prevErrors) => ({
// ...prevErrors,
// [type]: errorMessage,
// }));
// setIsError(true);
// isValid = false;
// break;
// }
// }

if (!validateTargetData(jsonData, sheetName, targetError)) {
// setShowInfoCard(true);
// isValid = false;
// break;
}
}
if(targetError.length >0){
if (targetError.length > 0) {
const errorMessage = targetError.join(", ");
setErrorsType((prevErrors) => ({
...prevErrors,
[type]: errorMessage,
}));
...prevErrors,
[type]: errorMessage,
}));
setShowInfoCard(true);
isValid =false;
}
else{
isValid = false;
} else {
setErrorsType((prevErrors) => ({
...prevErrors,
[type]: "", // Clear the error message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1365,9 +1365,14 @@ const SetupCampaign = ({ hierarchyType }) => {
// setting the current step when the key is changed on the basis of the config
useEffect(() => {
setCurrentStep(Number(filteredConfig?.[0]?.form?.[0]?.stepCount - 1));
setShowToast(null);
// setShowToast(null);
}, [currentKey, filteredConfig]);

useEffect(() => {
// setCurrentStep(Number(filteredConfig?.[0]?.form?.[0]?.stepCount - 1));
setShowToast(null);
}, [currentKey]);

const closeToast = () => {
setShowToast(null);
};
Expand Down

0 comments on commit b3a0b33

Please sign in to comment.