1 | import React from 'react'
|
---|
2 |
|
---|
3 | import { useRouter } from 'next/router'
|
---|
4 |
|
---|
5 | import { useEffect, useState } from 'react'
|
---|
6 | import { useDispatch, useSelector } from 'react-redux'
|
---|
7 |
|
---|
8 | import { setStyle } from '../../redux/reducers/styleSlice'
|
---|
9 |
|
---|
10 | import Head from 'next/head'
|
---|
11 |
|
---|
12 | import axios from "axios";
|
---|
13 |
|
---|
14 | const 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 |
|
---|
73 | export default Activate
|
---|
74 |
|
---|
75 | export async function getServerSideProps(context) {
|
---|
76 | return {
|
---|
77 | props: {
|
---|
78 | id: context.query.id
|
---|
79 | },
|
---|
80 | }
|
---|
81 | } |
---|