correct redirect back from submission, submission loading and env in submission api request
This commit is contained in:
parent
b77c99dba5
commit
3ff0c6ea87
2
.env
2
.env
@ -2,4 +2,4 @@ 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-localhost
|
REACT_APP_KC_CLIENT_ID=gonito-dev-localhost
|
||||||
|
|
||||||
REACT_APP_API=https://gonito.net/api
|
REACT_APP_API=https://gonito-back-dev.csi.wmi.amu.edu.pl/api
|
@ -1,30 +1,38 @@
|
|||||||
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, setLoading) => {
|
const challengeSubmission = (
|
||||||
const details = {
|
challengeName,
|
||||||
'f1': description,
|
repoUrl,
|
||||||
'f3': repoUrl,
|
repoBranch,
|
||||||
'f4': repoBranch
|
description,
|
||||||
};
|
setLoading
|
||||||
let formBody = [];
|
) => {
|
||||||
for (let property in details) {
|
const details = {
|
||||||
let encodedKey = encodeURIComponent(property);
|
f1: description,
|
||||||
let encodedValue = encodeURIComponent(details[property]);
|
f3: repoUrl,
|
||||||
formBody.push(encodedKey + '=' + encodedValue);
|
f4: repoBranch,
|
||||||
}
|
};
|
||||||
formBody = formBody.join('&');
|
let formBody = [];
|
||||||
fetch(`${API}/challenge-submission/${challengeName}`, {
|
for (let property in details) {
|
||||||
method: 'POST',
|
let encodedKey = encodeURIComponent(property);
|
||||||
headers: {
|
let encodedValue = encodeURIComponent(details[property]);
|
||||||
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
|
formBody.push(encodedKey + '=' + encodedValue);
|
||||||
'Authorization': `Bearer ${KeyCloakService.getToken()}`
|
}
|
||||||
},
|
formBody = formBody.join('&');
|
||||||
body: formBody
|
fetch(`${API}/challenge-submission/${challengeName}`, {
|
||||||
}).then((resp) => resp.json())
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
|
||||||
|
Authorization: `Bearer ${KeyCloakService.getToken()}`,
|
||||||
|
},
|
||||||
|
body: formBody,
|
||||||
|
})
|
||||||
|
.then((resp) => resp.json())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
window.location.replace(`https://gonito.net/open-view-progress/${data}#form`);
|
const processUrl = API.replace('/api', '');
|
||||||
|
window.location.replace(`${processUrl}/open-view-progress/${data}#form`);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Container, FlexColumn, FlexRow, Svg } from '../../utils/containers';
|
import { Container, FlexColumn, FlexRow, Svg } from '../../utils/containers';
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import { H1, H2, Medium } from '../../utils/fonts';
|
import { H1, Medium } from '../../utils/fonts';
|
||||||
import theme from '../../utils/theme';
|
import theme from '../../utils/theme';
|
||||||
import MobileChallengeMenu from './MobileChallengeMenu';
|
import MobileChallengeMenu from './MobileChallengeMenu';
|
||||||
import Leaderboard from './Leaderboard/Leaderboard';
|
import Leaderboard from './Leaderboard/Leaderboard';
|
||||||
@ -70,29 +70,33 @@ const Challenge = (props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const mobileRender = () => {
|
const mobileRender = () => {
|
||||||
return (
|
if (!loading) {
|
||||||
<FlexColumn
|
return (
|
||||||
minHeight="100vh"
|
<FlexColumn
|
||||||
gap="12px"
|
minHeight="100vh"
|
||||||
alignmentY="flex-start"
|
gap="12px"
|
||||||
padding="66px 0 0 0"
|
alignmentY="flex-start"
|
||||||
>
|
padding="66px 0 0 0"
|
||||||
<Loading visible={loading} />
|
>
|
||||||
<H1 as="h1" margin="0 0 8px 0" textAlign="center">
|
<Loading visible={loading} />
|
||||||
{challenge.title}
|
<H1 as="h1" margin="0 0 8px 0" textAlign="center">
|
||||||
</H1>
|
{challenge.title}
|
||||||
<MobileChallengeMenu
|
</H1>
|
||||||
challengeName={challengeName}
|
<MobileChallengeMenu
|
||||||
section={props.section}
|
challengeName={challengeName}
|
||||||
/>
|
section={props.section}
|
||||||
<Container
|
/>
|
||||||
width="75%"
|
<Container
|
||||||
height="1px"
|
width="75%"
|
||||||
backgroundColor={theme.colors.dark}
|
height="1px"
|
||||||
/>
|
backgroundColor={theme.colors.dark}
|
||||||
{sectionRender()}
|
/>
|
||||||
</FlexColumn>
|
{sectionRender()}
|
||||||
);
|
</FlexColumn>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return <Loading />;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const desktopRender = () => {
|
const desktopRender = () => {
|
||||||
@ -131,19 +135,7 @@ const Challenge = (props) => {
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return (
|
return <Loading />;
|
||||||
<FlexColumn
|
|
||||||
position="fixed"
|
|
||||||
top="0"
|
|
||||||
left="0"
|
|
||||||
width="100%"
|
|
||||||
height="100vh"
|
|
||||||
zIndex="10"
|
|
||||||
>
|
|
||||||
<H2 as="h1">Submission processing...</H2>
|
|
||||||
<Loading />
|
|
||||||
</FlexColumn>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ const DesktopChallengeMenu = (props) => {
|
|||||||
<Option
|
<Option
|
||||||
key={`challenge_menu_option-${index}`}
|
key={`challenge_menu_option-${index}`}
|
||||||
as={Link}
|
as={Link}
|
||||||
active={index === props.section}
|
active={index === props.section ? 1 : 0}
|
||||||
to={`/challenge/${props.challengeName}/${options[index]
|
to={`/challenge/${props.challengeName}/${options[index]
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.replace(' ', '')}`}
|
.replace(' ', '')}`}
|
||||||
|
@ -1,50 +1,89 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import {FlexColumn} from '../../utils/containers';
|
import { createPortal } from 'react-dom';
|
||||||
import {H2, Menu} from '../../utils/fonts';
|
import { FlexColumn } from '../../utils/containers';
|
||||||
|
import { H2, Menu } from '../../utils/fonts';
|
||||||
import SubmitInput from '../generic/SubmitInput';
|
import SubmitInput from '../generic/SubmitInput';
|
||||||
import Button from '../generic/Button';
|
import Button from '../generic/Button';
|
||||||
import theme from '../../utils/theme';
|
import theme from '../../utils/theme';
|
||||||
import challengeSubmission from '../../api/challengeSubmissionPost';
|
import challengeSubmission from '../../api/challengeSubmissionPost';
|
||||||
|
import Loading from '../generic/Loading';
|
||||||
|
|
||||||
const Submit = (props) => {
|
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 [loading, setLoading] = React.useState(false);
|
||||||
|
|
||||||
const descriptionHandler = (e) => {
|
const descriptionHandler = (e) => {
|
||||||
setDescription(e.target.value);
|
setDescription(e.target.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const repoUrlHandler = (e) => {
|
const repoUrlHandler = (e) => {
|
||||||
setRepoUrl(e.target.value);
|
setRepoUrl(e.target.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const repoBranchHandler = (e) => {
|
const repoBranchHandler = (e) => {
|
||||||
setRepoBranch(e.target.value);
|
setRepoBranch(e.target.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const challengeSubmissionSubmit = () => {
|
const challengeSubmissionSubmit = () => {
|
||||||
challengeSubmission(props.challengeName, repoUrl, repoBranch, description, props.setLoading);
|
setLoading(true);
|
||||||
};
|
challengeSubmission(
|
||||||
|
props.challengeName,
|
||||||
return (
|
repoUrl,
|
||||||
<FlexColumn margin='40px 0 0 0' padding='24px' as='section' gap='64px' maxWidth='624px' width='100%'
|
repoBranch,
|
||||||
alignmentX='flex-start'>
|
description,
|
||||||
<H2 as='h2' width='100%' textAlign='center'>
|
setLoading
|
||||||
Submit a solution to the challenge
|
|
||||||
</H2>
|
|
||||||
<FlexColumn width='100%' gap='32px'>
|
|
||||||
<SubmitInput label='Submission description' handler={descriptionHandler}/>
|
|
||||||
<SubmitInput label='Submission repo URL' handler={repoUrlHandler}/>
|
|
||||||
<SubmitInput label='Submission repo branch' handler={repoBranchHandler}/>
|
|
||||||
</FlexColumn>
|
|
||||||
<Button width='122px' height='44px' handler={challengeSubmissionSubmit}>
|
|
||||||
<Menu color={theme.colors.white}>
|
|
||||||
Submit
|
|
||||||
</Menu>
|
|
||||||
</Button>
|
|
||||||
</FlexColumn>
|
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!loading) {
|
||||||
|
return (
|
||||||
|
<FlexColumn
|
||||||
|
margin="40px 0 0 0"
|
||||||
|
padding="24px"
|
||||||
|
as="section"
|
||||||
|
gap="64px"
|
||||||
|
maxWidth="624px"
|
||||||
|
width="100%"
|
||||||
|
alignmentX="flex-start"
|
||||||
|
>
|
||||||
|
<H2 as="h2" width="100%" textAlign="center">
|
||||||
|
Submit a solution to the challenge
|
||||||
|
</H2>
|
||||||
|
<FlexColumn width="100%" gap="32px">
|
||||||
|
<SubmitInput
|
||||||
|
label="Submission description"
|
||||||
|
handler={descriptionHandler}
|
||||||
|
/>
|
||||||
|
<SubmitInput label="Submission repo URL" handler={repoUrlHandler} />
|
||||||
|
<SubmitInput
|
||||||
|
label="Submission repo branch"
|
||||||
|
handler={repoBranchHandler}
|
||||||
|
/>
|
||||||
|
</FlexColumn>
|
||||||
|
<Button width="122px" height="44px" handler={challengeSubmissionSubmit}>
|
||||||
|
<Menu color={theme.colors.white}>Submit</Menu>
|
||||||
|
</Button>
|
||||||
|
</FlexColumn>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return createPortal(
|
||||||
|
<FlexColumn
|
||||||
|
position="fixed"
|
||||||
|
top="0"
|
||||||
|
left="0"
|
||||||
|
width="100%"
|
||||||
|
height="100vh"
|
||||||
|
zIndex="100"
|
||||||
|
backgroundColor={theme.colors.white}
|
||||||
|
>
|
||||||
|
<H2 as="h1">Submission processing...</H2>
|
||||||
|
<Loading />
|
||||||
|
</FlexColumn>,
|
||||||
|
document.body
|
||||||
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Submit;
|
export default Submit;
|
Loading…
Reference in New Issue
Block a user