diff --git a/src/api/challengeSubmissionPost.js b/src/api/challengeSubmissionPost.js new file mode 100644 index 0000000..38f3737 --- /dev/null +++ b/src/api/challengeSubmissionPost.js @@ -0,0 +1,29 @@ +import KeyCloakService from '../services/KeyCloakService'; +import {API} from '../utils/globals'; + +async function postData(url = '', data = {}) { + const response = await fetch(url, { + method: 'POST', + mode: 'no-cors', + cache: 'no-cache', + credentials: 'same-origin', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${KeyCloakService.getToken()}` + }, + redirect: 'follow', + referrerPolicy: 'no-referrer', + body: JSON.stringify(data) + }); + return response.json(); +} + +const challengeSubmission = (challengeName, repoUrl, repoBranch, description) => { + postData(`${API}/challenge-submission/${challengeName}`, + {f1: description, f3: repoUrl, f4: repoBranch}) + .then((data) => { + console.log(data); + }); +}; + +export default challengeSubmission; diff --git a/src/components/elements/SubmitInput.js b/src/components/elements/SubmitInput.js new file mode 100644 index 0000000..19c6206 --- /dev/null +++ b/src/components/elements/SubmitInput.js @@ -0,0 +1,19 @@ +import React from 'react'; +import {FlexColumn} from '../../utils/containers'; +import {Medium} from '../../utils/fonts'; +import theme from '../../utils/theme'; + +const SubmitInput = (props) => { + return ( + + + {props.label} + + props.handler(e)} padding='4px'/> + + ); +}; + +export default SubmitInput; \ No newline at end of file diff --git a/src/components/sections/Submit.js b/src/components/sections/Submit.js index c28e7a1..8424a55 100644 --- a/src/components/sections/Submit.js +++ b/src/components/sections/Submit.js @@ -1,13 +1,48 @@ import React from 'react'; import {FlexColumn} from '../../utils/containers'; -import {H2} from '../../utils/fonts'; +import {H2, Menu} from '../../utils/fonts'; +import SubmitInput from '../elements/SubmitInput'; +import Button from '../elements/Button'; +import theme from '../../utils/theme'; +import challengeSubmission from '../../api/challengeSubmissionPost'; + +const Submit = (props) => { + const [description, setDescription] = React.useState(''); + const [repoUrl, setRepoUrl] = React.useState(''); + const [repoBranch, setRepoBranch] = React.useState(''); + + const descriptionHandler = (e) => { + setDescription(e.target.value); + }; + + const repoUrlHandler = (e) => { + setRepoUrl(e.target.value); + }; + + const repoBranchHandler = (e) => { + setRepoBranch(e.target.value); + }; + + const challengeSubmissionSubmit = () => { + challengeSubmission(props.challengeName, repoUrl, repoBranch, description); + }; -const Submit = () => { return ( - -

- Submit + +

+ Submit a solution to the challenge

+ + + + + +
); };