mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 10:11:13 -05:00
Fix: Resolve TypeScript errors
This commit is contained in:
@@ -253,7 +253,7 @@ export function EmailChangeDialog({ open, onOpenChange, currentEmail, userId }:
|
||||
metadata: {
|
||||
currentEmail,
|
||||
newEmail: data.newEmail,
|
||||
errorType: error.constructor.name
|
||||
errorType: error instanceof Error ? error.constructor.name : 'Unknown'
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@@ -78,7 +78,7 @@ const SidebarProvider = React.forwardRef<
|
||||
state,
|
||||
open,
|
||||
setOpen,
|
||||
isMobile,
|
||||
isMobile: isMobile ?? false,
|
||||
openMobile,
|
||||
setOpenMobile,
|
||||
toggleSidebar,
|
||||
|
||||
@@ -86,7 +86,7 @@ export function EntityMultiImageUploader({
|
||||
.from('photos')
|
||||
.select('id, cloudflare_image_url, cloudflare_image_id, caption, title')
|
||||
.eq('entity_type', entityType)
|
||||
.eq('entity_id', entityId)
|
||||
.eq('entity_id', entityId || '')
|
||||
.order('created_at', { ascending: false });
|
||||
|
||||
if (error) throw error;
|
||||
@@ -314,7 +314,7 @@ export function EntityMultiImageUploader({
|
||||
|
||||
const existingCount = value.uploaded.filter(img => !img.isLocal).length;
|
||||
const newCount = value.uploaded.filter(img => img.isLocal).length;
|
||||
const parts = [];
|
||||
const parts: string[] = [];
|
||||
|
||||
if (mode === 'edit' && existingCount > 0) {
|
||||
parts.push(`${existingCount} existing photo${existingCount !== 1 ? 's' : ''}`);
|
||||
|
||||
@@ -68,7 +68,7 @@ export function EntityPhotoGallery({
|
||||
url: photo.cloudflare_image_url,
|
||||
caption: photo.caption || undefined,
|
||||
title: photo.title || undefined,
|
||||
user_id: photo.submitted_by,
|
||||
user_id: photo.submitted_by || '',
|
||||
created_at: photo.created_at,
|
||||
})) || [];
|
||||
|
||||
@@ -148,7 +148,7 @@ export function EntityPhotoGallery({
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-col sm:flex-row gap-2 w-full sm:w-auto">
|
||||
{isModerator && photos.length > 0 && (
|
||||
{isModerator() && photos.length > 0 && (
|
||||
<Button onClick={() => setShowManagement(true)} variant="outline" className="gap-2 w-full sm:w-auto">
|
||||
<Settings className="w-4 h-4" />
|
||||
<span className="sm:inline">Manage</span>
|
||||
|
||||
@@ -78,7 +78,11 @@ export function PhotoManagementDialog({
|
||||
.order('order_index', { ascending: true });
|
||||
|
||||
if (error) throw error;
|
||||
setPhotos(data || []);
|
||||
setPhotos((data || []).map(p => ({
|
||||
...p,
|
||||
order_index: p.order_index ?? 0,
|
||||
is_featured: p.is_featured ?? false
|
||||
})) as Photo[]);
|
||||
} catch (error: unknown) {
|
||||
toast({
|
||||
title: 'Error',
|
||||
|
||||
@@ -110,6 +110,9 @@ export function UppyPhotoSubmissionUpload({
|
||||
const { uploadURL, id: cloudflareId } = uploadData;
|
||||
|
||||
// Upload file to Cloudflare
|
||||
if (!photo.file) {
|
||||
throw new Error('Photo file is missing');
|
||||
}
|
||||
const formData = new FormData();
|
||||
formData.append('file', photo.file);
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ export function useEntityCache() {
|
||||
const uncachedIds = getUncachedIds(type, ids);
|
||||
if (uncachedIds.length === 0) {
|
||||
// All entities are cached, return them
|
||||
return ids.map(id => getCached(type, id)).filter(Boolean);
|
||||
return ids.map(id => getCached(type, id)).filter((item): item is EntityTypeMap[T] => item !== undefined);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -316,10 +316,12 @@ export function useModerationActions(config: ModerationActionsConfig): Moderatio
|
||||
});
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
toast({
|
||||
title: `Content ${data.action}`,
|
||||
description: `The ${data.item.type} has been ${data.action}`,
|
||||
});
|
||||
if (data) {
|
||||
toast({
|
||||
title: `Content ${data.action}`,
|
||||
description: `The ${data.item.type} has been ${data.action}`,
|
||||
});
|
||||
}
|
||||
},
|
||||
onSettled: () => {
|
||||
// Always refetch to ensure consistency
|
||||
|
||||
@@ -113,12 +113,21 @@ export function useProfileCache() {
|
||||
|
||||
// Cache the fetched profiles
|
||||
if (data) {
|
||||
data.forEach((profile: CachedProfile) => {
|
||||
setCached(profile.user_id, profile);
|
||||
data.forEach((profile) => {
|
||||
const cachedProfile: CachedProfile = {
|
||||
...profile,
|
||||
display_name: profile.display_name || undefined,
|
||||
avatar_url: profile.avatar_url || undefined
|
||||
};
|
||||
setCached(profile.user_id, cachedProfile);
|
||||
});
|
||||
}
|
||||
|
||||
return data || [];
|
||||
return (data || []).map(profile => ({
|
||||
...profile,
|
||||
display_name: profile.display_name || undefined,
|
||||
avatar_url: profile.avatar_url || undefined
|
||||
}));
|
||||
} catch (error: unknown) {
|
||||
logger.error('Failed to bulk fetch profiles:', { error: getErrorMessage(error) });
|
||||
return [];
|
||||
|
||||
@@ -64,13 +64,13 @@ export function useStatesProvinces(country?: string) {
|
||||
const { data, error } = await supabase
|
||||
.from('locations')
|
||||
.select('state_province')
|
||||
.eq('country', country)
|
||||
.eq('country', country || '')
|
||||
.not('state_province', 'is', null);
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
const uniqueStates = Array.from(
|
||||
new Set(data?.map(item => item.state_province) || [])
|
||||
new Set(data?.map(item => item.state_province).filter((s): s is string => s != null) || [])
|
||||
).sort();
|
||||
|
||||
setStatesProvinces(
|
||||
@@ -153,7 +153,7 @@ export function useRideModels(manufacturerId?: string) {
|
||||
const { data, error } = await supabase
|
||||
.from('ride_models')
|
||||
.select('id, name')
|
||||
.eq('manufacturer_id', manufacturerId)
|
||||
.eq('manufacturer_id', manufacturerId || '')
|
||||
.order('name');
|
||||
|
||||
if (error) throw error;
|
||||
@@ -198,7 +198,7 @@ export function useCompanyHeadquarters() {
|
||||
if (error) throw error;
|
||||
|
||||
const uniqueHeadquarters = Array.from(
|
||||
new Set(data?.map(item => item.headquarters_location) || [])
|
||||
new Set(data?.map(item => item.headquarters_location).filter((hq): hq is string => hq != null) || [])
|
||||
).sort();
|
||||
|
||||
setHeadquarters(
|
||||
|
||||
@@ -18,7 +18,7 @@ export function useProfile(userId: string | undefined) {
|
||||
// Use get_filtered_profile RPC for privacy-aware field filtering
|
||||
const { data, error } = await supabase.rpc('get_filtered_profile', {
|
||||
_profile_user_id: userId,
|
||||
_viewer_id: viewerId
|
||||
_viewer_id: viewerId || ''
|
||||
});
|
||||
|
||||
if (error) {
|
||||
|
||||
@@ -99,8 +99,8 @@ export function useSearch(options: UseSearchOptions = {}) {
|
||||
type: 'park',
|
||||
title: park.name,
|
||||
subtitle: [park.location?.city, park.location?.state_province, park.location?.country].filter(Boolean).join(', '),
|
||||
image: park.banner_image_url || park.card_image_url,
|
||||
rating: park.average_rating,
|
||||
image: park.banner_image_url || park.card_image_url || undefined,
|
||||
rating: park.average_rating ?? undefined,
|
||||
slug: park.slug,
|
||||
data: park
|
||||
});
|
||||
@@ -125,8 +125,8 @@ export function useSearch(options: UseSearchOptions = {}) {
|
||||
type: 'ride',
|
||||
title: ride.name,
|
||||
subtitle: `at ${ride.park?.name || 'Unknown Park'}`,
|
||||
image: ride.image_url,
|
||||
rating: ride.average_rating,
|
||||
image: ride.image_url || undefined,
|
||||
rating: ride.average_rating ?? undefined,
|
||||
slug: ride.slug,
|
||||
data: ride
|
||||
});
|
||||
@@ -147,7 +147,7 @@ export function useSearch(options: UseSearchOptions = {}) {
|
||||
type: 'company',
|
||||
title: company.name,
|
||||
subtitle: company.company_type?.replace('_', ' ').replace(/\b\w/g, l => l.toUpperCase()) || 'Company',
|
||||
image: company.logo_url,
|
||||
image: company.logo_url || undefined,
|
||||
slug: company.slug,
|
||||
data: company
|
||||
});
|
||||
|
||||
@@ -29,8 +29,8 @@ export function useVersionComparison(
|
||||
// Use the database function to get diff
|
||||
const { data, error: rpcError } = await supabase.rpc('get_version_diff', {
|
||||
p_entity_type: entityType,
|
||||
p_from_version_id: fromVersionId,
|
||||
p_to_version_id: toVersionId
|
||||
p_from_version_id: fromVersionId || '',
|
||||
p_to_version_id: toVersionId || ''
|
||||
});
|
||||
|
||||
if (rpcError) throw rpcError;
|
||||
|
||||
@@ -564,11 +564,11 @@ export async function submitParkUpdate(
|
||||
submission_id: submissionData.id,
|
||||
item_type: 'park',
|
||||
action_type: 'edit',
|
||||
item_data: {
|
||||
item_data: JSON.parse(JSON.stringify({
|
||||
...extractChangedFields(data, existingPark),
|
||||
park_id: parkId, // Always include for relational integrity
|
||||
images: processedImages as unknown as Json
|
||||
},
|
||||
images: processedImages
|
||||
})) as Json,
|
||||
original_data: JSON.parse(JSON.stringify(existingPark)),
|
||||
status: 'pending' as const,
|
||||
order_index: 0
|
||||
|
||||
Reference in New Issue
Block a user