Apply all API enhancements

This commit is contained in:
gpt-engineer-app[bot]
2025-10-30 23:55:18 +00:00
parent 8f4110d890
commit d40f0f13aa
10 changed files with 435 additions and 45 deletions

View File

@@ -23,6 +23,7 @@ import { supabase } from '@/integrations/supabase/client';
import { useAuth } from '@/hooks/useAuth';
import { useToast } from '@/hooks/use-toast';
import { getErrorMessage } from '@/lib/errorHandler';
import { useQueryInvalidation } from '@/lib/queryInvalidation';
interface ReportButtonProps {
entityType: 'review' | 'profile' | 'content_submission';
@@ -45,6 +46,9 @@ export function ReportButton({ entityType, entityId, className }: ReportButtonPr
const [loading, setLoading] = useState(false);
const { user } = useAuth();
const { toast } = useToast();
// Cache invalidation for moderation queue
const { invalidateModerationQueue, invalidateModerationStats } = useQueryInvalidation();
const handleSubmit = async () => {
if (!user || !reportType) return;
@@ -61,6 +65,10 @@ export function ReportButton({ entityType, entityId, className }: ReportButtonPr
if (error) throw error;
// Invalidate moderation caches
invalidateModerationQueue();
invalidateModerationStats();
toast({
title: "Report Submitted",
description: "Thank you for your report. We'll review it shortly.",

View File

@@ -11,6 +11,7 @@ import { useAuth } from '@/hooks/useAuth';
import { useUserRole } from '@/hooks/useUserRole';
import { handleError, handleSuccess, getErrorMessage } from '@/lib/errorHandler';
import { logger } from '@/lib/logger';
import { useQueryInvalidation } from '@/lib/queryInvalidation';
// Type-safe role definitions
const VALID_ROLES = ['admin', 'moderator', 'user'] as const;
@@ -67,6 +68,9 @@ export function UserRoleManager() {
isSuperuser,
permissions
} = useUserRole();
// Cache invalidation for role changes
const { invalidateUserAuth, invalidateModerationStats } = useQueryInvalidation();
const fetchUserRoles = async () => {
try {
const {
@@ -187,6 +191,11 @@ export function UserRoleManager() {
if (error) throw error;
handleSuccess('Role Granted', `User has been granted ${getRoleLabel(role)} role`);
// Invalidate caches instead of manual refetch
invalidateUserAuth(userId);
invalidateModerationStats(); // Role changes affect who can moderate
setNewUserSearch('');
setNewRole('');
setSearchResults([]);
@@ -209,7 +218,16 @@ export function UserRoleManager() {
error
} = await supabase.from('user_roles').delete().eq('id', roleId);
if (error) throw error;
handleSuccess('Role Revoked', 'User role has been revoked');
// Invalidate caches instead of manual refetch
const revokedRole = userRoles.find(r => r.id === roleId);
if (revokedRole) {
invalidateUserAuth(revokedRole.user_id);
invalidateModerationStats();
}
fetchUserRoles();
} catch (error: unknown) {
handleError(error, {