You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
166 lines
3.9 KiB
166 lines
3.9 KiB
import React from "react";
|
|
import prisma from '../lib/prisma'
|
|
|
|
import Image from 'next/image';
|
|
import * as Yup from 'yup';
|
|
import Head from "next/head";
|
|
import { signIn, useSession } from "next-auth/react";
|
|
import { yupResolver } from "@hookform/resolvers/yup";
|
|
import { useForm } from "react-hook-form";
|
|
|
|
import { AiOutlineGoogle } from 'react-icons/ai'
|
|
|
|
import Router from "next/router";
|
|
|
|
|
|
import style from '../styles/Connexion.module.css';
|
|
|
|
import imageConnexion from '../public/images/connexion_image.png'
|
|
|
|
|
|
import Link from "next/link";
|
|
|
|
import { SiGnuprivacyguard } from 'react-icons/si'
|
|
|
|
|
|
|
|
|
|
|
|
type LoginSubmitForm = {
|
|
email: string,
|
|
acceptTerms: boolean
|
|
};
|
|
|
|
|
|
|
|
const MainPage = () => {
|
|
const { data: session } = useSession();
|
|
|
|
const validationSchema = Yup.object().shape({
|
|
email: Yup.string().email(),
|
|
acceptTerms: Yup.bool().oneOf(
|
|
[true],
|
|
"Accepter les conditions est obligatoire"
|
|
)
|
|
})
|
|
|
|
const {
|
|
register,
|
|
handleSubmit,
|
|
watch,
|
|
trigger,
|
|
formState: { errors }
|
|
} = useForm<LoginSubmitForm>({
|
|
resolver: yupResolver(validationSchema)
|
|
});
|
|
|
|
|
|
const term = watch("acceptTerms")
|
|
const connexionWithGoogle = async () => {
|
|
if (term) {
|
|
signIn("google");
|
|
}
|
|
//relance une vérification de la checkbox
|
|
await trigger("acceptTerms");
|
|
}
|
|
|
|
const onSubmit = async (data: LoginSubmitForm) => {
|
|
|
|
|
|
// 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);
|
|
// }
|
|
};
|
|
|
|
|
|
return (
|
|
<>
|
|
<Head>
|
|
<title>Connexion</title>
|
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="" />
|
|
</Head>
|
|
|
|
<div className={`${style['bloc-content']} col-12 col-lg-6`}>
|
|
|
|
|
|
<h1 className="fw-light">Connexion</h1>
|
|
<SiGnuprivacyguard size={50} />
|
|
|
|
<form onSubmit={handleSubmit(onSubmit)}>
|
|
<div className="form-group mx-auto my-3 w-100">
|
|
|
|
<div className="mb-3">
|
|
|
|
<input
|
|
type="email"
|
|
className={`form-control ${errors.email ? 'is-invalid' : ''}`}
|
|
placeholder="Email..."
|
|
|
|
{...register("email")}
|
|
/>
|
|
</div>
|
|
<div className="d-grid">
|
|
<button type="submit" className="btn btn-primary">
|
|
Se connecter avec mon email
|
|
</button>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<hr />
|
|
|
|
<div className="d-grid">
|
|
<button onClick={connexionWithGoogle} type="button" className={`btn btn-primary ${style.loginButton}`} style={{ backgroundColor: "#dd4b39" }}>
|
|
<span className={style.logo}><AiOutlineGoogle /></span>Se connecter avec google
|
|
</button>
|
|
</div>
|
|
|
|
<div className="form-check">
|
|
<label
|
|
htmlFor="acceptTerms"
|
|
className="form-check-label"
|
|
>
|
|
J'ai lu et j'accepte les
|
|
conditions
|
|
</label>
|
|
<input
|
|
type="checkbox"
|
|
className="form-check-input"
|
|
{...register("acceptTerms")}
|
|
name="acceptTerms"
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
<div className="invalid-feedback alert alert-danger">{errors.acceptTerms?.message}</div>
|
|
<div className="invalid-feedback alert alert-danger">{errors.email?.message}</div>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</>)
|
|
};
|
|
|
|
export default MainPage;
|
|
|
|
|