Skip to content

Commit

Permalink
Update UploadDataCustom.js (#1528)
Browse files Browse the repository at this point in the history
* Update UploadDataCustom.js

* Update health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UploadDataCustom.js

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

* Update UploadDataCustom.js

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
ashish-egov and coderabbitai[bot] authored Oct 16, 2024
1 parent 7bea7bb commit f887c42
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const UploadDataCustom = React.memo(({ formData, onSelect, ...props }) => {
const [resourceId, setResourceId] = useState(null);
const [showPreview, setShowPreview] = useState(false);
// TODO : Remove hard coded id
const id = searchParams.get("campaignId") || "274f60e0-f6d8-4bf9-b4da-a714a9046e93";
const id = searchParams.get("campaignId") || null;
const { data: Schemas, isLoading: isThisLoading } = Digit.Hooks.useCustomMDMS(
tenantId,
"HCM-ADMIN-CONSOLE",
Expand Down Expand Up @@ -125,9 +125,8 @@ const UploadDataCustom = React.memo(({ formData, onSelect, ...props }) => {
}
}, [type, props?.props?.sessionData]);


useEffect(() => {
const fetchData = async () => {
const generateData = async () => {
if(boundaryHierarchy && type && id) {
const ts = new Date().getTime();
const reqCriteria = {
url: `/project-factory/v1/data/_generate`,
Expand All @@ -154,11 +153,13 @@ const UploadDataCustom = React.memo(({ formData, onSelect, ...props }) => {
} catch (error) {
console.error("Error fetching data:", error);
}
};
if(boundaryHierarchy && downloadError){
fetchData();
}
}, [type, boundaryHierarchy, downloadError]);
};


useEffect(() => {
generateData();
}, [type, boundaryHierarchy, id]);


useEffect(() => {
Expand Down Expand Up @@ -584,6 +585,7 @@ const UploadDataCustom = React.memo(({ formData, onSelect, ...props }) => {
onSuccess: async (result) => {
if (result?.GeneratedResource?.[0]?.status === "failed") {
setDownloadError(true);
generateData();
setShowToast({ key: "error", label: t("ERROR_WHILE_DOWNLOADING") });
return;
}
Expand All @@ -594,7 +596,8 @@ const UploadDataCustom = React.memo(({ formData, onSelect, ...props }) => {
}
if (!result?.GeneratedResource?.[0]?.fileStoreid || result?.GeneratedResource?.length == 0) {
setDownloadError(true);
setShowToast({ key: "info", label: t("HCM_PLEASE_WAIT_TRY_IN_SOME_TIME") });
generateData();
setShowToast({ key: "info", label: t("ERROR_WHILE_DOWNLOADING") });
return;
}
const filesArray = [result?.GeneratedResource?.[0]?.fileStoreid];
Expand All @@ -616,11 +619,12 @@ const UploadDataCustom = React.memo(({ formData, onSelect, ...props }) => {
}
} else {
setDownloadError(true);
setShowToast({ key: "info", label: t("HCM_PLEASE_WAIT") });
setShowToast({ key: "info", label: t("ERROR_WHILE_DOWNLOADING_FROM_FILESTORE") });
}
},
onError: (result) => {
setDownloadError(true);
generateData();
setShowToast({ key: "error", label: t("ERROR_WHILE_DOWNLOADING") });
},
}
Expand Down

0 comments on commit f887c42

Please sign in to comment.