Skip to content

Commit c2f8d98

Browse files
committed
feat: add page to confirm your mail after registering (#68)
1 parent 1064d75 commit c2f8d98

File tree

3 files changed

+86
-2
lines changed

3 files changed

+86
-2
lines changed

app/confirm-email/[token]/actions.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"use server"
2+
3+
export const postMailConfirmationToken = async (token: string): Promise<any> => {
4+
try {
5+
const response = await fetch(`${process.env.CC_API_URL}/accounts/confirm-account`, {
6+
method: "POST",
7+
headers: {
8+
"Content-Type": "application/json",
9+
},
10+
body: JSON.stringify({ token }),
11+
});
12+
13+
if (!response.ok) {
14+
const errorResponse = await response.json();
15+
if (errorResponse.error) {
16+
if (typeof errorResponse.error === 'string') {
17+
return { error: errorResponse.error };
18+
} else if (errorResponse.error.token) {
19+
return { error: errorResponse.error.token.join(' ') };
20+
} else if (errorResponse.error.non_field_errors) {
21+
return { error: errorResponse.error.non_field_errors.join(' ') };
22+
}
23+
}
24+
return { error: "An unexpected error occurred." };
25+
}
26+
27+
return { success: true };
28+
} catch (error) {
29+
return { error: "An unexpected error occurred." };
30+
}
31+
};

app/confirm-email/[token]/page.tsx

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"use client"
2+
import {usePathname} from "next/navigation";
3+
import {postMailConfirmationToken} from "./actions";
4+
import React, {useEffect, useState} from "react";
5+
import Panel from "../../common/uiLibrary/panel";
6+
import ContactInformation from "../../(home)/contactInformation";
7+
8+
const MailConfirmationPage = () => {
9+
const [response, setResponse] = useState<{ success?: boolean; error?: string }>({});
10+
const token = usePathname().split('/').filter(Boolean).pop();
11+
12+
useEffect(() => {
13+
const fetchData = async () => {
14+
if (token) {
15+
return await postMailConfirmationToken(token);
16+
}
17+
};
18+
19+
fetchData().then(r => {
20+
setResponse(r);
21+
});
22+
}, []);
23+
24+
if (!token) {
25+
return <main>
26+
</main>;
27+
}
28+
29+
return (
30+
<main className="flex flex-col justify-between min-h-screen pt-8 pb-16 lg:pt-16 lg:pb-24">
31+
<div>
32+
<Panel>
33+
<div
34+
className="mb-4 text-4xl text-center font-extrabold leading-tight lg:mb-6 text-white">
35+
{response.success ? (
36+
<h1>Confirmation successful!</h1>
37+
) : (
38+
<h1>{response.error || 'Waiting for confirmation...'}</h1>
39+
)}
40+
</div>
41+
</Panel>
42+
</div>
43+
<ContactInformation/>
44+
</main>
45+
);
46+
};
47+
48+
export default MailConfirmationPage;

app/layout.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Clown from "./clown/clown";
44
import {Metadata} from "next";
55
import DefaultNavbar from "./common/defaultNavbar";
66
import { Analytics } from '@vercel/analytics/react';
7+
import type { Viewport } from 'next'
78

89
export const metadata: Metadata = {
910
title: 'Unitystation - The Space Station 13 Remake Made in Unity',
@@ -20,9 +21,7 @@ export const metadata: Metadata = {
2021
'roleplaying game',
2122
],
2223
description: 'Unitystation is a free and open-source chaotic multiplayer role-playing and simulation game made in Unity. Remake of the cult classic Space Station 13.',
23-
colorScheme: 'dark',
2424
authors: {name: 'Unitystation Team', url: 'https://github.com/unitystation'},
25-
viewport: {width: "device-width", initialScale: 1},
2625
robots: {follow: true, index: true},
2726
openGraph: {
2827
type: 'website',
@@ -38,6 +37,12 @@ export const metadata: Metadata = {
3837
}
3938
}
4039

40+
export const viewport: Viewport = {
41+
themeColor: 'black',
42+
width: 'device-width',
43+
initialScale: 1,
44+
}
45+
4146
export default function RootLayout({children,}: { children: React.ReactNode; }) {
4247

4348
return (

0 commit comments

Comments
 (0)