Skip to content

Commit 9178d5d

Browse files
committed
refactor(web): add-and-update-user-logic
1 parent 763bf0b commit 9178d5d

File tree

2 files changed

+14
-22
lines changed

2 files changed

+14
-22
lines changed

web/src/layout/Header/navbar/Menu/Settings/Notifications/FormContactDetails/EmailVerificationInfo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const EmailVerificationInfo: React.FC<IEmailInfo> = ({ toggleIsSettingsOpen }) =
6767
(e: React.FormEvent<HTMLFormElement>) => {
6868
e.preventDefault();
6969
if (!user) return;
70-
infoToast(`Sending verfication email ...`);
70+
infoToast(`Sending verification email ...`);
7171
updateEmail({ newEmail: user.email })
7272
.then(async (res) => {
7373
if (res) {

web/src/layout/Header/navbar/Menu/Settings/Notifications/FormContactDetails/index.tsx

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,15 @@ const FormContactDetails: React.FC<ISettings> = ({ toggleIsSettingsOpen }) => {
6969
if (!address) {
7070
return;
7171
}
72-
72+
const handleSuccess = (action: string) => {
73+
successToast(`${action} successful!`);
74+
toggleIsSettingsOpen();
75+
};
76+
77+
const handleError = (action: string, err: Error) => {
78+
console.error(`${action} failed:`, err);
79+
errorToast(`${action} failed: ${err?.message || "Unknown error"}`);
80+
};
7381
// if user exists then update email
7482
if (userExists) {
7583
if (!isEmailUpdateable) return;
@@ -78,32 +86,16 @@ const FormContactDetails: React.FC<ISettings> = ({ toggleIsSettingsOpen }) => {
7886
};
7987
infoToast("Updating email ...");
8088
updateEmail(data)
81-
.then(async (res) => {
82-
if (res) {
83-
successToast("Email updated successfully!");
84-
toggleIsSettingsOpen();
85-
}
86-
})
87-
.catch((err) => {
88-
console.log(err);
89-
errorToast(`Updating email failed: ${err?.message}`);
90-
});
89+
.then((res) => res && handleSuccess("Email update"))
90+
.catch((err) => handleError("Email update", err));
9191
} else {
9292
const data = {
9393
email: emailInput,
9494
};
9595
infoToast("Adding user ...");
9696
addUser(data)
97-
.then(async (res) => {
98-
if (res) {
99-
successToast("User added successfully!");
100-
toggleIsSettingsOpen();
101-
}
102-
})
103-
.catch((err) => {
104-
console.log(err);
105-
errorToast(`Adding user failed: ${err?.message}`);
106-
});
97+
.then((res) => res && handleSuccess("User addition"))
98+
.catch((err) => handleError("User addition", err));
10799
}
108100
};
109101

0 commit comments

Comments
 (0)