mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 18:11:13 -05:00
feat: Implement High Priority Console Cleanup
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { invokeWithTracking } from '@/lib/edgeFunctionTracking';
|
import { invokeWithTracking } from '@/lib/edgeFunctionTracking';
|
||||||
|
import { logger } from '@/lib/logger';
|
||||||
|
import { getErrorMessage } from '@/lib/errorHandler';
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { Label } from '@/components/ui/label';
|
import { Label } from '@/components/ui/label';
|
||||||
@@ -168,11 +170,19 @@ export function UppyPhotoSubmissionUpload({
|
|||||||
));
|
));
|
||||||
|
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error('Upload error:', error);
|
const errorMsg = getErrorMessage(error);
|
||||||
|
logger.error('Photo submission upload failed', {
|
||||||
|
photoTitle: photo.title,
|
||||||
|
photoOrder: photo.order,
|
||||||
|
fileName: photo.file?.name,
|
||||||
|
error: errorMsg
|
||||||
|
});
|
||||||
|
|
||||||
setPhotos(prev => prev.map(p =>
|
setPhotos(prev => prev.map(p =>
|
||||||
p === photo ? { ...p, uploadStatus: 'failed' as const } : p
|
p === photo ? { ...p, uploadStatus: 'failed' as const } : p
|
||||||
));
|
));
|
||||||
throw new Error(`Failed to upload ${photo.title || 'photo'}: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
||||||
|
throw new Error(`Failed to upload ${photo.title || 'photo'}: ${errorMsg}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,11 +258,19 @@ export function UppyPhotoSubmissionUpload({
|
|||||||
setPhotos([]);
|
setPhotos([]);
|
||||||
onSubmissionComplete?.();
|
onSubmissionComplete?.();
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error('Submission error:', error);
|
const errorMsg = getErrorMessage(error);
|
||||||
|
logger.error('Photo submission failed', {
|
||||||
|
entityType,
|
||||||
|
entityId,
|
||||||
|
photoCount: photos.length,
|
||||||
|
userId: user?.id,
|
||||||
|
error: errorMsg
|
||||||
|
});
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
variant: 'destructive',
|
variant: 'destructive',
|
||||||
title: 'Submission Failed',
|
title: 'Submission Failed',
|
||||||
description: error instanceof Error ? error.message : 'There was an error submitting your photos. Please try again.',
|
description: errorMsg || 'There was an error submitting your photos. Please try again.',
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
setIsSubmitting(false);
|
setIsSubmitting(false);
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import React, { useRef, useState } from 'react';
|
|||||||
import { supabase } from '@/integrations/supabase/client';
|
import { supabase } from '@/integrations/supabase/client';
|
||||||
import { useToast } from '@/hooks/use-toast';
|
import { useToast } from '@/hooks/use-toast';
|
||||||
import { invokeWithTracking } from '@/lib/edgeFunctionTracking';
|
import { invokeWithTracking } from '@/lib/edgeFunctionTracking';
|
||||||
|
import { logger } from '@/lib/logger';
|
||||||
|
import { getErrorMessage } from '@/lib/errorHandler';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
import { Upload, X, Eye, Loader2, CheckCircle } from 'lucide-react';
|
import { Upload, X, Eye, Loader2, CheckCircle } from 'lucide-react';
|
||||||
@@ -201,11 +203,18 @@ export function UppyPhotoUpload({
|
|||||||
newUrls.push(url);
|
newUrls.push(url);
|
||||||
setUploadProgress(Math.round(((i + 1) / totalFiles) * 100));
|
setUploadProgress(Math.round(((i + 1) / totalFiles) * 100));
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error(`Upload failed for ${file.name}:`, error);
|
const errorMsg = getErrorMessage(error);
|
||||||
|
logger.error('File upload failed', {
|
||||||
|
fileName: file.name,
|
||||||
|
fileSize: file.size,
|
||||||
|
fileType: file.type,
|
||||||
|
error: errorMsg
|
||||||
|
});
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
variant: 'destructive',
|
variant: 'destructive',
|
||||||
title: 'Upload Failed',
|
title: 'Upload Failed',
|
||||||
description: `Failed to upload "${file.name}": ${error instanceof Error ? error.message : 'Unknown error'}`,
|
description: `Failed to upload "${file.name}": ${errorMsg}`,
|
||||||
});
|
});
|
||||||
onUploadError?.(error as Error);
|
onUploadError?.(error as Error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { useState, useEffect } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import { supabase } from '@/integrations/supabase/client';
|
import { supabase } from '@/integrations/supabase/client';
|
||||||
import { ComboboxOption } from '@/components/ui/combobox';
|
import { ComboboxOption } from '@/components/ui/combobox';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import { logger } from '@/lib/logger';
|
||||||
|
import { getErrorMessage } from '@/lib/errorHandler';
|
||||||
|
|
||||||
export function useCountries() {
|
export function useCountries() {
|
||||||
const [countries, setCountries] = useState<ComboboxOption[]>([]);
|
const [countries, setCountries] = useState<ComboboxOption[]>([]);
|
||||||
@@ -28,7 +31,11 @@ export function useCountries() {
|
|||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error('Error fetching countries:', error);
|
const errorMsg = getErrorMessage(error);
|
||||||
|
logger.error('Failed to fetch countries', { error: errorMsg });
|
||||||
|
toast.error('Failed to load countries', {
|
||||||
|
description: 'Please refresh the page and try again.',
|
||||||
|
});
|
||||||
setCountries([]);
|
setCountries([]);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@@ -73,7 +80,11 @@ export function useStatesProvinces(country?: string) {
|
|||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error('Error fetching states/provinces:', error);
|
const errorMsg = getErrorMessage(error);
|
||||||
|
logger.error('Failed to fetch states/provinces', { country, error: errorMsg });
|
||||||
|
toast.error('Failed to load states/provinces', {
|
||||||
|
description: 'Please refresh the page and try again.',
|
||||||
|
});
|
||||||
setStatesProvinces([]);
|
setStatesProvinces([]);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@@ -109,7 +120,11 @@ export function useManufacturers() {
|
|||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error('Error fetching manufacturers:', error);
|
const errorMsg = getErrorMessage(error);
|
||||||
|
logger.error('Failed to fetch manufacturers', { error: errorMsg });
|
||||||
|
toast.error('Failed to load manufacturers', {
|
||||||
|
description: 'Please refresh the page and try again.',
|
||||||
|
});
|
||||||
setManufacturers([]);
|
setManufacturers([]);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@@ -150,7 +165,11 @@ export function useRideModels(manufacturerId?: string) {
|
|||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error('Error fetching ride models:', error);
|
const errorMsg = getErrorMessage(error);
|
||||||
|
logger.error('Failed to fetch ride models', { manufacturerId, error: errorMsg });
|
||||||
|
toast.error('Failed to load ride models', {
|
||||||
|
description: 'Please refresh the page and try again.',
|
||||||
|
});
|
||||||
setRideModels([]);
|
setRideModels([]);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@@ -189,7 +208,11 @@ export function useCompanyHeadquarters() {
|
|||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error('Error fetching headquarters:', error);
|
const errorMsg = getErrorMessage(error);
|
||||||
|
logger.error('Failed to fetch headquarters', { error: errorMsg });
|
||||||
|
toast.error('Failed to load headquarters', {
|
||||||
|
description: 'Please refresh the page and try again.',
|
||||||
|
});
|
||||||
setHeadquarters([]);
|
setHeadquarters([]);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@@ -225,7 +248,11 @@ export function useOperators() {
|
|||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error('Error fetching operators:', error);
|
const errorMsg = getErrorMessage(error);
|
||||||
|
logger.error('Failed to fetch operators', { error: errorMsg });
|
||||||
|
toast.error('Failed to load operators', {
|
||||||
|
description: 'Please refresh the page and try again.',
|
||||||
|
});
|
||||||
setOperators([]);
|
setOperators([]);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@@ -261,7 +288,11 @@ export function usePropertyOwners() {
|
|||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error('Error fetching property owners:', error);
|
const errorMsg = getErrorMessage(error);
|
||||||
|
logger.error('Failed to fetch property owners', { error: errorMsg });
|
||||||
|
toast.error('Failed to load property owners', {
|
||||||
|
description: 'Please refresh the page and try again.',
|
||||||
|
});
|
||||||
setPropertyOwners([]);
|
setPropertyOwners([]);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ export function useEntityVersions(entityType: EntityType, entityId: string) {
|
|||||||
}
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
const errorMsg = getErrorMessage(error);
|
const errorMsg = getErrorMessage(error);
|
||||||
console.error('Error fetching versions:', errorMsg);
|
logger.error('Failed to fetch versions', { entityType, entityId, error: errorMsg });
|
||||||
|
|
||||||
if (isMountedRef.current && currentRequestId === requestCounterRef.current) {
|
if (isMountedRef.current && currentRequestId === requestCounterRef.current) {
|
||||||
toast.error(errorMsg);
|
toast.error(errorMsg);
|
||||||
@@ -141,7 +141,7 @@ export function useEntityVersions(entityType: EntityType, entityId: string) {
|
|||||||
return data;
|
return data;
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
const errorMsg = getErrorMessage(error);
|
const errorMsg = getErrorMessage(error);
|
||||||
console.error('Error comparing versions:', errorMsg);
|
logger.error('Failed to compare versions', { entityType, fromVersionId, toVersionId, error: errorMsg });
|
||||||
if (isMountedRef.current) {
|
if (isMountedRef.current) {
|
||||||
toast.error(errorMsg);
|
toast.error(errorMsg);
|
||||||
}
|
}
|
||||||
@@ -173,7 +173,7 @@ export function useEntityVersions(entityType: EntityType, entityId: string) {
|
|||||||
return data;
|
return data;
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
const errorMsg = getErrorMessage(error);
|
const errorMsg = getErrorMessage(error);
|
||||||
console.error('Error rolling back version:', errorMsg);
|
logger.error('Failed to rollback version', { entityType, entityId, targetVersionId, error: errorMsg });
|
||||||
if (isMountedRef.current) {
|
if (isMountedRef.current) {
|
||||||
toast.error(errorMsg);
|
toast.error(errorMsg);
|
||||||
}
|
}
|
||||||
@@ -194,6 +194,7 @@ export function useEntityVersions(entityType: EntityType, entityId: string) {
|
|||||||
try {
|
try {
|
||||||
supabase.removeChannel(channelRef.current);
|
supabase.removeChannel(channelRef.current);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
|
logger.error('Failed to cleanup realtime subscription', { entityType, entityId, error: getErrorMessage(error) });
|
||||||
console.error('Error removing previous channel:', error);
|
console.error('Error removing previous channel:', error);
|
||||||
} finally {
|
} finally {
|
||||||
channelRef.current = null;
|
channelRef.current = null;
|
||||||
@@ -226,6 +227,7 @@ export function useEntityVersions(entityType: EntityType, entityId: string) {
|
|||||||
return () => {
|
return () => {
|
||||||
if (channelRef.current) {
|
if (channelRef.current) {
|
||||||
supabase.removeChannel(channelRef.current).catch((error) => {
|
supabase.removeChannel(channelRef.current).catch((error) => {
|
||||||
|
logger.error('Failed to cleanup realtime subscription', { entityType, entityId, error: getErrorMessage(error) });
|
||||||
console.error('Error removing channel:', error);
|
console.error('Error removing channel:', error);
|
||||||
});
|
});
|
||||||
channelRef.current = null;
|
channelRef.current = null;
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import { supabase } from '@/integrations/supabase/client';
|
|||||||
import { Park, Ride, Company } from '@/types/database';
|
import { Park, Ride, Company } from '@/types/database';
|
||||||
import { logger } from '@/lib/logger';
|
import { logger } from '@/lib/logger';
|
||||||
import * as storage from '@/lib/localStorage';
|
import * as storage from '@/lib/localStorage';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import { getErrorMessage } from '@/lib/errorHandler';
|
||||||
|
|
||||||
export interface SearchResult {
|
export interface SearchResult {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -165,9 +167,18 @@ export function useSearch(options: UseSearchOptions = {}) {
|
|||||||
|
|
||||||
setResults(searchResults.slice(0, limit));
|
setResults(searchResults.slice(0, limit));
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error('Search error:', error);
|
const errorMsg = getErrorMessage(error);
|
||||||
const errorMessage = error instanceof Error ? error.message : 'Failed to search. Please try again.';
|
logger.error('Search failed', {
|
||||||
setError(errorMessage);
|
query: searchQuery,
|
||||||
|
types,
|
||||||
|
error: errorMsg
|
||||||
|
});
|
||||||
|
|
||||||
|
toast.error('Search failed', {
|
||||||
|
description: 'Unable to search. Please try again.',
|
||||||
|
});
|
||||||
|
|
||||||
|
setError('Failed to search. Please try again.');
|
||||||
setResults([]);
|
setResults([]);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user