Skip to content

Commit

Permalink
Fixes facility cover image from not reloading after upload (ohcnetwor…
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad authored and UdaySagar-Git committed Aug 23, 2024
1 parent 8aa4e9f commit 62febd1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
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"
}

0 comments on commit 62febd1

Please sign in to comment.