From 481a72929e1180452f32c8897f4f52dea2f9f2cd Mon Sep 17 00:00:00 2001 From: cherif Date: Fri, 9 Dec 2022 23:11:47 +0100 Subject: [PATCH] eee --- src/components/GestionAdministrative.js | 45 +++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/components/GestionAdministrative.js b/src/components/GestionAdministrative.js index e8db1ff..527a7e9 100644 --- a/src/components/GestionAdministrative.js +++ b/src/components/GestionAdministrative.js @@ -1389,6 +1389,9 @@ function GestionAdministrative(props) { const hiddenFileInput = React.useRef(null); + const [liste_participants_file_change_api, setliste_participants_file_change_api] = useState(); + const [liste_participants_file_change_result, setliste_participants_file_change_result] = useState(); + const [liste_participants_file_change_message, setliste_participants_file_change_message] = useState(); const liste_participants_file_change = event => { const fileUploaded = event.target.files[0]; let file_size = event.target.files[0].size; @@ -1401,6 +1404,41 @@ function GestionAdministrative(props) { } setparticipant_file_name(event.target.files[0].name); + + const formData = new FormData(); + formData.append('File', fileUploaded); + //formData.append('token', 'K3cw63eKokKSbV4spjQ48SUNnfy80yrXfA'); + const stored_cookie = getCookie('tokenmysypart'); + + formData.append("token", stored_cookie); + formData.append("session_id", mysession); + //console.log("token = " + stored_cookie); + + fetch( + process.env.REACT_APP_API_URL + "myclass/api/AddStagiairetoClass_mass/", + { + method: 'POST', + body: formData, + } + ) + .then((response) => response.json()) + .then((result) => { + if (String(result['message']) === String("true")) { + //console.log('Success:', result['message']); + setliste_participants_file_change_result(result['message']); + setliste_participants_file_change_api("true"); + } + else { + setliste_participants_file_change_message(result['message']); + setliste_participants_file_change_api("false"); + } + + }) + .catch((error) => { + console.error('Error:', error); + setliste_participants_file_change_api("false"); + }); + }; return ( @@ -2036,8 +2074,11 @@ function GestionAdministrative(props) { }} id='menu_import_participant' name='menu_import_participant'>Import participants  
- - {participant_file_name} + + {participant_file_name}
+ {String(liste_participants_file_change_api) === String("false") && } + {String(liste_participants_file_change_api) !== String("false") && } +