1- import {
2- Box ,
3- FormControl ,
4- Image ,
5- Input ,
6- Text ,
7- useToast ,
8- } from '@chakra-ui/react' ;
1+ import { Box , Image , Input , Text , useToast } from '@chakra-ui/react' ;
92import { LessonPlanFile } from '@utils/types' ;
103import { useRef , useState } from 'react' ;
114
125interface FileUploadProps {
136 lessonPlan : File | null ;
147 setLessonPlan : ( file : File | null ) => void ;
158 existingFile ?: LessonPlanFile | null ;
9+ isDisabled : boolean ;
1610}
1711
1812export const FileUpload : React . FC < FileUploadProps > = ( {
1913 lessonPlan,
2014 setLessonPlan,
2115 existingFile,
16+ isDisabled,
2217} ) => {
2318 const [ isDragging , setIsDragging ] = useState ( false ) ;
2419 const inputRef = useRef < HTMLInputElement > ( null ) ;
@@ -32,33 +27,39 @@ export const FileUpload: React.FC<FileUploadProps> = ({
3227 title : 'Invalid File Type' ,
3328 description : 'Please upload a valid PDF file.' ,
3429 status : 'error' ,
35- duration : 4000 ,
30+ duration : 5000 ,
3631 isClosable : true ,
3732 } ) ;
3833 }
3934 } ;
4035
4136 const handleFileChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
42- if ( e . target . files && e . target . files . length > 0 ) {
43- const file = e . target . files [ 0 ] ;
37+ if ( isDisabled ) return ;
38+
39+ const file = e . target . files ?. [ 0 ] ;
40+ if ( file ) {
4441 validateAndSetFile ( file ) ;
4542 }
4643 } ;
4744
4845 const handleDragOver = ( e : React . DragEvent ) => {
46+ if ( isDisabled ) return ;
4947 e . preventDefault ( ) ;
5048 setIsDragging ( true ) ;
5149 } ;
5250
5351 const handleDragLeave = ( ) => {
52+ if ( isDisabled ) return ;
5453 setIsDragging ( false ) ;
5554 } ;
5655
5756 const handleDrop = ( e : React . DragEvent ) => {
57+ if ( isDisabled ) return ;
5858 e . preventDefault ( ) ;
5959 setIsDragging ( false ) ;
60- if ( e . dataTransfer . files && e . dataTransfer . files . length > 0 ) {
61- const file = e . dataTransfer . files [ 0 ] ;
60+
61+ const file = e . dataTransfer . files ?. [ 0 ] ;
62+ if ( file ) {
6263 validateAndSetFile ( file ) ;
6364 }
6465 } ;
@@ -69,11 +70,20 @@ export const FileUpload: React.FC<FileUploadProps> = ({
6970 as = "label"
7071 htmlFor = "fileUpload"
7172 border = "1px dashed"
72- borderColor = { isDragging ? 'primaryBlue.300' : 'outline' }
73+ borderColor = {
74+ isDisabled
75+ ? 'neutralGray.300'
76+ : isDragging
77+ ? 'primaryBlue.300'
78+ : 'outline'
79+ }
80+ bg = { isDisabled ? 'neutralGray.50' : 'transparent' }
81+ opacity = { isDisabled ? 0.6 : 1 }
82+ pointerEvents = { isDisabled ? 'none' : 'auto' }
7383 borderRadius = "10px"
7484 p = { 5 }
7585 textAlign = "center"
76- cursor = " pointer"
86+ cursor = { isDisabled ? 'not-allowed' : ' pointer' }
7787 display = "flex"
7888 flexDirection = "column"
7989 alignItems = "center"
@@ -100,6 +110,7 @@ export const FileUpload: React.FC<FileUploadProps> = ({
100110 onChange = { handleFileChange }
101111 accept = "application/pdf"
102112 display = "none"
113+ disabled = { isDisabled }
103114 />
104115 </ >
105116 ) ;
0 commit comments