diff --git a/src/components/forms/DynamicForm.tsx b/src/components/forms/DynamicForm.tsx index dcdd8e0..0089c7a 100644 --- a/src/components/forms/DynamicForm.tsx +++ b/src/components/forms/DynamicForm.tsx @@ -73,13 +73,9 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId: } }); } - const imageFieldIds = new Set( - res.fields.filter(f => f.data_type === 'image' || f.data_type === 'file').map(f => f.id) - ); const mapPrefillData = (sourceData: Record) => { res.fields.forEach(f => { - if (imageFieldIds.has(f.id)) return; const getBaseId = (id: string) => id.replace(/_\d+$/, ''); @@ -131,13 +127,13 @@ export function DynamicForm({ client, activityId: initialActivityId, instanceId: if (customPrefillData) { Object.entries(customPrefillData).forEach(([k, v]) => { - if (!imageFieldIds.has(k)) defaultValues[k] = v; + defaultValues[k] = v; }); } if (chainedPrefillData) { Object.entries(chainedPrefillData).forEach(([k, v]) => { - if (!imageFieldIds.has(k)) defaultValues[k] = v; + defaultValues[k] = v; }); } if (currentActivityId === DAILY_REPORTS.activities.PUNCH_OUT.uid) { diff --git a/src/components/forms/fields/FileInput.tsx b/src/components/forms/fields/FileInput.tsx index 6717a8b..080dd59 100644 --- a/src/components/forms/fields/FileInput.tsx +++ b/src/components/forms/fields/FileInput.tsx @@ -1,12 +1,20 @@ import { useState, useEffect } from 'react'; +import { APP_ID } from '../../../api/config'; +import { orderBookingClient } from '../../../api/clients'; -export function ImagePreview({ file }: { file: File }) { +export function ImagePreview({ file }: { file: any }) { const [url, setUrl] = useState(null); useEffect(() => { - const objectUrl = URL.createObjectURL(file); - setUrl(objectUrl); - return () => URL.revokeObjectURL(objectUrl); + if (file instanceof File) { + const objectUrl = URL.createObjectURL(file); + setUrl(objectUrl); + return () => URL.revokeObjectURL(objectUrl); + } else if (file && file.uuid) { + setUrl(`${orderBookingClient.baseUrl}/app/${APP_ID}/view/files/${file.uuid}/preview`); + } else if (typeof file === 'string' && file.startsWith('http')) { + setUrl(file); + } }, [file]); if (!url) return null; @@ -26,7 +34,7 @@ export function FileInput({ value: File[] | undefined | null | unknown; onChange: (files: File[]) => void; }) { - const files = Array.isArray(value) ? value : (value instanceof File ? [value] : []); + const files = Array.isArray(value) ? value : (value ? [value] : []); const handleFileChange = (e: React.ChangeEvent) => { if (e.target.files && e.target.files.length > 0) { @@ -68,7 +76,7 @@ export function FileInput({ ) : (
- {file.name} + {file.name || file.original_name || 'File'}
)}