mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 14:31:11 -05:00
Fix Recent Activity errors
This commit is contained in:
@@ -50,7 +50,9 @@ export const RecentActivity = forwardRef<RecentActivityRef>((props, ref) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fetch recent approved/rejected submissions
|
// Fetch recent approved/rejected submissions
|
||||||
const { data: submissions, error: submissionsError } = await supabase
|
let submissions: any[] = [];
|
||||||
|
try {
|
||||||
|
const { data, error } = await supabase
|
||||||
.from('content_submissions')
|
.from('content_submissions')
|
||||||
.select('id, status, reviewed_at, reviewer_id, submission_type')
|
.select('id, status, reviewed_at, reviewer_id, submission_type')
|
||||||
.in('status', ['approved', 'rejected'])
|
.in('status', ['approved', 'rejected'])
|
||||||
@@ -58,10 +60,27 @@ export const RecentActivity = forwardRef<RecentActivityRef>((props, ref) => {
|
|||||||
.order('reviewed_at', { ascending: false })
|
.order('reviewed_at', { ascending: false })
|
||||||
.limit(15);
|
.limit(15);
|
||||||
|
|
||||||
if (submissionsError) throw submissionsError;
|
if (error) {
|
||||||
|
handleError(error, {
|
||||||
|
action: 'Load Recent Activity - Submissions',
|
||||||
|
userId: user?.id,
|
||||||
|
metadata: { silent }
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
submissions = data || [];
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error, {
|
||||||
|
action: 'Load Recent Activity - Submissions Query',
|
||||||
|
userId: user?.id,
|
||||||
|
metadata: { silent }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch recent report resolutions
|
// Fetch recent report resolutions
|
||||||
const { data: reports, error: reportsError } = await supabase
|
let reports: any[] = [];
|
||||||
|
try {
|
||||||
|
const { data, error } = await supabase
|
||||||
.from('reports')
|
.from('reports')
|
||||||
.select('id, status, reviewed_at, reviewed_by, reported_entity_type')
|
.select('id, status, reviewed_at, reviewed_by, reported_entity_type')
|
||||||
.in('status', ['reviewed', 'dismissed'])
|
.in('status', ['reviewed', 'dismissed'])
|
||||||
@@ -69,10 +88,27 @@ export const RecentActivity = forwardRef<RecentActivityRef>((props, ref) => {
|
|||||||
.order('reviewed_at', { ascending: false })
|
.order('reviewed_at', { ascending: false })
|
||||||
.limit(15);
|
.limit(15);
|
||||||
|
|
||||||
if (reportsError) throw reportsError;
|
if (error) {
|
||||||
|
handleError(error, {
|
||||||
|
action: 'Load Recent Activity - Reports',
|
||||||
|
userId: user?.id,
|
||||||
|
metadata: { silent }
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
reports = data || [];
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error, {
|
||||||
|
action: 'Load Recent Activity - Reports Query',
|
||||||
|
userId: user?.id,
|
||||||
|
metadata: { silent }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch recent review moderations
|
// Fetch recent review moderations
|
||||||
const { data: reviews, error: reviewsError } = await supabase
|
let reviews: any[] = [];
|
||||||
|
try {
|
||||||
|
const { data, error } = await supabase
|
||||||
.from('reviews')
|
.from('reviews')
|
||||||
.select('id, moderation_status, moderated_at, moderated_by, park_id, ride_id')
|
.select('id, moderation_status, moderated_at, moderated_by, park_id, ride_id')
|
||||||
.in('moderation_status', ['approved', 'rejected', 'flagged'])
|
.in('moderation_status', ['approved', 'rejected', 'flagged'])
|
||||||
@@ -80,22 +116,56 @@ export const RecentActivity = forwardRef<RecentActivityRef>((props, ref) => {
|
|||||||
.order('moderated_at', { ascending: false })
|
.order('moderated_at', { ascending: false })
|
||||||
.limit(15);
|
.limit(15);
|
||||||
|
|
||||||
if (reviewsError) throw reviewsError;
|
if (error) {
|
||||||
|
handleError(error, {
|
||||||
|
action: 'Load Recent Activity - Reviews',
|
||||||
|
userId: user?.id,
|
||||||
|
metadata: { silent }
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
reviews = data || [];
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error, {
|
||||||
|
action: 'Load Recent Activity - Reviews Query',
|
||||||
|
userId: user?.id,
|
||||||
|
metadata: { silent }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Get unique moderator IDs
|
// Get unique moderator IDs with safe filtering
|
||||||
const moderatorIds: string[] = [
|
const moderatorIds: string[] = [
|
||||||
...(submissions?.map(s => s.reviewer_id).filter((id): id is string => id != null) || []),
|
...(submissions.map(s => s.reviewer_id).filter((id): id is string => id != null)),
|
||||||
...(reports?.map(r => r.reviewed_by).filter((id): id is string => id != null) || []),
|
...(reports.map(r => r.reviewed_by).filter((id): id is string => id != null)),
|
||||||
...(reviews?.map(r => r.moderated_by).filter((id): id is string => id != null) || []),
|
...(reviews.map(r => r.moderated_by).filter((id): id is string => id != null)),
|
||||||
].filter((id, index, arr) => arr.indexOf(id) === index);
|
].filter((id, index, arr) => arr.indexOf(id) === index);
|
||||||
|
|
||||||
// Fetch moderator profiles
|
// Fetch moderator profiles only if we have IDs
|
||||||
const { data: profiles } = await supabase
|
let profileMap = new Map();
|
||||||
|
if (moderatorIds.length > 0) {
|
||||||
|
try {
|
||||||
|
const { data: profiles, error: profilesError } = await supabase
|
||||||
.from('profiles')
|
.from('profiles')
|
||||||
.select('user_id, username, display_name, avatar_url')
|
.select('user_id, username, display_name, avatar_url')
|
||||||
.in('user_id', moderatorIds);
|
.in('user_id', moderatorIds);
|
||||||
|
|
||||||
const profileMap = new Map(profiles?.map(p => [p.user_id, p]) || []);
|
if (profilesError) {
|
||||||
|
handleError(profilesError, {
|
||||||
|
action: 'Load Recent Activity - Profiles',
|
||||||
|
userId: user?.id,
|
||||||
|
metadata: { moderatorIds: moderatorIds.length }
|
||||||
|
});
|
||||||
|
} else if (profiles) {
|
||||||
|
profileMap = new Map(profiles.map(p => [p.user_id, p]));
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
handleError(error, {
|
||||||
|
action: 'Load Recent Activity - Profiles Query',
|
||||||
|
userId: user?.id,
|
||||||
|
metadata: { moderatorIds: moderatorIds.length }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Combine all activities
|
// Combine all activities
|
||||||
const allActivities: ActivityItem[] = [
|
const allActivities: ActivityItem[] = [
|
||||||
|
|||||||
@@ -35,14 +35,30 @@ export const handleError = (
|
|||||||
? error.message
|
? error.message
|
||||||
: 'An unexpected error occurred';
|
: 'An unexpected error occurred';
|
||||||
|
|
||||||
// Log to console/monitoring
|
// Log to console/monitoring with enhanced debugging
|
||||||
|
const stack = error instanceof Error ? error.stack : undefined;
|
||||||
|
|
||||||
logger.error('Error occurred', {
|
logger.error('Error occurred', {
|
||||||
...context,
|
...context,
|
||||||
error: error instanceof Error ? error.message : String(error),
|
error: error instanceof Error ? error.message : String(error),
|
||||||
stack: error instanceof Error ? error.stack : undefined,
|
stack,
|
||||||
errorId,
|
errorId,
|
||||||
|
errorType: typeof error,
|
||||||
|
errorConstructor: error?.constructor?.name,
|
||||||
|
hasStack: !!stack,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Additional debug logging when stack is missing
|
||||||
|
if (!stack) {
|
||||||
|
console.error('[handleError] Error without stack trace:', {
|
||||||
|
type: typeof error,
|
||||||
|
constructor: error?.constructor?.name,
|
||||||
|
error: error,
|
||||||
|
context,
|
||||||
|
errorId
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Log to database with breadcrumbs (non-blocking)
|
// Log to database with breadcrumbs (non-blocking)
|
||||||
try {
|
try {
|
||||||
const envContext = captureEnvironmentContext();
|
const envContext = captureEnvironmentContext();
|
||||||
|
|||||||
Reference in New Issue
Block a user