Merge branch 'feature/administration-buttuon' into develop
This commit is contained in:
commit
e066b631e1
7 files changed
+156
-11
No files matched your search
Generated
+28
@@ -16,6 +16,8 @@
|
|||||||
"bootstrap": "^5.2.2",
|
"bootstrap": "^5.2.2",
|
||||||
"chance": "^1.1.9",
|
"chance": "^1.1.9",
|
||||||
"crypto-random-string": "^3.0.0",
|
"crypto-random-string": "^3.0.0",
|
||||||
|
"date-format": "^4.0.14",
|
||||||
|
"dateformat": "^5.0.3",
|
||||||
"js-confetti": "^0.11.0",
|
"js-confetti": "^0.11.0",
|
||||||
"next": "13.0.2",
|
"next": "13.0.2",
|
||||||
"next-auth": "4.16.4",
|
"next-auth": "4.16.4",
|
||||||
@@ -900,6 +902,22 @@
|
|||||||
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.1.tgz",
|
||||||
"integrity": "sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw=="
|
"integrity": "sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw=="
|
||||||
},
|
},
|
||||||
|
"node_modules/date-format": {
|
||||||
|
"version": "4.0.14",
|
||||||
|
"resolved": "https://registry.npmjs.org/date-format/-/date-format-4.0.14.tgz",
|
||||||
|
"integrity": "sha512-39BOQLs9ZjKh0/patS9nrT8wc3ioX3/eA/zgbKNopnF2wCqJEoxywwwElATYvRsXdnOxA/OQeQoFZ3rFjVajhg==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/dateformat": {
|
||||||
|
"version": "5.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/dateformat/-/dateformat-5.0.3.tgz",
|
||||||
|
"integrity": "sha512-Kvr6HmPXUMerlLcLF+Pwq3K7apHpYmGDVqrxcDasBg86UcKeTSNWbEzU8bwdXnxnR44FtMhJAxI4Bov6Y/KUfA==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12.20"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/debug": {
|
"node_modules/debug": {
|
||||||
"version": "4.3.4",
|
"version": "4.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||||
@@ -4339,6 +4357,16 @@
|
|||||||
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.1.tgz",
|
||||||
"integrity": "sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw=="
|
"integrity": "sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw=="
|
||||||
},
|
},
|
||||||
|
"date-format": {
|
||||||
|
"version": "4.0.14",
|
||||||
|
"resolved": "https://registry.npmjs.org/date-format/-/date-format-4.0.14.tgz",
|
||||||
|
"integrity": "sha512-39BOQLs9ZjKh0/patS9nrT8wc3ioX3/eA/zgbKNopnF2wCqJEoxywwwElATYvRsXdnOxA/OQeQoFZ3rFjVajhg=="
|
||||||
|
},
|
||||||
|
"dateformat": {
|
||||||
|
"version": "5.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/dateformat/-/dateformat-5.0.3.tgz",
|
||||||
|
"integrity": "sha512-Kvr6HmPXUMerlLcLF+Pwq3K7apHpYmGDVqrxcDasBg86UcKeTSNWbEzU8bwdXnxnR44FtMhJAxI4Bov6Y/KUfA=="
|
||||||
|
},
|
||||||
"debug": {
|
"debug": {
|
||||||
"version": "4.3.4",
|
"version": "4.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
"bootstrap": "^5.2.2",
|
"bootstrap": "^5.2.2",
|
||||||
"chance": "^1.1.9",
|
"chance": "^1.1.9",
|
||||||
"crypto-random-string": "^3.0.0",
|
"crypto-random-string": "^3.0.0",
|
||||||
|
"date-format": "^4.0.14",
|
||||||
|
"dateformat": "^5.0.3",
|
||||||
"js-confetti": "^0.11.0",
|
"js-confetti": "^0.11.0",
|
||||||
"next": "13.0.2",
|
"next": "13.0.2",
|
||||||
"next-auth": "4.16.4",
|
"next-auth": "4.16.4",
|
||||||
|
|||||||
+36
-6
@@ -1,6 +1,8 @@
|
|||||||
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 Image from 'next/image';
|
import Image from 'next/image';
|
||||||
import * as Yup from 'yup';
|
import * as Yup from 'yup';
|
||||||
@@ -14,6 +16,8 @@ import { AiOutlineCheck } from 'react-icons/ai'
|
|||||||
|
|
||||||
import Router from "next/router";
|
import Router from "next/router";
|
||||||
|
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
|
|
||||||
import style from '../styles/Connexion.module.css';
|
import style from '../styles/Connexion.module.css';
|
||||||
|
|
||||||
@@ -92,11 +96,14 @@ const Admin = (props: Props) => {
|
|||||||
const [response, setResponse] = useState(null)
|
const [response, setResponse] = useState(null)
|
||||||
const [currentUser, setCurrentUser] = useState(null)
|
const [currentUser, setCurrentUser] = useState(null)
|
||||||
const [users, setUsers] = useState(props.users)
|
const [users, setUsers] = useState(props.users)
|
||||||
|
const [currentUserGain, setCurrentUserGain] = useState(null)
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
|
|
||||||
const { register, setValue, handleSubmit, formState: { errors } } = useForm<FormData>({
|
const { register, setValue, handleSubmit, formState: { errors } } = useForm<FormData>({
|
||||||
});
|
});
|
||||||
|
|
||||||
const fetcher = async (url, method, body = {}) => {
|
const fetcher = async (url, method, body = {}, callback?: any) => {
|
||||||
try {
|
try {
|
||||||
await fetch(url, {
|
await fetch(url, {
|
||||||
method,
|
method,
|
||||||
@@ -106,7 +113,7 @@ const Admin = (props: Props) => {
|
|||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.then(async (data) => {
|
.then(async (data) => {
|
||||||
setResponse(data);
|
setResponse(data);
|
||||||
setUsers(data.res)
|
callback;
|
||||||
if (data.err) {
|
if (data.err) {
|
||||||
toast.error(data.err, {
|
toast.error(data.err, {
|
||||||
position: "top-center",
|
position: "top-center",
|
||||||
@@ -178,8 +185,10 @@ const Admin = (props: Props) => {
|
|||||||
fetcher('/api/user/delete', 'DELETE', body)
|
fetcher('/api/user/delete', 'DELETE', body)
|
||||||
};
|
};
|
||||||
|
|
||||||
const selectUser = (user: User) => {
|
const selectUser = (user: any) => {
|
||||||
|
console.log('d', user.gains)
|
||||||
setCurrentUser(user);
|
setCurrentUser(user);
|
||||||
|
setCurrentUserGain(user.gains)
|
||||||
setValue("name", user.name)
|
setValue("name", user.name)
|
||||||
setValue("email", user.email)
|
setValue("email", user.email)
|
||||||
setValue("surname", user.surname)
|
setValue("surname", user.surname)
|
||||||
@@ -188,6 +197,26 @@ const Admin = (props: Props) => {
|
|||||||
setValue("phoneNumber", user.phoneNumber)
|
setValue("phoneNumber", user.phoneNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const changeGiftStatus = async (gain: Gain) => {
|
||||||
|
const body = { gain }
|
||||||
|
fetcher('/api/user/update-gift', 'PUT', body)
|
||||||
|
console.log('g', gain);
|
||||||
|
|
||||||
|
// setCurrentUserGain(gain)
|
||||||
|
// router.refresh();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Head>
|
<Head>
|
||||||
@@ -217,6 +246,7 @@ const Admin = (props: Props) => {
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{users.map((info: User, index: number) => {
|
{users.map((info: User, index: number) => {
|
||||||
|
|
||||||
return <tr key={index} className={`${style.cursor}`} onClick={() => selectUser(info)}>
|
return <tr key={index} className={`${style.cursor}`} onClick={() => selectUser(info)}>
|
||||||
<th scope="row">{++index}</th>
|
<th scope="row">{++index}</th>
|
||||||
<td>{info.surname}</td>
|
<td>{info.surname}</td>
|
||||||
@@ -320,19 +350,19 @@ const Admin = (props: Props) => {
|
|||||||
<th scope="col">Codes joués</th>
|
<th scope="col">Codes joués</th>
|
||||||
<th scope="col">Cadeaux</th>
|
<th scope="col">Cadeaux</th>
|
||||||
<th scope="col">Retiré en magasin</th>
|
<th scope="col">Retiré en magasin</th>
|
||||||
<th scope="col">Retrait</th>
|
|
||||||
<th scope="col">Date Retrait</th>
|
<th scope="col">Date Retrait</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{currentUser?.gains.map((gain: Gain, index: number) => {
|
{currentUserGain.map((gain: Gain, index: number) => {
|
||||||
return <tr key={index}>
|
return <tr key={index}>
|
||||||
<th scope="row">{++index}</th>
|
<th scope="row">{++index}</th>
|
||||||
<td>{gain?.codeCadeau}</td>
|
<td>{gain?.codeCadeau}</td>
|
||||||
<td>{props.produits[gain.produitId - 1].nomProduit}</td>
|
<td>{props.produits[gain.produitId - 1].nomProduit}</td>
|
||||||
<td>{gain?.retrait ? '❌ déja récupéré' : '✔️ disponible'}</td>
|
<td>{gain?.retrait ? '❌ déja récupéré' : '✔️ disponible'}</td>
|
||||||
|
<td>{gain?.dateRetrait ? dateFormat(gain?.dateRetrait, "dd/mm/yyyy") : ''}</td>
|
||||||
<td>
|
<td>
|
||||||
<button className="btn btn-primary">OUI</button>
|
<button className="btn btn-primary" disabled={gain?.retrait} onClick={() => changeGiftStatus(gain)}>OUI</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import prisma from '../../../lib/prisma';
|
|||||||
|
|
||||||
|
|
||||||
//api qui va rendre un utilisateur admin (pour les developpeurs)
|
//api qui va rendre un utilisateur admin (pour les developpeurs)
|
||||||
//--> http://localhost:3000/api/superadmin/admin?pass=1234 (a effacer)
|
//--> http://localhost:3000/api/superadmin/make-admin?pass=1234 (a effacer)
|
||||||
|
|
||||||
export default async function makeMeAdmin(req: NextApiRequest, res: NextApiResponse) {
|
export default async function makeMeAdmin(req: NextApiRequest, res: NextApiResponse) {
|
||||||
const { pass } = req.query;
|
const { pass } = req.query;
|
||||||
@@ -23,7 +23,7 @@ export default async function makeMeAdmin(req: NextApiRequest, res: NextApiRespo
|
|||||||
role: Role.SUPERADMIN,
|
role: Role.SUPERADMIN,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return res.status(200).send({ message: 'Profiled updated welcome SUPERADMIN !' });
|
return res.status(200).send({ message: 'Profiled updated welcome ADMIN !' });
|
||||||
} else {
|
} else {
|
||||||
res.status(401).send({ message: 'Unauthorized' })
|
res.status(401).send({ message: 'Unauthorized' })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
import prisma from '../../../lib/prisma';
|
||||||
|
import chance from 'chance'
|
||||||
|
import cryptoRandomString from 'crypto-random-string';
|
||||||
|
|
||||||
|
|
||||||
|
import { NextApiRequest, NextApiResponse } from 'next';
|
||||||
|
import { getSession } from 'next-auth/react';
|
||||||
|
import { Cadeaux } from '../../../enum/cadeaux.enum';
|
||||||
|
import { Role } from '../../../enum/role.enum';
|
||||||
|
import { Gain } from '.prisma/client';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//API gain qui va generer un code cadeau qui sera sur la facture du client
|
||||||
|
//On part du principe qu'une 'API caisse'(qu'on ne gere pas) déclenche l'appel à l'API gain
|
||||||
|
|
||||||
|
export default async function updtateGift(req: NextApiRequest, res: NextApiResponse) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const session = await getSession({ req })
|
||||||
|
|
||||||
|
const { gain } = req.body;
|
||||||
|
|
||||||
|
// est-ce la méthode est un POST ou PUT?
|
||||||
|
// if (req.method !== ("POST" || 'PUT')) {
|
||||||
|
// throw new Error(
|
||||||
|
// `The HTTP ${req.method} method is not supported at this route.`
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
|
// est-ce que utilisateur est connecté ?
|
||||||
|
if (!session) {
|
||||||
|
res.status(401).json({ err: "Vous devez être connecté" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//récupération des gain de l'utilisateur et mise à jour
|
||||||
|
const updatedGain: Gain = await prisma.gain.update({
|
||||||
|
where: { id: gain.id },
|
||||||
|
data: {
|
||||||
|
retrait: true,
|
||||||
|
dateRetrait: new Date()
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const updatedCurrentUser = await prisma.user.findFirst({
|
||||||
|
where: { id: updatedGain.userId },
|
||||||
|
include: { gains: true }
|
||||||
|
})
|
||||||
|
|
||||||
|
// est-ce que utilisateur est un client classique ? Donc interdit pour lui de faire des updates
|
||||||
|
// A ACTIVER EN PRODUCTION
|
||||||
|
// if (user.role === 'USER') {
|
||||||
|
// res.status(401).json({ err: "Vous n'avez pas l'autorisation" });
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
res.status(200).send({ message: `Le gain a ont été mis à jour !`, res: updatedCurrentUser });
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
+2
-2
@@ -37,8 +37,8 @@ async function main() {
|
|||||||
console.log(`Created user with id: ${user.id}`)
|
console.log(`Created user with id: ${user.id}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
//création de 5 gains
|
//création de gains
|
||||||
for (let i = 1; i <= 5; i++) {
|
for (let i = 1; i <= (50); i++) {
|
||||||
await generateGains();
|
await generateGains();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,6 +91,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@keyframes blinking {
|
@keyframes blinking {
|
||||||
|
|
||||||
0%,
|
0%,
|
||||||
50%,
|
50%,
|
||||||
100% {
|
100% {
|
||||||
@@ -113,7 +114,7 @@
|
|||||||
|
|
||||||
.aButton {
|
.aButton {
|
||||||
position: relative;
|
position: relative;
|
||||||
z-index: 9992;
|
z-index: 9000;
|
||||||
}
|
}
|
||||||
|
|
||||||
.aButton:after {
|
.aButton:after {
|
||||||
|
|||||||
Reference in new issue
Block a user