challenge submit refactor

This commit is contained in:
Mateusz Tylka 2022-12-05 11:36:08 +01:00
parent b490104ef0
commit 4f6da92d7d
3 changed files with 9 additions and 9 deletions

2
.env
View File

@ -1,3 +1,3 @@
REACT_APP_KC_URL=https://auth-dev.csi.wmi.amu.edu.pl/ REACT_APP_KC_URL=https://auth-dev.csi.wmi.amu.edu.pl/
REACT_APP_KC_REALM=gonito-dev REACT_APP_KC_REALM=gonito-dev
REACT_APP_KC_CLIENT_ID=gonito-dev-heroku REACT_APP_KC_CLIENT_ID=gonito-dev-localhost

View File

@ -1,7 +1,7 @@
import KeyCloakService from '../services/KeyCloakService'; import KeyCloakService from '../services/KeyCloakService';
import {API} from '../utils/globals'; import {API} from '../utils/globals';
const challengeSubmission = (challengeName, repoUrl, repoBranch, description) => { const challengeSubmission = (challengeName, repoUrl, repoBranch, description, setData) => {
const details = { const details = {
'f1': description, 'f1': description,
'f3': repoUrl, 'f3': repoUrl,
@ -14,14 +14,15 @@ const challengeSubmission = (challengeName, repoUrl, repoBranch, description) =>
formBody.push(encodedKey + '=' + encodedValue); formBody.push(encodedKey + '=' + encodedValue);
} }
formBody = formBody.join('&'); formBody = formBody.join('&');
return fetch(`${API}/challenge-submission/${challengeName}`, { fetch(`${API}/challenge-submission/${challengeName}`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8', 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
'Authorization': `Bearer ${KeyCloakService.getToken()}` 'Authorization': `Bearer ${KeyCloakService.getToken()}`
}, },
body: formBody body: formBody
}); }).then((resp) => resp.json())
.then((data) => setData(data));
}; };
export default challengeSubmission; export default challengeSubmission;

View File

@ -10,6 +10,7 @@ const Submit = (props) => {
const [description, setDescription] = React.useState(''); const [description, setDescription] = React.useState('');
const [repoUrl, setRepoUrl] = React.useState(''); const [repoUrl, setRepoUrl] = React.useState('');
const [repoBranch, setRepoBranch] = React.useState(''); const [repoBranch, setRepoBranch] = React.useState('');
const [responseNumber, setResponseNumber] = React.useState(0);
const descriptionHandler = (e) => { const descriptionHandler = (e) => {
setDescription(e.target.value); setDescription(e.target.value);
@ -24,10 +25,8 @@ const Submit = (props) => {
}; };
const challengeSubmissionSubmit = () => { const challengeSubmissionSubmit = () => {
challengeSubmission(props.challengeName, repoUrl, repoBranch, description) challengeSubmission(props.challengeName, repoUrl, repoBranch, description, setResponseNumber);
.then((response) => response.text()) console.log(responseNumber);
.then((data) => console.log(data));
props.popUpMessageHandler('Submit success!', 'Check your entries.');
}; };
return ( return (