Skip to content

Commit 268daca

Browse files
committed
refactor(web): add-and-update-user-logic
1 parent c7617de commit 268daca

File tree

3 files changed

+28
-42
lines changed

3 files changed

+28
-42
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

web/src/pages/NewTransaction/NavigationButtons/NextButton.tsx

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ const NextButton: React.FC<INextButton> = ({ nextRoute }) => {
9494
user &&
9595
![user.email, ""].includes(notificationEmail)
9696
) {
97+
const handleSuccess = (action: string) => {
98+
successToast(`${action} successful!`);
99+
navigate(nextRoute);
100+
};
101+
102+
const handleError = (action: string, err: Error) => {
103+
console.error(`${action} failed:`, err);
104+
errorToast(`${action} failed: ${err?.message || "Unknown error"}`);
105+
};
106+
97107
// if user exists then update email
98108
if (userExists) {
99109
if (!isEmailUpdateable) {
@@ -105,32 +115,16 @@ const NextButton: React.FC<INextButton> = ({ nextRoute }) => {
105115
};
106116
infoToast("Updating email ...");
107117
updateEmail(data)
108-
.then(async (res) => {
109-
if (res) {
110-
successToast("Email updated successfully!");
111-
navigate(nextRoute);
112-
}
113-
})
114-
.catch((err) => {
115-
console.log(err);
116-
errorToast(`Updating email failed: ${err?.message}`);
117-
});
118+
.then((res) => res && handleSuccess("Email update"))
119+
.catch((err) => handleError("Email update", err));
118120
} else {
119121
const data = {
120122
email: notificationEmail,
121123
};
122124
infoToast("Adding user ...");
123125
addUser(data)
124-
.then(async (res) => {
125-
if (res) {
126-
successToast("User added successfully!");
127-
navigate(nextRoute);
128-
}
129-
})
130-
.catch((err) => {
131-
console.log(err);
132-
errorToast(`Adding user failed: ${err?.message}`);
133-
});
126+
.then((res) => res && handleSuccess("User addition"))
127+
.catch((err) => handleError("User addition", err));
134128
}
135129
} else {
136130
navigate(nextRoute);

0 commit comments

Comments
 (0)