diff --git a/src/Components/Facility/FacilityHome.tsx b/src/Components/Facility/FacilityHome.tsx index f1322e4d20e..477a95ab71c 100644 --- a/src/Components/Facility/FacilityHome.tsx +++ b/src/Components/Facility/FacilityHome.tsx @@ -4,7 +4,7 @@ import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor"; import { FacilityModel } from "./models"; import { FACILITY_FEATURE_TYPES, USER_TYPES } from "../../Common/constants"; import DropdownMenu, { DropdownItem } from "../Common/components/Menu"; -import { lazy, useState } from "react"; +import { lazy, useEffect, useState } from "react"; import ButtonV2 from "../Common/components/ButtonV2"; import CareIcon from "../../CAREUI/icons/CareIcon"; @@ -58,6 +58,8 @@ export const FacilityHome = ({ facilityId }: Props) => { const [openDeleteDialog, setOpenDeleteDialog] = useState(false); const [editCoverImage, setEditCoverImage] = useState(false); const [coverImageEdited, setCoverImageEdited] = useState(false); + const [coverImageLoaded, setCoverImageLoaded] = useState(false); + const [coverImageUrl, setCoverImageUrl] = useState(""); const authUser = useAuthUser(); const { @@ -75,6 +77,27 @@ export const FacilityHome = ({ facilityId }: Props) => { }, }); + const fetchImage = async () => { + try { + let imageUrl = facilityData?.read_cover_image_url; + if (imageUrl) { + await fetch(`${imageUrl}`, { + headers: { "Force-Revalidate": "1" }, + credentials: "include", + mode: "no-cors", + }); + imageUrl += "?" + Date.now(); + setCoverImageUrl(imageUrl); + } + } catch (error) { + return; + } + }; + + useEffect(() => { + setCoverImageUrl(facilityData?.read_cover_image_url); + }, [facilityData?.read_cover_image_url]); + const handleDeleteClose = () => { setOpenDeleteDialog(false); }; @@ -125,11 +148,12 @@ export const FacilityHome = ({ facilityId }: Props) => { const CoverImage = () => ( <> {facilityData?.name} setCoverImageLoaded(true)} /> - {coverImageEdited && ( + {coverImageEdited && !coverImageLoaded && (
{t("cover_image_updated_note")} @@ -163,6 +187,7 @@ export const FacilityHome = ({ facilityId }: Props) => { open={editCoverImage} onSave={() => { facilityFetch(); + fetchImage(); setCoverImageEdited(true); }} onClose={() => setEditCoverImage(false)}