Skip to content

Commit

Permalink
🪟 🐛 Fix duplicate success/warning message (#9371)
Browse files Browse the repository at this point in the history
  • Loading branch information
josephkmh committed Oct 19, 2023
1 parent 6103a25 commit d73edb0
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 44 deletions.
69 changes: 39 additions & 30 deletions airbyte-webapp/src/packages/cloud/services/auth/AuthService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,36 +193,45 @@ export const AuthenticationProvider: React.FC<React.PropsWithChildren<unknown>>
await authService.resetPassword(email);
},
async sendEmailVerification(): Promise<void> {
return authService.sendEmailVerifiedLink().catch((error) => {
switch (error.code) {
case AuthErrorCodes.NETWORK_REQUEST_FAILED:
registerNotification({
id: error.code,
text: formatMessage({
id: FirebaseAuthMessageId.NetworkFailure,
}),
type: "error",
});
break;
case AuthErrorCodes.TOO_MANY_ATTEMPTS_TRY_LATER:
registerNotification({
id: error.code,
text: formatMessage({
id: FirebaseAuthMessageId.TooManyRequests,
}),
type: "warning",
});
break;
default:
registerNotification({
id: error.code,
text: formatMessage({
id: FirebaseAuthMessageId.DefaultError,
}),
type: "error",
});
}
});
return authService
.sendEmailVerifiedLink()
.then(() => {
registerNotification({
id: "workspace.emailVerificationResendSuccess",
text: formatMessage({ id: "credits.emailVerification.resendConfirmation" }),
type: "success",
});
})
.catch((error) => {
switch (error.code) {
case AuthErrorCodes.NETWORK_REQUEST_FAILED:
registerNotification({
id: error.code,
text: formatMessage({
id: FirebaseAuthMessageId.NetworkFailure,
}),
type: "error",
});
break;
case AuthErrorCodes.TOO_MANY_ATTEMPTS_TRY_LATER:
registerNotification({
id: error.code,
text: formatMessage({
id: FirebaseAuthMessageId.TooManyRequests,
}),
type: "warning",
});
break;
default:
registerNotification({
id: error.code,
text: formatMessage({
id: FirebaseAuthMessageId.DefaultError,
}),
type: "error",
});
}
});
},
async verifyEmail(code: string): Promise<void> {
await authService.confirmEmailVerify(code);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
import { FormattedMessage, useIntl } from "react-intl";
import { FormattedMessage } from "react-intl";

import { Message } from "components/ui/Message";

import { AuthSendEmailVerification } from "core/services/auth";
import { useNotificationService } from "hooks/services/Notification";

interface EmailVerificationHintProps {
variant: "info" | "warning" | "error";
sendEmailVerification: AuthSendEmailVerification;
}
export const EmailVerificationHint: React.FC<EmailVerificationHintProps> = ({ sendEmailVerification, variant }) => {
const { registerNotification } = useNotificationService();
const { formatMessage } = useIntl();

const onResendVerificationMail = async () => {
// the shared error handling inside `sendEmailVerification` suffices
try {
await sendEmailVerification();
registerNotification({
id: "workspace.emailVerificationResendSuccess",
text: formatMessage({ id: "credits.emailVerification.resendConfirmation" }),
type: "success",
});
} catch (e) {}
return sendEmailVerification();
};

return (
Expand Down

0 comments on commit d73edb0

Please sign in to comment.