fix popUpMessageHandler, and popUp message when delete submission impossible

This commit is contained in:
Mateusz Tylka 2023-06-28 19:12:06 +02:00
parent 74e0ef19db
commit 69f65846c2
12 changed files with 47 additions and 30 deletions

View File

@ -16,13 +16,14 @@ const App = () => {
const renderApp = React.useCallback(() => { const renderApp = React.useCallback(() => {
return ( return (
<ThemeProvider theme={theme}> <ThemeProvider theme={theme}>
<PopUpMessageManager>
<BrowserRouter> <BrowserRouter>
<PopUpMessageManager>
<NavigationManager> <NavigationManager>
<RoutingManager /> <RoutingManager />
</NavigationManager> </NavigationManager>
</BrowserRouter>
</PopUpMessageManager> </PopUpMessageManager>
</BrowserRouter>
</ThemeProvider> </ThemeProvider>
); );
}, []); }, []);

View File

@ -4,7 +4,7 @@ import LoggedBar from '../../components/navigation/LoggedBar';
import KeyCloakService from '../../services/KeyCloakService'; import KeyCloakService from '../../services/KeyCloakService';
import { CHILDREN_WITH_PROPS, IS_MOBILE } from '../../utils/globals'; import { CHILDREN_WITH_PROPS, IS_MOBILE } from '../../utils/globals';
const NavigationManager = (props) => { const NavigationManager = ({children, popUpMessageHandler}) => {
const [loggedBarVisible, setLoggedBarVisible] = React.useState('100vw'); const [loggedBarVisible, setLoggedBarVisible] = React.useState('100vw');
const [loggedBarHover, setLoggedBarHover] = React.useState(false); const [loggedBarHover, setLoggedBarHover] = React.useState(false);
const [navOptions, setNavOptions] = React.useState(true); const [navOptions, setNavOptions] = React.useState(true);
@ -27,7 +27,7 @@ const NavigationManager = (props) => {
<> <>
<NavBar <NavBar
loggedBarVisibleHandler={loggedBarVisibleHandler} loggedBarVisibleHandler={loggedBarVisibleHandler}
popUpMessageHandler={props.popUpMessageHandler} popUpMessageHandler={popUpMessageHandler}
navOptions={navOptions} navOptions={navOptions}
/> />
{!IS_MOBILE() && ( {!IS_MOBILE() && (
@ -39,7 +39,7 @@ const NavigationManager = (props) => {
username={KeyCloakService.getUsername()} username={KeyCloakService.getUsername()}
/> />
)} )}
{CHILDREN_WITH_PROPS(props.children, { hideNavOptions, showNavOptions })} {CHILDREN_WITH_PROPS(children, { hideNavOptions, showNavOptions, popUpMessageHandler })}
</> </>
); );
}; };

View File

@ -5,11 +5,13 @@ import { CHILDREN_WITH_PROPS } from '../../utils/globals';
const PopUpMessageManager = (props) => { const PopUpMessageManager = (props) => {
const [popUpHeader, setPopUpHeader] = React.useState(''); const [popUpHeader, setPopUpHeader] = React.useState('');
const [popUpMessage, setPopUpMessage] = React.useState(''); const [popUpMessage, setPopUpMessage] = React.useState('');
const [borderColor, setBorderColor] = React.useState(null);
const [confirmPopUpHandler, setConfirmPopUpHandler] = React.useState(null); const [confirmPopUpHandler, setConfirmPopUpHandler] = React.useState(null);
const popUpMessageHandler = (header, message, confirmHandler) => { const popUpMessageHandler = (header, message, confirmHandler=null, borderColor=null) => {
setPopUpHeader(header); setPopUpHeader(header);
setPopUpMessage(message); setPopUpMessage(message);
setBorderColor(borderColor);
if (confirmHandler !== null && confirmHandler !== undefined) { if (confirmHandler !== null && confirmHandler !== undefined) {
setConfirmPopUpHandler(() => confirmHandler()); setConfirmPopUpHandler(() => confirmHandler());
} else { } else {
@ -24,6 +26,7 @@ const PopUpMessageManager = (props) => {
header={popUpHeader} header={popUpHeader}
message={popUpMessage} message={popUpMessage}
confirmHandler={confirmPopUpHandler} confirmHandler={confirmPopUpHandler}
borderColor={borderColor}
popUpMessageHandler={popUpMessageHandler} popUpMessageHandler={popUpMessageHandler}
/> />
); );

View File

@ -24,7 +24,7 @@ const RoutingManager = (props) => {
/> />
<Route <Route
path={`${CHALLENGE_PAGE}/:challengeId/allentries`} path={`${CHALLENGE_PAGE}/:challengeId/allentries`}
element={<Challenge section={CHALLENGE_SECTIONS.ALL_ENTRIES} />} element={<Challenge section={CHALLENGE_SECTIONS.ALL_ENTRIES} popUpMessageHandler={props.popUpMessageHandler} />}
/> />
<Route <Route
path={`${CHALLENGE_PAGE}/:challengeId/readme`} path={`${CHALLENGE_PAGE}/:challengeId/readme`}
@ -41,13 +41,13 @@ const RoutingManager = (props) => {
/> />
<Route <Route
path={`${CHALLENGE_PAGE}/:challengeId/myentries`} path={`${CHALLENGE_PAGE}/:challengeId/myentries`}
element={<Challenge section={CHALLENGE_SECTIONS.MY_ENTRIES} />} element={<Challenge section={CHALLENGE_SECTIONS.MY_ENTRIES} popUpMessageHandler={props.popUpMessageHandler} />}
/> />
<Route <Route
path={`${CHALLENGE_PAGE}/:challengeId/submit`} path={`${CHALLENGE_PAGE}/:challengeId/submit`}
element={<Challenge section={CHALLENGE_SECTIONS.SUBMIT} />} element={<Challenge section={CHALLENGE_SECTIONS.SUBMIT} />}
/> />
<Route path={CHALLENGES_PAGE} element={<Challenges />} /> <Route path={CHALLENGES_PAGE} element={<Challenges popUpMessageHandler={props.popUpMessageHandler} />} />
<Route <Route
path={POLICY_PRIVACY_PAGE} path={POLICY_PRIVACY_PAGE}
element={ element={
@ -74,8 +74,8 @@ const RoutingManager = (props) => {
/> />
{KeyCloakService.isLoggedIn() ? ( {KeyCloakService.isLoggedIn() ? (
<> <>
<Route exact path="/" element={<Challenges />} /> <Route exact path="/" element={<Challenges popUpMessageHandler={props.popUpMessageHandler} />} />
<Route element={<Challenges />} /> <Route element={<Challenges popUpMessageHandler={props.popUpMessageHandler} />} />
</> </>
) : ( ) : (
<> <>

View File

@ -9,7 +9,7 @@ const deleteSubmission = async (submissionId) => {
Authorization: `Bearer ${KeyCloakService.getToken()}`, Authorization: `Bearer ${KeyCloakService.getToken()}`,
}, },
}) })
.then((resp) => resp.json()) .then((resp) => resp.text())
.then((data) => { .then((data) => {
console.log(data); console.log(data);
}); });

View File

@ -28,13 +28,13 @@ const PopupMessage = (props) => {
borderRadius="12px" borderRadius="12px"
backgroundColor={theme.colors.white} backgroundColor={theme.colors.white}
padding="56px" padding="56px"
border={`4px solid ${theme.colors.green}`} border={`4px solid ${props.borderColor ? props.borderColor : theme.colors.green}`}
> >
<FlexColumn gap="48px" margin="0 0 48px 0"> <FlexColumn gap="48px" margin="0 0 48px 0">
<H3>{props.header}</H3> <H3>{props.header}</H3>
<Body>{props.message}</Body> <Body>{props.message}</Body>
</FlexColumn> </FlexColumn>
<Button handler={confirmPopUp}>Ok</Button> <Button backgroundColor={props.borderColor ? props.borderColor : theme.colors.green} handler={confirmPopUp}>Ok</Button>
</FlexColumn> </FlexColumn>
</FlexColumn> </FlexColumn>
); );

View File

@ -4,19 +4,35 @@ import TableHeader from './components/TableHeader';
import TableRowItems from './components/TableRowItems'; import TableRowItems from './components/TableRowItems';
import RowsBackgroundStyle from './styles/RowsBackgroundStyle'; import RowsBackgroundStyle from './styles/RowsBackgroundStyle';
import TableRowFooter from './components/TableRowFooter'; import TableRowFooter from './components/TableRowFooter';
import KeyCloakService from '../../../services/KeyCloakService';
import deleteSubmission from '../../../api/deleteSubmission'; import deleteSubmission from '../../../api/deleteSubmission';
import theme from '../../../utils/theme';
const Table = ({ items, orderedKeys, sortByUpdate, rowFooter = true }) => { const Table = ({ items, orderedKeys, popUpMessageHandler, sortByUpdate, rowFooter = true }) => {
const [, updateState] = React.useState(); const [, updateState] = React.useState();
const tableUpdate = React.useCallback(() => updateState({}), []); const tableUpdate = React.useCallback(() => updateState({}), []);
const [deletedItems, setDeletedItems] = React.useState([]); const [deletedItems, setDeletedItems] = React.useState([]);
const itemsToRender = items.filter((item) => !deletedItems.includes(item)); const itemsToRender = items.filter((item) => !deletedItems.includes(item));
const deleteItem = async (item) => { const deleteItem = async (item) => {
if (item.submitter === KeyCloakService.getUsername()) {
await deleteSubmission(item.id); await deleteSubmission(item.id);
let newDeletedItems = deletedItems.slice(); let newDeletedItems = deletedItems.slice();
newDeletedItems.push(item); newDeletedItems.push(item);
setDeletedItems(newDeletedItems); setDeletedItems(newDeletedItems);
popUpMessageHandler(
'Complete',
`Submission "${item.id}" deleted`,
);
}
else {
popUpMessageHandler(
'Error',
"You can't delete this submission!",
null,
theme.colors.red
);
}
}; };
return ( return (

View File

@ -10,7 +10,6 @@ const renderTags = (tags, i) => {
); );
}); });
} }
return <FlexRow className="TableStyle__tag">submission without tags</FlexRow>;
}; };
export default renderTags; export default renderTags;

View File

@ -10,7 +10,7 @@ import { CALC_PAGES, ELEMENTS_PER_PAGE } from '../../utils/globals';
import searchQueryHandler from './searchHandler'; import searchQueryHandler from './searchHandler';
import orderKeys from './orderKeys'; import orderKeys from './orderKeys';
const NewTablePageTest = (props) => { const AllEntries = (props) => {
const [entriesAll, setEntriesAll] = React.useState([]); const [entriesAll, setEntriesAll] = React.useState([]);
const [entries, setEntries] = React.useState([]); const [entries, setEntries] = React.useState([]);
const [pageNr, setPageNr] = React.useState(1); const [pageNr, setPageNr] = React.useState(1);
@ -134,6 +134,7 @@ const NewTablePageTest = (props) => {
items={elements} items={elements}
orderedKeys={orderKeys(entries[0])} orderedKeys={orderKeys(entries[0])}
sortByUpdate={sortByUpdate} sortByUpdate={sortByUpdate}
popUpMessageHandler={props.popUpMessageHandler}
/> />
// </div> // </div>
)} )}
@ -154,4 +155,4 @@ const NewTablePageTest = (props) => {
); );
}; };
export default NewTablePageTest; export default AllEntries;

View File

@ -15,18 +15,15 @@ import { CHALLENGE_SECTIONS, RENDER_ICO } from '../../utils/globals';
import textIco from '../../assets/text_ico.svg'; import textIco from '../../assets/text_ico.svg';
import getChallengeInfo from '../../api/getChallengeInfo'; import getChallengeInfo from '../../api/getChallengeInfo';
import Loading from '../../components/generic/Loading'; import Loading from '../../components/generic/Loading';
import getUser from '../../api/getUser';
import AllEntries from '../AllEntries/AllEntries'; import AllEntries from '../AllEntries/AllEntries';
const Challenge = (props) => { const Challenge = (props) => {
const challengeName = useParams().challengeId; const challengeName = useParams().challengeId;
const [challenge, setChallenge] = React.useState([]); const [challenge, setChallenge] = React.useState([]);
const [loading, setLoading] = React.useState(true); const [loading, setLoading] = React.useState(true);
const [user, setUser] = React.useState('');
React.useEffect(() => { React.useEffect(() => {
getChallengeInfo(setChallenge, setLoading, challengeName); getChallengeInfo(setChallenge, setLoading, challengeName);
getUser(setUser);
}, [challengeName]); }, [challengeName]);
const sectionRender = () => { const sectionRender = () => {
@ -36,12 +33,11 @@ const Challenge = (props) => {
<Leaderboard <Leaderboard
challengeName={challengeName} challengeName={challengeName}
mainMetric={challenge.mainMetric} mainMetric={challenge.mainMetric}
user={user}
/> />
); );
case CHALLENGE_SECTIONS.ALL_ENTRIES: case CHALLENGE_SECTIONS.ALL_ENTRIES:
return ( return (
<AllEntries challengeName={challengeName} setLoading={setLoading} /> <AllEntries challengeName={challengeName} setLoading={setLoading} popUpMessageHandler={props.popUpMessageHandler} />
); );
case CHALLENGE_SECTIONS.README: case CHALLENGE_SECTIONS.README:
return ( return (
@ -57,11 +53,10 @@ const Challenge = (props) => {
<HowTo <HowTo
popUpMessageHandler={props.popUpMessageHandler} popUpMessageHandler={props.popUpMessageHandler}
challengeName={challengeName} challengeName={challengeName}
user={user}
/> />
); );
case CHALLENGE_SECTIONS.MY_ENTRIES: case CHALLENGE_SECTIONS.MY_ENTRIES:
return <MyEntries challengeName={challengeName} />; return <MyEntries challengeName={challengeName} popUpMessageHandler={props.popUpMessageHandler} />;
case CHALLENGE_SECTIONS.SUBMIT: case CHALLENGE_SECTIONS.SUBMIT:
return <Submit challengeName={challengeName} setLoading={setLoading} />; return <Submit challengeName={challengeName} setLoading={setLoading} />;
default: default:

View File

@ -7,6 +7,7 @@ import HowToContent from './components/HowToContent';
const HowTo = (props) => { const HowTo = (props) => {
const [userFullInfo, setUserFullInfo] = React.useState(null); const [userFullInfo, setUserFullInfo] = React.useState(null);
const username = KeyCloakService.getUsername();
React.useEffect(() => { React.useEffect(() => {
getFullUser(setUserFullInfo); getFullUser(setUserFullInfo);
@ -31,7 +32,7 @@ const HowTo = (props) => {
<FlexColumn maxWidth="680px" alignmentX="flex-start" gap="48px"> <FlexColumn maxWidth="680px" alignmentX="flex-start" gap="48px">
<HowToContent <HowToContent
userFullInfo={userFullInfo} userFullInfo={userFullInfo}
user={props.user ? props.user : 'yourID'} user={username ? username : 'yourID'}
challengeName={props.challengeName} challengeName={props.challengeName}
/> />
</FlexColumn> </FlexColumn>

View File

@ -2,6 +2,7 @@ const colors = {
white: '#FCFCFC', white: '#FCFCFC',
green: '#1B998B', green: '#1B998B',
blue: '#4B8FF0', blue: '#4B8FF0',
red: '#FF1B1C',
green03: 'rgba(27, 153, 139, 0.3)', green03: 'rgba(27, 153, 139, 0.3)',
green05: 'rgba(27, 153, 139, 0.5)', green05: 'rgba(27, 153, 139, 0.5)',
green08: 'rgba(27, 153, 139, 0.8)', green08: 'rgba(27, 153, 139, 0.8)',