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

fixed validation logic #846

Merged
merged 2 commits into from
Jun 12, 2024
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
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
Loading