parent
7827aa119f
commit
65efdcac94
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,235 @@
|
||||
import React, { useEffect, useState, useSyncExternalStore } from "react";
|
||||
import prisma from '../lib/prisma'
|
||||
|
||||
|
||||
import Image from 'next/image';
|
||||
import * as Yup from 'yup';
|
||||
import Head from "next/head";
|
||||
import { getCsrfToken, getSession, signIn, useSession } from "next-auth/react";
|
||||
import { yupResolver } from "@hookform/resolvers/yup";
|
||||
import "yup-phone";
|
||||
import { SubmitHandler, useForm } from "react-hook-form";
|
||||
|
||||
import { AiOutlineCheck } 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 { GrValidate } from 'react-icons/gr'
|
||||
import { toast } from "react-toastify";
|
||||
import { Token } from "nodemailer/lib/xoauth2";
|
||||
import { isGeneratorFunction } from "util/types";
|
||||
import { UserProps } from "../types/user";
|
||||
import { UserGainProps } from "../types/userGain";
|
||||
import { Gain, Produit, User } from "@prisma/client";
|
||||
|
||||
|
||||
type FormData = {
|
||||
email: string;
|
||||
name: string;
|
||||
surname: string;
|
||||
address: string;
|
||||
zipCode: string;
|
||||
phoneNumber: string;
|
||||
};
|
||||
|
||||
export async function getServerSideProps(context) {
|
||||
const session = await getSession(context)
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: {
|
||||
email: session?.user.email
|
||||
}
|
||||
});
|
||||
|
||||
const userGains = await prisma.gain.findMany({
|
||||
where: {
|
||||
userId: user.id
|
||||
},
|
||||
include: {
|
||||
produit: true
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
return {
|
||||
props: {
|
||||
user: JSON.parse(JSON.stringify(user)),
|
||||
userGains: JSON.parse(JSON.stringify(userGains)),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type Props = {
|
||||
user: User;
|
||||
userGains: Gain;
|
||||
}
|
||||
|
||||
const MonCompte = (props: Props) => {
|
||||
|
||||
const { data: session, status } = useSession();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
console.log('user', props.user);
|
||||
console.log('userGains', props.userGains);
|
||||
}, [])
|
||||
|
||||
const validationSchema = Yup.object().shape({
|
||||
name: Yup.string()
|
||||
.trim()
|
||||
.min(2, "le nom doit comporter au moins 2 caractères")
|
||||
.max(20, "le nom ne doit pas dépasser 20 caractères"),
|
||||
surname: Yup.string()
|
||||
.trim()
|
||||
.min(2, "le prenom doit comporter au moins 2 caractères")
|
||||
.max(20, "le prenom ne doit pas dépasser 20 caractères"),
|
||||
address: Yup.string()
|
||||
.trim()
|
||||
.max(50, "l'adresse ne doit pas dépasser 50 caractères"),
|
||||
zipCode: Yup.number()
|
||||
.typeError("le code postal est invalide"),
|
||||
phoneNumber: Yup.string()
|
||||
.phone("FR", true, "le numéro de téléphone est invalide")
|
||||
});
|
||||
|
||||
const { register, setValue, handleSubmit, formState: { errors } } = useForm<FormData>({
|
||||
resolver: yupResolver(validationSchema)
|
||||
});
|
||||
const onSubmit: SubmitHandler<FormData> = data => console.log(data);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
<title>Mon Compte</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="" />
|
||||
</Head>
|
||||
|
||||
<div className={`${style['masthead']} d-flex justify-content-center align-items-center text-center`}>
|
||||
<div className="container align-items-center d-flex flex-column">
|
||||
|
||||
<div className={`${style['bloc-content']} col-12 col-md-12`}>
|
||||
<h1 className="fw-light">Mon Compte</h1>
|
||||
<hr />
|
||||
<div className="row">
|
||||
<div className="col-md-6 col-sm-12">
|
||||
<h1 className="fw-light">Mes informations</h1>
|
||||
<hr />
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
<div className="form-group">
|
||||
|
||||
<div className="form-group row">
|
||||
<label htmlFor="staticEmail" className="col-sm-3 col-form-label">Email :</label>
|
||||
<div className="col-sm-9">
|
||||
<input type="text" readOnly className="form-control-plaintext text-sm-center" id="staticEmail" value={session?.user.email || ''} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="form-group row">
|
||||
<label htmlFor="inputName" className="col-sm-3 col-form-label">Nom :</label>
|
||||
<div className="col-sm-9">
|
||||
<input {...register("name")} className={`form-control ${errors.name ? 'is-invalid' : ''}`} id="inputName" placeholder="John..." />
|
||||
<div className="invalid-feedback alert alert-danger mt-2">{errors.name?.message}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="form-group row">
|
||||
<label htmlFor="surname" className="col-sm-3 col-form-label">Prenom :</label>
|
||||
<div className="col-sm-9">
|
||||
<input {...register("surname")} className={`form-control ${errors.surname ? 'is-invalid' : ''}`} id="surname" placeholder="Doe..." />
|
||||
<div className="invalid-feedback alert alert-danger mt-2">{errors.surname?.message}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="form-group row">
|
||||
<label htmlFor="address" className="col-sm-3 col-form-label">Adresse :</label>
|
||||
<div className="col-sm-9">
|
||||
<input {...register("address")} className={`form-control ${errors.address ? 'is-invalid' : ''}`} id="address" placeholder="1 rue de la paix..." />
|
||||
<div className="invalid-feedback alert alert-danger mt-2">{errors.address?.message}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="form-group row">
|
||||
<label htmlFor="zipCode" className="col-sm-3 col-form-label">Code postale :</label>
|
||||
<div className="col-sm-9">
|
||||
<input {...register("zipCode")} className={`form-control ${errors.zipCode ? 'is-invalid' : ''}`} id="zipCode" placeholder="95000..." />
|
||||
<div className="invalid-feedback alert alert-danger mt-2">{errors.zipCode?.message}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="form-group row">
|
||||
<label htmlFor="phoneNumber" className="col-sm-3 col-form-label">Téléphone :</label>
|
||||
<div className="col-sm-9">
|
||||
<input {...register("phoneNumber")} className={`form-control ${errors.phoneNumber ? 'is-invalid' : ''}`} id="phoneNumber" placeholder="0123456789..." />
|
||||
<div className="invalid-feedback alert alert-danger mt-2">{errors.phoneNumber?.message}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
className="btn btn-primary mt-2"
|
||||
>
|
||||
Sauvegarder les changements
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div className="col-md-6 col-sm-12">
|
||||
<h1 className="fw-light">Mes cadeaux</h1>
|
||||
<hr />
|
||||
{!props.userGains && <p>Pas encore de cadeau gagné</p>}
|
||||
</div>
|
||||
<table className="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">#</th>
|
||||
<th scope="col">Mes codes joué</th>
|
||||
<th scope="col">Mes cadeaux</th>
|
||||
<th scope="col">Handle</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{props.userGains.map((info: any) => {
|
||||
<tr>
|
||||
<th scope="row"></th>
|
||||
<td>Mark</td>
|
||||
<td>Otto</td>
|
||||
<td>@mdo</td>
|
||||
</tr>
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</div >
|
||||
|
||||
</div>
|
||||
</div >
|
||||
</>)
|
||||
};
|
||||
|
||||
export default MonCompte;
|
||||
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- You are about to alter the column `prixTtc` on the `Produit` table. The data in that column could be lost. The data in that column will be cast from `Decimal(65,30)` to `Integer`.
|
||||
- You are about to drop the `Post` table. If the table is not empty, all the data it contains will be lost.
|
||||
- You are about to drop the `Profile` table. If the table is not empty, all the data it contains will be lost.
|
||||
|
||||
*/
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Post" DROP CONSTRAINT "Post_authorId_fkey";
|
||||
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Profile" DROP CONSTRAINT "Profile_userId_fkey";
|
||||
|
||||
-- DropIndex
|
||||
DROP INDEX "Gain_userId_key";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Produit" ALTER COLUMN "prixTtc" SET DATA TYPE INTEGER;
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" ADD COLUMN "address" TEXT,
|
||||
ADD COLUMN "phoneNumber" TEXT,
|
||||
ADD COLUMN "surname" TEXT,
|
||||
ADD COLUMN "zipCode" TEXT;
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "Post";
|
||||
|
||||
-- DropTable
|
||||
DROP TABLE "Profile";
|
||||
|
After Width: | Height: | Size: 8.2 KiB |
|
After Width: | Height: | Size: 552 KiB |
@ -1,4 +1,9 @@
|
||||
export type UserProps = {
|
||||
role?: string;
|
||||
email?: string
|
||||
name: string;
|
||||
role: string;
|
||||
email: string;
|
||||
surname?: string;
|
||||
address?: string;
|
||||
zipCode?: string;
|
||||
phoneNumber?: string;
|
||||
}
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
import { Produit } from ".prisma/client";
|
||||
|
||||
export type UserGainProps = {
|
||||
codeCadeau: string;
|
||||
dateRetrait: Date;
|
||||
produit: Produit;
|
||||
produitId: number;
|
||||
actif: Boolean;
|
||||
}
|
||||
Loading…
Reference in new issue