import { ExclamationIcon, PhotographIcon } from '@heroicons/react/outline'; import React, { SyntheticEvent, useContext, useState } from 'react'; import { FieldContext } from '../../../Contexts'; import InlineErrors from '../shared/InlineErrors'; import Label from '../shared/Label'; import PrivacyBarrier from '../shared/PrivacyBarrier'; import { TypeInput } from '../../../Types'; import Vapor from 'laravel-vapor'; interface ImageProperties extends TypeInput { label?: string; defer?: boolean; } export default function Image(props: ImageProperties): JSX.Element { const [uploadError, setUploadError] = useState(); const context = useContext(FieldContext); const { id, name, label, disabled, placeholder } = props; const [uploadProgress, setUploadProcess] = useState(0); function upload(e: SyntheticEvent) { // @ts-ignore const fileName = e.target.files[0].name; // @ts-ignore const type = e.target.files[0].type; // @ts-ignore Vapor.store(e.target.files[0], { // @ts-ignore signedStorageUrl: '/reactive/signed-transfer', visibility: 'public-read', // @ts-ignore progress: (progress: number) => { setUploadProcess(Math.round(progress * 100)); }, }) .then((response: any) => { context.onChange({ ...response.file, name: fileName, mime: type, url: `${response.file?.store}/${response.file?.id}`, }); }) .catch(({ message }) => setUploadError(message)); } return ( <>