From 77ddf9821693ef6d882209a56c3164571dbe94ac Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 12 Dec 2022 00:27:56 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=201.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 2 + package-lock.json | 30 +++++++++++ package.json | 2 + pages/admin.tsx | 100 ++++++++++++++++++++++++++++--------- pages/api/apiGain/index.ts | 5 ++ 5 files changed, 116 insertions(+), 23 deletions(-) diff --git a/.env b/.env index c66426c..b628d1f 100644 --- a/.env +++ b/.env @@ -18,5 +18,7 @@ EMAIL_FROM=contact@dsp-archiwebo21-ad-ec-cb-mt.fr DATABASE_URL="postgres://postgres:postgrespwd@127.0.0.1:5454/thetiptop" +ACTIVATION_API=true + diff --git a/package-lock.json b/package-lock.json index 0d28433..683e931 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,6 +15,7 @@ "@types/nodemailer": "^6.4.6", "bootstrap": "^5.2.2", "chance": "^1.1.9", + "chart.js": "^4.0.1", "crypto-random-string": "^3.0.0", "date-format": "^4.0.14", "dateformat": "^5.0.3", @@ -23,6 +24,7 @@ "next-auth": "4.16.4", "nodemailer": "^6.8.0", "react": "18.2.0", + "react-chartjs-2": "^5.0.1", "react-dom": "18.2.0", "react-hook-form": "^7.39.2", "react-icons": "^4.6.0", @@ -2688,6 +2690,14 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/chart.js": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/chart.js/-/chart.js-4.0.1.tgz", + "integrity": "sha512-5/8/9eBivwBZK81mKvmIwTb2Pmw4D/5h1RK9fBWZLLZ8mCJ+kfYNmV9rMrGoa5Hgy2/wVDBMLSUDudul2/9ihA==", + "engines": { + "pnpm": "^7.0.0" + } + }, "node_modules/ci-info": { "version": "3.7.0", "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.7.0.tgz", @@ -7253,6 +7263,15 @@ "node": ">=0.10.0" } }, + "node_modules/react-chartjs-2": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/react-chartjs-2/-/react-chartjs-2-5.0.1.tgz", + "integrity": "sha512-u38C9OxynlNCBp+79grgXRs7DSJ9w8FuQ5/HO5FbYBbri8HSZW+9SWgjVshLkbXBfXnMGWakbHEtvN0nL2UG7Q==", + "peerDependencies": { + "chart.js": "^4.0.0", + "react": "^16.8.0 || ^17.0.0 || ^18.0.0" + } + }, "node_modules/react-dom": { "version": "18.2.0", "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz", @@ -10880,6 +10899,11 @@ "resolved": "https://registry.npmjs.org/character-entities/-/character-entities-2.0.2.tgz", "integrity": "sha512-shx7oQ0Awen/BRIdkjkvz54PnEEI/EjwXDSIZp86/KKdbafHh1Df/RYGBhn4hbe2+uKC9FnT5UCEdyPz3ai9hQ==" }, + "chart.js": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/chart.js/-/chart.js-4.0.1.tgz", + "integrity": "sha512-5/8/9eBivwBZK81mKvmIwTb2Pmw4D/5h1RK9fBWZLLZ8mCJ+kfYNmV9rMrGoa5Hgy2/wVDBMLSUDudul2/9ihA==" + }, "ci-info": { "version": "3.7.0", "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.7.0.tgz", @@ -14132,6 +14156,12 @@ "loose-envify": "^1.1.0" } }, + "react-chartjs-2": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/react-chartjs-2/-/react-chartjs-2-5.0.1.tgz", + "integrity": "sha512-u38C9OxynlNCBp+79grgXRs7DSJ9w8FuQ5/HO5FbYBbri8HSZW+9SWgjVshLkbXBfXnMGWakbHEtvN0nL2UG7Q==", + "requires": {} + }, "react-dom": { "version": "18.2.0", "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz", diff --git a/package.json b/package.json index b895a81..eaadcd7 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "@types/nodemailer": "^6.4.6", "bootstrap": "^5.2.2", "chance": "^1.1.9", + "chart.js": "^4.0.1", "crypto-random-string": "^3.0.0", "date-format": "^4.0.14", "dateformat": "^5.0.3", @@ -27,6 +28,7 @@ "next-auth": "4.16.4", "nodemailer": "^6.8.0", "react": "18.2.0", + "react-chartjs-2": "^5.0.1", "react-dom": "18.2.0", "react-hook-form": "^7.39.2", "react-icons": "^4.6.0", diff --git a/pages/admin.tsx b/pages/admin.tsx index 8dfd54b..78714bf 100644 --- a/pages/admin.tsx +++ b/pages/admin.tsx @@ -1,9 +1,6 @@ import React, { useEffect, useState, useSyncExternalStore } from "react"; import prisma from '../lib/prisma' - import dateFormat, { masks } from "dateformat"; - - import Image from 'next/image'; import * as Yup from 'yup'; 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 "yup-phone"; import { SubmitHandler, useForm } from "react-hook-form"; - import { AiOutlineCheck } from 'react-icons/ai' - import Router from "next/router"; - import { useRouter } from 'next/navigation'; - - import style from '../styles/Connexion.module.css'; - import imageConnexion from '../public/images/connexion_image.png' - - import Link from "next/link"; - - - - import { TfiInfoAlt } from 'react-icons/tfi' import { TfiGift } from 'react-icons/tfi' - - 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, 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 = { 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({}) return { props: { user: JSON.parse(JSON.stringify(user)), 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 = { user: User; produits: Produit[]; - users: any + users: any, + tickets: Gain[] + totalTirageRestant: TicketsRestants } const Admin = (props: Props) => { @@ -103,6 +99,47 @@ const Admin = (props: Props) => { const isSuperAdmin = session?.user['role'] === Role.SUPERADMIN 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({ }); @@ -264,11 +301,28 @@ const Admin = (props: Props) => {

-

Utilisateurs

+

Dashboard Administration


+ + +
+
+
+

Total tirages restant 📈 {props.totalTirageRestant?.total?.toString()}

+ +
+
+ +
+ + {(isAdmin || isSuperAdmin) &&
-

Grand jeu concours séléction l'utilisateur gagnant pour les 1 an de thé

+

Grand jeu concours : séléctionner l'utilisateur gagnant pour les 1 an de thé

+

En cliquant sur le bouton

+

👇

+
} @@ -292,7 +346,7 @@ const Admin = (props: Props) => { {++index} {info.surname} {info.name} - {info.isBigWinner && '🌟🌟🌟'}{info.email} + {info.isBigWinner && '🎁'}{info.email}