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,11 +1,17 @@
|
|||||||
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 = (
|
||||||
|
challengeName,
|
||||||
|
repoUrl,
|
||||||
|
repoBranch,
|
||||||
|
description,
|
||||||
|
setLoading
|
||||||
|
) => {
|
||||||
const details = {
|
const details = {
|
||||||
'f1': description,
|
f1: description,
|
||||||
'f3': repoUrl,
|
f3: repoUrl,
|
||||||
'f4': repoBranch
|
f4: repoBranch,
|
||||||
};
|
};
|
||||||
let formBody = [];
|
let formBody = [];
|
||||||
for (let property in details) {
|
for (let property in details) {
|
||||||
@ -18,13 +24,15 @@ const challengeSubmission = (challengeName, repoUrl, repoBranch, description, se
|
|||||||
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((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,6 +70,7 @@ const Challenge = (props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const mobileRender = () => {
|
const mobileRender = () => {
|
||||||
|
if (!loading) {
|
||||||
return (
|
return (
|
||||||
<FlexColumn
|
<FlexColumn
|
||||||
minHeight="100vh"
|
minHeight="100vh"
|
||||||
@ -93,6 +94,9 @@ const Challenge = (props) => {
|
|||||||
{sectionRender()}
|
{sectionRender()}
|
||||||
</FlexColumn>
|
</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,15 +1,18 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { createPortal } from 'react-dom';
|
||||||
import { FlexColumn } from '../../utils/containers';
|
import { FlexColumn } from '../../utils/containers';
|
||||||
import { H2, Menu } from '../../utils/fonts';
|
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);
|
||||||
@ -24,27 +27,63 @@ const Submit = (props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
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