✅add : correction ajout de gain et api test code
This commit is contained in:
1 parent
04423aa6c7
commit
fec63499c6
16 files changed
+339
-83
No files matched your search
+54
-39
@@ -1,4 +1,4 @@
|
||||
import React from "react";
|
||||
import React, { useState } from "react";
|
||||
import Layout from "../components/Layout";
|
||||
import prisma from '../lib/prisma'
|
||||
|
||||
@@ -29,9 +29,6 @@ import { GetServerSideProps } from "next";
|
||||
|
||||
import { toast } from "react-toastify";
|
||||
|
||||
// // doesn't do anything, supposed to add the land in <html>
|
||||
// import "next.config.mjs";
|
||||
|
||||
|
||||
type CodeSubmitForm = {
|
||||
codeCadeau: string;
|
||||
@@ -40,9 +37,10 @@ type CodeSubmitForm = {
|
||||
|
||||
const MainPage = () => {
|
||||
const { data: session } = useSession();
|
||||
const [response, setResponse] = useState(null)
|
||||
|
||||
const validationSchema = Yup.object().shape({
|
||||
codeCadeau: Yup.string().trim().required("Veuillez rentrer un code cadeau !"),
|
||||
// codeCadeau: Yup.string().trim().required("Veuillez rentrer un code cadeau !"),
|
||||
});
|
||||
|
||||
const {
|
||||
@@ -55,43 +53,60 @@ const MainPage = () => {
|
||||
|
||||
const onSubmit = async (data: CodeSubmitForm) => {
|
||||
|
||||
toast.error(errors.codeCadeau?.message, {
|
||||
position: "top-center",
|
||||
autoClose: 5000,
|
||||
hideProgressBar: false,
|
||||
closeOnClick: true,
|
||||
pauseOnHover: true,
|
||||
draggable: true,
|
||||
progress: undefined,
|
||||
theme: "light",
|
||||
});
|
||||
|
||||
|
||||
|
||||
if (!session) {
|
||||
return <Layout>
|
||||
<p>Vous devez vous connecter pour tester votre !</p>
|
||||
</Layout>
|
||||
if (!errors) {
|
||||
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);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
try {
|
||||
const body = { codeCadeau: data.codeCadeau };
|
||||
await fetch(`/api/testcode`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
setResponse(data);
|
||||
console.log('response', data);
|
||||
if (data.err) {
|
||||
console.log('ERR', data);
|
||||
toast.error(data.err, {
|
||||
position: "top-center",
|
||||
autoClose: 2000,
|
||||
hideProgressBar: false,
|
||||
closeOnClick: true,
|
||||
pauseOnHover: true,
|
||||
draggable: true,
|
||||
progress: undefined,
|
||||
theme: "light",
|
||||
});
|
||||
return;
|
||||
// await Router.push("/profile");
|
||||
}
|
||||
console.log('SUCESS', data);
|
||||
toast.success(data.success, {
|
||||
position: "top-center",
|
||||
autoClose: 5000,
|
||||
hideProgressBar: false,
|
||||
closeOnClick: true,
|
||||
pauseOnHover: true,
|
||||
draggable: true,
|
||||
progress: undefined,
|
||||
theme: "light",
|
||||
});
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('ERROR :', error);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -162,7 +177,7 @@ const MainPage = () => {
|
||||
|
||||
/>
|
||||
<small id="codeHelp" className="form-text text-muted">Code à usage unique</small>
|
||||
<div className="invalid-feedback alert alert-danger">{errors.codeCadeau?.message}</div>
|
||||
<div className="invalid-feedback">{errors.codeCadeau?.message}</div>
|
||||
</div>
|
||||
<div className="form-group mx-auto my-3 w-100">
|
||||
<button type="submit" className={`${style['aButton']} btn btn-primary`}>Découvrir mon cadeau !</button>
|
||||
|
||||
Reference in new issue
Block a user