import { Icon, IconButton } from "@chakra-ui/react"; import { useErrorHandler } from "@strata-foundation/react"; import React from "react"; import { useAsyncCallback } from "react-async-hook"; import { IoMdAttach } from "react-icons/io"; export function FileAttachment({ onUpload, }: { onUpload: (files: FileList) => Promise; }) { const hiddenFileInput = React.useRef(null); const { execute, loading, error } = useAsyncCallback(onUpload); const { handleErrors } = useErrorHandler(); handleErrors(error); const handleImageChange = async (e: React.ChangeEvent) => { const files = e.target.files!; try { await execute(files); } finally { if (hiddenFileInput.current) { hiddenFileInput.current.value = "" } } }; return ( <> hiddenFileInput.current!.click()} icon={} /> ); }