Skip to content

Commit

Permalink
added redirections after logging in or out
Browse files Browse the repository at this point in the history
  • Loading branch information
Smilinko committed Dec 8, 2023
1 parent 7224c59 commit 87a872d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/components/PageLayout/Authentication/Authentication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {useSeminarInfo} from '@/utils/useSeminarInfo'
import {Overlay} from '../../Overlay/Overlay'
import {LoginForm} from '../LoginForm/LoginForm'
import styles from './Authentication.module.scss'
import { useRouter } from 'next/router'

Check failure on line 10 in src/components/PageLayout/Authentication/Authentication.tsx

View workflow job for this annotation

GitHub Actions / branch-test

Replace `·useRouter·` with `useRouter`

export const Authentication: FC = () => {
const [displayAuthenticationOverlay, setDisplayAuthenticationOverlay] = useState(false)
Expand All @@ -18,6 +19,15 @@ export const Authentication: FC = () => {

const {seminar} = useSeminarInfo()

const router = useRouter()

Check failure on line 22 in src/components/PageLayout/Authentication/Authentication.tsx

View workflow job for this annotation

GitHub Actions / branch-test

Delete `·`

const redirectLogout = () => {
logout()
if (router.asPath.endsWith("profil") || router.asPath.endsWith("profil/uprava")) {

Check failure on line 26 in src/components/PageLayout/Authentication/Authentication.tsx

View workflow job for this annotation

GitHub Actions / branch-test

Replace `"profil")·||·router.asPath.endsWith("profil/uprava"` with `'profil')·||·router.asPath.endsWith('profil/uprava'`
router.push("/")

Check failure on line 27 in src/components/PageLayout/Authentication/Authentication.tsx

View workflow job for this annotation

GitHub Actions / branch-test

Replace `"/"` with `'/'`
}
}

if (!isAuthed) {
return (
<>
Expand All @@ -38,7 +48,7 @@ export const Authentication: FC = () => {
return (
<div className={styles.authenticationDisplayButtons}>
<Link href={`/${seminar}/profil`}>Profil</Link>
<span onClick={() => logout()}>Odhlásiť</span>
<span onClick={redirectLogout}>Odhlásiť</span>
</div>
)
}
Expand Down
12 changes: 11 additions & 1 deletion src/components/PageLayout/LoginForm/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {Button} from '@/components/Clickable/Clickable'
import styles from '@/components/FormItems/Form.module.scss'
import {FormInput} from '@/components/FormItems/FormInput/FormInput'
import {AuthContainer} from '@/utils/AuthContainer'
import { useRouter } from 'next/router'

Check failure on line 8 in src/components/PageLayout/LoginForm/LoginForm.tsx

View workflow job for this annotation

GitHub Actions / branch-test

Replace `·useRouter·` with `useRouter`

type LoginFormValues = {
email: string
Expand All @@ -24,8 +25,17 @@ export const LoginForm: FC<ILoginForm> = ({closeOverlay}) => {
const {login} = AuthContainer.useContainer()
const {handleSubmit, control} = useForm<LoginFormValues>({defaultValues})

const router = useRouter()

Check failure on line 28 in src/components/PageLayout/LoginForm/LoginForm.tsx

View workflow job for this annotation

GitHub Actions / branch-test

Delete `·`

const redirectClose = () => {
closeOverlay()
if (router.asPath.endsWith("registracia")) {

Check failure on line 32 in src/components/PageLayout/LoginForm/LoginForm.tsx

View workflow job for this annotation

GitHub Actions / branch-test

Replace `"registracia"` with `'registracia'`
router.push("/")

Check failure on line 33 in src/components/PageLayout/LoginForm/LoginForm.tsx

View workflow job for this annotation

GitHub Actions / branch-test

Replace `"/"` with `'/'`
}
}

const onSubmit: SubmitHandler<LoginFormValues> = (data) => {
login({data, onSuccess: closeOverlay})
login({data, onSuccess: redirectClose})
}

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

0 comments on commit 87a872d

Please sign in to comment.