Skip to content

Commit

Permalink
Login window popup when submitting
Browse files Browse the repository at this point in the history
  • Loading branch information
Smilinko committed Dec 9, 2023
1 parent cc8e55e commit 20a5d24
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {Stack} from '@mui/material'
import {useRouter} from 'next/router'
import {FC, useState} from 'react'

Expand All @@ -16,7 +17,7 @@ export const LoginFormWrapper: FC<LoginFormWrapperProps> = ({closeOverlay}) => {

if (form === 'login')
return (
<>
<Stack alignItems={'center'} gap={1}>
<LoginForm closeOverlay={closeOverlay} />
<Button
onClick={() => {
Expand All @@ -25,7 +26,7 @@ export const LoginFormWrapper: FC<LoginFormWrapperProps> = ({closeOverlay}) => {
>
Zabudnuté heslo
</Button>
</>
</Stack>
)

return (
Expand Down
34 changes: 29 additions & 5 deletions src/components/Problems/Problem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import {Button} from '@/components/Clickable/Button'
import {Link} from '@/components/Clickable/Link'
import {Problem as ProblemType} from '@/types/api/competition'

import {Dialog} from '../Dialog/Dialog'
import {Latex} from '../Latex/Latex'
import {LoginFormWrapper} from '../PageLayout/LoginFormWrapper/LoginFormWrapper'
import styles from './Problem.module.scss'
import {UploadProblemForm} from './UploadProblemForm'

Expand Down Expand Up @@ -45,16 +47,28 @@ export const Problem: FC<{
}
})
}

const close = () => {
setDisplayLoginDialog(false)
}

const handleUploadClick = () => {
if (!registered && canRegister) {
displayRegisterDialog()
} else if (!registered && !canRegister) {
setDisplayLoginDialog(true)
} else {
setDisplayProblemUploadForm((prevState) => !prevState)
setDisplayActions(false)
}
}

const toggleDisplayLoginDialog = () => {
setDisplayLoginDialog((prevState) => !prevState)
}

const [displayProblemUploadForm, setDisplayProblemUploadForm] = useState<boolean>(false)
const [displayLoginDialog, setDisplayLoginDialog] = useState<boolean>(false)
const [displayActions, setDisplayActions] = useState(true)

return (
Expand Down Expand Up @@ -84,6 +98,18 @@ export const Problem: FC<{
setDisplayActions={setDisplayActions}
/>
)}
{displayLoginDialog && (
<Dialog
open={displayLoginDialog}
close={close}
contentText={
<Stack alignItems={'center'} gap={3}>
<Typography variant="body1">Pre odovzdanie sa prihlás.</Typography>
<LoginFormWrapper closeOverlay={toggleDisplayLoginDialog} />
</Stack>
}
/>
)}
{displayActions && (
<Stack direction="row" mt={0.5} justifyContent="end" gap={4}>
{problem.solution_pdf && (
Expand Down Expand Up @@ -114,11 +140,9 @@ export const Problem: FC<{
<Button onClick={handleDiscussionButtonClick} variant="button2">
diskusia ({problem.num_comments}){' '}
</Button>
{(registered || canRegister) && (
<Button onClick={handleUploadClick} disabled={!canSubmit} variant="button2">
odovzdať
</Button>
)}
<Button onClick={handleUploadClick} disabled={!canSubmit} variant="button2">
odovzdať
</Button>
</Stack>
)}
</div>
Expand Down

0 comments on commit 20a5d24

Please sign in to comment.