|
|
|
@ -1,9 +1,6 @@
|
|
|
|
import React, { useEffect, useState, useSyncExternalStore } from "react";
|
|
|
|
import React, { useEffect, useState, useSyncExternalStore } from "react";
|
|
|
|
import prisma from '../lib/prisma'
|
|
|
|
import prisma from '../lib/prisma'
|
|
|
|
|
|
|
|
|
|
|
|
import dateFormat, { masks } from "dateformat";
|
|
|
|
import dateFormat, { masks } from "dateformat";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import Image from 'next/image';
|
|
|
|
import Image from 'next/image';
|
|
|
|
import * as Yup from 'yup';
|
|
|
|
import * as Yup from 'yup';
|
|
|
|
import Head from "next/head";
|
|
|
|
import Head from "next/head";
|
|
|
|
@ -11,34 +8,24 @@ import { getCsrfToken, getSession, signIn, useSession } from "next-auth/react";
|
|
|
|
import { yupResolver } from "@hookform/resolvers/yup";
|
|
|
|
import { yupResolver } from "@hookform/resolvers/yup";
|
|
|
|
import "yup-phone";
|
|
|
|
import "yup-phone";
|
|
|
|
import { SubmitHandler, useForm } from "react-hook-form";
|
|
|
|
import { SubmitHandler, useForm } from "react-hook-form";
|
|
|
|
|
|
|
|
|
|
|
|
import { AiOutlineCheck } from 'react-icons/ai'
|
|
|
|
import { AiOutlineCheck } from 'react-icons/ai'
|
|
|
|
|
|
|
|
|
|
|
|
import Router from "next/router";
|
|
|
|
import Router from "next/router";
|
|
|
|
|
|
|
|
|
|
|
|
import { useRouter } from 'next/navigation';
|
|
|
|
import { useRouter } from 'next/navigation';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import style from '../styles/Connexion.module.css';
|
|
|
|
import style from '../styles/Connexion.module.css';
|
|
|
|
|
|
|
|
|
|
|
|
import imageConnexion from '../public/images/connexion_image.png'
|
|
|
|
import imageConnexion from '../public/images/connexion_image.png'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import Link from "next/link";
|
|
|
|
import Link from "next/link";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { TfiInfoAlt } from 'react-icons/tfi'
|
|
|
|
import { TfiInfoAlt } from 'react-icons/tfi'
|
|
|
|
import { TfiGift } from 'react-icons/tfi'
|
|
|
|
import { TfiGift } from 'react-icons/tfi'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { toast } from "react-toastify";
|
|
|
|
import { toast } from "react-toastify";
|
|
|
|
import { Token } from "nodemailer/lib/xoauth2";
|
|
|
|
import { Token } from "nodemailer/lib/xoauth2";
|
|
|
|
import { isGeneratorFunction } from "util/types";
|
|
|
|
import { isGeneratorFunction } from "util/types";
|
|
|
|
import { UserProps } from "../types/user";
|
|
|
|
import { UserProps } from "../types/user";
|
|
|
|
import { UserGainProps } from "../types/userGain";
|
|
|
|
import { UserGainProps } from "../types/userGain";
|
|
|
|
import { Gain, Produit, Role, User } from "@prisma/client";
|
|
|
|
import { Gain, Produit, Role, TicketsRestants, User } from "@prisma/client";
|
|
|
|
|
|
|
|
import { Doughnut } from "react-chartjs-2";
|
|
|
|
|
|
|
|
import { Chart as ChartJS, ArcElement, Tooltip, Legend, RadialLinearScale } from 'chart.js';
|
|
|
|
|
|
|
|
import { PolarArea } from 'react-chartjs-2';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type FormData = {
|
|
|
|
type FormData = {
|
|
|
|
email: string;
|
|
|
|
email: string;
|
|
|
|
@ -74,13 +61,20 @@ export async function getServerSideProps(context) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const tickets = await prisma.gain.findMany({})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const totalTirageRestant = await prisma.ticketsRestants.findFirst({})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const produits = await prisma.produit.findMany({})
|
|
|
|
const produits = await prisma.produit.findMany({})
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
props: {
|
|
|
|
user: JSON.parse(JSON.stringify(user)),
|
|
|
|
user: JSON.parse(JSON.stringify(user)),
|
|
|
|
produits: JSON.parse(JSON.stringify(produits)),
|
|
|
|
produits: JSON.parse(JSON.stringify(produits)),
|
|
|
|
users: JSON.parse(JSON.stringify(users))
|
|
|
|
users: JSON.parse(JSON.stringify(users)),
|
|
|
|
|
|
|
|
tickets: JSON.parse(JSON.stringify(tickets)),
|
|
|
|
|
|
|
|
totalTirageRestant: JSON.parse(JSON.stringify(totalTirageRestant))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -88,7 +82,9 @@ export async function getServerSideProps(context) {
|
|
|
|
type Props = {
|
|
|
|
type Props = {
|
|
|
|
user: User;
|
|
|
|
user: User;
|
|
|
|
produits: Produit[];
|
|
|
|
produits: Produit[];
|
|
|
|
users: any
|
|
|
|
users: any,
|
|
|
|
|
|
|
|
tickets: Gain[]
|
|
|
|
|
|
|
|
totalTirageRestant: TicketsRestants
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const Admin = (props: Props) => {
|
|
|
|
const Admin = (props: Props) => {
|
|
|
|
@ -103,6 +99,47 @@ const Admin = (props: Props) => {
|
|
|
|
const isSuperAdmin = session?.user['role'] === Role.SUPERADMIN
|
|
|
|
const isSuperAdmin = session?.user['role'] === Role.SUPERADMIN
|
|
|
|
const bigWinner = users?.find((user) => user?.isBigWinner)
|
|
|
|
const bigWinner = users?.find((user) => user?.isBigWinner)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ChartJS.register(RadialLinearScale, ArcElement, Tooltip, Legend);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const TicketRestants = props.tickets?.filter(ticket => ticket.codeActif === true).length
|
|
|
|
|
|
|
|
const TicketUtilise = props.tickets?.filter(ticket => ticket.codeActif === false).length
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const TotalTirageRestant = props.totalTirageRestant?.total;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ticketDataChart = {
|
|
|
|
|
|
|
|
labels: ['Tickets généré utlisés', 'Tickets généré restants'],
|
|
|
|
|
|
|
|
datasets: [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
label: 'Tickets restants généré',
|
|
|
|
|
|
|
|
data: [TicketUtilise, TicketRestants],
|
|
|
|
|
|
|
|
backgroundColor: [
|
|
|
|
|
|
|
|
'rgba(255, 99, 132, 0.2)',
|
|
|
|
|
|
|
|
'rgba(54, 162, 235, 0.2)',
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
borderColor: [
|
|
|
|
|
|
|
|
'rgba(255, 99, 132, 1)',
|
|
|
|
|
|
|
|
'rgba(54, 162, 235, 1)',
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
borderWidth: 1,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const TotalTirageRestantData = {
|
|
|
|
|
|
|
|
labels: ['Total tirage restant'],
|
|
|
|
|
|
|
|
datasets: [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
label: 'Tirage de ticket',
|
|
|
|
|
|
|
|
data: [TotalTirageRestant],
|
|
|
|
|
|
|
|
backgroundColor: [
|
|
|
|
|
|
|
|
'rgba(54, 162, 235, 0.5)',
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
borderWidth: 1,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { register, setValue, handleSubmit, formState: { errors } } = useForm<FormData>({
|
|
|
|
const { register, setValue, handleSubmit, formState: { errors } } = useForm<FormData>({
|
|
|
|
});
|
|
|
|
});
|
|
|
|
@ -264,11 +301,28 @@ const Admin = (props: Props) => {
|
|
|
|
<div className="row">
|
|
|
|
<div className="row">
|
|
|
|
<div className="col-md-12 col-sm-12">
|
|
|
|
<div className="col-md-12 col-sm-12">
|
|
|
|
<hr />
|
|
|
|
<hr />
|
|
|
|
<h1 className="fw-light">Utilisateurs <TfiInfoAlt size={40} /></h1>
|
|
|
|
<h1 className="fw-light">Dashboard Administration</h1>
|
|
|
|
<hr />
|
|
|
|
<hr />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div className="container" style={{ width: '30vw' }}>
|
|
|
|
|
|
|
|
<div className="row">
|
|
|
|
|
|
|
|
<div className="col-12 justify-content-center">
|
|
|
|
|
|
|
|
<p>Total tirages restant 📈 {props.totalTirageRestant?.total?.toString()}</p>
|
|
|
|
|
|
|
|
<Doughnut
|
|
|
|
|
|
|
|
data={ticketDataChart} />
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{(isAdmin ||
|
|
|
|
{(isAdmin ||
|
|
|
|
isSuperAdmin) && <div>
|
|
|
|
isSuperAdmin) && <div>
|
|
|
|
<p className="fw-light">Grand jeu concours séléction l'utilisateur gagnant pour les 1 an de thé</p>
|
|
|
|
<p className="fw-light">Grand jeu concours : séléctionner l'utilisateur gagnant pour les 1 an de thé</p>
|
|
|
|
|
|
|
|
<p className="fw-light">En cliquant sur le bouton</p>
|
|
|
|
|
|
|
|
<p className="fw-light"> 👇</p>
|
|
|
|
|
|
|
|
|
|
|
|
<button className="btn btn-primary" disabled={users?.some((user) => user?.isBigWinner)} onClick={selectWinUser}>Séléctionner</button>
|
|
|
|
<button className="btn btn-primary" disabled={users?.some((user) => user?.isBigWinner)} onClick={selectWinUser}>Séléctionner</button>
|
|
|
|
<hr />
|
|
|
|
<hr />
|
|
|
|
</div>}
|
|
|
|
</div>}
|
|
|
|
@ -292,7 +346,7 @@ const Admin = (props: Props) => {
|
|
|
|
<th scope="row">{++index}</th>
|
|
|
|
<th scope="row">{++index}</th>
|
|
|
|
<td>{info.surname}</td>
|
|
|
|
<td>{info.surname}</td>
|
|
|
|
<td>{info.name}</td>
|
|
|
|
<td>{info.name}</td>
|
|
|
|
<td>{info.isBigWinner && '🌟🌟🌟'}{info.email}</td>
|
|
|
|
<td>{info.isBigWinner && '🎁'}{info.email}</td>
|
|
|
|
<td>
|
|
|
|
<td>
|
|
|
|
<select className="custom-select" defaultValue={info.role} onChange={(e) => onChangeRole(e, info)}>
|
|
|
|
<select className="custom-select" defaultValue={info.role} onChange={(e) => onChangeRole(e, info)}>
|
|
|
|
<option value="USER">Client</option>
|
|
|
|
<option value="USER">Client</option>
|
|
|
|
|