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

HLM-6270: Elimated Generate API & enhance download API, Date logic fixes #966

Merged
merged 4 commits into from
Jun 27, 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 @@ -887,42 +887,6 @@ const UploadData = ({ formData, onSelect, ...props }) => {
fetchData();
}, [errorsType]);

const { data: facilityId, isLoading: isFacilityLoading, refetch: refetchFacility } = Digit.Hooks.campaign.useGenerateIdCampaign({
type: "facilityWithBoundary",
hierarchyType: params?.hierarchyType,
campaignId: id,
// config: {
// enabled: setTimeout(fetchUpload || (fetchBoundary && currentKey > 6)),
// },
config: {
enabled: enabled,
},
});

const { data: boundaryId, isLoading: isBoundaryLoading, refetch: refetchBoundary } = Digit.Hooks.campaign.useGenerateIdCampaign({
type: "boundary",
hierarchyType: params?.hierarchyType,
campaignId: id,
// config: {
// enabled: fetchUpload || (fetchBoundary && currentKey > 6),
// },
config: {
enabled: enabled,
},
});

const { data: userId, isLoading: isUserLoading, refetch: refetchUser } = Digit.Hooks.campaign.useGenerateIdCampaign({
type: "userWithBoundary",
hierarchyType: params?.hierarchyType,
campaignId: id,
// config: {
// enabled: fetchUpload || (fetchBoundary && currentKey > 6),
// },
config: {
enabled: enabled,
},
});

const Template = {
url: "/project-factory/v1/data/_download",
params: {
Expand All @@ -935,35 +899,35 @@ const UploadData = ({ formData, onSelect, ...props }) => {
const mutation = Digit.Hooks.useCustomAPIMutationHook(Template);

const downloadTemplate = async () => {
if (type === "boundary" && params?.isBoundaryLoading) {
setDownloadError(true);
setShowToast({ key: "info", label: t("HCM_PLEASE_WAIT_TRY_IN_SOME_TIME") });
return;
}
if (type === "facilityWithBoundary" && params?.isFacilityLoading) {
setDownloadError(true);
setShowToast({ key: "info", label: t("HCM_PLEASE_WAIT_TRY_IN_SOME_TIME") });
return;
}
if (type === "userWithBoundary" && params?.isUserLoading) {
setDownloadError(true);
setShowToast({ key: "info", label: t("HCM_PLEASE_WAIT_TRY_IN_SOME_TIME") });
return;
}
if (!params?.boundaryId || !params?.facilityId || !params?.userId) {
setEnabled(true);
// if (type === "boundary" && params?.isBoundaryLoading) {
// setDownloadError(true);
// setShowToast({ key: "info", label: t("HCM_PLEASE_WAIT_TRY_IN_SOME_TIME") });
// return;
// }
// if (type === "facilityWithBoundary" && params?.isFacilityLoading) {
// setDownloadError(true);
// setShowToast({ key: "info", label: t("HCM_PLEASE_WAIT_TRY_IN_SOME_TIME") });
// return;
// }
// if (type === "userWithBoundary" && params?.isUserLoading) {
// setDownloadError(true);
// setShowToast({ key: "info", label: t("HCM_PLEASE_WAIT_TRY_IN_SOME_TIME") });
// return;
// }
// if (!params?.boundaryId || !params?.facilityId || !params?.userId) {
// setEnabled(true);

setDownloadError(true);
setShowToast({ key: "info", label: t("HCM_PLEASE_WAIT_TRY_IN_SOME_TIME") });
return;
}
// setDownloadError(true);
// setShowToast({ key: "info", label: t("HCM_PLEASE_WAIT_TRY_IN_SOME_TIME") });
// return;
// }
await mutation.mutate(
{
params: {
tenantId: tenantId,
type: type,
hierarchyType: params?.hierarchyType,
id: type === "boundary" ? params?.boundaryId : type === "facilityWithBoundary" ? params?.facilityId : params?.userId,
campaignId: id,
},
},
{
Expand All @@ -973,6 +937,11 @@ const UploadData = ({ formData, onSelect, ...props }) => {
setShowToast({ key: "error", label: t("ERROR_WHILE_DOWNLOADING") });
return;
}
if (result?.GeneratedResource?.[0]?.status === "inprogress") {
setDownloadError(true);
setShowToast({ key: "info", label: t("HCM_PLEASE_WAIT_TRY_IN_SOME_TIME") });
return;
}
if (!result?.GeneratedResource?.[0]?.fileStoreid || result?.GeneratedResource?.length == 0) {
setDownloadError(true);
setShowToast({ key: "info", label: t("HCM_PLEASE_WAIT_TRY_IN_SOME_TIME") });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export const UICustomizations = {
status: ["creating", "created"],
createdBy: Digit.UserService.getUser().info.uuid,
campaignsIncludeDates: true,
startDate: Date.now(),
endDate: Date.now(),
startDate: Digit.Utils.pt.convertDateToEpoch(new Date().toISOString().split("T")[0], "daystart"),
endDate: Digit.Utils.pt.convertDateToEpoch(new Date().toISOString().split("T")[0]),
pagination: {
sortBy: "createdTime",
sortOrder: "desc",
Expand Down Expand Up @@ -114,7 +114,7 @@ export const UICustomizations = {
data.body.CampaignDetails = {
tenantId: tenantId,
status: ["creating", "created"],
endDate: Date.now() - 24 * 60 * 60 * 1000,
endDate: Digit.Utils.pt.convertDateToEpoch(new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString().split("T")[0]),
createdBy: Digit.UserService.getUser().info.uuid,
pagination: {
sortBy: "createdTime",
Expand Down Expand Up @@ -207,7 +207,7 @@ export const UICustomizations = {
status: ["creating", "created"],
createdBy: Digit.UserService.getUser().info.uuid,
campaignsIncludeDates: false,
startDate: Date.now() + 24 * 60 * 60 * 1000,
startDate: Digit.Utils.pt.convertDateToEpoch(new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString().split("T")[0], "daystart"),
pagination: {
sortBy: "createdTime",
sortOrder: "desc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ const SetupCampaign = ({ hierarchyType }) => {
const [userEnabled, setUserEnabled] = useState(false);
const [active, setActive] = useState(0);
const { data: hierarchyConfig } = Digit.Hooks.useCustomMDMS(tenantId, "HCM-ADMIN-CONSOLE", [{ name: "hierarchyConfig" }]);
const [refetchGenerate, setRefetchGenerate] = useState(null);
// const [refetchGenerate, setRefetchGenerate] = useState(null);
// const hierarchyType = hierarchyConfig?.["HCM-ADMIN-CONSOLE"]?.hierarchyConfig?.[0]?.hierarchy;

// const lowestHierarchy = hierarchyConfig?.["HCM-ADMIN-CONSOLE"]?.hierarchyConfig?.[0]?.lowestHierarchy;
Expand Down Expand Up @@ -403,53 +403,53 @@ const SetupCampaign = ({ hierarchyType }) => {
setParams({ ...restructureFormData });
}, [params, draftData, isLoading, projectType]);

useEffect(() => {
setTimeout(() => {
setEnabled(fetchUpload || (fetchBoundary && currentKey > 3));
setFacilityEnabled(refetchGenerate || (!dataParams?.boundaryId && (fetchUpload || (fetchBoundary && currentKey > 3))));
setTargetEnabled(refetchGenerate || (!dataParams?.facilityId && (fetchUpload || (fetchBoundary && currentKey > 3))));
setUserEnabled(refetchGenerate || (!dataParams?.userId && (fetchUpload || (fetchBoundary && currentKey > 3))));
}, 3000);
if (refetchGenerate === true) {
setRefetchGenerate(false);
}
}, [fetchUpload, fetchBoundary, currentKey, dataParams, refetchGenerate]);

const { data: facilityId, isLoading: isFacilityLoading, refetch: refetchFacility } = Digit.Hooks.campaign.useGenerateIdCampaign({
type: "facilityWithBoundary",
hierarchyType: hierarchyType,
campaignId: id,
// config: {
// enabled: setTimeout(fetchUpload || (fetchBoundary && currentKey > 6)),
// },
config: {
enabled: facilityEnabled,
},
});

const { data: boundaryId, isLoading: isBoundaryLoading, refetch: refetchBoundary } = Digit.Hooks.campaign.useGenerateIdCampaign({
type: "boundary",
hierarchyType: hierarchyType,
campaignId: id,
// config: {
// enabled: fetchUpload || (fetchBoundary && currentKey > 6),
// },
config: {
enabled: targetEnabled,
},
});

const { data: userId, isLoading: isUserLoading, refetch: refetchUser } = Digit.Hooks.campaign.useGenerateIdCampaign({
type: "userWithBoundary",
hierarchyType: hierarchyType,
campaignId: id,
// config: {
// enabled: fetchUpload || (fetchBoundary && currentKey > 6),
// },
config: {
enabled: userEnabled,
},
});
// useEffect(() => {
// setTimeout(() => {
// setEnabled(fetchUpload || (fetchBoundary && currentKey > 3));
// setFacilityEnabled(refetchGenerate || (!dataParams?.boundaryId && (fetchUpload || (fetchBoundary && currentKey > 3))));
// setTargetEnabled(refetchGenerate || (!dataParams?.facilityId && (fetchUpload || (fetchBoundary && currentKey > 3))));
// setUserEnabled(refetchGenerate || (!dataParams?.userId && (fetchUpload || (fetchBoundary && currentKey > 3))));
// }, 3000);
// if (refetchGenerate === true) {
// setRefetchGenerate(false);
// }
// }, [fetchUpload, fetchBoundary, currentKey, dataParams, refetchGenerate]);

// const { data: facilityId, isLoading: isFacilityLoading, refetch: refetchFacility } = Digit.Hooks.campaign.useGenerateIdCampaign({
// type: "facilityWithBoundary",
// hierarchyType: hierarchyType,
// campaignId: id,
// // config: {
// // enabled: setTimeout(fetchUpload || (fetchBoundary && currentKey > 6)),
// // },
// config: {
// enabled: facilityEnabled,
// },
// });

// const { data: boundaryId, isLoading: isBoundaryLoading, refetch: refetchBoundary } = Digit.Hooks.campaign.useGenerateIdCampaign({
// type: "boundary",
// hierarchyType: hierarchyType,
// campaignId: id,
// // config: {
// // enabled: fetchUpload || (fetchBoundary && currentKey > 6),
// // },
// config: {
// enabled: targetEnabled,
// },
// });

// const { data: userId, isLoading: isUserLoading, refetch: refetchUser } = Digit.Hooks.campaign.useGenerateIdCampaign({
// type: "userWithBoundary",
// hierarchyType: hierarchyType,
// campaignId: id,
// // config: {
// // enabled: fetchUpload || (fetchBoundary && currentKey > 6),
// // },
// config: {
// enabled: userEnabled,
// },
// });

useEffect(() => {
if (draftData?.additionalDetails?.facilityId && draftData?.additionalDetails?.targetId && draftData?.additionalDetails?.userId) {
Expand All @@ -462,24 +462,17 @@ const SetupCampaign = ({ hierarchyType }) => {
hierarchy: hierarchyDefinition?.BoundaryHierarchy?.[0],
});
}
}, [isBoundaryLoading, isFacilityLoading, isUserLoading, facilityId, boundaryId, userId, hierarchyDefinition?.BoundaryHierarchy?.[0], draftData]); // Only run if dataParams changes

}, [hierarchyDefinition?.BoundaryHierarchy?.[0], draftData]); // Only run if dataParams changes

useEffect(() => {
if (hierarchyDefinition?.BoundaryHierarchy?.[0]) {
if (hierarchyDefinition?.BoundaryHierarchy?.[0]) {
setDataParams({
...dataParams,
facilityId: facilityId,
boundaryId: boundaryId,
userId: userId,
hierarchyType: hierarchyType,
hierarchy: hierarchyDefinition?.BoundaryHierarchy?.[0],
isBoundaryLoading,
isFacilityLoading,
isUserLoading,
});
}
}, [isBoundaryLoading, isFacilityLoading, isUserLoading, facilityId, boundaryId, userId, hierarchyDefinition?.BoundaryHierarchy?.[0], draftData]);
}, [hierarchyDefinition?.BoundaryHierarchy?.[0], draftData]);
useEffect(() => {
setCampaignConfig(CampaignConfig(totalFormData, dataParams, isSubmitting, summaryErrors));
}, [totalFormData, dataParams, isSubmitting, summaryErrors]);
Expand Down Expand Up @@ -1096,7 +1089,7 @@ const SetupCampaign = ({ hierarchyType }) => {
totalFormData?.HCM_CAMPAIGN_SELECTING_BOUNDARY_DATA?.boundaryType?.selectedData
);
setFetchUpload(true);
setRefetchGenerate(checkEqual === false ? true : false);
// setRefetchGenerate(checkEqual === false ? true : false);
return true;
} else {
setShowToast({ key: "error", label: `${t("HCM_SELECT_BOUNDARY")}` });
Expand Down
Loading