@@ -10,12 +10,16 @@ const initialUsers = [
1010] ;
1111
1212const UserContainer = ( { user, handleUserToggle } ) => {
13+ const [ loading , setLoading ] = useState ( false ) ;
14+
1315 const handleToggle = ( field , newValue ) => {
1416 handleUserToggle ( user . id , field , newValue ) ;
1517 } ;
1618
17- const handleFileChange = ( event , userId ) => {
18- const file = event . target . files [ 0 ] ; // İlk dosyayı al
19+ const handleFileChange = ( event , userId , recipientId ) => {
20+ setLoading ( true ) ;
21+ const file = event . target . files [ 0 ] ;
22+
1923 if ( file ) {
2024 if ( file . size > 256 ) {
2125 alert ( "Dosya boyutu 256 byte'ı geçemez. Lütfen daha küçük bir dosya yükleyin." ) ;
@@ -24,31 +28,34 @@ const UserContainer = ({ user, handleUserToggle }) => {
2428
2529 console . log ( "Seçilen dosya:" , file ) ;
2630
27-
2831 const formData = new FormData ( ) ;
2932 formData . append ( 'file' , file ) ;
33+ formData . append ( 'userId' , userId ) ;
34+ formData . append ( 'recipientId' , recipientId ) ;
3035
31- axios . post ( `http://localhost:8080/upload/ ${ userId } ` , formData , {
36+ axios . post ( `http://localhost:8080/upload` , formData , {
3237 headers : {
3338 'Content-Type' : 'multipart/form-data'
3439 }
40+ } ) . then ( response => {
41+ console . log ( "Dosya başarıyla yüklendi:" , response . data ) ;
3542 } )
36- . then ( response => {
37- console . log ( "Dosya başarıyla yüklendi:" , response . data ) ;
38- // Başarılı yüklemeden sonra yapılacak işlemler
39- } )
4043 . catch ( error => {
4144 console . error ( "Dosya yüklenirken hata oluştu:" , error ) ;
4245 } ) ;
4346 } else {
44- alert ( "Lütfen bir dosya seçin." ) ; // Dosya seçilmediyse uyarı
47+ alert ( "Lütfen bir dosya seçin." ) ;
4548 }
49+ setLoading ( false ) ;
4650 } ;
4751
4852
4953
54+
5055 return (
51- < div className = { "user-container" } >
56+ < >
57+ { loading && < div className = { "loading-overlay" } > < div className = { "main-spinner" } > </ div > </ div > }
58+ < div className = { "user-container" } >
5259 < p className = { "font-bold" } style = { { color : "var(--orange-color-1)" } } > { user . name } </ p >
5360
5461 < div className = { "custom-row" } style = { { gap :0 } } >
@@ -98,7 +105,7 @@ const UserContainer = ({ user, handleUserToggle }) => {
98105 type = "file"
99106 id = { `fileInput-${ user . id } ` }
100107 accept = ".txt,.pdf,.doc,.docx"
101- onChange = { ( event ) => handleFileChange ( event , user . id ) }
108+ onChange = { ( event ) => handleFileChange ( event , user . id , user . id ) }
102109 style = { { display : 'none' } }
103110 />
104111 ) }
@@ -121,6 +128,7 @@ const UserContainer = ({ user, handleUserToggle }) => {
121128 </ div >
122129 </ div >
123130 </ div >
131+ </ >
124132 ) ;
125133} ;
126134
0 commit comments