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

Feature/front/guilds page #15

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# DISCORD secrets
DISCORD_TOKEN=
DISCORD_CLIENT_ID=
DISCORD_TOKEN=

DATABASE_URL=

Expand Down
29 changes: 0 additions & 29 deletions apps/front/app/App.tsx

This file was deleted.

56 changes: 56 additions & 0 deletions apps/front/app/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use client';

import React from 'react';
import { InternalError, NotFound, Unauthorized } from '../utils/errors';
import Link from 'next/link';

type BaseError = {
code: number;
title: string;

description: string;
};

const Error = ({ error: thrownError }: { error: Error }) => {
let error: BaseError;
switch (thrownError.message) {
case Unauthorized.title:
error = Unauthorized;
break;
case NotFound.title:
error = NotFound;
break;
default:
error = InternalError;
}

return (
<div className="grid place-items-center py-24 px-6 sm:py-32 lg:px-8">
<div className="text-center">
<p className="text-base font-semibold text-light-primary dark:text-dark-primary">
{error.code}
</p>
<h1 className="mt-4 text-3xl font-bold tracking-tight text-light-dark-grey dark:text-dark-white sm:text-5xl">
{error.title}
</h1>
<p className="mt-6 text-base leading-7 text-light-light-grey dark:text-white">
{error.description}
</p>
<div className="mt-10 flex items-center justify-center gap-x-6">
<Link
href="/"
className="rounded-md bg-none px-3.5 py-2.5 text-sm font-semibold text-light-primary dark:text-dark-primary shadow-sm border-2 border-light-primary dark:border-dark-primary hover:bg-light-primary dark:hover:bg-dark-primary hover:text-light-white dark:hover:text-dark-black">
Go back home
</Link>
<Link
href="mailto:[email protected]"
className="text-sm font-semibold text-light-dark-grey dark:text-dark-white hover:underline">
Contact support <span aria-hidden="true">&rarr;</span>
</Link>
</div>
</div>
</div>
);
};

export default Error;
12 changes: 12 additions & 0 deletions apps/front/app/guilds/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';

export const metadata = {
title: {
default: 'Guilds',
template: '%s | Guilds',
},
};

export default function RootLayout({ children }) {
return <>{children}</>;
}
23 changes: 23 additions & 0 deletions apps/front/app/guilds/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import { getServerSession } from 'next-auth';
import { authOptions } from '../../pages/api/auth/[...nextauth]';
import Guilds from '../../components/app/guilds/Guilds';
import Unauthorized from '../../components/errors/Unauthorized';

export const dynamic = 'force-dynamic';

const GuildsPage = async () => {
const user = (await getServerSession(authOptions))?.user;
if (!user) {
return <Unauthorized />;
}

return (
<>
{/* @ts-expect-error waiting for TypeScript fix */}
<Guilds user={user} />
</>
);
};

export default GuildsPage;
7 changes: 5 additions & 2 deletions apps/front/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ export const metadata = {
default: 'Ch43 Bot',
template: '%s | Ch43 Bot',
},
description: 'The Ch43 bot to ensure students validity & uniqueness.',
icons: {
icon: '/vinci-logo.png',
},
};

export default function RootLayout({ children }) {
return (
<html>
<html lang="en" className="light">
<body>
<div className="App">{children}</div>
<div className="text-center min-h-screen flex items-center justify-center flex-col text-light-black dark:text-dark-white text-[calc(10px+2vmin)]">
{children}
</div>
</body>
</html>
);
Expand Down
23 changes: 22 additions & 1 deletion apps/front/app/loading.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
import React from 'react';

const Loading = () => {
return <div>Loading...</div>;
return (
<div role="status">
<svg
aria-hidden="true"
className="inline w-10 h-10 mr-2 text-gray-200 animate-spin dark:text-gray-600 fill-light-primary dark:fill-dark-primary"
viewBox="0 0 100 101"
fill="none"
xmlns="http://www.w3.org/2000/svg">
<path
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="currentColor"
/>
<path
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="currentFill"
/>
</svg>
<span className="sr-only">Loading...</span>
</div>
);
};

export default Loading;
13 changes: 8 additions & 5 deletions apps/front/app/not-found.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// import { redirect } from 'next/navigation';
import React from 'react';
'use client';

import { NotFound as NotFoundError } from '../utils/errors';
import { useEffect } from 'react';

const NotFound = () => {
//TODO : change when debugged
// redirect('/');
useEffect(() => {
throw new NotFoundError();
}, []);

return <p>404 - Not found</p>;
return <></>;
};

export default NotFound;
7 changes: 5 additions & 2 deletions apps/front/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import App from './App';
import Unauthenticated from '../components/app/Unauthenticated';
import Authenticated from '../components/app/Authenticated';
import { authOptions } from '../pages/api/auth/[...nextauth]';
import { getServerSession } from 'next-auth';

Expand All @@ -15,7 +16,9 @@ const Home = async () => {
return (
<>
<p>Welcome to Ch43 Bot</p>
<App user={user} />
<span className="text-light-primary dark:text-dark-primary">
{!user ? <Unauthenticated /> : <Authenticated user={user} />}
</span>
</>
);
};
Expand Down
4 changes: 2 additions & 2 deletions apps/front/app/verify/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { notFound } from 'next/navigation';
import { getUserToVerify } from '../../../utils/getters';
import Unauthenticated from './Unauthenticated';
import Authenticated from './Authenticated';
import Authenticated from '../../../components/app/verify/[id]/Authenticated';
import Unauthenticated from '../../../components/app/verify/[id]/Unauthenticated';
import { getServerSession } from 'next-auth';
import { authOptions } from '../../../pages/api/auth/[...nextauth]';

Expand Down
21 changes: 21 additions & 0 deletions apps/front/components/app/Authenticated.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use client';

import React from 'react';
import { useLogin } from '../../utils/hooks';

const Authenticated = ({ user }: { user: { name?: string } }) => {
const { logout } = useLogin();

return (
<>
{user.name}
<p>
<button className="login-button" onClick={logout}>
LOGOUT
</button>
</p>
</>
);
};

export default Authenticated;
18 changes: 18 additions & 0 deletions apps/front/components/app/Unauthenticated.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use client';

import React from 'react';
import { useLogin } from '../../utils/hooks';

const Unauthenticated = () => {
const { login } = useLogin();

return (
<>
<button className="login-button" onClick={login}>
LOGIN
</button>
</>
);
};

export default Unauthenticated;
31 changes: 31 additions & 0 deletions apps/front/components/app/guilds/Guild.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use client';

import React from 'react';
import Image from 'next/image';
import Link from 'next/link';

const Guild = ({ guild }) => {
return (
<div className="w-60 h-44 shadow-md bg-white dark:bg-dark-dark-grey rounded h-fit overflow-hidden flex flex-col justify-between">
{guild.icon && (
<Image
src={guild.icon}
alt={guild.name}
width={50}
height={50}
className="rounded-full mx-auto mt-4"
/>
)}
<p className="w-max text-xl mx-auto text-light-black dark:text-dark-white">
{guild.name}
</p>
<Link
href={`/guilds/${guild.id}`}
className="block w-full bg-none px-3.5 py-2.5 text-sm font-semibold text-light-primary dark:text-dark-primary border-t-[1px] border-light-primary dark:border-dark-primary hover:bg-light-primary dark:hover:bg-dark-primary hover:text-light-white dark:hover:text-dark-dark-grey">
Details
</Link>
</div>
);
};

export default Guild;
34 changes: 34 additions & 0 deletions apps/front/components/app/guilds/Guilds.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import { getUserGuilds } from '../../../utils/getters';
import Guild from './Guild';
import Unauthorized from '../../errors/Unauthorized';
import Link from 'next/link';

const Guilds = async ({ user }) => {
const guilds = await getUserGuilds(user as { email: string });
if (!guilds.length) {
return <Unauthorized />;
}

return (
<div>
<h1 className="mb-8 sm:mb-16 text-3xl sm:text-5xl font-bold text-light-primary dark:text-dark-primary">
Your administrable guilds
</h1>
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4 place-items-center">
{guilds.map((guild) => (
<Guild key={guild.id} guild={guild} />
))}
<div className="w-60 h-44 shadow-md bg-white dark:bg-dark-dark-grey hover:bg-light-primary dark:hover:bg-dark-primary rounded h-fit overflow-hidden flex justify-center items-center text-light-primary dark:text-dark-primary hover:text-light-white dark:hover:text-dark-dark-grey">
<Link
href={`https://discord.com/api/oauth2/authorize?client_id=${process.env.DISCORD_CLIENT_ID}&permissions=8&scope=bot`}
target="_blank">
+
</Link>
</div>
</div>
</div>
);
};

export default Guilds;
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ const Authenticated = ({
return (
<>
<p>{message}</p>
<span className="App-title">{user.name}</span>
<span className="text-light-primary dark:text-dark-primary">
{user.name}
</span>
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use client';

import React from 'react';
import { useLogin } from '../../../utils/hooks';
import { useLogin } from '../../../../utils/hooks';

const Unauthenticated = () => {
const { login } = useLogin();

return (
<>
<p>Click on the button below in order to complete the verification</p>
<button className="App-button" onClick={login}>
<button className="login-button" onClick={login}>
CONFIRM
</button>
</>
Expand Down
14 changes: 14 additions & 0 deletions apps/front/components/errors/Unauthorized.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use client';

import { useEffect } from 'react';
import { Unauthorized as UnauthorizedError } from '../../utils/errors';

const Unauthorized = () => {
useEffect(() => {
throw new UnauthorizedError();
}, []);

return <></>;
};

export default Unauthorized;
Loading