Skip to content

Commit 3c0263c

Browse files
committed
Fix image reupload bug
1 parent c93470e commit 3c0263c

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

frontend/src/api/user.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { AuthStatus, UploadProfilePictureResponse } from "@/types/user";
44
import Cookie from "js-cookie";
55
import Swal from "sweetalert2";
66

7-
const toast = Swal.mixin({
7+
export const ToastComponent = Swal.mixin({
88
toast: true,
99
position: "top-end",
1010
showConfirmButton: false,
@@ -88,7 +88,7 @@ export const verifyToken = async (token: string) => {
8888
};
8989

9090
export const login = async (email: string, password: string) => {
91-
toast.fire({
91+
ToastComponent.fire({
9292
icon: "info",
9393
title: "Logging in...",
9494
});
@@ -105,7 +105,7 @@ export const login = async (email: string, password: string) => {
105105
const data = await response.json();
106106

107107
if (response.status !== 200) {
108-
toast.fire({
108+
ToastComponent.fire({
109109
icon: "error",
110110
title: data.message,
111111
});
@@ -134,7 +134,7 @@ export const register = async (
134134
password: string,
135135
username: string
136136
) => {
137-
toast.fire({
137+
ToastComponent.fire({
138138
icon: "info",
139139
title: "Registering...",
140140
});
@@ -152,7 +152,7 @@ export const register = async (
152152
const data = await response.json();
153153

154154
if (response.status !== 201) {
155-
toast.fire({
155+
ToastComponent.fire({
156156
icon: "error",
157157
title: data.message,
158158
});
@@ -175,7 +175,7 @@ export const getUser = async (userId = "") => {
175175
const data = await response.json();
176176

177177
if (response.status !== 200) {
178-
toast.fire({
178+
ToastComponent.fire({
179179
icon: "error",
180180
title: data.message,
181181
});
@@ -208,14 +208,14 @@ export const updateUser = async (userData: {
208208
console.log(data);
209209

210210
if (response.status !== 200) {
211-
toast.fire({
211+
ToastComponent.fire({
212212
icon: "error",
213213
title: data.message,
214214
});
215215
return false;
216216
}
217217

218-
toast.fire({
218+
ToastComponent.fire({
219219
icon: "success",
220220
title: "Profile updated successfully",
221221
});
@@ -241,7 +241,7 @@ export const getFileUrl = async (
241241
const data: UploadProfilePictureResponse = await res.json();
242242

243243
if (res.status !== 200) {
244-
toast.fire({
244+
ToastComponent.fire({
245245
icon: "error",
246246
title: res.statusText,
247247
});
@@ -251,7 +251,7 @@ export const getFileUrl = async (
251251
};
252252

253253
export const requestPasswordReset = async (email: string) => {
254-
toast.fire({
254+
ToastComponent.fire({
255255
icon: "info",
256256
title: "Requesting password reset...",
257257
});
@@ -269,14 +269,14 @@ export const requestPasswordReset = async (email: string) => {
269269
console.log(data);
270270

271271
if (response.status !== 200) {
272-
toast.fire({
272+
ToastComponent.fire({
273273
icon: "error",
274274
title: data.message,
275275
});
276276
return false;
277277
}
278278

279-
toast.fire({
279+
ToastComponent.fire({
280280
icon: "success",
281281
title: "Password reset requested. Please check your email.",
282282
});
@@ -298,7 +298,7 @@ export const checkPasswordResetCode = async (code: string) => {
298298
const data = await response.json();
299299

300300
if (response.status !== 200) {
301-
toast.fire({
301+
ToastComponent.fire({
302302
icon: "error",
303303
title: data.message,
304304
});
@@ -322,7 +322,7 @@ export const resetPasswordWithCode = async (code: string, password: string) => {
322322
const data = await response.json();
323323

324324
if (response.status !== 200) {
325-
toast.fire({
325+
ToastComponent.fire({
326326
icon: "error",
327327
title: data.message,
328328
});

frontend/src/app/(user)/user/me/page.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
getUserId,
1919
updateUser,
2020
getFileUrl,
21+
ToastComponent,
2122
} from "@/api/user";
2223
import { useEffect, useRef, useState } from "react";
2324
import { User } from "@/types/user";
@@ -91,7 +92,6 @@ const ProfilePage = () => {
9192
}, [form]);
9293

9394
const onSubmit = async (data: z.infer<typeof formSchema>) => {
94-
console.log(data);
9595
// remove unnecessary fields
9696
if (!data.password) delete data.password;
9797
if (data.password && data.password.length < 8) {
@@ -117,7 +117,7 @@ const ProfilePage = () => {
117117
) => {
118118
console.log("Uploading profile picture...");
119119
try {
120-
if (e.target.files) {
120+
if (e.target.files && e.target.files.length > 0) {
121121
const imageFile = e.target.files[0];
122122
const formData = new FormData();
123123
formData.append("profilePicture", imageFile);
@@ -134,7 +134,6 @@ const ProfilePage = () => {
134134
} catch (error) {
135135
console.log(error);
136136
} finally {
137-
console.log("Done");
138137
setIsLoading(false);
139138
}
140139
};

0 commit comments

Comments
 (0)