mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 18:11:12 -05:00
Implement type safety and JSONB elimination
This commit is contained in:
@@ -2,6 +2,7 @@ import { useCallback } from 'react';
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
import { useToast } from '@/hooks/use-toast';
|
||||
import { logger } from '@/lib/logger';
|
||||
import { getErrorMessage } from '@/lib/errorHandler';
|
||||
import type { User } from '@supabase/supabase-js';
|
||||
import type { ModerationItem } from '@/types/moderation';
|
||||
|
||||
@@ -176,11 +177,11 @@ export function useModerationActions(config: ModerationActionsConfig): Moderatio
|
||||
});
|
||||
|
||||
logger.log(`✅ Action ${action} completed for ${item.id}`);
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
logger.error('❌ Error performing action:', error);
|
||||
toast({
|
||||
title: 'Error',
|
||||
description: error.message || `Failed to ${action} content`,
|
||||
description: getErrorMessage(error) || `Failed to ${action} content`,
|
||||
variant: 'destructive',
|
||||
});
|
||||
throw error;
|
||||
@@ -211,11 +212,11 @@ export function useModerationActions(config: ModerationActionsConfig): Moderatio
|
||||
});
|
||||
|
||||
logger.log(`✅ Submission ${item.id} deleted`);
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
logger.error('❌ Error deleting submission:', error);
|
||||
toast({
|
||||
title: 'Error',
|
||||
description: 'Failed to delete submission',
|
||||
description: getErrorMessage(error),
|
||||
variant: 'destructive',
|
||||
});
|
||||
throw error;
|
||||
@@ -243,11 +244,11 @@ export function useModerationActions(config: ModerationActionsConfig): Moderatio
|
||||
});
|
||||
|
||||
logger.log(`✅ Submission ${item.id} reset to pending`);
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
logger.error('❌ Error resetting submission:', error);
|
||||
toast({
|
||||
title: 'Reset Failed',
|
||||
description: error.message,
|
||||
description: getErrorMessage(error),
|
||||
variant: 'destructive',
|
||||
});
|
||||
} finally {
|
||||
@@ -294,11 +295,11 @@ export function useModerationActions(config: ModerationActionsConfig): Moderatio
|
||||
});
|
||||
|
||||
logger.log(`✅ Retried ${failedItems.length} failed items for ${item.id}`);
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
logger.error('❌ Error retrying items:', error);
|
||||
toast({
|
||||
title: 'Retry Failed',
|
||||
description: error.message || 'Failed to retry items',
|
||||
description: getErrorMessage(error) || 'Failed to retry items',
|
||||
variant: 'destructive',
|
||||
});
|
||||
} finally {
|
||||
|
||||
@@ -10,7 +10,7 @@ import { useQueryClient } from '@tanstack/react-query';
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
import { logger } from '@/lib/logger';
|
||||
import { MODERATION_CONSTANTS } from '@/lib/moderation/constants';
|
||||
import type { RealtimeChannel } from '@supabase/supabase-js';
|
||||
import type { RealtimeChannel, RealtimePostgresChangesPayload } from '@supabase/supabase-js';
|
||||
import type { ModerationItem, EntityFilter, StatusFilter } from '@/types/moderation';
|
||||
import type { useEntityCache } from './useEntityCache';
|
||||
import type { useProfileCache } from './useProfileCache';
|
||||
@@ -21,6 +21,18 @@ import {
|
||||
buildModerationItem,
|
||||
} from '@/lib/moderation/realtime';
|
||||
|
||||
/**
|
||||
* Type-safe interface for submission content from realtime events
|
||||
*/
|
||||
interface SubmissionContent {
|
||||
action?: string;
|
||||
name?: string;
|
||||
entity_slug?: string;
|
||||
entity_name?: string;
|
||||
entity_id?: string;
|
||||
park_id?: string;
|
||||
}
|
||||
|
||||
type EntityCacheReturn = ReturnType<typeof useEntityCache>;
|
||||
type ProfileCacheReturn = ReturnType<typeof useProfileCache>;
|
||||
|
||||
@@ -164,7 +176,7 @@ export function useRealtimeSubscriptions(
|
||||
* Resolve entity names for a submission
|
||||
*/
|
||||
const resolveEntityNames = useCallback(async (submission: any) => {
|
||||
const content = submission.content as any;
|
||||
const content = submission.content as SubmissionContent;
|
||||
let entityName = content?.name || 'Unknown';
|
||||
let parkName: string | undefined;
|
||||
|
||||
@@ -242,8 +254,8 @@ export function useRealtimeSubscriptions(
|
||||
/**
|
||||
* Handle new submission INSERT event
|
||||
*/
|
||||
const handleInsert = useCallback(async (payload: any) => {
|
||||
const newSubmission = payload.new as any;
|
||||
const handleInsert = useCallback(async (payload: RealtimePostgresChangesPayload<any>) => {
|
||||
const newSubmission = payload.new;
|
||||
|
||||
logger.log('🆕 Realtime INSERT:', newSubmission.id);
|
||||
|
||||
@@ -314,9 +326,9 @@ export function useRealtimeSubscriptions(
|
||||
/**
|
||||
* Handle submission UPDATE event
|
||||
*/
|
||||
const handleUpdate = useCallback(async (payload: any) => {
|
||||
const updatedSubmission = payload.new as any;
|
||||
const oldSubmission = payload.old as any;
|
||||
const handleUpdate = useCallback(async (payload: RealtimePostgresChangesPayload<any>) => {
|
||||
const updatedSubmission = payload.new;
|
||||
const oldSubmission = payload.old;
|
||||
|
||||
logger.log('🔄 Realtime UPDATE:', updatedSubmission.id);
|
||||
|
||||
@@ -339,7 +351,8 @@ export function useRealtimeSubscriptions(
|
||||
}
|
||||
|
||||
// Skip debounce for status changes (critical updates)
|
||||
const isStatusChange = oldSubmission?.status !== updatedSubmission.status;
|
||||
const isStatusChange = oldSubmission && 'status' in oldSubmission
|
||||
&& oldSubmission.status !== updatedSubmission?.status;
|
||||
|
||||
if (isStatusChange) {
|
||||
logger.log('⚡ Status change detected, invalidating immediately');
|
||||
|
||||
Reference in New Issue
Block a user