Skip to content

Commit 656b54f

Browse files
refactor(user): update verify email page (#1538)
* refactor: update verify email page * style: fix coding standard * refactor: update max width
1 parent ed3e3f8 commit 656b54f

3 files changed

Lines changed: 31 additions & 27 deletions

File tree

packages/i18n/src/locales/en/user.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"toastMessages": {
4545
"alreadyVerified": "Email is already verified.",
4646
"error": "Something went wrong. Please try again.",
47-
"invalidToken": "The token is invalid.",
47+
"invalidToken": "This email verification link is no more valid. Either it has been already used or has expired.",
4848
"resendError": "Something went wrong. Please try again.",
4949
"resendSuccess": "Email resent successfully.",
5050
"success": "Email verified successfully.",

packages/i18n/src/locales/fr/user.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"messages": {
3535
"alreadyVerified": "Email is already verified. Please try refreshing the page. (fr)",
3636
"error": "Something went wrong. Please try again. (fr)",
37-
"invalidToken": "The token is invalid. (fr)",
37+
"invalidToken": "This email verification link is no more valid. Either it has been already used or has expired. (fr)",
3838
"resendEmailInfo": "Not received yet? (fr)",
3939
"success": "Email verified successfully. (fr)",
4040
"unverified": "We've sent an email to <strong>{{ email }}</strong> with a link for verification. Please check your inbox. (fr)",

packages/user/src/views/VerifyEmail.tsx

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useTranslation } from "@prefabs.tech/react-i18n";
2-
import { AuthPage } from "@prefabs.tech/react-ui";
2+
import { AuthPage, Message } from "@prefabs.tech/react-ui";
33
import { useContext, useEffect, useState } from "react";
44
import { toast } from "react-toastify";
55

@@ -12,7 +12,9 @@ import { UserContextType, useConfig, userContext } from "..";
1212
export const VerifyEmail = ({ centered = true }: { centered?: boolean }) => {
1313
const [verifyEmailLoading, setVerifyEmailLoading] = useState<boolean>(true);
1414
const [status, setStatus] = useState<string | undefined>("");
15+
const [error, setError] = useState(false);
1516
const [isEmailUpdated, setIsEmailUpdated] = useState(false);
17+
1618
const { t } = useTranslation("user");
1719
const { user, setUser } = useContext(userContext) as UserContextType;
1820
const config = useConfig();
@@ -21,30 +23,20 @@ export const VerifyEmail = ({ centered = true }: { centered?: boolean }) => {
2123
if (user) {
2224
verifyEmail()
2325
.then(async (response) => {
24-
if (response) {
25-
setStatus(response.status);
26-
switch (response.status) {
27-
case EMAIL_VERIFICATION.OK: {
28-
const userInfo = await getMe(config.apiBaseUrl);
29-
if (user.email !== userInfo.data.email) {
30-
toast.success(
31-
t("emailVerification.toastMessages.updateSuccess"),
32-
);
33-
setIsEmailUpdated(true);
34-
} else {
35-
toast.success(t("emailVerification.toastMessages.success"));
36-
setIsEmailUpdated(false);
37-
}
38-
setUser(userInfo.data);
39-
break;
40-
}
41-
case EMAIL_VERIFICATION.EMAIL_VERIFICATION_INVALID_TOKEN_ERROR:
42-
toast.error(t("emailVerification.toastMessages.invalidToken"));
43-
break;
44-
default:
45-
toast.error(`${t("emailVerification.toastMessages.error")}`);
46-
break;
26+
setStatus(response?.status);
27+
28+
if (response && response.status === EMAIL_VERIFICATION.OK) {
29+
const userInfo = await getMe(config.apiBaseUrl);
30+
31+
if (user.email !== userInfo.data.email) {
32+
toast.success(t("emailVerification.toastMessages.updateSuccess"));
33+
setIsEmailUpdated(true);
34+
} else {
35+
toast.success(t("emailVerification.toastMessages.success"));
36+
setIsEmailUpdated(false);
4737
}
38+
39+
setUser(userInfo.data);
4840
}
4941
})
5042
.catch(() => {
@@ -74,12 +66,24 @@ export const VerifyEmail = ({ centered = true }: { centered?: boolean }) => {
7466
message = t("emailVerification.messages.invalidToken");
7567
break;
7668
default:
69+
setError(true);
7770
message = t("emailVerification.messages.error");
7871
}
7972

8073
return (
8174
<>
82-
<p>{message}</p>
75+
{error ? (
76+
<Message
77+
enableClose={true}
78+
message={message}
79+
onClose={() => {
80+
setError(false);
81+
}}
82+
severity="danger"
83+
/>
84+
) : (
85+
<p>{message}</p>
86+
)}
8387
</>
8488
);
8589
};

0 commit comments

Comments
 (0)