⚡️ add - api generationGain , api superadmin , readme , fichier de seed
This commit is contained in:
1 parent
141d9e53e8
commit
e85117b2c7
25 files changed
+768
-310
No files matched your search
+68
-41
@@ -1,60 +1,87 @@
|
||||
import React from "react";
|
||||
import type { GetServerSideProps } from "next";
|
||||
import Layout from "../components/Layout";
|
||||
import Post, { PostProps } from "../components/Post";
|
||||
import prisma from '../lib/prisma'
|
||||
|
||||
export const getServerSideProps: GetServerSideProps = async () => {
|
||||
const feed = await prisma.post.findMany({
|
||||
where: {
|
||||
published: true,
|
||||
},
|
||||
include: {
|
||||
author: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
import { yupResolver } from "@hookform/resolvers/yup";
|
||||
import { useForm } from "react-hook-form";
|
||||
import * as Yup from 'yup';
|
||||
import { useSession } from "next-auth/react";
|
||||
|
||||
type CodeSubmitForm = {
|
||||
codeCadeau: string;
|
||||
};
|
||||
|
||||
const MainPage = () => {
|
||||
const { data: session } = useSession();
|
||||
|
||||
const validationSchema = Yup.object().shape({
|
||||
codeCadeau: Yup.string().trim().required("Vous n'avez pas rentrer de code cadeau !"),
|
||||
});
|
||||
return {
|
||||
props: { feed },
|
||||
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
formState: { errors }
|
||||
} = useForm<CodeSubmitForm>({
|
||||
resolver: yupResolver(validationSchema)
|
||||
});
|
||||
|
||||
const onSubmit = async (data: CodeSubmitForm) => {
|
||||
|
||||
if (!session) {
|
||||
return <Layout>
|
||||
<p>Vous devez vous connecter pour tester votre !</p>
|
||||
</Layout>
|
||||
}
|
||||
|
||||
|
||||
|
||||
// try {
|
||||
// const body = { bioValue: data.bio };
|
||||
// await fetch(`/api/profile`, {
|
||||
// method: "POST",
|
||||
// headers: { "Content-Type": "application/json" },
|
||||
// body: JSON.stringify(body),
|
||||
// })
|
||||
// .then((res) => res.json())
|
||||
// .then((data) => {
|
||||
// setResponse(data);
|
||||
// console.log('response', data);
|
||||
// })
|
||||
// await Router.push("/profile");
|
||||
// } catch (error) {
|
||||
// console.error(error);
|
||||
// }
|
||||
};
|
||||
};
|
||||
|
||||
type Props = {
|
||||
feed: PostProps[];
|
||||
};
|
||||
|
||||
const Blog = (props : Props) => {
|
||||
|
||||
return (
|
||||
<Layout>
|
||||
<div className="page">
|
||||
<h1>Public Feed</h1>
|
||||
<h1>TheTipTop - jeu concours !</h1>
|
||||
<main>
|
||||
{props.feed.map((post) => (
|
||||
<div key={post.id} className="post">
|
||||
<Post post={post} />
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
<div className="form-group">
|
||||
<label>Entre votre code :</label>
|
||||
<input
|
||||
placeholder="A123456B..."
|
||||
type="text"
|
||||
{...register('codeCadeau')}
|
||||
className={`form-control ${errors.codeCadeau ? 'is-invalid' : ''}`}
|
||||
/>
|
||||
<div className="invalid-feedback">{errors.codeCadeau?.message}</div>
|
||||
</div>
|
||||
))}
|
||||
<div className="form-group">
|
||||
<button type="submit" className="btn btn-primary">
|
||||
Tester mon code cadeau !
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</main>
|
||||
</div>
|
||||
<style jsx>{`
|
||||
.post {
|
||||
background: white;
|
||||
transition: box-shadow 0.1s ease-in;
|
||||
}
|
||||
|
||||
.post:hover {
|
||||
box-shadow: 1px 1px 3px #aaa;
|
||||
}
|
||||
|
||||
.post + .post {
|
||||
margin-top: 2rem;
|
||||
}
|
||||
`}</style>
|
||||
</Layout>
|
||||
);
|
||||
};
|
||||
|
||||
export default Blog;
|
||||
export default MainPage;
|
||||
Reference in new issue
Block a user