🚀 1.4
This commit is contained in:
1 parent
d0c86bfb19
commit
77ddf98216
5 files changed
+116
-23
No files matched your search
@@ -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"
|
DATABASE_URL="postgres://postgres:postgrespwd@127.0.0.1:5454/thetiptop"
|
||||||
|
|
||||||
|
ACTIVATION_API=true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Generated
+30
@@ -15,6 +15,7 @@
|
|||||||
"@types/nodemailer": "^6.4.6",
|
"@types/nodemailer": "^6.4.6",
|
||||||
"bootstrap": "^5.2.2",
|
"bootstrap": "^5.2.2",
|
||||||
"chance": "^1.1.9",
|
"chance": "^1.1.9",
|
||||||
|
"chart.js": "^4.0.1",
|
||||||
"crypto-random-string": "^3.0.0",
|
"crypto-random-string": "^3.0.0",
|
||||||
"date-format": "^4.0.14",
|
"date-format": "^4.0.14",
|
||||||
"dateformat": "^5.0.3",
|
"dateformat": "^5.0.3",
|
||||||
@@ -23,6 +24,7 @@
|
|||||||
"next-auth": "4.16.4",
|
"next-auth": "4.16.4",
|
||||||
"nodemailer": "^6.8.0",
|
"nodemailer": "^6.8.0",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
|
"react-chartjs-2": "^5.0.1",
|
||||||
"react-dom": "18.2.0",
|
"react-dom": "18.2.0",
|
||||||
"react-hook-form": "^7.39.2",
|
"react-hook-form": "^7.39.2",
|
||||||
"react-icons": "^4.6.0",
|
"react-icons": "^4.6.0",
|
||||||
@@ -2688,6 +2690,14 @@
|
|||||||
"url": "https://github.com/sponsors/wooorm"
|
"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": {
|
"node_modules/ci-info": {
|
||||||
"version": "3.7.0",
|
"version": "3.7.0",
|
||||||
"resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.7.0.tgz",
|
"resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.7.0.tgz",
|
||||||
@@ -7253,6 +7263,15 @@
|
|||||||
"node": ">=0.10.0"
|
"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": {
|
"node_modules/react-dom": {
|
||||||
"version": "18.2.0",
|
"version": "18.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz",
|
"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",
|
"resolved": "https://registry.npmjs.org/character-entities/-/character-entities-2.0.2.tgz",
|
||||||
"integrity": "sha512-shx7oQ0Awen/BRIdkjkvz54PnEEI/EjwXDSIZp86/KKdbafHh1Df/RYGBhn4hbe2+uKC9FnT5UCEdyPz3ai9hQ=="
|
"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": {
|
"ci-info": {
|
||||||
"version": "3.7.0",
|
"version": "3.7.0",
|
||||||
"resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.7.0.tgz",
|
"resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.7.0.tgz",
|
||||||
@@ -14132,6 +14156,12 @@
|
|||||||
"loose-envify": "^1.1.0"
|
"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": {
|
"react-dom": {
|
||||||
"version": "18.2.0",
|
"version": "18.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz",
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
"@types/nodemailer": "^6.4.6",
|
"@types/nodemailer": "^6.4.6",
|
||||||
"bootstrap": "^5.2.2",
|
"bootstrap": "^5.2.2",
|
||||||
"chance": "^1.1.9",
|
"chance": "^1.1.9",
|
||||||
|
"chart.js": "^4.0.1",
|
||||||
"crypto-random-string": "^3.0.0",
|
"crypto-random-string": "^3.0.0",
|
||||||
"date-format": "^4.0.14",
|
"date-format": "^4.0.14",
|
||||||
"dateformat": "^5.0.3",
|
"dateformat": "^5.0.3",
|
||||||
@@ -27,6 +28,7 @@
|
|||||||
"next-auth": "4.16.4",
|
"next-auth": "4.16.4",
|
||||||
"nodemailer": "^6.8.0",
|
"nodemailer": "^6.8.0",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
|
"react-chartjs-2": "^5.0.1",
|
||||||
"react-dom": "18.2.0",
|
"react-dom": "18.2.0",
|
||||||
"react-hook-form": "^7.39.2",
|
"react-hook-form": "^7.39.2",
|
||||||
"react-icons": "^4.6.0",
|
"react-icons": "^4.6.0",
|
||||||
|
|||||||
+77
-23
@@ -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>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { NextApiRequest, NextApiResponse } from 'next';
|
|||||||
import { getSession } from 'next-auth/react';
|
import { getSession } from 'next-auth/react';
|
||||||
import { Cadeaux } from '../../../enum/cadeaux.enum';
|
import { Cadeaux } from '../../../enum/cadeaux.enum';
|
||||||
import { Role } from '../../../enum/role.enum';
|
import { Role } from '../../../enum/role.enum';
|
||||||
|
import process from 'process';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -19,6 +20,10 @@ export default async function apiGain(req: NextApiRequest, res: NextApiResponse)
|
|||||||
const { pass } = req.query;
|
const { pass } = req.query;
|
||||||
const goodPassword = pass === 'P9RDK2b47x1XQV5s3fSaW6erGpzTNudk8jZwCycJYtMHAqhEnm';
|
const goodPassword = pass === 'P9RDK2b47x1XQV5s3fSaW6erGpzTNudk8jZwCycJYtMHAqhEnm';
|
||||||
|
|
||||||
|
if (!process.env.ACTION_API) {
|
||||||
|
return res.status(401).send({ message: 'Unauthorized' })
|
||||||
|
}
|
||||||
|
|
||||||
//récuperation des tickets disponible
|
//récuperation des tickets disponible
|
||||||
const getTickets = await prisma.ticketsRestants.findFirst({
|
const getTickets = await prisma.ticketsRestants.findFirst({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
Reference in new issue
Block a user