Skip to content

Commit ad3018f

Browse files
committed
Add e-mail re-confrimation page
Fixes: #46
1 parent ae0e2e9 commit ad3018f

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

apps/client/src/components/Pages/User/UserConfirmEmailTab.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
import UserEmailReconfirmForm from '../../User/UserEmailReconfirmForm';
2+
13
function UserConfirmEmailTab() {
24
return (
35
<div className="mt-8">
46
<h2 className="mb-4 text-3xl">Confirm email</h2>
7+
<p className="mb-6 text-muted">
8+
Confirm your e-mail account to enhance security of your account and unlock some features.
9+
</p>
10+
<UserEmailReconfirmForm />
511
</div>
612
);
713
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import axios from 'axios';
2+
import classNames from 'classnames';
3+
import { useContext, useState } from 'react';
4+
import { BsCheckCircle, BsXCircle } from 'react-icons/bs';
5+
import { UserContext } from '../../context/UserContext';
6+
import { Utils } from '../../utils/utils';
7+
import Alert from '../Helpers/Alert';
8+
import Button from '../Button';
9+
10+
function UserEmailReconfirmForm() {
11+
const { user } = useContext(UserContext);
12+
13+
const [loading, setLoading] = useState(false);
14+
const [error, setError] = useState<string | null>(null);
15+
const [success, setSuccess] = useState<boolean>(false);
16+
17+
function onSubmit() {
18+
setLoading(true);
19+
setError(null);
20+
setSuccess(false);
21+
22+
axios
23+
.post('/api/auth-emails/confirm-email/start')
24+
.then(() => setSuccess(true))
25+
.catch((err) => setError(Utils.requestErrorToString(err)))
26+
.finally(() => setLoading(false));
27+
}
28+
29+
return (
30+
<div>
31+
{error && <Alert>{error}</Alert>}
32+
{success && (
33+
<Alert variant="success">
34+
We&apos;ve sent e-mail confirmation instructions to the e-mail address you have provided.
35+
If you haven&apos;t received this email in few minutes, please check your spam folder.
36+
</Alert>
37+
)}
38+
<div className="mb-8 rounded-md border px-3 py-4">
39+
<div className="font-medium text-muted">Confirmation status:</div>
40+
<div
41+
className={classNames(
42+
'flex items-center gap-2',
43+
user.isConfirmed ? 'text-success' : 'text-danger',
44+
)}
45+
>
46+
{user.isConfirmed ? (
47+
<>
48+
<BsCheckCircle /> <span>E-mail address confirmed</span>
49+
</>
50+
) : (
51+
<>
52+
<BsXCircle /> <span>E-mail address not confirmed</span>
53+
</>
54+
)}
55+
</div>
56+
</div>
57+
58+
<Button
59+
disabled={user.isConfirmed || success || loading}
60+
onClick={onSubmit}
61+
>
62+
Send confirmation email
63+
</Button>
64+
</div>
65+
);
66+
}
67+
export default UserEmailReconfirmForm;

0 commit comments

Comments
 (0)