Fix: Resolve TypeScript errors

This commit is contained in:
gpt-engineer-app[bot]
2025-11-03 02:28:57 +00:00
parent f6c409fac4
commit 9e8e8719b4
14 changed files with 48 additions and 30 deletions

View File

@@ -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'
}
}
);

View File

@@ -78,7 +78,7 @@ const SidebarProvider = React.forwardRef<
state,
open,
setOpen,
isMobile,
isMobile: isMobile ?? false,
openMobile,
setOpenMobile,
toggleSidebar,

View File

@@ -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' : ''}`);

View File

@@ -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>

View File

@@ -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',

View File

@@ -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);

View 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 {

View File

@@ -316,10 +316,12 @@ export function useModerationActions(config: ModerationActionsConfig): Moderatio
});
},
onSuccess: (data) => {
if (data) {
toast({
title: `Content ${data.action}`,
description: `The ${data.item.type} has been ${data.action}`,
});
}
},
onSettled: () => {
// Always refetch to ensure consistency

View File

@@ -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 [];

View File

@@ -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(

View File

@@ -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) {

View File

@@ -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
});

View File

@@ -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;

View File

@@ -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