Skip to content

Commit

Permalink
Upload api update (#1449)
Browse files Browse the repository at this point in the history
* 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 <nabeel.md@egovernments.org>
  • Loading branch information
mithunhegde-egov and nabeelmd-eGov authored Oct 3, 2024
1 parent 8e7a305 commit e42053a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion micro-ui/web/micro-ui-internals/packages/css/package.json
Original file line number Diff line number Diff line change
@@ -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 <jagan.kumar@egov.org.in>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();


Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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);
};

Expand Down Expand Up @@ -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(() => {
Expand All @@ -146,6 +161,9 @@ const TenantConfigUpload = () => {
setToastMessage(error.message);
setIsError(true);
setShowToast(true);
setTimeout(() => {
setShowToast(false);
}, 2000);
}
};

Expand Down
2 changes: 1 addition & 1 deletion micro-ui/web/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<link
href="https://fonts.googleapis.com/css2?family=Roboto+Condensed:wght@400;500;700&family=Roboto:wght@400;500;700&display=swap"
rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="https://unpkg.com/@egovernments/digit-ui-css@1.8.2-beta.33/dist/index.css" />
<link rel="stylesheet" href="https://unpkg.com/@egovernments/digit-ui-css@1.8.2-beta.34/dist/index.css" />
<link rel="stylesheet" href="https://unpkg.com/@egovernments/digit-ui-components-css@0.0.2-beta.34/dist/index.css"/>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#00bcd1" />
Expand Down

0 comments on commit e42053a

Please sign in to comment.