Approve tool use

This commit is contained in:
gpt-engineer-app[bot]
2025-10-20 12:58:09 +00:00
parent 4983960138
commit 6f1baef8c0
7 changed files with 263 additions and 34 deletions

View File

@@ -9,7 +9,8 @@ import { useQuery } from '@tanstack/react-query';
import { supabase } from '@/integrations/supabase/client';
import { useAuth } from '@/hooks/useAuth';
import { toast } from 'sonner';
import { getErrorMessage } from '@/lib/errorHandler';
import { getErrorMessage, handleError } from '@/lib/errorHandler';
import { logger } from '@/lib/logger';
import { deleteTimelineEvent } from '@/lib/entitySubmissionHelpers';
import type { EntityType, TimelineEvent } from '@/types/timeline';
@@ -114,11 +115,11 @@ export function EntityTimelineManager({
toast.success('Event deleted', {
description: 'Your timeline event has been deleted successfully.'
});
} catch (error) {
const errorMsg = getErrorMessage(error);
console.error('Delete error:', errorMsg);
toast.error('Failed to delete event', {
description: errorMsg
} catch (error: unknown) {
handleError(error, {
action: 'Delete Timeline Event',
userId: user?.id,
metadata: { eventId }
});
}
};

View File

@@ -46,7 +46,7 @@ import { Loader2, Trash } from 'lucide-react';
import { useAuth } from '@/hooks/useAuth';
import { useToast } from '@/hooks/use-toast';
import { submitTimelineEvent, submitTimelineEventUpdate, deleteTimelineEvent } from '@/lib/entitySubmissionHelpers';
import { getErrorMessage } from '@/lib/errorHandler';
import { handleError } from '@/lib/errorHandler';
import type {
EntityType,
TimelineEventFormData,
@@ -170,12 +170,11 @@ export function TimelineEventEditorDialog({
form.reset();
onOpenChange(false);
onSuccess?.();
} catch (error) {
console.error('Failed to submit timeline event:', error);
toast({
title: 'Submission failed',
description: error instanceof Error ? error.message : 'Failed to submit timeline event',
variant: 'destructive',
} catch (error: unknown) {
handleError(error, {
action: isEditing ? 'Update Timeline Event' : 'Submit Timeline Event',
userId: user?.id,
metadata: { entityType, entityId }
});
} finally {
setIsSubmitting(false);
@@ -196,13 +195,11 @@ export function TimelineEventEditorDialog({
onOpenChange(false);
setShowDeleteConfirm(false);
form.reset();
} catch (error) {
const errorMsg = getErrorMessage(error);
console.error('Delete error:', errorMsg);
toast({
title: 'Failed to delete event',
description: errorMsg,
variant: 'destructive',
} catch (error: unknown) {
handleError(error, {
action: 'Delete Timeline Event',
userId: user?.id,
metadata: { eventId: existingEvent?.id }
});
} finally {
setIsDeleting(false);

View File

@@ -3235,6 +3235,94 @@ export type Database = {
},
]
}
timeline_event_submissions: {
Row: {
created_at: string
description: string | null
display_order: number | null
entity_id: string
entity_type: string
event_date: string
event_date_precision: string
event_type: string
from_entity_id: string | null
from_location_id: string | null
from_value: string | null
id: string
is_public: boolean | null
submission_id: string
title: string
to_entity_id: string | null
to_location_id: string | null
to_value: string | null
updated_at: string
}
Insert: {
created_at?: string
description?: string | null
display_order?: number | null
entity_id: string
entity_type: string
event_date: string
event_date_precision: string
event_type: string
from_entity_id?: string | null
from_location_id?: string | null
from_value?: string | null
id?: string
is_public?: boolean | null
submission_id: string
title: string
to_entity_id?: string | null
to_location_id?: string | null
to_value?: string | null
updated_at?: string
}
Update: {
created_at?: string
description?: string | null
display_order?: number | null
entity_id?: string
entity_type?: string
event_date?: string
event_date_precision?: string
event_type?: string
from_entity_id?: string | null
from_location_id?: string | null
from_value?: string | null
id?: string
is_public?: boolean | null
submission_id?: string
title?: string
to_entity_id?: string | null
to_location_id?: string | null
to_value?: string | null
updated_at?: string
}
Relationships: [
{
foreignKeyName: "timeline_event_submissions_from_location_id_fkey"
columns: ["from_location_id"]
isOneToOne: false
referencedRelation: "locations"
referencedColumns: ["id"]
},
{
foreignKeyName: "timeline_event_submissions_submission_id_fkey"
columns: ["submission_id"]
isOneToOne: false
referencedRelation: "content_submissions"
referencedColumns: ["id"]
},
{
foreignKeyName: "timeline_event_submissions_to_location_id_fkey"
columns: ["to_location_id"]
isOneToOne: false
referencedRelation: "locations"
referencedColumns: ["id"]
},
]
}
user_blocks: {
Row: {
blocked_id: string

View File

@@ -7,6 +7,7 @@ import { extractChangedFields } from './submissionChangeDetection';
import type { CompanyDatabaseRecord, TimelineEventDatabaseRecord } from '@/types/company-data';
import { logger } from './logger';
import { getErrorMessage } from './errorHandler';
import type { TimelineEventFormData, EntityType } from '@/types/timeline';
/**
* ═══════════════════════════════════════════════════════════════════
@@ -153,9 +154,6 @@ export interface RideModelFormData {
card_image_id?: string;
}
// Import timeline types
import type { TimelineEventFormData, TimelineSubmissionData, EntityType } from '@/types/timeline';
/**
* ⚠️ CRITICAL SECURITY PATTERN ⚠️
*
@@ -1183,7 +1181,7 @@ export async function submitTimelineEvent(
};
const items = [{
item_type: 'milestone',
item_type: 'timeline_event',
action_type: 'create',
item_data: itemData,
order_index: 0,
@@ -1192,7 +1190,7 @@ export async function submitTimelineEvent(
const { data: submissionId, error } = await supabase
.rpc('create_submission_with_items', {
p_user_id: userId,
p_submission_type: 'milestone',
p_submission_type: 'timeline_event',
p_content: content,
p_items: items as unknown as Json[],
});
@@ -1255,7 +1253,7 @@ export async function submitTimelineEventUpdate(
'create_submission_with_items',
{
p_user_id: userId,
p_submission_type: 'milestone',
p_submission_type: 'timeline_event',
p_content: {
action: 'edit',
event_id: eventId,
@@ -1263,7 +1261,7 @@ export async function submitTimelineEventUpdate(
} as unknown as Json,
p_items: [
{
item_type: 'milestone',
item_type: 'timeline_event',
action_type: 'edit',
item_data: itemData,
original_data: originalEvent,
@@ -1290,12 +1288,7 @@ export async function submitTimelineEventUpdate(
};
}
/**
* Delete a timeline event (only pending/own events)
* @param eventId - Timeline event ID
* @param userId - Current user ID
* @throws Error if event not found or cannot be deleted
*/
export async function deleteTimelineEvent(
eventId: string,
userId: string

View File

@@ -90,3 +90,21 @@ export interface RideModelSubmissionData {
card_image_url?: string | null;
card_image_id?: string | null;
}
export interface TimelineEventItemData {
entity_id: string;
entity_type: 'park' | 'ride' | 'company' | 'ride_model';
event_type: string;
event_date: string; // ISO date
event_date_precision: 'day' | 'month' | 'year';
title: string;
description?: string | null;
from_value?: string | null;
to_value?: string | null;
from_entity_id?: string | null;
to_entity_id?: string | null;
from_location_id?: string | null;
to_location_id?: string | null;
display_order?: number;
is_public?: boolean;
}