import { Button, ButtonProps, chakra } from '@chakra-ui/react' import React, { ChangeEvent, useState } from 'react' import { compressFile, uploadFile } from 'services/utils' type UploadButtonProps = { filePath: string includeFileName?: boolean onFileUploaded: (url: string) => void } & ButtonProps export const UploadButton = ({ filePath, includeFileName, onFileUploaded, ...props }: UploadButtonProps) => { const [isUploading, setIsUploading] = useState(false) const handleInputChange = async (e: ChangeEvent) => { if (!e.target?.files) return setIsUploading(true) const file = e.target.files[0] const { url } = await uploadFile( await compressFile(file), filePath + (includeFileName ? `/${file.name}` : '') ) if (url) onFileUploaded(url) setIsUploading(false) } return ( <> ) }