Skip to content

Commit 6579bb5

Browse files
committed
some cleanups
1 parent 70f7037 commit 6579bb5

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

apps/web/actions/organization/upload-organization-icon.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export async function uploadOrganizationIcon(
4848
throw new Error("File must be an image");
4949
}
5050

51-
// Validate file size (limit to 2MB)
5251
if (file.size > MAX_FILE_SIZE_BYTES) {
5352
throw new Error("File size must be less than 1MB");
5453
}

apps/web/app/(org)/dashboard/settings/account/Settings.tsx

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ export const Settings = ({
8989
return () => window.removeEventListener("beforeunload", handleBeforeUnload);
9090
}, [hasChanges]);
9191

92-
const {
93-
mutate: uploadProfileImageMutation,
94-
isPending: isUploadingProfileImage,
95-
} = useMutation({
92+
const uploadProfileImageMutation = useMutation({
9693
mutationFn: async (file: File) => {
9794
const formData = new FormData();
9895
formData.append("image", file);
@@ -116,10 +113,7 @@ export const Settings = ({
116113
},
117114
});
118115

119-
const {
120-
mutate: removeProfileImageMutation,
121-
isPending: isRemovingProfileImage,
122-
} = useMutation({
116+
const removeProfileImageMutation = useMutation({
123117
mutationFn: removeProfileImage,
124118
onSuccess: (result) => {
125119
if (result.success) {
@@ -140,21 +134,22 @@ export const Settings = ({
140134
});
141135

142136
const isProfileImageMutating =
143-
isUploadingProfileImage || isRemovingProfileImage;
137+
uploadProfileImageMutation.isPending ||
138+
removeProfileImageMutation.isPending;
144139

145140
const handleProfileImageChange = (file: File | null) => {
146141
if (!file || isProfileImageMutating) {
147142
return;
148143
}
149-
uploadProfileImageMutation(file);
144+
uploadProfileImageMutation.mutate(file);
150145
};
151146

152147
const handleProfileImageRemove = () => {
153148
if (isProfileImageMutating) {
154149
return;
155150
}
156151
setProfileImageOverride(null);
157-
removeProfileImageMutation();
152+
removeProfileImageMutation.mutate();
158153
};
159154

160155
return (
@@ -177,8 +172,8 @@ export const Settings = ({
177172
onChange={handleProfileImageChange}
178173
onRemove={handleProfileImageRemove}
179174
disabled={isProfileImageMutating}
180-
isUploading={isUploadingProfileImage}
181-
isRemoving={isRemovingProfileImage}
175+
isUploading={uploadProfileImageMutation.isPending}
176+
isRemoving={removeProfileImageMutation.isPending}
182177
/>
183178
</Card>
184179
<Card className="space-y-4">

apps/web/app/(org)/dashboard/settings/account/components/ProfileImage.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ export function ProfileImage({
4545
toast.error("File size must be 1MB or less");
4646
return;
4747
}
48-
if (file && file.size <= sizeLimit) {
49-
const objectUrl = URL.createObjectURL(file);
50-
setPreviewUrl(objectUrl);
51-
onChange?.(file);
48+
if (previewUrl && previewUrl !== initialPreviewUrl) {
49+
URL.revokeObjectURL(previewUrl);
5250
}
51+
const objectUrl = URL.createObjectURL(file);
52+
setPreviewUrl(objectUrl);
53+
onChange?.(file);
5354
};
5455

5556
const handleRemove = () => {

0 commit comments

Comments
 (0)