Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login popup when submitting done properly #292

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 8 additions & 5 deletions src/components/Problems/Problem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const Problem: FC<{
isAfterDeadline: boolean
invalidateSeriesQuery: () => Promise<void>
displayRegisterDialog: () => void
displayLoginDialog: () => void
}> = ({
problem,
registered,
Expand All @@ -35,6 +36,7 @@ export const Problem: FC<{
isAfterDeadline,
invalidateSeriesQuery,
displayRegisterDialog,
displayLoginDialog,
}) => {
const handleDiscussionButtonClick = () => {
setDisplaySideContent((prevState) => {
Expand All @@ -45,9 +47,12 @@ export const Problem: FC<{
}
})
}

const handleUploadClick = () => {
if (!registered && canRegister) {
displayRegisterDialog()
} else if (!registered && !canRegister) {
displayLoginDialog()
} else {
setDisplayProblemUploadForm((prevState) => !prevState)
setDisplayActions(false)
Expand Down Expand Up @@ -114,11 +119,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
15 changes: 15 additions & 0 deletions src/components/Problems/Problems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {useHasPermissions} from '@/utils/useHasPermissions'

import {Dialog} from '../Dialog/Dialog'
import {Loading} from '../Loading/Loading'
import {LoginFormWrapper} from '../PageLayout/LoginFormWrapper/LoginFormWrapper'
import {Discussion} from './Discussion'
import {Problem} from './Problem'
import styles from './Problems.module.scss'
Expand Down Expand Up @@ -117,6 +118,9 @@ export const Problems: FC = () => {
closeRegisterDialog()
}

const [displayLoginDialog, setDisplayLoginDialog] = useState<boolean>(false)
const closeLoginDialog = () => setDisplayLoginDialog(false)

return (
<>
<Dialog
Expand Down Expand Up @@ -154,6 +158,16 @@ export const Problems: FC = () => {
</Stack>
}
/>
<Dialog
open={displayLoginDialog}
close={closeLoginDialog}
contentText={
<Stack alignItems={'center'} gap={3}>
<Typography variant="body1">Pre odovzdanie sa prihlás.</Typography>
<LoginFormWrapper closeOverlay={closeLoginDialog} />
</Stack>
}
/>
<Stack gap={5}>
{(loading.semesterListIsLoading ||
loading.currentSeriesIsLoading ||
Expand All @@ -177,6 +191,7 @@ export const Problems: FC = () => {
isAfterDeadline={isAfterDeadline}
invalidateSeriesQuery={invalidateSeriesQuery}
displayRegisterDialog={() => setDisplayRegisterDialog(true)}
displayLoginDialog={() => setDisplayLoginDialog(true)}
/>
))}

Expand Down
Loading