mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 14:11:13 -05:00
Improve error handling and navigation safety across the application
Add robust error handling for image uploads, improve navigation logic in AutocompleteSearch with toast notifications for missing identifiers, refine useIsMobile hook return type, and update Supabase function error reporting to handle non-Error types. Replit-Commit-Author: Agent Replit-Commit-Session-Id: a759d451-40bf-440d-96f5-a19ad6af18a8 Replit-Commit-Checkpoint-Type: intermediate_checkpoint
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
import type { Json } from '@/integrations/supabase/types';
|
||||
import { ImageAssignments } from '@/components/upload/EntityMultiImageUploader';
|
||||
import { uploadPendingImages } from './imageUploadHelper';
|
||||
|
||||
@@ -21,11 +22,16 @@ export async function submitCompanyCreation(
|
||||
// Upload any pending local images first
|
||||
let processedImages = data.images;
|
||||
if (data.images?.uploaded && data.images.uploaded.length > 0) {
|
||||
const uploadedImages = await uploadPendingImages(data.images.uploaded);
|
||||
processedImages = {
|
||||
...data.images,
|
||||
uploaded: uploadedImages
|
||||
};
|
||||
try {
|
||||
const uploadedImages = await uploadPendingImages(data.images.uploaded);
|
||||
processedImages = {
|
||||
...data.images,
|
||||
uploaded: uploadedImages
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(`Failed to upload images for ${companyType} creation:`, error);
|
||||
throw new Error('Failed to upload images. Please check your connection and try again.');
|
||||
}
|
||||
}
|
||||
|
||||
// Create the main submission record
|
||||
@@ -59,7 +65,7 @@ export async function submitCompanyCreation(
|
||||
founded_year: data.founded_year,
|
||||
headquarters_location: data.headquarters_location,
|
||||
company_type: companyType,
|
||||
images: processedImages as any
|
||||
images: processedImages as unknown as Json
|
||||
},
|
||||
status: 'pending',
|
||||
order_index: 0
|
||||
@@ -88,11 +94,16 @@ export async function submitCompanyUpdate(
|
||||
// Upload any pending local images first
|
||||
let processedImages = data.images;
|
||||
if (data.images?.uploaded && data.images.uploaded.length > 0) {
|
||||
const uploadedImages = await uploadPendingImages(data.images.uploaded);
|
||||
processedImages = {
|
||||
...data.images,
|
||||
uploaded: uploadedImages
|
||||
};
|
||||
try {
|
||||
const uploadedImages = await uploadPendingImages(data.images.uploaded);
|
||||
processedImages = {
|
||||
...data.images,
|
||||
uploaded: uploadedImages
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(`Failed to upload images for ${existingCompany.company_type} update:`, error);
|
||||
throw new Error('Failed to upload images. Please check your connection and try again.');
|
||||
}
|
||||
}
|
||||
|
||||
// Create the main submission record
|
||||
@@ -127,7 +138,7 @@ export async function submitCompanyUpdate(
|
||||
website_url: data.website_url,
|
||||
founded_year: data.founded_year,
|
||||
headquarters_location: data.headquarters_location,
|
||||
images: processedImages as any
|
||||
images: processedImages as unknown as Json
|
||||
},
|
||||
original_data: JSON.parse(JSON.stringify(existingCompany)),
|
||||
status: 'pending',
|
||||
|
||||
Reference in New Issue
Block a user