Skip to content

Commit

Permalink
User upload changes (#1546)
Browse files Browse the repository at this point in the history
* Added userscreen changes

* Update health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/useResourceData.js

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

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
ashish-egov and coderabbitai[bot] authored Oct 17, 2024
1 parent 28729a9 commit 649f09c
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 47 deletions.
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;
}

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);
}
}
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";
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")
}
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 ")}
</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")}
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 () => {
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,
additionalDetails: {
source: "microplan"
}
}
}
}
try {
await axios.post(reqCriteria.url, reqCriteria.body);
} catch (error) {
var errorLabel;
if (error?.response && error?.response?.data) {
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")}
</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")}
</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
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",
"roles": [
"MICROPLAN_ADMIN"
]
Expand Down

0 comments on commit 649f09c

Please sign in to comment.