gestion supp user admin
This commit is contained in:
85
app/auth/reactivate/ReactivateForm.tsx
Normal file
85
app/auth/reactivate/ReactivateForm.tsx
Normal file
@@ -0,0 +1,85 @@
|
||||
"use client";
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import { reactivateUserAccount } from '@/app/actions/auth';
|
||||
import { toast } from 'react-hot-toast';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { Loader2, CheckCircle2 } from 'lucide-react';
|
||||
|
||||
export default function ReactivateForm({ userId }: { userId: string }) {
|
||||
const [reason, setReason] = useState("");
|
||||
const [isPending, setIsPending] = useState(false);
|
||||
const [isSuccess, setIsSuccess] = useState(false);
|
||||
const router = useRouter();
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!reason.trim()) {
|
||||
toast.error("Merci de préciser la raison");
|
||||
return;
|
||||
}
|
||||
|
||||
setIsPending(true);
|
||||
try {
|
||||
const result = await reactivateUserAccount(userId, reason);
|
||||
if (result.success) {
|
||||
setIsSuccess(true);
|
||||
toast.success("Votre compte a été réactivé !");
|
||||
setTimeout(() => router.push("/login"), 3000);
|
||||
} else {
|
||||
toast.error(result.error || "Une erreur est survenue");
|
||||
}
|
||||
} catch (error) {
|
||||
toast.error("Erreur de connexion");
|
||||
} finally {
|
||||
setIsPending(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (isSuccess) {
|
||||
return (
|
||||
<div className="text-center animate-in zoom-in-95 duration-500">
|
||||
<div className="w-20 h-20 bg-emerald-100 rounded-full flex items-center justify-center text-emerald-500 mx-auto mb-6">
|
||||
<CheckCircle2 className="w-12 h-12" />
|
||||
</div>
|
||||
<h2 className="text-2xl font-bold text-slate-900 mb-2">C'est fait !</h2>
|
||||
<p className="text-slate-600">
|
||||
Votre compte est à nouveau actif. Vous allez être redirigé vers la page de connexion dans quelques secondes...
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="space-y-6">
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-slate-700 mb-2">
|
||||
Pourquoi souhaitez-vous réactiver votre compte ?
|
||||
</label>
|
||||
<textarea
|
||||
required
|
||||
value={reason}
|
||||
onChange={(e) => setReason(e.target.value)}
|
||||
placeholder="Dites-nous ce qui vous a fait changer d'avis..."
|
||||
className="w-full h-32 px-4 py-3 bg-slate-50 border border-slate-200 rounded-2xl focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 transition-all resize-none text-slate-900"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isPending}
|
||||
className="w-full py-4 bg-indigo-600 text-white rounded-2xl font-bold shadow-lg shadow-indigo-200 hover:bg-indigo-700 transition-all flex items-center justify-center gap-2 disabled:opacity-50"
|
||||
>
|
||||
{isPending ? (
|
||||
<Loader2 className="w-5 h-5 animate-spin" />
|
||||
) : (
|
||||
"Réactiver mon compte maintenant"
|
||||
)}
|
||||
</button>
|
||||
|
||||
<p className="text-center text-xs text-slate-400">
|
||||
En cliquant sur ce bouton, vous annulez la procédure de suppression en cours.
|
||||
</p>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
67
app/auth/reactivate/page.tsx
Normal file
67
app/auth/reactivate/page.tsx
Normal file
@@ -0,0 +1,67 @@
|
||||
import React from 'react';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
import ReactivateForm from './ReactivateForm';
|
||||
import { ShieldCheck, AlertTriangle } from 'lucide-react';
|
||||
import Link from 'next/link';
|
||||
|
||||
export default async function ReactivatePage({ searchParams: searchParamsPromise }: { searchParams: Promise<{ id?: string }> }) {
|
||||
const searchParams = await searchParamsPromise;
|
||||
const userId = searchParams.id;
|
||||
|
||||
if (!userId) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center p-6 bg-slate-50">
|
||||
<div className="max-w-md w-full bg-white rounded-3xl shadow-xl p-8 text-center">
|
||||
<AlertTriangle className="w-16 h-16 text-amber-500 mx-auto mb-4" />
|
||||
<h1 className="text-2xl font-bold text-slate-900 mb-2">Lien invalide</h1>
|
||||
<p className="text-slate-600 mb-6">Ce lien de réactivation est incomplet ou expiré.</p>
|
||||
<Link href="/" className="inline-block px-8 py-3 bg-indigo-600 text-white rounded-xl font-bold shadow-lg shadow-indigo-200 hover:bg-indigo-700 transition-all">
|
||||
Retour à l'accueil
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { id: userId },
|
||||
select: { id: true, name: true, deletedAt: true }
|
||||
});
|
||||
|
||||
if (!user || !user.deletedAt) {
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center p-6 bg-slate-50">
|
||||
<div className="max-w-md w-full bg-white rounded-3xl shadow-xl p-8 text-center">
|
||||
<ShieldCheck className="w-16 h-16 text-emerald-500 mx-auto mb-4" />
|
||||
<h1 className="text-2xl font-bold text-slate-900 mb-2">Compte déjà actif</h1>
|
||||
<p className="text-slate-600 mb-6">Votre compte est déjà actif ou n'a jamais été marqué pour suppression.</p>
|
||||
<Link href="/login" className="inline-block px-8 py-3 bg-indigo-600 text-white rounded-xl font-bold shadow-lg shadow-indigo-200 hover:bg-indigo-700 transition-all">
|
||||
Se connecter
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex items-center justify-center p-6 bg-slate-50">
|
||||
<div className="max-w-xl w-full bg-white rounded-3xl shadow-xl p-10">
|
||||
<div className="text-center mb-8">
|
||||
<div className="w-20 h-20 bg-indigo-100 rounded-2xl flex items-center justify-center text-indigo-600 mx-auto mb-4">
|
||||
<ShieldCheck className="w-10 h-10" />
|
||||
</div>
|
||||
<h1 className="text-3xl font-bold text-slate-900">Réactiver mon compte</h1>
|
||||
<p className="text-slate-500 mt-2">Heureux de vous revoir, {user.name} !</p>
|
||||
</div>
|
||||
|
||||
<div className="bg-amber-50 border border-amber-200 rounded-2xl p-5 mb-8">
|
||||
<p className="text-sm text-amber-800 leading-relaxed">
|
||||
Votre compte était programmé pour une suppression définitive. En le réactivant, vous conservez toutes vos données, vos messages et vos favoris.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<ReactivateForm userId={userId} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user