Skip to content

Commit

Permalink
Merge pull request #380 from COS301-SE-2024/hotfix/signup_with_email
Browse files Browse the repository at this point in the history
PR: hotfix/signup_with_email
  • Loading branch information
ShamaKamina authored Oct 1, 2024
2 parents a68ab15 + 368ea80 commit 0df1685
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions frontend/lib/api/updateProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ const updateUserProfile = async (
}

const formData = new FormData();
formData.append("fullname", updatedUser.fullname);
formData.append("username", updatedUser.username);
formData.append("bio", updatedUser.bio);

if (updatedUser.fullname) formData.append("fullname", updatedUser.fullname);
if (updatedUser.username) formData.append("username", updatedUser.username);
if (updatedUser.bio) formData.append("bio", updatedUser.bio);
if (updatedUser.location) {
formData.append("location", JSON.stringify(updatedUser.location));
}
Expand All @@ -29,6 +30,11 @@ const updateUserProfile = async (
formData.append("profile_picture", file);
}

// Don't send the request if there's nothing to update
if (formData.entries().next().done) {
return user; // Return the original user if no updates
}

const url = `${process.env.NEXT_PUBLIC_BACKEND_URL}/api/users/${user.user_id}`;
const response = await fetch(url, {
method: "PUT",
Expand Down

0 comments on commit 0df1685

Please sign in to comment.