From d398c97429b57bf087127a3a08d335a605a831a1 Mon Sep 17 00:00:00 2001 From: openhands Date: Wed, 4 Jun 2025 22:13:56 +0000 Subject: [PATCH] Fix frontend TypeScript types and API integration - Updated frontend types to match backend API schema (key_top instead of title) - Fixed TypeError in summary filtering by using correct field names - Updated SummaryForm to match backend API endpoints - Removed unused title fields from forms - Added proper null checks and fallback values - Updated CORS settings for current runtime environment - Fixed API integration for both URL and text summarization endpoints --- backend/app/core/config.py | 4 +- .../src/components/shared/summary-form.tsx | 64 ++++++------------- .../src/components/shared/summary-history.tsx | 4 +- .../src/components/shared/summary-result.tsx | 12 ++-- frontend/src/types/index.ts | 22 +++---- 5 files changed, 39 insertions(+), 67 deletions(-) diff --git a/backend/app/core/config.py b/backend/app/core/config.py index a6f5963..b5bacf6 100644 --- a/backend/app/core/config.py +++ b/backend/app/core/config.py @@ -15,8 +15,8 @@ class Settings(BaseSettings): "http://localhost:3000", "http://localhost:12000", "http://localhost:12001", - "https://work-1-nddcgiroczfpnzeg.prod-runtime.all-hands.dev", - "https://work-2-nddcgiroczfpnzeg.prod-runtime.all-hands.dev" + "https://work-1-akhmacjqfeabtotb.prod-runtime.all-hands.dev", + "https://work-2-akhmacjqfeabtotb.prod-runtime.all-hands.dev" ] # External APIs diff --git a/frontend/src/components/shared/summary-form.tsx b/frontend/src/components/shared/summary-form.tsx index 2bf9cef..43ab392 100644 --- a/frontend/src/components/shared/summary-form.tsx +++ b/frontend/src/components/shared/summary-form.tsx @@ -16,12 +16,10 @@ import type { SummaryCreate, SummaryResponse } from '@/types' const urlSchema = z.object({ url: z.string().url('Please enter a valid URL'), - title: z.string().min(1, 'Title is required'), }) const textSchema = z.object({ - content: z.string().min(10, 'Content must be at least 10 characters'), - title: z.string().min(1, 'Title is required'), + text: z.string().min(10, 'Content must be at least 10 characters'), }) type UrlFormData = z.infer @@ -39,15 +37,13 @@ export function SummaryForm({ onSummaryCreated }: SummaryFormProps) { resolver: zodResolver(urlSchema), defaultValues: { url: '', - title: '', }, }) const textForm = useForm({ resolver: zodResolver(textSchema), defaultValues: { - content: '', - title: '', + text: '', }, }) @@ -55,7 +51,6 @@ export function SummaryForm({ onSummaryCreated }: SummaryFormProps) { setIsLoading(true) try { const payload: SummaryCreate = { - title: data.title, url: data.url, } const response = await api.post('/api/v1/summaries/', payload) @@ -72,12 +67,19 @@ export function SummaryForm({ onSummaryCreated }: SummaryFormProps) { const onTextSubmit = async (data: TextFormData) => { setIsLoading(true) try { - const payload: SummaryCreate = { - title: data.title, - content: data.content, + const payload = { + text: data.text, } - const response = await api.post('/api/v1/summaries/', payload) - onSummaryCreated(response.data) + const response = await api.post('/api/v1/summaries/text', payload) + // Convert text summary response to match SummaryResponse format + const summaryResponse: SummaryResponse = { + id: Date.now(), // Temporary ID since text summaries aren't stored + summary: response.data.summary, + key_top: 'Text Summary', + created_at: new Date().toISOString(), + updated_at: new Date().toISOString(), + } + onSummaryCreated(summaryResponse) textForm.reset() } catch (error: any) { console.error('Error creating summary:', error) @@ -104,20 +106,6 @@ export function SummaryForm({ onSummaryCreated }: SummaryFormProps) {
-
- - - {urlForm.formState.errors.title && ( -

- {urlForm.formState.errors.title.message} -

- )} -
-
- - - {textForm.formState.errors.title && ( -

- {textForm.formState.errors.title.message} -

- )} -
- -
- +