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 Bugs in User and Facility Avatar Upload and Deletion Workflow #10547

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
baf7c34
Fix User Avatar Delete Workflow
rajku-dev Feb 10, 2025
47fc60d
Fix Lint
rajku-dev Feb 11, 2025
4f01089
Merge branch 'develop' into issue/10525/user-avatat-delete-bug
rajku-dev Feb 11, 2025
b4a21bb
Disable `Save` button after upading/uploading cover facility cover photo
rajku-dev Feb 11, 2025
a794120
fix `Uplaoding` not showing on clicking save button
rajku-dev Feb 11, 2025
d94134d
fix uplaoding button glitch after deleting facility avatar
rajku-dev Feb 11, 2025
d000c7d
Merge branch 'develop' into issue/10525/user-avatat-delete-bug
rajku-dev Feb 11, 2025
f7c6426
Merge branch 'develop' into issue/10525/user-avatat-delete-bug
rajku-dev Feb 12, 2025
ffd91d9
fix preview not showing
rajku-dev Feb 13, 2025
9b1034e
Merge branch 'issue/10525/user-avatat-delete-bug' of https://github.c…
rajku-dev Feb 13, 2025
c0ecfc5
fix preview not showing in FacilityAvatar
rajku-dev Feb 13, 2025
bd87f6f
fix lint
rajku-dev Feb 13, 2025
85c872a
remove console log
rajku-dev Feb 13, 2025
b42c183
Merge branch 'develop' into issue/10525/user-avatat-delete-bug
rajku-dev Feb 13, 2025
c04c9f8
Merge branch 'develop' into issue/10525/user-avatat-delete-bug
rajku-dev Feb 13, 2025
0467610
fix merge conflict errors
rajku-dev Feb 13, 2025
2d89b35
Merge branch 'develop' into issue/10525/user-avatat-delete-bug
rajku-dev Feb 13, 2025
7202c2a
Merge branch 'develop' into issue/10525/user-avatat-delete-bug
nihal467 Feb 18, 2025
e4cf424
Merge branch 'develop' into issue/10525/user-avatat-delete-bug
rajku-dev Feb 18, 2025
f7dcfc7
Merge branch 'develop' into issue/10525/user-avatat-delete-bug
rajku-dev Feb 18, 2025
0dce732
Merge branch 'develop' into issue/10525/user-avatat-delete-bug
rajku-dev Feb 19, 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
18 changes: 12 additions & 6 deletions src/components/Common/AvatarEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
open: boolean;
imageUrl?: string;
handleUpload: (file: File, onError: () => void) => Promise<void>;
handleDelete: (onError: () => void) => Promise<void>;
handleDelete: (onSuccess: () => void, onError: () => void) => Promise<void>;
onClose?: () => void;
hint?: React.ReactNode;
}
Expand Down Expand Up @@ -134,14 +134,20 @@
} finally {
setIsCaptureImgBeingUploaded(false);
setIsProcessing(false);
setSelectedFile(undefined);
}
};

const deleteAvatar = async () => {
setIsProcessing(true);
await handleDelete(() => {
setIsProcessing(false);
});
await handleDelete(
() => {
setIsProcessing(false);
setPreview(undefined);
setPreviewImage(null);
},
() => setIsProcessing(false),
);
};

const dragProps = useDragAndDrop();
Expand Down Expand Up @@ -189,11 +195,11 @@
<div className="flex max-h-screen min-h-96 w-full flex-col overflow-auto">
{!isCameraOpen ? (
<>
{preview || imageUrl ? (
{imageUrl || preview ? (
<>
<div className="flex flex-1 items-center justify-center rounded-lg">
<img
src={preview || imageUrl}
src={imageUrl || preview}
alt="cover-photo"
className="h-full w-full object-cover"
/>
Expand Down
8 changes: 6 additions & 2 deletions src/components/Facility/FacilityHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const FacilityHome = ({ facilityId }: Props) => {
formData.append("cover_image", file);
const url = `${careConfig.apiUrl}/api/v1/facility/${facilityId}/cover_image/`;

uploadFile(
await uploadFile(
url,
formData,
"POST",
Expand All @@ -159,9 +159,13 @@ export const FacilityHome = ({ facilityId }: Props) => {
},
);
};
const handleCoverImageDelete = async (onError: () => void) => {
const handleCoverImageDelete = async (
onSuccess: () => void,
onError: () => void,
) => {
try {
await deleteAvatar();
onSuccess();
} catch {
onError();
}
Expand Down
11 changes: 8 additions & 3 deletions src/components/Users/UserAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function UserAvatar({ username }: { username: string }) {
const authUser = useAuthUser();
const queryClient = useQueryClient();

const { mutate: mutateAvatarDelete } = useMutation({
const { mutateAsync: mutateAvatarDelete } = useMutation({
mutationFn: mutate(routes.deleteProfilePicture, {
pathParams: { username },
}),
Expand Down Expand Up @@ -82,13 +82,18 @@ export default function UserAvatar({ username }: { username: string }) {
);
};

const handleAvatarDelete = async (onError: () => void) => {
const handleAvatarDelete = async (
onSuccess: () => void,
onError: () => void,
) => {
try {
mutateAvatarDelete();
await mutateAvatarDelete();
onSuccess();
} catch {
onError();
}
};

return (
<>
<AvatarEditModal
Expand Down
Loading