|
|
|
@ -88,7 +88,7 @@ export async function getServerSideProps(context) {
|
|
|
|
type Props = {
|
|
|
|
type Props = {
|
|
|
|
user: User;
|
|
|
|
user: User;
|
|
|
|
produits: Produit[];
|
|
|
|
produits: Produit[];
|
|
|
|
users: User[]
|
|
|
|
users: any
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const Admin = (props: Props) => {
|
|
|
|
const Admin = (props: Props) => {
|
|
|
|
@ -99,6 +99,10 @@ const Admin = (props: Props) => {
|
|
|
|
const [currentUserGain, setCurrentUserGain] = useState(null)
|
|
|
|
const [currentUserGain, setCurrentUserGain] = useState(null)
|
|
|
|
const router = useRouter()
|
|
|
|
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>({
|
|
|
|
const { register, setValue, handleSubmit, formState: { errors } } = useForm<FormData>({
|
|
|
|
});
|
|
|
|
});
|
|
|
|
@ -206,8 +210,8 @@ const Admin = (props: Props) => {
|
|
|
|
|
|
|
|
|
|
|
|
const selectWinUser = async () => {
|
|
|
|
const selectWinUser = async () => {
|
|
|
|
const customers = users.filter((user) => user.role === 'USER')
|
|
|
|
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", {
|
|
|
|
toast.error("Il n'y a pas encore d'utilisateur", {
|
|
|
|
position: "top-center",
|
|
|
|
position: "top-center",
|
|
|
|
autoClose: 2000,
|
|
|
|
autoClose: 2000,
|
|
|
|
@ -220,8 +224,26 @@ const Admin = (props: Props) => {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
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 }
|
|
|
|
const body = { selectedUserEmail: winUser.email }
|
|
|
|
|
|
|
|
console.log(body)
|
|
|
|
fetcher('/api/user/bigwinner', 'PUT', body)
|
|
|
|
fetcher('/api/user/bigwinner', 'PUT', body)
|
|
|
|
setTimeout(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
router.refresh();
|
|
|
|
router.refresh();
|
|
|
|
@ -244,13 +266,14 @@ const Admin = (props: Props) => {
|
|
|
|
<hr />
|
|
|
|
<hr />
|
|
|
|
<h1 className="fw-light">Utilisateurs <TfiInfoAlt size={40} /></h1>
|
|
|
|
<h1 className="fw-light">Utilisateurs <TfiInfoAlt size={40} /></h1>
|
|
|
|
<hr />
|
|
|
|
<hr />
|
|
|
|
{(session?.user['role'] === 'ADMIN' ||
|
|
|
|
{(isAdmin ||
|
|
|
|
session?.user['role'] === 'SUPERADMIN') && <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é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 />
|
|
|
|
<hr />
|
|
|
|
</div>}
|
|
|
|
</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 <= 0 && <p>Pas encore d'utilisateur</p>}
|
|
|
|
{users.length >= 1 &&
|
|
|
|
{users.length >= 1 &&
|
|
|
|
<table className={`table table-hover`}>
|
|
|
|
<table className={`table table-hover`}>
|
|
|
|
@ -265,23 +288,16 @@ const Admin = (props: Props) => {
|
|
|
|
</thead>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<tbody>
|
|
|
|
{users.map((info: User, index: number) => {
|
|
|
|
{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)}>
|
|
|
|
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>
|
|
|
|
<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>
|
|
|
|
<option value="SELLER">Vendeur</option>
|
|
|
|
{(isAdmin || isSuperAdmin) && <option value="SELLER">Vendeur</option>}
|
|
|
|
{isAdmin && <option value="ADMIN">Administrateur</option>}
|
|
|
|
{(isAdmin || isSuperAdmin) && <option value="ADMIN">Administrateur</option>}
|
|
|
|
{isSuperAdmin && <option value="SUPERADMIN">SuperAdmin</option>}
|
|
|
|
{isSuperAdmin && <option value="SUPERADMIN">SuperAdmin</option>}
|
|
|
|
|
|
|
|
|
|
|
|
</select>
|
|
|
|
</select>
|
|
|
|
|