@@ -44,26 +44,33 @@ const Page = () => {
44
44
// };
45
45
46
46
const handlePrint = async ( ) => {
47
- // file validation
48
47
const maxFileSize = 5 * 1024 * 1024 ;
48
+ const allowedFileTypes = [ "application/pdf" , "image/jpeg" , "image/png" , "image/gif" ] ;
49
49
const files = fileInputRef . current ?. files as FileList | null ;
50
- if ( ! files || files . length == 0 ) {
50
+
51
+ if ( ! files || files . length === 0 ) {
51
52
toast . error ( "No files selected" ) ;
52
53
return ;
53
54
} else if ( files . length > 5 ) {
54
55
toast . error ( "More than 5 files selected" ) ;
55
56
return ;
56
57
}
58
+
57
59
for ( const file of files ) {
58
60
if ( file . size > maxFileSize ) {
59
61
toast . error ( `File ${ file . name } is more than 5MB` ) ;
60
62
return ;
61
63
}
64
+
65
+ if ( ! allowedFileTypes . includes ( file . type ) ) {
66
+ toast . error ( `File type of ${ file . name } is not allowed. Only PDFs and images are accepted.` ) ;
67
+ return ;
68
+ }
62
69
}
63
70
64
71
const formData = new FormData ( ) ;
65
72
for ( const file of files ) {
66
- formData . append ( "files" , file ) ; // append each file
73
+ formData . append ( "files" , file ) ; // append each file
67
74
}
68
75
formData . append ( "slot" , slot ) ;
69
76
formData . append ( "subject" , subject ) ;
@@ -94,6 +101,7 @@ const Page = () => {
94
101
error : ( err : ApiError ) => err . message ,
95
102
}
96
103
) ;
104
+
97
105
if ( result ?. message === "Email sent successfully!" ) {
98
106
// setTimeout(() => {
99
107
// router.push("/");
@@ -102,6 +110,7 @@ const Page = () => {
102
110
} catch ( e ) { }
103
111
} ;
104
112
113
+
105
114
106
115
const handleSubjectSelect = ( value : string ) => {
107
116
setSubject ( value ) ;
0 commit comments