✅ ajout de page mon compte - en cours
This commit is contained in:
1 parent
7827aa119f
commit
65efdcac94
19 files changed
+2126
-92
No files matched your search
+76
-25
@@ -28,20 +28,34 @@ import { GetServerSideProps } from "next";
|
||||
|
||||
import { toast } from "react-toastify";
|
||||
|
||||
import footerGrass from '../public/images/footer_image.webp'
|
||||
|
||||
// // doesn't do anything, supposed to add the land in <html>
|
||||
// import "next.config.mjs";
|
||||
|
||||
import arrowUp from '../public/images/png/arrowup.png'
|
||||
|
||||
import footerGrass from '../public/images/footer_image.webp'
|
||||
|
||||
|
||||
type CodeSubmitForm = {
|
||||
codeCadeau: string;
|
||||
};
|
||||
|
||||
type ResponseData = {
|
||||
success: string,
|
||||
winProduct: {
|
||||
actif: boolean,
|
||||
id: number,
|
||||
nomProduit: string,
|
||||
prixTtc: number
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
const MainPage = () => {
|
||||
|
||||
const { data: session } = useSession();
|
||||
const [response, setResponse] = useState(null)
|
||||
const [response, setResponse] = useState<ResponseData | null>(null)
|
||||
const [winAnimation, setWinAnimation] = useState(false)
|
||||
|
||||
const validationSchema = Yup.object().shape({
|
||||
// codeCadeau: Yup.string().trim().required("Veuillez rentrer un code cadeau !"),
|
||||
@@ -55,21 +69,25 @@ const MainPage = () => {
|
||||
resolver: yupResolver(validationSchema)
|
||||
});
|
||||
|
||||
const mountedStyle = {
|
||||
animation: "inAnimation 250ms ease-in"
|
||||
};
|
||||
const unmountedStyle = {
|
||||
animation: "outAnimation 270ms ease-out",
|
||||
animationFillMode: "forwards"
|
||||
};
|
||||
|
||||
|
||||
const onSubmit = async (data: CodeSubmitForm) => {
|
||||
|
||||
if (!errors) {
|
||||
if (!session) {
|
||||
return <Layout>
|
||||
<p>Vous devez vous connecter pour tester votre !</p>
|
||||
<p>Vous devez vous connecter pour tester votre code cadeau!</p>
|
||||
</Layout>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
try {
|
||||
const body = { codeCadeau: data.codeCadeau };
|
||||
await fetch(`/api/testcode`, {
|
||||
@@ -78,9 +96,8 @@ const MainPage = () => {
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((data) => {
|
||||
.then(async (data) => {
|
||||
setResponse(data);
|
||||
console.log('response', data);
|
||||
if (data.err) {
|
||||
console.log('ERR', data);
|
||||
toast.error(data.err, {
|
||||
@@ -96,24 +113,23 @@ const MainPage = () => {
|
||||
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",
|
||||
});
|
||||
setWinAnimation(true)
|
||||
await confettiTime();
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('ERROR :', error);
|
||||
}
|
||||
};
|
||||
|
||||
const confettiTime = async (): Promise<void> => {
|
||||
const JSConfetti = (await import('js-confetti')).default
|
||||
const jsConfetti = new JSConfetti()
|
||||
jsConfetti.addConfetti()
|
||||
}
|
||||
|
||||
const getCadeau = () => {
|
||||
Router.push("/mon-compte")
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
@@ -163,7 +179,7 @@ const MainPage = () => {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="col-12 align-items-center d-flex flex-column">
|
||||
{!winAnimation && <div className="col-12 align-items-center d-flex flex-column">
|
||||
<div className={`${style['bloc-content']} col-12 col-md-6`}>
|
||||
<div className={`${style['imageWrapper']}`}>
|
||||
<Image
|
||||
@@ -193,7 +209,42 @@ const MainPage = () => {
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>}
|
||||
|
||||
|
||||
{winAnimation && <div className="col-12 align-items-center d-flex flex-column">
|
||||
|
||||
<div className={`${style['cadeau-bloc-content']} col-12 col-md-6`} onClick={() => setWinAnimation(false)}
|
||||
>
|
||||
<div className={`${style['cadeau-bloc']}`}>
|
||||
<h1>Vous avez gagnez : un {response.winProduct.nomProduit} !</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className={`${style['imageWrapper']}`}>
|
||||
<Image
|
||||
src={arrowUp}
|
||||
alt="thetiptop flèche haute"
|
||||
|
||||
width={50}
|
||||
height={50}
|
||||
className={`${style['rotatingImage']}`}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div className="row">
|
||||
<button onClick={getCadeau} className={`${style['aButton']} btn btn-primary`}>Voir mes cadeaux !</button>
|
||||
<button onClick={() => setWinAnimation(false)} className={`${style['aButton']} btn btn-primary mt-2`}>Rejouer un ticket !</button>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>}
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user