11import { useRef } from 'react' ;
2+ import { NotificationManager } from 'react-notifications' ;
23
34import DiscreeteDropdown from '../components/DiscreeteDropdown' ;
45
5- function PictureUploadAction ( { id, backend, handleImageUrl } ) {
6+ function PictureUploadAction ( { id, backend, handleImageUrl } ) {
67 const fileInputRef = useRef ( null ) ;
78
89 const handleClick = ( ) => {
@@ -11,7 +12,15 @@ function PictureUploadAction ({ id, backend, handleImageUrl }) {
1112
1213 const handleFileChange = ( event ) => {
1314 const file = event . target . files [ 0 ] ;
14- if ( file ) backend . putAttachment ( id , file , ( response ) => {
15+
16+ if ( ! file ) return ;
17+
18+ if ( ! file . type . startsWith ( 'image/' ) ) {
19+ NotificationManager . warning ( 'Please choose an image file (png,jpg,jpeg...).' , '' , 2000 ) ;
20+ return ;
21+ }
22+
23+ backend . putAttachment ( id , file , ( response ) => {
1524 handleImageUrl ( `` ) ;
1625 } ) ;
1726 } ;
@@ -24,6 +33,7 @@ function PictureUploadAction ({ id, backend, handleImageUrl }) {
2433 < input
2534 id = "image-input"
2635 type = "file"
36+ accept = "image/apng, image/avif, image/gif, image/jpeg, image/png, image/svg+xml, image/webp"
2737 ref = { fileInputRef }
2838 style = { { display : 'none' } }
2939 onChange = { handleFileChange }
0 commit comments