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

User upload changes #1546

Merged
merged 3 commits into from
Oct 17, 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 @@ -80,24 +80,31 @@ export const useResourceData = async (data, hierarchyType, type, tenantId, id ,
const baseDelay = baseTimeOut?.baseTimeout?.[0]?.baseTimeOut;
const maxTime = baseTimeOut?.baseTimeout?.[0]?.maxTime;
let retryInterval = Math.min(baseDelay * jsonDataLength , maxTime);
if(typeof retryInterval !== "number"){
retryInterval = 1000;
}
Comment on lines +83 to +85
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure retryInterval is a valid finite number

The condition if(typeof retryInterval !== "number") may not correctly handle cases where retryInterval is NaN or Infinity, since typeof NaN and typeof Infinity both return "number". This means that if retryInterval is not a finite number, it won't be reset to 1000 as intended.

Consider using if(!isFinite(retryInterval)) to check for non-finite numbers.

Apply this diff to improve the type checking:

-if(typeof retryInterval !== "number"){
+if(!isFinite(retryInterval)){
   retryInterval = 1000;
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if(typeof retryInterval !== "number"){
retryInterval = 1000;
}
if(!isFinite(retryInterval)){
retryInterval = 1000;
}


await new Promise((resolve) => setTimeout(resolve, retryInterval));

// Retry until a response is received
while (status !== "failed" && status !== "invalid" && status !== "completed") {
searchResponse = await Digit.CustomService.getResponse({
url: "/project-factory/v1/data/_search",
body: {
SearchCriteria: {
id: [response?.ResourceDetails?.id],
tenantId: tenantId,
type: Type,
try {
searchResponse = await Digit.CustomService.getResponse({
url: "/project-factory/v1/data/_search",
body: {
SearchCriteria: {
id: [response?.ResourceDetails?.id],
tenantId: tenantId,
type: Type,
},
},
},
});
status = searchResponse?.ResourceDetails?.[0]?.status;
if (status !== "failed" && status !== "invalid" && status !== "completed") {
await new Promise((resolve) => setTimeout(resolve, retryInterval));
});
status = searchResponse?.ResourceDetails?.[0]?.status;
if (status !== "failed" && status !== "invalid" && status !== "completed") {
await new Promise((resolve) => setTimeout(resolve, retryInterval));
}
} catch (error) {
console.error("Error while fetching data:", error);
ashish-egov marked this conversation as resolved.
Show resolved Hide resolved
}
}
if (Error.isError) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ const UploadDataCustom = React.memo(({ formData, onSelect, ...props }) => {
const fileData = fileUrl?.map((i) => {
const urlParts = i?.url?.split("/");
// const fileName = urlParts[urlParts?.length - 1]?.split("?")?.[0];
const fileName = type === "boundary" ? "Target Template" : type === "facilityWithBoundary" ? "Facility Template" : "User Template";
const fileName = type === "boundary" ? "Population Template" : type === "facilityWithBoundary" ? "Facility Template" : "User Template";
ashish-egov marked this conversation as resolved.
Show resolved Hide resolved
return {
...i,
filename: fileName,
Expand Down Expand Up @@ -789,18 +789,18 @@ const UploadDataCustom = React.memo(({ formData, onSelect, ...props }) => {
footerclassName={"popUpFooter"}
heading={
type === "boundary"
? t("ES_CAMPAIGN_UPLOAD_BOUNDARY_DATA_MODAL_HEADER")
? t("MP_CAMPAIGN_UPLOAD_BOUNDARY_DATA_MODAL_HEADER")
: type === "facilityWithBoundary"
? t("ES_CAMPAIGN_UPLOAD_FACILITY_DATA_MODAL_HEADER")
: t("ES_CAMPAIGN_UPLOAD_USER_DATA_MODAL_HEADER")
? t("MP_CAMPAIGN_UPLOAD_FACILITY_DATA_MODAL_HEADER")
: t("MP_CAMPAIGN_UPLOAD_USER_DATA_MODAL_HEADER")
ashish-egov marked this conversation as resolved.
Show resolved Hide resolved
}
children={[
<div>
{type === "boundary"
? t("ES_CAMPAIGN_UPLOAD_BOUNDARY_DATA_MODAL_TEXT")
? t("MP_CAMPAIGN_UPLOAD_BOUNDARY_DATA_MODAL_TEXT")
: type === "facilityWithBoundary"
? t("ES_CAMPAIGN_UPLOAD_FACILITY_DATA_MODAL_TEXT")
: t("ES_CAMPAIGN_UPLOAD_USER_DATA_MODAL_TEXT ")}
? t("MP_CAMPAIGN_UPLOAD_FACILITY_DATA_MODAL_TEXT")
: t("MP_CAMPAIGN_UPLOAD_USER_DATA_MODAL_TEXT ")}
ashish-egov marked this conversation as resolved.
Show resolved Hide resolved
</div>,
]}
onOverlayClick={() => {
Expand All @@ -811,7 +811,7 @@ const UploadDataCustom = React.memo(({ formData, onSelect, ...props }) => {
type={"button"}
size={"large"}
variation={"secondary"}
label={t("HCM_CAMPAIGN_UPLOAD_CANCEL")}
label={t("MP_CAMPAIGN_UPLOAD_SKIP")}
ashish-egov marked this conversation as resolved.
Show resolved Hide resolved
onClick={() => {
setShowPopUp(false);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useTranslation } from "react-i18next";
import { InfoCard, PopUp, Toast, Button, Stepper, TextBlock, Card } from "@egovernments/digit-ui-components";
import { ActionBar, SubmitBar } from "@egovernments/digit-ui-react-components";
import axios from "axios";
import { Link } from "react-router-dom";
import { Link, useHistory } from "react-router-dom";
import { ArrowBack } from "@egovernments/digit-ui-svg-components";


Expand All @@ -21,6 +21,7 @@ const UserUpload = React.memo(() => {
const { t } = useTranslation();
const tenantId = Digit.ULBService.getCurrentTenantId();
const [uploadedFile, setUploadedFile] = useState([]);
const history = useHistory();
const [errorsType, setErrorsType] = useState({});
const [showToast, setShowToast] = useState(null);
const [sheetErrors, setSheetErrors] = useState(0);
Expand Down Expand Up @@ -66,14 +67,13 @@ const UserUpload = React.memo(() => {
setShowToast(null);
};

useEffect(() => {
useEffect(async () => {
ashish-egov marked this conversation as resolved.
Show resolved Hide resolved
const fetchData = async () => {
if (!errorsType[type] && uploadedFile?.length > 0 && !isSuccess) {
// setShowToast({ key: "info", label: t("HCM_VALIDATION_IN_PROGRESS") });
setIsValidation(true);
// setIsError(true);
setLoader(true);

try {
const temp = await Digit.Hooks.campaign.useResourceData(
uploadedFile,
Expand Down Expand Up @@ -189,7 +189,7 @@ const UserUpload = React.memo(() => {
}
};

fetchData();
await fetchData();
}, [errorsType]);

const onBulkUploadSubmit = async (file) => {
Expand Down Expand Up @@ -366,6 +366,57 @@ const UserUpload = React.memo(() => {
generateData();
}, [id, boundaryHierarchy]);

const onSubmit = async () => {
setDownloadTemplateLoader(true);
if (isSuccess && uploadedFile?.length > 0 && uploadedFile?.[0]?.filestoreId) {
const fileId = uploadedFile?.[0]?.filestoreId;
const ts = new Date().getTime();
const reqCriteria = {
url: `/project-factory/v1/data/_create`,
body: {
RequestInfo: {
authToken: Digit.UserService.getUser().access_token,
msgId: `${ts}|${Digit.StoreData.getCurrentLanguage()}`
},
ResourceDetails: {
tenantId: Digit.ULBService.getCurrentTenantId(),
type: "user",
fileStoreId: fileId,
hierarchyType: boundaryHierarchy,
campaignId: id,
action: "create",
campaignId: id,
ashish-egov marked this conversation as resolved.
Show resolved Hide resolved
additionalDetails: {
source: "microplan"
}
}
}
}
try {
await axios.post(reqCriteria.url, reqCriteria.body);
} catch (error) {
var errorLabel;
ashish-egov marked this conversation as resolved.
Show resolved Hide resolved
if (error?.response && error?.response?.data) {
ashish-egov marked this conversation as resolved.
Show resolved Hide resolved
const errorMessage = error?.response?.data?.Errors?.[0]?.message;
const errorDescription = error?.response?.data?.Errors?.[0]?.description;
if (errorDescription) {
errorLabel = `${errorMessage} : ${errorDescription}`;
} else {
errorLabel = String(error?.message);
}
}
console.error("Error fetching data:", error);
setShowToast({ key: "error", label: errorLabel });
setDownloadTemplateLoader(false);
return;
}
history.push(`/${window.contextPath}/employee/microplan/upload-user-success`);
}
else {
setShowToast({ key: "error", label: t("ERROR_MANDATORY_FIELDS_FOR_SUBMIT") });
}
setDownloadTemplateLoader(false);
}

return (
<>
Expand All @@ -376,7 +427,7 @@ const UserUpload = React.memo(() => {
<Card>
<div className="campaign-bulk-upload">
<Header className="digit-form-composer-sub-header">
{t("WBH_UPLOAD_USER")}
{t("MP_UPLOAD_USER")}
ashish-egov marked this conversation as resolved.
Show resolved Hide resolved
</Header>
<Button
label={t("WBH_DOWNLOAD_TEMPLATE")}
Expand All @@ -389,7 +440,7 @@ const UserUpload = React.memo(() => {
</div>
{uploadedFile.length === 0 && (
<div className="info-text">
{t("HCM_USER_MESSAGE")}
{t("MP_USER_MESSAGE")}
ashish-egov marked this conversation as resolved.
Show resolved Hide resolved
</div>
)}
<BulkUpload onSubmit={onBulkUploadSubmit} fileData={uploadedFile} onFileDelete={onFileDelete} onFileDownload={onFileDownload} />
Expand Down Expand Up @@ -460,29 +511,26 @@ const UserUpload = React.memo(() => {
)}
{showPreview && <XlsPreview file={processedFile?.[0]} onDownload={() => onFileDownload(processedFile?.[0])} onBack={() => setShowPreview(false)} />}
</div>
<ActionBar className={"custom-action-bar-success-screen"}>
{/* Back button */}
<Button
type="button"
className="custom-button custom-button-left-icon"
label={t("GO_BACK_HOME")}
// onButtonClick={clickGoHome}
isSuffix={false}
variation={"secondary"}
icon={<ArrowBack className={"icon"} width={"1.5rem"} height={"1.5rem"} />}
/>
{/* Next/Submit button */}
<a style={{ textDecoration: "none" }} href={"/workbench-ui/employee/"}>
<ActionBar style={{ display: "flex", justifyContent: "space-between", alignItems: "center", width: "100%", zIndex: "1" }}>
<Link to="/microplan-ui/employee/microplan/user-management" style={{ textDecoration: "none" }}>
<Button
type="button"
className="custom-button"
label={t("GO_TO_HCM")}
isSuffix={true}
variation={"primary"}
textStyles={{ padding: 0, margin: 0 }}
style={{ margin: "0.5rem", minWidth: "12rem", marginLeft: "6rem" }}
className="previous-button"
variation="secondary"
label={t("BACK")}
icon={"ArrowBack"}
/>
</a>
</Link>
<Button
ashish-egov marked this conversation as resolved.
Show resolved Hide resolved
style={{ margin: "0.5rem", minWidth: "12rem" }}
className="next-button"
variation="primary"
label={t("SUBMIT")}
onClick={onSubmit}
/>
</ActionBar>


</>
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const UserManagementConfig = {
"links": [
{
"text": "BULK_UPLOAD_USERS",
"url": "/employee",
"url": "/employee/microplan/upload-user",
ashish-egov marked this conversation as resolved.
Show resolved Hide resolved
"roles": [
"MICROPLAN_ADMIN"
]
Expand Down