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

Fix Notifications for Facility Cover Image Deletion #7609

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
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
30 changes: 16 additions & 14 deletions src/Components/Facility/CoverImageEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const CoverImageEditModal = ({
onDelete,
facility,
}: Props) => {
const [isUploading, setIsUploading] = useState(false);
const [isProcessing, setIsProcessing] = useState(false);
const [selectedFile, setSelectedFile] = useState<any>();
const [preview, setPreview] = useState<string>();
const [isCameraOpen, setIsCameraOpen] = useState<boolean>(false);
Expand Down Expand Up @@ -106,7 +106,7 @@ const CoverImageEditModal = ({
const formData = new FormData();
formData.append("cover_image", selectedFile);
const url = `/api/v1/facility/${facility.id}/cover_image/`;
setIsUploading(true);
setIsProcessing(true);

uploadFile(
url,
Expand All @@ -123,34 +123,36 @@ const CoverImageEditModal = ({
Notification.Error({
msg: "Something went wrong!",
});
setIsUploading(false);
setIsProcessing(false);
}
},
null,
() => {
Notification.Error({
msg: "Network Failure. Please check your internet connectivity.",
});
setIsUploading(false);
setIsProcessing(false);
},
);

await sleep(1000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AnkurPrabhu can remove this and check if there is any sideeffects

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@khavinshankar can we connect on slack today i had some doubts.

setIsUploading(false);
setIsProcessing(false);
setIsCaptureImgBeingUploaded(false);
onSave && onSave();
closeModal();
};

const handleDelete = async () => {
setIsProcessing(true);
const { res } = await request(routes.deleteFacilityCoverImage, {
pathParams: { id: facility.id! },
});
if (res?.ok) {
Success({ msg: "Cover image deleted" });
onDelete?.();
closeModal();
}
setIsProcessing(false);
onDelete?.();
closeModal();
};

const hasImage = !!(preview || facility.read_cover_image_url);
Expand Down Expand Up @@ -277,29 +279,29 @@ const CoverImageEditModal = ({
closeModal();
dragProps.setFileDropError("");
}}
disabled={isUploading}
disabled={isProcessing}
/>
{facility.read_cover_image_url && (
<ButtonV2
variant="danger"
onClick={handleDelete}
disabled={isUploading}
disabled={isProcessing}
>
{t("delete")}
</ButtonV2>
)}
<ButtonV2
id="save-cover-image"
onClick={handleUpload}
disabled={isUploading}
disabled={isProcessing}
>
{isUploading ? (
{isProcessing ? (
<CareIcon icon="l-spinner" className="animate-spin text-lg" />
) : (
<CareIcon icon="l-save" className="text-lg" />
)}
<span>
{isUploading ? `${t("uploading")}...` : `${t("save")}`}
{isProcessing ? `${t("uploading")}...` : `${t("save")}`}
</span>
</ButtonV2>
</div>
Expand Down Expand Up @@ -365,7 +367,7 @@ const CoverImageEditModal = ({
setPreviewImage(null);
}}
className="my-2 w-full"
disabled={isUploading}
disabled={isProcessing}
>
{t("retake")}
</ButtonV2>
Expand Down Expand Up @@ -430,7 +432,7 @@ const CoverImageEditModal = ({
>
{t("retake")}
</ButtonV2>
<Submit disabled={isUploading} onClick={handleUpload}>
<Submit disabled={isProcessing} onClick={handleUpload}>
{isCaptureImgBeingUploaded ? (
<>
<CareIcon
Expand Down
Loading