Skip to content

Commit

Permalink
Fixed bug (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
angela139 authored Jan 9, 2025
1 parent c084e64 commit ccffb4c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions client/src/components/Profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,21 @@ const Profile = ({ user }: ProfileClientProps) => {
const size = useWindowSize();
const isMobile = (size.width ?? 0) <= 870;
const [editProfile, setEditProfile] = useState(false);
const [currentUser, setCurrentUser] = useState(user);

const {
register,
handleSubmit,
reset,
formState: { errors },
} = useForm<UpdateProfileValues>({
defaultValues: user,
defaultValues: currentUser,
});

const onSubmit: SubmitHandler<UpdateProfileValues> = async updateProfile => {
try {
const updatedUser = await UserAPI.updateCurrentUserProfile(updateProfile);
setCurrentUser(updatedUser);
setEditProfile(prevState => !prevState);
reset(updatedUser);
} catch (error) {
Expand All @@ -53,7 +55,7 @@ const Profile = ({ user }: ProfileClientProps) => {
};

const clearFields = () => {
reset(user);
reset(currentUser);
setEditProfile(prevState => !prevState);
};

Expand Down

0 comments on commit ccffb4c

Please sign in to comment.