mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 06:51:12 -05:00
Add ban reason to profiles
This commit is contained in:
@@ -8,6 +8,7 @@ export function useBanCheck() {
|
||||
const { user } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
const [isBanned, setIsBanned] = useState(false);
|
||||
const [banReason, setBanReason] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -21,15 +22,21 @@ export function useBanCheck() {
|
||||
try {
|
||||
const { data: profile } = await supabase
|
||||
.from('profiles')
|
||||
.select('banned')
|
||||
.select('banned, ban_reason')
|
||||
.eq('user_id', user.id)
|
||||
.single();
|
||||
|
||||
if (profile?.banned) {
|
||||
setIsBanned(true);
|
||||
setBanReason(profile.ban_reason || null);
|
||||
|
||||
const reason = profile.ban_reason
|
||||
? `Reason: ${profile.ban_reason}`
|
||||
: 'Contact support for assistance.';
|
||||
|
||||
toast({
|
||||
title: 'Account Suspended',
|
||||
description: 'Your account has been suspended. Contact support for assistance.',
|
||||
description: `Your account has been suspended. ${reason}`,
|
||||
variant: 'destructive',
|
||||
duration: Infinity // Don't auto-dismiss
|
||||
});
|
||||
@@ -58,14 +65,20 @@ export function useBanCheck() {
|
||||
filter: `user_id=eq.${user.id}`
|
||||
},
|
||||
(payload) => {
|
||||
const newProfile = payload.new as { banned: boolean };
|
||||
const newProfile = payload.new as { banned: boolean; ban_reason: string | null };
|
||||
|
||||
// Handle BAN event
|
||||
if (newProfile.banned && !isBanned) {
|
||||
setIsBanned(true);
|
||||
setBanReason(newProfile.ban_reason || null);
|
||||
|
||||
const reason = newProfile.ban_reason
|
||||
? `Reason: ${newProfile.ban_reason}`
|
||||
: 'Contact support for assistance.';
|
||||
|
||||
toast({
|
||||
title: 'Account Suspended',
|
||||
description: 'Your account has been suspended. Contact support for assistance.',
|
||||
description: `Your account has been suspended. ${reason}`,
|
||||
variant: 'destructive',
|
||||
duration: Infinity
|
||||
});
|
||||
@@ -76,6 +89,7 @@ export function useBanCheck() {
|
||||
// Handle UNBAN event
|
||||
if (!newProfile.banned && isBanned) {
|
||||
setIsBanned(false);
|
||||
setBanReason(null);
|
||||
toast({
|
||||
title: 'Account Restored',
|
||||
description: 'Your account has been unbanned. You can now use the application normally.',
|
||||
@@ -92,5 +106,5 @@ export function useBanCheck() {
|
||||
};
|
||||
}, [user, navigate]);
|
||||
|
||||
return { isBanned, loading };
|
||||
return { isBanned, loading, banReason };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user