Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add page for mail confirmation #68

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions app/confirm-email/[token]/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"use server"

export const postMailConfirmationToken = async (token: string): Promise<any> => {
try {
const response = await fetch(`${process.env.CC_API_URL}/accounts/confirm-account`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ token }),
});

if (!response.ok) {
const errorResponse = await response.json();
if (errorResponse.error) {
if (typeof errorResponse.error === 'string') {
return { error: errorResponse.error };
} else if (errorResponse.error.token) {
return { error: errorResponse.error.token.join(' ') };
} else if (errorResponse.error.non_field_errors) {
return { error: errorResponse.error.non_field_errors.join(' ') };
}
}
return { error: "An unexpected error occurred." };
}

return { success: true };
} catch (error) {
return { error: "An unexpected error occurred." };
}
};
48 changes: 48 additions & 0 deletions app/confirm-email/[token]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"use client"
import {usePathname} from "next/navigation";
import {postMailConfirmationToken} from "./actions";
import React, {useEffect, useState} from "react";
import Panel from "../../common/uiLibrary/panel";
import ContactInformation from "../../(home)/contactInformation";

const MailConfirmationPage = () => {
const [response, setResponse] = useState<{ success?: boolean; error?: string }>({});
const token = usePathname().split('/').filter(Boolean).pop();

useEffect(() => {
const fetchData = async () => {
if (token) {
return await postMailConfirmationToken(token);
}
};

fetchData().then(r => {
setResponse(r);
});
}, []);

if (!token) {
return <main>
</main>;
}

return (
<main className="flex flex-col justify-between min-h-screen pt-8 pb-16 lg:pt-16 lg:pb-24">
<div>
<Panel>
<div
className="mb-4 text-4xl text-center font-extrabold leading-tight lg:mb-6 text-white">
{response.success ? (
<h1>Confirmation successful!</h1>
) : (
<h1>{response.error || 'Waiting for confirmation...'}</h1>
)}
</div>
</Panel>
</div>
<ContactInformation/>
</main>
);
};

export default MailConfirmationPage;
9 changes: 7 additions & 2 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Clown from "./clown/clown";
import {Metadata} from "next";
import DefaultNavbar from "./common/defaultNavbar";
import { Analytics } from '@vercel/analytics/react';
import type { Viewport } from 'next'

export const metadata: Metadata = {
title: 'Unitystation - The Space Station 13 Remake Made in Unity',
Expand All @@ -20,9 +21,7 @@ export const metadata: Metadata = {
'roleplaying game',
],
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.',
colorScheme: 'dark',
authors: {name: 'Unitystation Team', url: 'https://github.com/unitystation'},
viewport: {width: "device-width", initialScale: 1},
robots: {follow: true, index: true},
openGraph: {
type: 'website',
Expand All @@ -38,6 +37,12 @@ export const metadata: Metadata = {
}
}

export const viewport: Viewport = {
themeColor: 'black',
width: 'device-width',
initialScale: 1,
}

export default function RootLayout({children,}: { children: React.ReactNode; }) {

return (
Expand Down
Loading