reset modal values on close

This commit is contained in:
Zamitto 2024-06-18 21:43:06 -03:00
parent a8624058e4
commit 1eef86a40c
2 changed files with 19 additions and 4 deletions

View file

@ -25,7 +25,7 @@ const updateProfile = async (
_event: Electron.IpcMainInvokeEvent,
displayName: string,
newProfileImagePath: string | null
): Promise<UserProfile | null> => {
): Promise<UserProfile> => {
if (!newProfileImagePath) {
return (await patchUserProfile(displayName)).data;
}

View file

@ -55,9 +55,8 @@ export const UserEditProfileModal = ({
patchUser(displayName, newImagePath)
.then(() => {
updateUser();
setNewImagePath(null);
showSuccessToast("Salvo com sucesso");
onClose();
cleanFormAndClose();
})
.catch(() => {
showErrorToast("Tente novamente");
@ -66,9 +65,25 @@ export const UserEditProfileModal = ({
setIsSaving(false);
});
};
const resetModal = () => {
setDisplayName(userProfile.displayName);
setNewImagePath(null);
setNewImageBase64(null);
};
const cleanFormAndClose = () => {
resetModal();
onClose();
};
return (
<>
<Modal visible={visible} title="Editar Perfil" onClose={onClose}>
<Modal
visible={visible}
title="Editar Perfil"
onClose={cleanFormAndClose}
>
<section
style={{
display: "flex",