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

Error messages should clearly specify the exact issue encountered during facility cover image uploads #9727

Closed
Closed
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b021ac0
error message clarify the exact issue
modamaan Jan 4, 2025
428fae3
error message showed
modamaan Jan 4, 2025
7fdd467
Merge branch 'develop' into issues/9720/cover-image-upload
modamaan Jan 4, 2025
8d56a8d
updated
modamaan Jan 5, 2025
f52873d
Merge branch 'issues/9720/cover-image-upload' of https://github.com/m…
modamaan Jan 5, 2025
5cf957e
toast notification added
modamaan Jan 5, 2025
49e1adb
Merge remote-tracking branch 'upstream/develop' into issues/9720/cove…
modamaan Jan 5, 2025
9e9fac2
Merge branch 'develop' into issues/9720/cover-image-upload
modamaan Jan 5, 2025
decb8f1
Merge branch 'issues/9720/cover-image-upload' of https://github.com/m…
modamaan Jan 10, 2025
b7c6123
toast code updated
modamaan Jan 10, 2025
3876755
Merge branch 'develop' into issues/9720/cover-image-upload
modamaan Jan 10, 2025
3bedc39
Merge branch 'develop' into issues/9720/cover-image-upload
modamaan Jan 14, 2025
91db6d7
Merge remote-tracking branch 'upstream/develop' into issues/9720/cove…
modamaan Jan 14, 2025
8e04a68
errorhandler updated
modamaan Jan 14, 2025
108f3e4
handleStructuredErrors function called
modamaan Jan 14, 2025
ab88fbf
Merge branch 'issues/9720/cover-image-upload' of https://github.com/m…
modamaan Jan 14, 2025
b5ab30d
removed latest added code
modamaan Jan 14, 2025
c8021e8
reduced the function calling code
modamaan Jan 14, 2025
b23acb9
button width updated
modamaan Jan 14, 2025
61406ff
Merge remote-tracking branch 'upstream/develop' into issues/9720/cove…
modamaan Jan 21, 2025
3ca79fc
Merge branch 'develop' into issues/9720/cover-image-upload
modamaan Jan 21, 2025
e58a5e0
notification added in change avatar
modamaan Jan 21, 2025
2b30487
Merge branch 'issues/9720/cover-image-upload' of https://github.com/m…
modamaan Jan 21, 2025
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
79 changes: 56 additions & 23 deletions src/components/Facility/FacilityHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,30 +134,63 @@
};

const handleCoverImageUpload = async (file: File, onError: () => void) => {
const formData = new FormData();
formData.append("cover_image", file);
const url = `${careConfig.apiUrl}/api/v1/facility/${facilityId}/cover_image/`;

uploadFile(
url,
formData,
"POST",
{ Authorization: getAuthorizationHeader() },
async (xhr: XMLHttpRequest) => {
if (xhr.status === 200) {
await sleep(1000);
facilityFetch();
Notification.Success({ msg: "Cover image updated." });
setEditCoverImage(false);
} else {
onError();
}
},
null,
() => {
const allowedFormats = ["image/jpg", "image/jpeg", "image/png"];
const maxSizeInBytes = 1 * 1024 * 1024; // 1MB

if (file.size > maxSizeInBytes) {
Notification.Error({ msg: "Max size for image uploaded should be 1MB." });
onError();
return;
}

const img = new Image();
img.src = URL.createObjectURL(file);
Fixed Show fixed Hide fixed

img.onload = async () => {
if (!allowedFormats.includes(file.type)) {
Notification.Error({ msg: "Allowed formats are jpg, png, jpeg." });
onError();
},
);
return;
}

if (img.width !== img.height) {
Notification.Error({
msg: "Aspect ratio for the image should be 1:1.",
});
onError();
return;
}

const formData = new FormData();
formData.append("cover_image", file);
const url = `${careConfig.apiUrl}/api/v1/facility/${facilityId}/cover_image/`;

uploadFile(
url,
formData,
"POST",
{ Authorization: getAuthorizationHeader() },
async (xhr: XMLHttpRequest) => {
if (xhr.status === 200) {
await sleep(1000);
facilityFetch();
Notification.Success({ msg: "Cover image updated." });
setEditCoverImage(false);
} else {
onError();
}
},
null,
() => {
onError();
},
);
};

img.onerror = () => {
Notification.Error({ msg: "Invalid image file." });
onError();
};
};

const handleCoverImageDelete = async (onError: () => void) => {
Expand Down
Loading