feat: Execute production readiness plan

This commit is contained in:
gpt-engineer-app[bot]
2025-10-20 13:41:54 +00:00
parent 368b97da04
commit 7f425ecb94
10 changed files with 108 additions and 141 deletions

View File

@@ -10,7 +10,7 @@ import { Badge } from '@/components/ui/badge';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from '@/components/ui/alert-dialog';
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import { useToast } from '@/hooks/use-toast';
import { handleError, handleSuccess } from '@/lib/errorHandler';
interface UserProfile {
id: string;
@@ -26,7 +26,6 @@ interface UserProfile {
export function ProfileManager() {
const { user } = useAuth();
const { permissions, loading: roleLoading } = useUserRole();
const { toast } = useToast();
const [profiles, setProfiles] = useState<UserProfile[]>([]);
const [loading, setLoading] = useState(true);
@@ -69,12 +68,10 @@ export function ProfileManager() {
);
setProfiles(profilesWithRoles);
} catch (error) {
console.error('Error fetching profiles:', error);
toast({
title: "Error",
description: "Failed to fetch user profiles.",
variant: "destructive",
} catch (error: unknown) {
handleError(error, {
action: 'Load User Profiles',
userId: user?.id
});
} finally {
setLoading(false);
@@ -105,19 +102,15 @@ export function ProfileManager() {
if (logError) console.error('Error logging action:', logError);
toast({
title: "Success",
description: `User ${ban ? 'banned' : 'unbanned'} successfully.`,
});
handleSuccess('Success', `User ${ban ? 'banned' : 'unbanned'} successfully.`);
// Refresh profiles
fetchProfiles();
} catch (error) {
console.error('Error updating user ban status:', error);
toast({
title: "Error",
description: `Failed to ${ban ? 'ban' : 'unban'} user.`,
variant: "destructive",
} catch (error: unknown) {
handleError(error, {
action: `${ban ? 'Ban' : 'Unban'} User`,
userId: user?.id,
metadata: { targetUserId, ban }
});
} finally {
setActionLoading(null);
@@ -144,19 +137,19 @@ export function ProfileManager() {
} else {
// Check permissions before allowing role assignment
if (newRole === 'admin' && !permissions.can_manage_admin_roles) {
toast({
title: "Access Denied",
description: "You don't have permission to assign admin roles.",
variant: "destructive",
handleError(new Error('Insufficient permissions'), {
action: 'Assign Admin Role',
userId: user?.id,
metadata: { targetUserId, attemptedRole: newRole }
});
return;
}
if (newRole === 'superuser') {
toast({
title: "Access Denied",
description: "Superuser roles can only be assigned directly in the database.",
variant: "destructive",
handleError(new Error('Cannot assign superuser via UI'), {
action: 'Assign Superuser Role',
userId: user?.id,
metadata: { targetUserId }
});
return;
}
@@ -184,19 +177,15 @@ export function ProfileManager() {
if (logError) console.error('Error logging action:', logError);
toast({
title: "Success",
description: `User role updated successfully.`,
});
handleSuccess('Success', 'User role updated successfully.');
// Refresh profiles
fetchProfiles();
} catch (error) {
console.error('Error updating user role:', error);
toast({
title: "Error",
description: "Failed to update user role.",
variant: "destructive",
} catch (error: unknown) {
handleError(error, {
action: 'Update User Role',
userId: user?.id,
metadata: { targetUserId, newRole, previousRoles: currentRoles }
});
} finally {
setActionLoading(null);