diff --git a/components/form.js b/components/form.js index d8b85900..7deeb164 100644 --- a/components/form.js +++ b/components/form.js @@ -25,6 +25,7 @@ import textAreaCaret from 'textarea-caret' import ReactDatePicker from 'react-datepicker' import 'react-datepicker/dist/react-datepicker.css' import { debounce } from './use-debounce-callback' +import { ImageUpload } from './image' export function SubmitButton ({ children, variant, value, onClick, disabled, cost, ...props @@ -221,7 +222,9 @@ export function MarkdownInput ({ label, topLevel, groupClassName, onChange, setH preview - + + console.log('icon click')} /> + } + +export function ImageUpload ({ children, className, onSelect, onSuccess }) { + const ref = useRef() + const toaster = useToast() + + return ( + <> + { + if (e.target.files.length === 0) { + return + } + const file = e.target.files[0] + if (UPLOAD_TYPES_ALLOW.indexOf(file.type) === -1) { + toaster.danger(`image must be ${UPLOAD_TYPES_ALLOW.map(t => t.replace('image/', '')).join(', ')}`) + return + } + onSelect?.(file) + // TODO find out if this is needed and if so, why (copied from components/upload.js) + e.target.value = null + }} + /> +
ref.current?.click()} style={{ cursor: 'pointer' }}> + {children} +
+ + ) +}