Fix: Correct ban migration logic

This commit is contained in:
gpt-engineer-app[bot]
2025-10-30 12:03:55 +00:00
parent e5de404e59
commit db101bc5f2
8 changed files with 509 additions and 52 deletions

View File

@@ -22,7 +22,7 @@ export function useBanCheck() {
try {
const { data: profile } = await supabase
.from('profiles')
.select('banned, ban_reason')
.select('banned, ban_reason, ban_expires_at')
.eq('user_id', user.id)
.single();
@@ -33,10 +33,21 @@ export function useBanCheck() {
const reason = profile.ban_reason
? `Reason: ${profile.ban_reason}`
: 'Contact support for assistance.';
// Add expiration info
let expirationText = '';
if (profile.ban_expires_at) {
const expiresAt = new Date(profile.ban_expires_at);
const now = new Date();
const daysLeft = Math.ceil((expiresAt.getTime() - now.getTime()) / (1000 * 60 * 60 * 24));
expirationText = ` This ban will expire in ${daysLeft} day${daysLeft !== 1 ? 's' : ''}.`;
} else {
expirationText = ' This is a permanent ban.';
}
toast({
title: 'Account Suspended',
description: `Your account has been suspended. ${reason}`,
description: `Your account has been suspended. ${reason}${expirationText}`,
variant: 'destructive',
duration: Infinity // Don't auto-dismiss
});
@@ -65,7 +76,7 @@ export function useBanCheck() {
filter: `user_id=eq.${user.id}`
},
(payload) => {
const newProfile = payload.new as { banned: boolean; ban_reason: string | null };
const newProfile = payload.new as { banned: boolean; ban_reason: string | null; ban_expires_at: string | null };
// Handle BAN event
if (newProfile.banned && !isBanned) {
@@ -75,10 +86,21 @@ export function useBanCheck() {
const reason = newProfile.ban_reason
? `Reason: ${newProfile.ban_reason}`
: 'Contact support for assistance.';
// Add expiration info
let expirationText = '';
if (newProfile.ban_expires_at) {
const expiresAt = new Date(newProfile.ban_expires_at);
const now = new Date();
const daysLeft = Math.ceil((expiresAt.getTime() - now.getTime()) / (1000 * 60 * 60 * 24));
expirationText = ` This ban will expire in ${daysLeft} day${daysLeft !== 1 ? 's' : ''}.`;
} else {
expirationText = ' This is a permanent ban.';
}
toast({
title: 'Account Suspended',
description: `Your account has been suspended. ${reason}`,
description: `Your account has been suspended. ${reason}${expirationText}`,
variant: 'destructive',
duration: Infinity
});