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

Tasks from Dorot #482

Merged
merged 12 commits into from
Nov 24, 2024
6 changes: 3 additions & 3 deletions src/components/Alert/AlertBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export const AlertBox: FC = () => {
contentText={container.alertBox?.message}
close={closeContainer}
>
<Stack direction={'row'} mt={3} justifyContent="center">
<Button variant="button1" onClick={closeContainer}>
Dobre
<Stack direction={'row'} mt={3} justifyContent="end">
<Button variant="button2" onClick={closeContainer}>
Potvrdiť
</Button>
</Stack>
</Dialog>
Expand Down
51 changes: 31 additions & 20 deletions src/components/CompetitionPage/CompetitionPage.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {Stack, Typography} from '@mui/material'
import Grid from '@mui/material/Unstable_Grid2'
import {useQuery} from '@tanstack/react-query'
import axios from 'axios'
import {useRouter} from 'next/router'
import {FC, useEffect} from 'react'
import {FC, Fragment, useEffect} from 'react'

import {Link} from '@/components/Clickable/Link'
import {Competition, Event} from '@/types/api/competition'
import {Competition, Event, PublicationTypes} from '@/types/api/competition'
import {BannerContainer} from '@/utils/BannerContainer'

import {UpcomingOrCurrentEventInfo} from './UpcomingOrCurrentEventInfo'
Expand Down Expand Up @@ -78,26 +79,36 @@ export const CompetitionPage: FC<CompetitionPageProps> = ({
</Typography>
)}
</Stack>
<Stack>
<Typography variant="h2">Archív</Typography>

<Stack gap={1}>
{history_events.map((event) => (
<Stack key={event.id} direction="row" sx={{justifyContent: 'space-between'}}>
<Typography variant="h3" component="span">
{name} {event.school_year}
</Typography>
<Stack direction="row" sx={{gap: {xs: 1, sm: 2}}}>
{event.publication_set.map((publication) => (
<Link variant="button2" key={publication.id} href={`/api${publication.file}`}>
{publication.name}
<Grid container spacing={2}>
{history_events.map((event) => {
const results = event.publication_set.find((p) => p.publication_type === PublicationTypes.RESULTS.id)
const problems = event.publication_set.find((p) => p.publication_type === PublicationTypes.PROBLEMS.id)
return (
<Fragment key={event.id}>
<Grid xs={8}>
<Typography variant="h2" component="span">
{name} {event.school_year}
</Typography>
</Grid>
<Grid xs={2} display="flex" justifyContent="end">
{results && (
<Link variant="button2" key={results.id} href={`/api${results.file}`}>
{results.name}
</Link>
))}
</Stack>
</Stack>
))}
</Stack>
</Stack>
)}
</Grid>
<Grid xs={2} display="flex" justifyContent="end">
{problems && (
<Link variant="button2" key={problems.id} href={`/api${problems.file}`}>
{problems.name}
</Link>
)}
</Grid>
</Fragment>
)
})}
</Grid>
</Stack>
)
}
2 changes: 2 additions & 0 deletions src/components/FormItems/FormInput/FormInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const FormInput = <
label,
type,
rules,
...props
}: TextFieldProps &
Pick<ControllerProps<TFieldValues, TName>, 'name' | 'control' | 'rules'> & {
label: string
Expand All @@ -31,6 +32,7 @@ export const FormInput = <
helperText={error?.message}
focused={false}
sx={formItemStyle}
{...props}
/>
)}
/>
Expand Down
7 changes: 6 additions & 1 deletion src/components/PageLayout/Banner/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export const Banner: FC = () => {

const bannerTextFormatted =
bannerMessages.length > 0 ? Array(10).fill(bannerMessages).flat().join(divider) + divider : undefined

if (!bannerTextFormatted) {
return null
}

return (
<Box
sx={{
Expand All @@ -21,7 +26,7 @@ export const Banner: FC = () => {
>
<Marquee gradient={false} speed={100}>
<Typography variant="h2" component="span" sx={{whiteSpace: 'nowrap'}}>
{bannerTextFormatted || '\u00A0'}
{bannerTextFormatted}
</Typography>
</Marquee>
</Box>
Expand Down
52 changes: 36 additions & 16 deletions src/components/PageLayout/LoginForm/LoginForm.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {Stack} from '@mui/material'
import {Visibility, VisibilityOff} from '@mui/icons-material'
import {Box, IconButton, Stack} from '@mui/material'
import {useRouter} from 'next/router'
import {FC, useState} from 'react'
import {SubmitHandler, useForm} from 'react-hook-form'

import {Button} from '@/components/Clickable/Button'
import {Link} from '@/components/Clickable/Link'
import {Dialog} from '@/components/Dialog/Dialog'
import {FormInput} from '@/components/FormItems/FormInput/FormInput'
import {AuthContainer} from '@/utils/AuthContainer'
Expand Down Expand Up @@ -53,6 +53,8 @@ export const LoginForm: FC<LoginFormProps> = ({closeDialog}) => {
setDisplayForgottenDialog((prev) => !prev)
}

const [showPassword, setShowPassword] = useState(false)

return (
<>
<Dialog open={displayForgottenDialog} close={toggleForgottenDialog} title="Zabudnuté heslo">
Expand All @@ -79,22 +81,40 @@ export const LoginForm: FC<LoginFormProps> = ({closeDialog}) => {
},
}}
/>
<FormInput control={control} name="password" label="Heslo" type="password" rules={requiredRule} />
</Stack>
<Stack direction={'row'} mt={3} gap={2} justifyContent="space-between">
<Stack gap={2} alignItems="start">
<FormInput
control={control}
name="password"
label="Heslo"
type={showPassword ? 'text' : 'password'}
rules={requiredRule}
InputProps={{
endAdornment: (
<IconButton onClick={() => setShowPassword(!showPassword)}>
{showPassword ? <VisibilityOff /> : <Visibility />}
</IconButton>
),
}}
/>
<Box alignSelf="end">
<Button variant="button3" type="button" onClick={toggleForgottenDialog}>
Zabudol som heslo
</Button>
<Link variant="button3" href={`/${seminar}/registracia`}>
Chcem sa registrovať
</Link>
</Stack>
<Stack direction={'column'} gap={2} alignItems="end" justifyContent="end">
<Button variant="button2" type="submit">
Prihlásiť sa
Zabudnuté heslo
</Button>
</Stack>
</Box>
</Stack>
<Stack direction={'row'} mt={3} gap={2} justifyContent="space-between">
<Button
variant="button2"
type="button"
onClick={() => {
closeDialog() // We want to force th dialog to close also on the registration page
router.push(`/${seminar}/registracia`)
}}
>
Registrovať
</Button>
<Button variant="button2" type="submit">
Prihlásiť
</Button>
</Stack>
</Stack>
</form>
Expand Down
14 changes: 5 additions & 9 deletions src/components/PageLayout/MenuMain/BottomButtons.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Box, Stack} from '@mui/material'

Check warning on line 1 in src/components/PageLayout/MenuMain/BottomButtons.tsx

View workflow job for this annotation

GitHub Actions / branch-test

'Box' is defined but never used
import {useRouter} from 'next/router'
import {FC, useState} from 'react'

Expand Down Expand Up @@ -29,27 +29,23 @@
}
}

const separator = <Box sx={{borderLeft: '2px solid white'}} />

return (
<Stack direction="row" sx={{mt: '1rem', justifyContent: 'center', gap: '10px'}}>
<Stack direction="row" flexWrap="wrap-reverse" sx={{mt: '1rem', justifyContent: 'center', gap: '10px'}}>
{!isAuthed ? (
<>
<Link invertColors variant="button2" href={`/${seminar}/registracia`}>
<Link invertColors variant="button1" href={`/${seminar}/registracia`}>
Registrovať
</Link>
{separator}
<Button invertColors variant="button2" onClick={toggleDisplayAuthenticationDialog}>
<Button invertColors variant="button1" onClick={toggleDisplayAuthenticationDialog}>
Prihlásiť
</Button>
</>
) : (
<>
<Link invertColors variant="button2" href={`/${seminar}/profil`}>
<Link invertColors variant="button1" href={`/${seminar}/profil`}>
Profil
</Link>
{separator}
<Button invertColors variant="button2" onClick={redirectLogout}>
<Button invertColors variant="button1" onClick={redirectLogout}>
Odhlásiť
</Button>
</>
Expand Down
4 changes: 0 additions & 4 deletions src/components/PageLayout/MenuMain/MenuMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,6 @@ const MenuMainItem: FC<{caption: string; url: string}> = ({caption, url}) => {
py: '4px',
px: '8px',
}}
textSx={{
fontStyle: 'normal',
textAlign: 'center',
}}
>
{caption}
</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const PasswordResetRequestForm: FC<PasswordResetRequestFormmProps> = ({cl
},
}}
/>
<Stack alignItems="center">
<Stack alignItems="end">
<Button variant="button2" type="submit">
Resetovať heslo
</Button>
Expand Down
36 changes: 31 additions & 5 deletions src/components/Profile/PasswordChangeForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {Stack} from '@mui/material'
import {Visibility, VisibilityOff} from '@mui/icons-material'
import {IconButton, Stack} from '@mui/material'
import {useMutation} from '@tanstack/react-query'
import axios, {AxiosError} from 'axios'
import {FC} from 'react'
import {FC, useState} from 'react'
import {SubmitHandler, useForm} from 'react-hook-form'

import {IGeneralPostResponse} from '@/types/api/general'
Expand Down Expand Up @@ -69,6 +70,10 @@ export const PasswordChangeDialog: FC<PasswordChangeDialogProps> = ({open, close

const requiredRule = {required: '* Toto pole nemôže byť prázdne.'}

const [showPassword1, setShowPassword1] = useState(false)
const [showPassword2, setShowPassword2] = useState(false)
const [showPassword3, setShowPassword3] = useState(false)

return (
<Dialog
open={open}
Expand All @@ -91,33 +96,54 @@ export const PasswordChangeDialog: FC<PasswordChangeDialogProps> = ({open, close
control={control}
name="old_password"
label="aktuálne heslo"
type="password"
type={showPassword1 ? 'text' : 'password'}
rules={requiredRule}
InputProps={{
endAdornment: (
<IconButton onClick={() => setShowPassword1(!showPassword1)}>
{showPassword1 ? <VisibilityOff /> : <Visibility />}
</IconButton>
),
}}
/>
<FormInput
control={control}
name="new_password1"
label="nové heslo"
type="password"
type={showPassword2 ? 'text' : 'password'}
rules={{
...requiredRule,
minLength: {
value: 8,
message: '* Toto heslo je príliš krátke. Musí obsahovať aspoň 8 znakov.',
},
}}
InputProps={{
endAdornment: (
<IconButton onClick={() => setShowPassword2(!showPassword2)}>
{showPassword2 ? <VisibilityOff /> : <Visibility />}
</IconButton>
),
}}
/>
<FormInput
control={control}
name="new_password2"
label="nové heslo znovu"
type="password"
type={showPassword3 ? 'text' : 'password'}
rules={{
...requiredRule,
validate: (val) => {
if (val !== getValues().new_password1) return '* Zadané heslá sa nezhodujú.'
},
}}
InputProps={{
endAdornment: (
<IconButton onClick={() => setShowPassword3(!showPassword3)}>
{showPassword3 ? <VisibilityOff /> : <Visibility />}
</IconButton>
),
}}
/>
</Stack>
</form>
Expand Down
28 changes: 23 additions & 5 deletions src/components/RegisterForm/RegisterForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Stack, Typography} from '@mui/material'
import {Visibility, VisibilityOff} from '@mui/icons-material'
import {IconButton, Stack, Typography} from '@mui/material'
import {useMutation} from '@tanstack/react-query'
import axios, {AxiosError} from 'axios'
import {useRouter} from 'next/router'
Expand Down Expand Up @@ -119,6 +120,9 @@ export const RegisterForm: FC = () => {
},
})

const [showPassword1, setShowPassword1] = useState(false)
const [showPassword2, setShowPassword2] = useState(false)

return (
<>
<Dialog
Expand Down Expand Up @@ -160,32 +164,46 @@ export const RegisterForm: FC = () => {
control={control}
name="password1"
label="heslo*"
type="password"
type={showPassword1 ? 'text' : 'password'}
rules={{
...requiredRule,
minLength: {
value: 8,
message: '* Toto heslo je príliš krátke. Musí obsahovať aspoň 8 znakov.',
},
}}
InputProps={{
endAdornment: (
<IconButton onClick={() => setShowPassword1(!showPassword1)}>
{showPassword1 ? <VisibilityOff /> : <Visibility />}
</IconButton>
),
}}
/>
<FormInput
control={control}
name="password2"
label="potvrdenie hesla*"
type="password"
type={showPassword2 ? 'text' : 'password'}
rules={{
...requiredRule,
validate: (val) => {
if (val !== getValues().password1) return '* Zadané heslá sa nezhodujú.'
},
}}
InputProps={{
endAdornment: (
<IconButton onClick={() => setShowPassword2(!showPassword2)}>
{showPassword2 ? <VisibilityOff /> : <Visibility />}
</IconButton>
),
}}
/>
<FormInput control={control} name="first_name" label="krstné meno*" rules={requiredRule} />
<FormInput control={control} name="last_name" label="priezvisko*" rules={requiredRule} />
<SchoolSubForm control={control} watch={watch} setValue={setValue} gap={2} />
<FormInput control={control} name="phone" label="telefónne číslo" rules={phoneRule} />
<FormInput control={control} name="parent_phone" label="telefónne číslo na rodiča" rules={phoneRule} />
<FormInput control={control} name="phone" label="telefón v tvare +421 ..." rules={phoneRule} />
<FormInput control={control} name="parent_phone" label="telefón na rodiča" rules={phoneRule} />
<Typography variant="body2" fontWeight={800}>
* takto označené polia sú povinné
</Typography>
Expand Down
Loading
Loading