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

Fixes facility cover image from not reloading after upload #8412

Merged
merged 3 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 6 additions & 7 deletions src/Components/Facility/CoverImageEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,14 @@ const CoverImageEditModal = ({
Authorization:
"Bearer " + localStorage.getItem(LocalStorageKeys.accessToken),
},
(xhr: XMLHttpRequest) => {
async (xhr: XMLHttpRequest) => {
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!",
Expand All @@ -145,12 +150,6 @@ const CoverImageEditModal = ({
setIsProcessing(false);
},
);

await sleep(1000);
setIsProcessing(false);
setIsCaptureImgBeingUploaded(false);
onSave && onSave();
closeModal();
};

const handleDelete = async () => {
Expand Down
25 changes: 19 additions & 6 deletions src/Components/Facility/FacilityHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const FacilityHome = ({ facilityId }: Props) => {
const { t } = useTranslation();
const [openDeleteDialog, setOpenDeleteDialog] = useState(false);
const [editCoverImage, setEditCoverImage] = useState(false);
const [coverImageEdited, setCoverImageEdited] = useState(false);
const authUser = useAuthUser();

useMessageListener((data) => console.log(data));
Expand Down Expand Up @@ -125,11 +126,20 @@ export const FacilityHome = ({ facilityId }: Props) => {
);

const CoverImage = () => (
<img
src={`${facilityData?.read_cover_image_url}`}
alt={facilityData?.name}
className="h-full w-full rounded-lg object-cover"
/>
<>
<img
src={`${facilityData?.read_cover_image_url}`}
alt={facilityData?.name}
className="h-full w-full rounded-lg object-cover"
/>
{coverImageEdited && (
<div className="absolute inset-x-0 bottom-0 w-full rounded-b-md bg-black/70 px-2 pb-0.5 backdrop-blur-sm">
<span className="text-center text-xs font-medium text-secondary-100">
{t("cover_image_updated_note")}
</span>
</div>
)}
</>
);

return (
Expand All @@ -155,7 +165,10 @@ export const FacilityHome = ({ facilityId }: Props) => {
/>
<CoverImageEditModal
open={editCoverImage}
onSave={() => facilityFetch()}
onSave={() => {
facilityFetch();
setCoverImageEdited(true);
}}
onClose={() => setEditCoverImage(false)}
onDelete={() => facilityFetch()}
facility={facilityData ?? ({} as FacilityModel)}
Expand Down
5 changes: 3 additions & 2 deletions src/Locale/en/Facility.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@
"duplicate_patient_record_confirmation": "Admit the patient record to your facility by adding the year of birth",
"duplicate_patient_record_rejection": "I confirm that the suspect / patient I want to create is not on the list.",
"duplicate_patient_record_birth_unknown": "Please contact your district care coordinator, the shifting facility or the patient themselves if you are not sure about the patient's year of birth.",
"patient_transfer_birth_match_note": "Note: Year of birth must match the patient to process the transfer request."
}
"patient_transfer_birth_match_note": "Note: Year of birth must match the patient to process the transfer request.",
"cover_image_updated_note": "It could take a while to see the updated cover image"
}
Loading