|
|
|
|
@ -186,7 +186,6 @@ const Admin = (props: Props) => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const selectUser = (user: any) => {
|
|
|
|
|
console.log('d', user.gains)
|
|
|
|
|
setCurrentUser(user);
|
|
|
|
|
setCurrentUserGain(user.gains)
|
|
|
|
|
setValue("name", user.name)
|
|
|
|
|
@ -203,21 +202,32 @@ const Admin = (props: Props) => {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
router.refresh();
|
|
|
|
|
}, 2000)
|
|
|
|
|
|
|
|
|
|
// setCurrentUserGain(gain)
|
|
|
|
|
// router.refresh();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const selectWinUser = async () => {
|
|
|
|
|
const customers = users.filter((user) => user.role === 'USER')
|
|
|
|
|
console.log('custo', customers)
|
|
|
|
|
if (customers.length <= 0) {
|
|
|
|
|
toast.error("Il n'y a pas encore d'utilisateur", {
|
|
|
|
|
position: "top-center",
|
|
|
|
|
autoClose: 2000,
|
|
|
|
|
hideProgressBar: false,
|
|
|
|
|
closeOnClick: true,
|
|
|
|
|
pauseOnHover: true,
|
|
|
|
|
draggable: true,
|
|
|
|
|
progress: undefined,
|
|
|
|
|
theme: "light",
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const winUser = customers[Math.floor(Math.random() * customers.length)]
|
|
|
|
|
const body = { selectedUserEmail: winUser.email }
|
|
|
|
|
fetcher('/api/user/bigwinner', 'PUT', body)
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
router.refresh();
|
|
|
|
|
}, 2000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
@ -234,11 +244,12 @@ const Admin = (props: Props) => {
|
|
|
|
|
<hr />
|
|
|
|
|
<h1 className="fw-light">Utilisateurs <TfiInfoAlt size={40} /></h1>
|
|
|
|
|
<hr />
|
|
|
|
|
|
|
|
|
|
<p className="fw-light">Grand jeu concours séléction utilisateur</p>
|
|
|
|
|
<button className="btn btn-primary">Séléctionner</button>
|
|
|
|
|
|
|
|
|
|
{(session?.user['role'] === 'ADMIN' ||
|
|
|
|
|
session?.user['role'] === 'SUPERADMIN') && <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>
|
|
|
|
|
<hr />
|
|
|
|
|
</div>}
|
|
|
|
|
|
|
|
|
|
{users.length <= 0 && <p>Pas encore d'utilisateur</p>}
|
|
|
|
|
{users.length >= 1 &&
|
|
|
|
|
@ -255,16 +266,24 @@ const Admin = (props: Props) => {
|
|
|
|
|
<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.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>
|
|
|
|
|
<option value="ADMIN">Administrateur</option>
|
|
|
|
|
{isAdmin && <option value="ADMIN">Administrateur</option>}
|
|
|
|
|
{isSuperAdmin && <option value="SUPERADMIN">SuperAdmin</option>}
|
|
|
|
|
|
|
|
|
|
</select>
|
|
|
|
|
</td>
|
|
|
|
|
<td><button className="btn btn-primary" onClick={() => onDeleteUser(info.email)}>Supprimer</button></td>
|
|
|
|
|
|