🚀 version 1.1
This commit is contained in:
1 parent
a3b0c85678
commit
caffe2c1b8
2 files changed
+36
-21
No files matched your search
+34
-18
@@ -88,7 +88,7 @@ export async function getServerSideProps(context) {
|
||||
type Props = {
|
||||
user: User;
|
||||
produits: Produit[];
|
||||
users: User[]
|
||||
users: any
|
||||
}
|
||||
|
||||
const Admin = (props: Props) => {
|
||||
@@ -99,6 +99,10 @@ const Admin = (props: Props) => {
|
||||
const [currentUserGain, setCurrentUserGain] = useState(null)
|
||||
const router = useRouter()
|
||||
|
||||
const isAdmin = session?.user['role'] === Role.ADMIN
|
||||
const isSuperAdmin = session?.user['role'] === Role.SUPERADMIN
|
||||
const bigWinner = users?.find((user) => user?.isBigWinner)
|
||||
|
||||
|
||||
const { register, setValue, handleSubmit, formState: { errors } } = useForm<FormData>({
|
||||
});
|
||||
@@ -206,8 +210,8 @@ const Admin = (props: Props) => {
|
||||
|
||||
const selectWinUser = async () => {
|
||||
const customers = users.filter((user) => user.role === 'USER')
|
||||
console.log('custo', customers)
|
||||
if (customers.length <= 0) {
|
||||
|
||||
if (users.length <= 0) {
|
||||
toast.error("Il n'y a pas encore d'utilisateur", {
|
||||
position: "top-center",
|
||||
autoClose: 2000,
|
||||
@@ -220,8 +224,26 @@ const Admin = (props: Props) => {
|
||||
});
|
||||
return;
|
||||
}
|
||||
const winUser = customers[Math.floor(Math.random() * customers.length)]
|
||||
|
||||
const customersWithTicket = customers.filter((user) => user.gains.length >= 1)
|
||||
|
||||
if (customersWithTicket.length <= 0) {
|
||||
toast.error("Il n'y a pas encore d'utilisateurs ayant joué", {
|
||||
position: "top-center",
|
||||
autoClose: 2000,
|
||||
hideProgressBar: false,
|
||||
closeOnClick: true,
|
||||
pauseOnHover: true,
|
||||
draggable: true,
|
||||
progress: undefined,
|
||||
theme: "light",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const winUser = customersWithTicket[Math.floor(Math.random() * customersWithTicket.length)]
|
||||
const body = { selectedUserEmail: winUser.email }
|
||||
console.log(body)
|
||||
fetcher('/api/user/bigwinner', 'PUT', body)
|
||||
setTimeout(() => {
|
||||
router.refresh();
|
||||
@@ -244,13 +266,14 @@ const Admin = (props: Props) => {
|
||||
<hr />
|
||||
<h1 className="fw-light">Utilisateurs <TfiInfoAlt size={40} /></h1>
|
||||
<hr />
|
||||
{(session?.user['role'] === 'ADMIN' ||
|
||||
session?.user['role'] === 'SUPERADMIN') && <div>
|
||||
{(isAdmin ||
|
||||
isSuperAdmin) && <div>
|
||||
<p className="fw-light">Grand jeu concours séléction l'utilisateur gagnant pour les 1 an de thé</p>
|
||||
<button className="btn btn-primary" disabled={users?.some((user) => user?.isBigWinner === true)} onClick={selectWinUser}>Séléctionner</button>
|
||||
<button className="btn btn-primary" disabled={users?.some((user) => user?.isBigWinner)} onClick={selectWinUser}>Séléctionner</button>
|
||||
<hr />
|
||||
</div>}
|
||||
|
||||
{bigWinner ? <p>Grand gagnant 📢</p> : <p>Pas encore de gagnant tiré au sort 🤫</p>}
|
||||
<p>{bigWinner && bigWinner.email}</p>
|
||||
{users.length <= 0 && <p>Pas encore d'utilisateur</p>}
|
||||
{users.length >= 1 &&
|
||||
<table className={`table table-hover`}>
|
||||
@@ -265,23 +288,16 @@ const Admin = (props: Props) => {
|
||||
</thead>
|
||||
<tbody>
|
||||
{users.map((info: User, index: number) => {
|
||||
|
||||
console.log('user role', users);
|
||||
|
||||
const isAdmin = ['SELLER', 'ADMIN'].includes(info.role);
|
||||
const isSuperAdmin = ['SELLER', 'ADMIN', 'SUPERADMIN'].includes(info.role);
|
||||
|
||||
|
||||
return <tr key={index} className={`${style.cursor}`} onClick={() => selectUser(info)}>
|
||||
<th scope="row">{++index}</th>
|
||||
<td>{info.surname}</td>
|
||||
<td>{info.name}</td>
|
||||
<td>{info.isBigWinner && '🌟'} {info.email}</td>
|
||||
<td>{info.isBigWinner && '🌟🌟🌟'}{info.email}</td>
|
||||
<td>
|
||||
<select className="custom-select" defaultValue={info.role} onChange={(e) => onChangeRole(e, info)}>
|
||||
<option value="USER">Client</option>
|
||||
<option value="SELLER">Vendeur</option>
|
||||
{isAdmin && <option value="ADMIN">Administrateur</option>}
|
||||
{(isAdmin || isSuperAdmin) && <option value="SELLER">Vendeur</option>}
|
||||
{(isAdmin || isSuperAdmin) && <option value="ADMIN">Administrateur</option>}
|
||||
{isSuperAdmin && <option value="SUPERADMIN">SuperAdmin</option>}
|
||||
|
||||
</select>
|
||||
|
||||
@@ -148,6 +148,7 @@ const MonCompte = (props: Props) => {
|
||||
<div className="container align-items-center d-flex flex-column">
|
||||
<div className={`${style['bloc-content']} col-12 col-md-12`}>
|
||||
<div className="row">
|
||||
<p>Vous avez été séléctionner pour gagner 1 an de thé !</p>
|
||||
<div className="col-md-6 col-sm-12">
|
||||
<hr />
|
||||
<h1 className="fw-light">Mes informations <TfiInfoAlt size={40} /></h1>
|
||||
@@ -223,9 +224,7 @@ const MonCompte = (props: Props) => {
|
||||
</thead>
|
||||
<tbody>
|
||||
{props.userGains.map((info: any, index: number) => {
|
||||
console.log('ii', info);
|
||||
|
||||
return <tr>
|
||||
return <tr key={index}>
|
||||
<th scope="row">{++index}</th>
|
||||
<td>{info.codeCadeau}</td>
|
||||
<td>{info.produit.nomProduit}</td>
|
||||
|
||||
Reference in new issue
Block a user