diff --git a/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/UploadData.js b/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/UploadData.js index f6d549b5623..a80ee93a53e 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/UploadData.js +++ b/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/UploadData.js @@ -48,6 +48,7 @@ const UploadData = ({ formData, onSelect, ...props }) => { const { data: Schemas, isLoading: isThisLoading } = Digit.Hooks.useCustomMDMS(tenantId, "HCM-ADMIN-CONSOLE", [{ name: "adminSchema" }]); const { data: readMe } = Digit.Hooks.useCustomMDMS(tenantId, "HCM-ADMIN-CONSOLE", [{ name: "ReadMeConfig" }]); + const { data: baseTimeOut } = Digit.Hooks.useCustomMDMS(tenantId, "HCM-ADMIN-CONSOLE", [{ name: "baseTimeOut" }]); const [sheetHeaders, setSheetHeaders] = useState({}); const [translatedSchema, setTranslatedSchema] = useState({}); const [readMeInfo, setReadMeInfo] = useState({}); @@ -711,13 +712,14 @@ const UploadData = ({ formData, onSelect, ...props }) => { setIsError(true); try { - const temp = await Digit.Hooks.campaign.useResourceData(uploadedFile, params?.hierarchyType, type, tenantId, id); + const temp = await Digit.Hooks.campaign.useResourceData(uploadedFile, params?.hierarchyType, type, tenantId, id , baseTimeOut?.["HCM-ADMIN-CONSOLE"]?.baseTimeOut?.[0]?.baseTimeOut); if (temp?.isError) { + setIsValidation(false); const errorMessage = temp?.error.replaceAll(":", "-"); setShowToast({ key: "error", label: errorMessage, transitionTime: 5000000 }); setIsError(true); setApiError(errorMessage); - setIsValidation(false); + return; } if (temp?.status === "completed") { diff --git a/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/configs/baseTimeOut.js b/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/configs/baseTimeOut.js new file mode 100644 index 00000000000..f0ff0ed19be --- /dev/null +++ b/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/configs/baseTimeOut.js @@ -0,0 +1,5 @@ +export const baseTimeOut = + { + baseTimeOut: 100 + }; + \ No newline at end of file diff --git a/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/useResourceData.js b/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/useResourceData.js index e5c489b2942..fb5e3cfbdd5 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/useResourceData.js +++ b/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/useResourceData.js @@ -1,5 +1,11 @@ -export const useResourceData = async (data, hierarchyType, type, tenantId, id) => { +import axios from 'axios'; +import * as XLSX from 'xlsx'; +import { baseTimeOut } from '../configs/baseTimeOut'; +export const useResourceData = async (data, hierarchyType, type, tenantId, id , baseTimeOut) => { + + let Type; + let jsonDataLength; let Error = { isError: false, error: {}, @@ -13,6 +19,29 @@ export const useResourceData = async (data, hierarchyType, type, tenantId, id) = Type = "boundaryWithTarget"; } try { + if(data){ + axios + .get("/filestore/v1/files/id", { + responseType: "arraybuffer", + headers: { + "Content-Type": "application/json", + Accept: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "auth-token": Digit.UserService.getUser()?.["access_token"], + }, + params: { + tenantId: Digit.ULBService.getCurrentTenantId(), + fileStoreId: data?.[0]?.filestoreId, + }, + }) + .then(async (res) => { + const fileData = res.data; + const workbook = XLSX.read(fileData, { type: 'buffer' }); + const sheetName = workbook.SheetNames[1]; + const worksheet = workbook.Sheets[sheetName]; + const jsonData = XLSX.utils.sheet_to_json(worksheet); + jsonDataLength = jsonData.length; + }); + } const responseTemp = await Digit.CustomService.getResponse({ url: "/project-factory/v1/data/_create", body: { @@ -27,7 +56,9 @@ export const useResourceData = async (data, hierarchyType, type, tenantId, id) = }, }, }); + response = responseTemp; + } catch (error) { if (error?.response && error?.response?.data) { const errorMessage = error?.response?.data?.Errors?.[0]?.message; @@ -46,6 +77,10 @@ export const useResourceData = async (data, hierarchyType, type, tenantId, id) = let searchResponse; let status = "validation-started"; + const baseDelay = baseTimeOut; + let retryInterval = baseDelay * jsonDataLength; + + await new Promise((resolve) => setTimeout(resolve, retryInterval)); // Retry until a response is received while (status !== "failed" && status !== "invalid" && status !== "completed") { @@ -61,7 +96,8 @@ export const useResourceData = async (data, hierarchyType, type, tenantId, id) = }); status = searchResponse?.ResourceDetails?.[0]?.status; if (status !== "failed" && status !== "invalid" && status !== "completed") { - await new Promise((resolve) => setTimeout(resolve, 5000)); + retryInterval *= 2; + await new Promise((resolve) => setTimeout(resolve, retryInterval)); } } if (Error.isError) {