|
|
|
@ -62,10 +62,7 @@ export async function getServerSideProps(context) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const tickets = await prisma.gain.findMany({})
|
|
|
|
const tickets = await prisma.gain.findMany({})
|
|
|
|
|
|
|
|
|
|
|
|
const totalTirageRestant = await prisma.ticketsRestants.findFirst({})
|
|
|
|
const totalTirageRestant = await prisma.ticketsRestants.findFirst({})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const produits = await prisma.produit.findMany({})
|
|
|
|
const produits = await prisma.produit.findMany({})
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
@ -93,6 +90,7 @@ const Admin = (props: Props) => {
|
|
|
|
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 [currentUserGain, setCurrentUserGain] = useState(null)
|
|
|
|
|
|
|
|
const [query, setQuery] = useState(null);
|
|
|
|
const router = useRouter()
|
|
|
|
const router = useRouter()
|
|
|
|
|
|
|
|
|
|
|
|
const isAdmin = session?.user['role'] === Role.ADMIN
|
|
|
|
const isAdmin = session?.user['role'] === Role.ADMIN
|
|
|
|
@ -285,7 +283,19 @@ const Admin = (props: Props) => {
|
|
|
|
setTimeout(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
router.refresh();
|
|
|
|
router.refresh();
|
|
|
|
}, 2000)
|
|
|
|
}, 2000)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const searchFilter = (array: any) => {
|
|
|
|
|
|
|
|
return array.filter(
|
|
|
|
|
|
|
|
(el: User) => el.email?.toLowerCase().includes(query)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const filtered = searchFilter(props.users)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
|
|
|
|
setQuery(e.target.value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
@ -322,14 +332,17 @@ const Admin = (props: Props) => {
|
|
|
|
<p className="fw-light">Grand jeu concours : séléctionner 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">En cliquant sur le bouton</p>
|
|
|
|
<p className="fw-light"> 👇</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>}
|
|
|
|
{bigWinner ? <p>Grand gagnant 📢</p> : <p>Pas encore de gagnant tiré au sort 🤫</p>}
|
|
|
|
{bigWinner ? <p>Grand gagnant 📢</p> : <p>Pas encore de gagnant tiré au sort 🤫</p>}
|
|
|
|
<p>{bigWinner && bigWinner.email}</p>
|
|
|
|
<p>{bigWinner && bigWinner.email}</p>
|
|
|
|
{users.length <= 0 && <p>Pas encore d'utilisateur</p>}
|
|
|
|
{users.length <= 0 && <p>Pas encore d'utilisateur</p>}
|
|
|
|
{users.length >= 1 &&
|
|
|
|
{users.length >= 1 && <>
|
|
|
|
|
|
|
|
<div className="input-group mb-3">
|
|
|
|
|
|
|
|
<span className="input-group-text" id="basic-addon1">🔎</span>
|
|
|
|
|
|
|
|
<input type="text" className="form-control" onChange={handleChange} placeholder='Rechercher un utilisateur avec son email...' aria-label="search" />
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<table className={`table table-hover`}>
|
|
|
|
<table className={`table table-hover`}>
|
|
|
|
<thead>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<tr>
|
|
|
|
@ -341,27 +354,27 @@ const Admin = (props: Props) => {
|
|
|
|
</tr>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<tbody>
|
|
|
|
{users.map((info: User, index: number) => {
|
|
|
|
{filtered.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>
|
|
|
|
<td>{info.name}</td>
|
|
|
|
<td>{info.name}</td>
|
|
|
|
<td>{info.isBigWinner && '🎁'}{info.email}</td>
|
|
|
|
<td>{info.isBigWinner && '🎁'}{info.email}</td>
|
|
|
|
<td>
|
|
|
|
{info.role !== Role.SELLER && <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>
|
|
|
|
{(isAdmin || isSuperAdmin) && <option value="SELLER">Vendeur</option>}
|
|
|
|
<option value="SELLER">Vendeur</option>
|
|
|
|
{(isAdmin || isSuperAdmin) && <option value="ADMIN">Administrateur</option>}
|
|
|
|
<option value="ADMIN">Administrateur</option>
|
|
|
|
{isSuperAdmin && <option value="SUPERADMIN">SuperAdmin</option>}
|
|
|
|
{isSuperAdmin && <option value="SUPERADMIN">SuperAdmin</option>}
|
|
|
|
|
|
|
|
|
|
|
|
</select>
|
|
|
|
</select>
|
|
|
|
</td>
|
|
|
|
</td>}
|
|
|
|
<td><button className="btn btn-primary" onClick={() => onDeleteUser(info.email)}>Supprimer</button></td>
|
|
|
|
{info.role !== Role.SELLER && <td><button className="btn btn-primary" onClick={() => onDeleteUser(info.email)}>Supprimer</button></td>}
|
|
|
|
</tr>
|
|
|
|
</tr>;
|
|
|
|
})}
|
|
|
|
})}
|
|
|
|
</tbody>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</table>
|
|
|
|
}
|
|
|
|
</>}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
@ -472,7 +485,7 @@ const Admin = (props: Props) => {
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div >
|
|
|
|
</div >
|
|
|
|
</div>
|
|
|
|
</div >
|
|
|
|
</>)
|
|
|
|
</>)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|