Skip to content

Commit

Permalink
fix: Show validation error message on facility cover image upload (#8625
Browse files Browse the repository at this point in the history
) (#8639)

Co-authored-by: rithviknishad <[email protected]>
Co-authored-by: Mohammed Nihal <[email protected]>
  • Loading branch information
3 people authored Sep 27, 2024
1 parent bbeab06 commit b6c9577
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
11 changes: 1 addition & 10 deletions src/Components/Facility/CoverImageEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Webcam from "react-webcam";
import { FacilityModel } from "./models";
import useWindowDimensions from "../../Common/hooks/useWindowDimensions";
import CareIcon from "../../CAREUI/icons/CareIcon";
import * as Notification from "../../Utils/Notifications.js";
import { useTranslation } from "react-i18next";
import { LocalStorageKeys } from "../../Common/constants";
import DialogModal from "../Common/Dialog";
Expand Down Expand Up @@ -130,25 +129,17 @@ const CoverImageEditModal = ({
"Bearer " + localStorage.getItem(LocalStorageKeys.accessToken),
},
async (xhr: XMLHttpRequest) => {
setIsProcessing(false);
if (xhr.status === 200) {
Success({ msg: "Cover image updated." });
setIsProcessing(false);
setIsCaptureImgBeingUploaded(false);
await sleep(1000);
onSave?.();
closeModal();
} else {
Notification.Error({
msg: "Something went wrong!",
});
setIsProcessing(false);
}
},
null,
() => {
Notification.Error({
msg: "Network Failure. Please check your internet connectivity.",
});
setIsProcessing(false);
},
);
Expand Down
14 changes: 14 additions & 0 deletions src/Utils/request/uploadFile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Dispatch, SetStateAction } from "react";
import { handleUploadPercentage } from "./utils";
import * as Notification from "../../Utils/Notifications.js";

const uploadFile = (
url: string,
Expand All @@ -19,6 +20,16 @@ const uploadFile = (

xhr.onload = () => {
onLoad(xhr);
if (400 <= xhr.status && xhr.status <= 499) {
const error = JSON.parse(xhr.responseText);
if (typeof error === "object" && !Array.isArray(error)) {
Object.values(error).forEach((msg) => {
Notification.Error({ msg: msg || "Something went wrong!" });
});
} else {
Notification.Error({ msg: error || "Something went wrong!" });
}
}
};

if (setUploadPercent != null) {
Expand All @@ -28,6 +39,9 @@ const uploadFile = (
}

xhr.onerror = () => {
Notification.Error({
msg: "Network Failure. Please check your internet connectivity.",
});
onError();
};
xhr.send(file);
Expand Down

0 comments on commit b6c9577

Please sign in to comment.