import { ImageAttachmentField, ImageAttachmentFieldProps } from '@/components/ra-fields'; import _ from 'lodash'; import { RecordContextProvider, useRecordContext } from 'ra-core'; import { ImageField } from 'ra-ui-materialui'; import { useEffect, useState } from 'react'; import { AttachmentInput, AttachmentInputProps } from './AttachmentInput'; type ImageAttachmentInputProps = Omit; function ImageAttachmentInput(props: ImageAttachmentInputProps) { const { source } = props; const record = useRecordContext(props); const { id: entityId } = record ?? {}; return ( ); } function Field(props: { entityId?: string; source?: string }) { const value = useRecordContext(); return _.isNil(value?.rawFile) ? ( ) : ( ); } function AttachmentPreview(props: ImageAttachmentFieldProps & { entityId?: string }) { const { entityId, ...rest } = props; const source = props.source ?? ''; const value = useRecordContext(); const [context, setContext] = useState(source ? { id: entityId, [source]: value } : { id: entityId }); useEffect(() => { setContext({ id: entityId, [source]: value }); }, [value, entityId, source]); return ( ); } export { ImageAttachmentInput };