|
|
|
|
@ -23,6 +23,7 @@ import Link from "next/link";
|
|
|
|
|
import { SiGnuprivacyguard } from 'react-icons/si'
|
|
|
|
|
import { toast } from "react-toastify";
|
|
|
|
|
import { Token } from "nodemailer/lib/xoauth2";
|
|
|
|
|
import { isGeneratorFunction } from "util/types";
|
|
|
|
|
|
|
|
|
|
export async function getServerSideProps(context) {
|
|
|
|
|
const csrfToken = await getCsrfToken(context)
|
|
|
|
|
@ -40,19 +41,17 @@ type Props = {
|
|
|
|
|
csrfToken: Token
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const MainPage = ({ csrfToken }: Props) => {
|
|
|
|
|
const { data: session } = useSession();
|
|
|
|
|
|
|
|
|
|
const validationSchema = Yup.object().shape({
|
|
|
|
|
email: Yup.string().email(
|
|
|
|
|
"Veuillez rentrer une adresse mail valide"
|
|
|
|
|
),
|
|
|
|
|
acceptTerms: Yup.bool().oneOf(
|
|
|
|
|
[true],
|
|
|
|
|
"Vous devez accepter les conditions obligatoire"
|
|
|
|
|
)
|
|
|
|
|
// email: Yup.string().email(
|
|
|
|
|
// "Veuillez rentrer une adresse mail valide"
|
|
|
|
|
// ),
|
|
|
|
|
// acceptTerms: Yup.bool().oneOf(
|
|
|
|
|
// [true],
|
|
|
|
|
// "Vous devez accepter les conditions obligatoire"
|
|
|
|
|
// )
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
@ -67,40 +66,34 @@ const MainPage = ({ csrfToken }: Props) => {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const term = watch("acceptTerms")
|
|
|
|
|
const acceptTermCheckBox = watch("acceptTerms")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const connexionWithGoogle = async () => {
|
|
|
|
|
clearErrors("acceptTerms")
|
|
|
|
|
if (term) {
|
|
|
|
|
signIn("google");
|
|
|
|
|
} else {
|
|
|
|
|
toast.error('Vous devez accepter les conditions obligatoire', {
|
|
|
|
|
position: "top-center",
|
|
|
|
|
autoClose: 5000,
|
|
|
|
|
hideProgressBar: false,
|
|
|
|
|
closeOnClick: true,
|
|
|
|
|
pauseOnHover: true,
|
|
|
|
|
draggable: true,
|
|
|
|
|
progress: undefined,
|
|
|
|
|
theme: "light",
|
|
|
|
|
});
|
|
|
|
|
//relance une vérification de la checkbox
|
|
|
|
|
// await trigger("acceptTerms");
|
|
|
|
|
if (onCheckTerms()) {
|
|
|
|
|
signIn("google")
|
|
|
|
|
}
|
|
|
|
|
await trigger("acceptTerms");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const onMailSubmit = async (data: LoginSubmitForm) => {
|
|
|
|
|
if (onCheckTerms()) {
|
|
|
|
|
signIn("email", { email: data.email, callbackUrl: `${window.location.origin}/create` })
|
|
|
|
|
}
|
|
|
|
|
await trigger("acceptTerms");
|
|
|
|
|
await trigger("email");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const onSubmit = async (data: LoginSubmitForm) => {
|
|
|
|
|
if (term && !errors.email?.message) {
|
|
|
|
|
console.log("email", data.email);
|
|
|
|
|
|
|
|
|
|
signIn("email", { email: data.email, callbackUrl: `${window.location.origin}/create` })
|
|
|
|
|
|
|
|
|
|
const onCheckTerms = (): any => {
|
|
|
|
|
if (acceptTermCheckBox) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
toast.error('Vous devez accepter les conditions obligatoire', {
|
|
|
|
|
toast.error('Vous devez accepter les conditions obligatoires', {
|
|
|
|
|
position: "top-center",
|
|
|
|
|
autoClose: 5000,
|
|
|
|
|
autoClose: 2000,
|
|
|
|
|
hideProgressBar: false,
|
|
|
|
|
closeOnClick: true,
|
|
|
|
|
pauseOnHover: true,
|
|
|
|
|
@ -139,8 +132,9 @@ const MainPage = ({ csrfToken }: Props) => {
|
|
|
|
|
</Head>
|
|
|
|
|
<div className={`${style['bloc-content']} col-12 col-lg-6`}>
|
|
|
|
|
<h1 className="fw-light">Connexion</h1>
|
|
|
|
|
|
|
|
|
|
<SiGnuprivacyguard size={50} />
|
|
|
|
|
<form onSubmit={handleSubmit(onSubmit)}>
|
|
|
|
|
<form onSubmit={handleSubmit(onMailSubmit)}>
|
|
|
|
|
<div className="form-group mx-auto my-3 w-100">
|
|
|
|
|
<input
|
|
|
|
|
type="email" id="email" name="email"
|
|
|
|
|
@ -153,7 +147,6 @@ const MainPage = ({ csrfToken }: Props) => {
|
|
|
|
|
Se connecter avec mon email
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="invalid-feedback alert alert-danger">{errors.email?.message}</div>
|
|
|
|
|
</div>
|
|
|
|
|
<hr />
|
|
|
|
|
<div className="d-grid">
|
|
|
|
|
@ -175,7 +168,6 @@ const MainPage = ({ csrfToken }: Props) => {
|
|
|
|
|
{...register("acceptTerms")}
|
|
|
|
|
name="acceptTerms"
|
|
|
|
|
/>
|
|
|
|
|
{/* <div className="invalid-feedback alert alert-danger">{errors.acceptTerms?.message}</div> */}
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</div >
|
|
|
|
|
|