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