frontend: FunctionsList et début de /admin

This commit is contained in:
Divlo
2020-04-11 21:07:13 +02:00
parent 02058fc2fb
commit c157f7e922
9 changed files with 213 additions and 98 deletions

View File

@@ -0,0 +1,31 @@
import { Fragment } from 'react';
import Cookies from "universal-cookie";
import HeadTag from '../../components/HeadTag';
import redirect from '../../utils/redirect';
const AdminFunctionComponent = (props) => {
if (!props.user.isAdmin && typeof window != 'undefined') {
return redirect({}, '/404');
}
return (
<Fragment>
<HeadTag />
<p>{props.slug}</p>
</Fragment>
);
}
export async function getServerSideProps({ req, params }) {
const cookies = new Cookies(req.headers.cookie);
const { slug } = params;
return {
props: {
user: { ...cookies.get('user') },
slug
}
};
}
export default AdminFunctionComponent;

View File

@@ -0,0 +1,18 @@
import Cookies from "universal-cookie";
const addFunction = (props) => {
return (
<p>Crée une nouvelle fonction</p>
);
}
export async function getServerSideProps({ req }) {
const cookies = new Cookies(req.headers.cookie);
return {
props: {
user: { ...cookies.get('user') }
}
};
}
export default addFunction;

View File

@@ -0,0 +1,39 @@
import { Fragment } from 'react';
import Link from 'next/link';
import Cookies from "universal-cookie";
import HeadTag from '../../components/HeadTag';
import FunctionsList from '../../components/FunctionsList/FunctionsList';
import redirect from '../../utils/redirect';
const Admin = (props) => {
if (!props.user.isAdmin && typeof window != 'undefined') {
return redirect({}, '/404');
}
return (
<Fragment>
<HeadTag title="Admin - FunctionProject" description="Page d'administration de FunctionProject." />
<FunctionsList isAdmin>
<div className="col-24">
<h1 className="Functions__title">Administration</h1>
<Link href={"/admin/addFunction"}>
<button style={{ margin: '0 0 40px 0' }} className="btn btn-dark">Crée une nouvelle fonction</button>
</Link>
</div>
</FunctionsList>
</Fragment>
);
}
export async function getServerSideProps({ req }) {
const cookies = new Cookies(req.headers.cookie);
return {
props: {
user: { ...cookies.get('user') }
}
};
}
export default Admin;