From e42053afae02bd643a164aa7848b063020222842 Mon Sep 17 00:00:00 2001 From: mithunhegde-egov <152362871+mithunhegde-egov@users.noreply.github.com> Date: Thu, 3 Oct 2024 11:46:31 +0530 Subject: [PATCH] Upload api update (#1449) * upload error message bug * logo mobile css and upload success message * upload labels changed * error message when no file is added * toast message time out and error checks * css version upgrade * review changes * remov unused state variables --------- Co-authored-by: nabeelmd-eGov --- .../packages/css/package.json | 2 +- .../css/src/pages/employee/sandbox.scss | 8 ++++++- .../tenantMgmt/ConfigUploaderComponent.js | 4 ++++ .../tenantMgmt/LogoUploaderComponent.js | 11 +++++++--- .../employee/tenantMgmt/TenantConfigUpload.js | 22 +++++++++++++++++-- micro-ui/web/public/index.html | 2 +- 6 files changed, 41 insertions(+), 8 deletions(-) diff --git a/micro-ui/web/micro-ui-internals/packages/css/package.json b/micro-ui/web/micro-ui-internals/packages/css/package.json index 75e3465310a..1f8a84d6783 100644 --- a/micro-ui/web/micro-ui-internals/packages/css/package.json +++ b/micro-ui/web/micro-ui-internals/packages/css/package.json @@ -1,6 +1,6 @@ { "name": "@egovernments/digit-ui-css", - "version": "1.8.2-beta.33", + "version": "1.8.2-beta.34", "license": "MIT", "main": "dist/index.css", "author": "Jagankumar ", diff --git a/micro-ui/web/micro-ui-internals/packages/css/src/pages/employee/sandbox.scss b/micro-ui/web/micro-ui-internals/packages/css/src/pages/employee/sandbox.scss index fd57fc82adf..2c6596859eb 100644 --- a/micro-ui/web/micro-ui-internals/packages/css/src/pages/employee/sandbox.scss +++ b/micro-ui/web/micro-ui-internals/packages/css/src/pages/employee/sandbox.scss @@ -379,11 +379,17 @@ .digit-topbar-ulb { .state { - width: 80px; + width: 5rem; height: 19px; } } +.digit-topbar .digit-header-img-ulb-wrapper-mobileview .digit-topbar-ulb-mobileview { + .state { + width: 5rem; + height: 19px; + } +} .digit-popup-footer.masterHandlerPopUpFooter { .digit-popup-footer-buttons { margin-left: unset; diff --git a/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/ConfigUploaderComponent.js b/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/ConfigUploaderComponent.js index bd1f7079348..c1d2d613d1b 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/ConfigUploaderComponent.js +++ b/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/ConfigUploaderComponent.js @@ -11,6 +11,7 @@ const ConfigUploaderComponent = ({ onSelect, ...props }) => { const [file, setFile] = useState(null); const [fileStoreId, setFileStoreId] = useState(null); const tenantId = Digit.ULBService.getCurrentTenantId(); + const [uploadErrorMessage, setUploadErrorMessage] = useState(""); const { t } = useTranslation(); @@ -20,9 +21,11 @@ const ConfigUploaderComponent = ({ onSelect, ...props }) => { const response = await Digit.UploadServices.Filestorage("Sandbox", file, tenantId); const fileStoreId = response?.data?.files?.[0]?.fileStoreId; setFileStoreId(fileStoreId) + setUploadErrorMessage(""); } catch (error) { setToastMessage(t("BANNER_UPLOAD_FAILED")); setIsError(true); + setUploadErrorMessage(t("BANNER_UPLOAD_FAILED")); setShowToast(true); setTimeout(() => { setShowToast(false); @@ -56,6 +59,7 @@ const ConfigUploaderComponent = ({ onSelect, ...props }) => { uploadedFiles={[]} variant="uploadFile" onUpload={(files) => selectFile(files)} + iserror={uploadErrorMessage} accept="image/*, .jpg, .png, .jpeg" // if (files && files.length > 0) { // handleUploadFile(files); diff --git a/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/LogoUploaderComponent.js b/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/LogoUploaderComponent.js index ce0a0be3251..d7751f0b82d 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/LogoUploaderComponent.js +++ b/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/LogoUploaderComponent.js @@ -5,25 +5,29 @@ import { useTranslation } from "react-i18next"; import { Fragment } from "react"; const LogoUploaderComponent = ({ onSelect, ...props }) => { - const [file, setFile] = useState(null); - const [fileStoreId, setFileStoreId] = useState(null); const [showToast, setShowToast] = useState(null); const [toastMessage, setToastMessage] = useState(""); const [isError, setIsError] = useState(false); + const [file, setFile] = useState(null); + const [fileStoreId, setFileStoreId] = useState(null); const tenantId = Digit.ULBService.getCurrentTenantId(); + const [uploadErrorMessage, setUploadErrorMessage] = useState(""); const { t } = useTranslation(); + const handleUploadFile = async () => { // Upload the file first try { const response = await Digit.UploadServices.Filestorage("Sandbox", file, tenantId); const fileStoreId = response?.data?.files?.[0]?.fileStoreId; setFileStoreId(fileStoreId) + setUploadErrorMessage(""); } catch (error) { setToastMessage(t("LOGO_UPLOAD_FAILED")); setIsError(true); + setUploadErrorMessage(t("LOGO_UPLOAD_FAILED")); setShowToast(true); setTimeout(() => { - closeToast(); + setShowToast(false); }, 2000); } }; @@ -52,6 +56,7 @@ const LogoUploaderComponent = ({ onSelect, ...props }) => { uploadedFiles={[]} variant="uploadFile" onUpload={(files) => selectFile(files)} + iserror={uploadErrorMessage} accept="image/*, .jpg, .png, .jpeg" // if (files && files.length > 0) { // handleUploadFile(files); diff --git a/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/TenantConfigUpload.js b/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/TenantConfigUpload.js index 576fec24bc3..ec3d49705db 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/TenantConfigUpload.js +++ b/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/pages/employee/tenantMgmt/TenantConfigUpload.js @@ -17,6 +17,7 @@ const TenantConfigUpload = () => { const [isError, setIsError] = useState(false); const [uploadData, setUploadData] = useState([]); // State to store the uploaded data const [tenantDocument, setDocuments] = useState([]); + const mutation = Digit.Hooks.useCustomAPIMutationHook({ @@ -74,6 +75,20 @@ const TenantConfigUpload = () => { type: data[key]?.type, }; }); + + const isBannerUndefined = documents.find(doc => doc.type === "bannerUrl")?.fileStoreId === undefined; + const isLogoUndefined = documents.find(doc => doc.type === "logoUrl")?.fileStoreId === undefined; + + if (isBannerUndefined && isLogoUndefined) { + setToastMessage(t("BOTH_FILESTOREIDS_ARE_UNDEFINED")); + setIsError(true); + setShowToast(true); + setTimeout(() => { + setShowToast(false); + }, 2000); + return; + } + setUploadData(documents); }; @@ -127,12 +142,12 @@ const TenantConfigUpload = () => { }, { onError: (error) => { - setToastMessage(error.message || t("ERROR_MESSAGE")); + setToastMessage(error.message || t("CONFIG_UPLOAD_ERROR_MESSAGE")); setIsError(true); setShowToast(true); }, onSuccess: () => { - setToastMessage(t("SANDBOX_TENANT_CREATE_SUCCESS_TOAST")); + setToastMessage(t("CONFIG_UPLOAD_SUCCESSFUL_TOAST_MESSAGE")); setIsError(false); setShowToast(true); setTimeout(() => { @@ -146,6 +161,9 @@ const TenantConfigUpload = () => { setToastMessage(error.message); setIsError(true); setShowToast(true); + setTimeout(() => { + setShowToast(false); + }, 2000); } }; diff --git a/micro-ui/web/public/index.html b/micro-ui/web/public/index.html index 5a71694e767..9a752021fbe 100644 --- a/micro-ui/web/public/index.html +++ b/micro-ui/web/public/index.html @@ -7,7 +7,7 @@ - +