Skip to content

Commit fb40dfa

Browse files
committed
rerender profile page after changes
1 parent 04382b0 commit fb40dfa

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

frontend/src/components/ChangePasswordModal/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { FAILED_PW_UPDATE_MESSAGE, SUCCESS_PW_UPDATE_MESSAGE } from '../../utils
88
interface ChangePasswordModalProps {
99
handleClose: () => void;
1010
userId: string;
11-
onUpdate: (message: string, isSuccess: boolean) => void;
11+
onUpdate: (isProfileEdit: boolean, message: string, isSuccess: boolean) => void;
1212
}
1313

1414
const ChangePasswordModal = forwardRef<HTMLDivElement, ChangePasswordModalProps>((props, ref) => {
@@ -40,14 +40,14 @@ const ChangePasswordModal = forwardRef<HTMLDivElement, ChangePasswordModalProps>
4040
},
4141
});
4242
handleClose();
43-
onUpdate(SUCCESS_PW_UPDATE_MESSAGE, true);
43+
onUpdate(false, SUCCESS_PW_UPDATE_MESSAGE, true);
4444
} catch (error) {
4545
if (axios.isAxiosError(error)) {
4646
const message =
4747
error.response?.data.message || FAILED_PW_UPDATE_MESSAGE;
48-
onUpdate(message, false);
48+
onUpdate(false, message, false);
4949
} else {
50-
onUpdate(FAILED_PW_UPDATE_MESSAGE, false);
50+
onUpdate(false, FAILED_PW_UPDATE_MESSAGE, false);
5151
}
5252
}
5353
};

frontend/src/components/EditProfileModal/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface EditProfileModalProps {
1010
currLastName: string;
1111
currBiography?: string;
1212
userId: string;
13-
onUpdate: (message: string, isSuccess: boolean) => void;
13+
onUpdate: (isProfileEdit: boolean, message: string, isSuccess: boolean) => void;
1414
}
1515

1616
const EditProfileModal = forwardRef<HTMLDivElement, EditProfileModalProps>((props, ref) => {
@@ -54,15 +54,15 @@ const EditProfileModal = forwardRef<HTMLDivElement, EditProfileModalProps>((prop
5454
},
5555
});
5656
handleClose();
57-
onUpdate(SUCCESS_PROFILE_UPDATE_MESSAGE, true);
57+
onUpdate(true, SUCCESS_PROFILE_UPDATE_MESSAGE, true);
5858
} catch (error) {
5959
console.error('Error:', error);
6060
if (axios.isAxiosError(error)) {
6161
const message =
6262
error.response?.data.message || FAILED_PROFILE_UPDATE_MESSAGE;
63-
onUpdate(message, false);
63+
onUpdate(true, message, false);
6464
} else {
65-
onUpdate(FAILED_PROFILE_UPDATE_MESSAGE, false);
65+
onUpdate(true, FAILED_PROFILE_UPDATE_MESSAGE, false);
6666
}
6767
}
6868
};

frontend/src/pages/Profile/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const ProfilePage: React.FC = () => {
3030
const [changePasswordOpen, setChangePasswordOpen] = useState(false);
3131
const handleChangePasswordOpen = () => setChangePasswordOpen(true);
3232
const handleChangePasswordClose = () => setChangePasswordOpen(false);
33+
const [isProfileChanged, setIsProfileChanged] = useState(false);
3334

3435
const { userId } = useParams<{ userId: string }>();
3536
const [userProfile, setUserProfile] = useState<UserProfile | null>(null);
@@ -49,7 +50,7 @@ const ProfilePage: React.FC = () => {
4950
})
5051
.catch(() => setUserProfile(null));
5152
// eslint-disable-next-line react-hooks/exhaustive-deps
52-
}, []);
53+
}, [isProfileChanged]);
5354

5455
if (!userProfile) {
5556
return (
@@ -60,9 +61,12 @@ const ProfilePage: React.FC = () => {
6061
);
6162
}
6263

63-
const notify = (message: string, isSuccess: boolean) => {
64+
const notify = (isProfileEdit: boolean, message: string, isSuccess: boolean) => {
6465
if (isSuccess) {
6566
toast.success(message);
67+
if (isProfileEdit) {
68+
setIsProfileChanged(true);
69+
}
6670
} else {
6771
toast.error(message);
6872
}

0 commit comments

Comments
 (0)