source: pages/activate/[id].js@ e007fcd

main
Last change on this file since e007fcd was e007fcd, checked in by anastasovv <simon@…>, 23 months ago

Now you need to activate your account via email & also added mail sending after server crash

  • Property mode set to 100644
File size: 2.1 KB
Line 
1import React from 'react'
2
3import { useRouter } from 'next/router'
4
5import { useEffect, useState } from 'react'
6import { useDispatch, useSelector } from 'react-redux'
7
8import { setStyle } from '../../redux/reducers/styleSlice'
9
10import Head from 'next/head'
11
12import axios from "axios";
13
14const Activate = (props) => {
15 const dispatch = useDispatch();
16
17 const router = useRouter();
18
19 const styleState = useSelector(state => state.style);
20
21 const [activated, setActivated] = useState(false);
22
23 useEffect(() => {
24 // display loading screen
25 dispatch(setStyle({
26 ...styleState.style,
27 displayLoadingScreen: true,
28 }));
29
30 const emailActivationId = props.id;
31
32 axios.get(`/api/postgre/activate/${emailActivationId}?action=activate_account`).then(res => {
33 if (res.data?.success) {
34 setActivated(true);
35 }
36
37 dispatch(setStyle({
38 ...styleState.style,
39 displayLoadingScreen: false,
40 }));
41 });
42 }, []);
43
44 function goHome() {
45 router.push('/');
46 }
47
48 return (
49 <>
50 <Head>
51 <title>Caessino - Activate account</title>
52 </Head>
53
54 <div className="fullscreen fs-centered activateScreen">
55 { activated ? (
56 <div>
57 <h3>Your account is activated.</h3>
58 <h3>You may now login at Caessino.</h3>
59 <button onClick={() => goHome()} className="primaryButton">Go To The Homepage</button>
60 </div>
61 ) : (
62 <div>
63 <h3>Wrong email activation id.</h3>
64 <h3>We were unable to activate your account.</h3>
65 <button onClick={() => goHome()} className="primaryButton">Go To The Homepage</button>
66 </div>
67 )}
68 </div>
69 </>
70 )
71}
72
73export default Activate
74
75export async function getServerSideProps(context) {
76 return {
77 props: {
78 id: context.query.id
79 },
80 }
81 }
Note: See TracBrowser for help on using the repository browser.