domain-watchdog/assets/pages/LoginPage.tsx

55 lines
1.8 KiB
TypeScript
Raw Normal View History

import React, { useContext, useEffect, useState} from 'react'
2024-12-30 23:50:15 +01:00
import {Button, Card} from 'antd'
2024-07-28 15:36:22 +02:00
import {t} from 'ttag'
2024-12-30 23:50:15 +01:00
import TextPage from './TextPage'
import {LoginForm} from '../components/LoginForm'
import {RegisterForm} from '../components/RegisterForm'
2025-10-31 23:13:45 +01:00
import useBreakpoint from "../hooks/useBreakpoint"
import {ConfigurationContext} from "../contexts"
2024-07-23 18:37:59 +02:00
2024-08-02 16:17:55 +02:00
export default function LoginPage() {
2024-08-05 03:11:03 +02:00
const [wantRegister, setWantRegister] = useState<boolean>(false)
const { configuration } = useContext(ConfigurationContext)
2025-10-31 13:46:17 +01:00
const md = useBreakpoint('md')
2024-07-26 18:31:47 +02:00
2024-08-05 03:11:03 +02:00
const toggleWantRegister = () => {
setWantRegister(!wantRegister)
2024-07-26 18:31:47 +02:00
}
2024-08-02 16:17:55 +02:00
useEffect(() => {
if(!configuration?.registerEnabled && configuration?.ssoLogin && configuration?.ssoAutoRedirect) {
window.location.href = '/login/oauth'
}
}, [configuration])
2024-08-02 16:17:55 +02:00
2025-10-31 13:46:17 +01:00
const grid = [
2025-10-31 22:52:45 +01:00
<Card.Grid key="form" style={{width: md ? '100%' : '50%', textAlign: 'center'}} hoverable={false}>
2025-10-31 13:46:17 +01:00
{wantRegister ? <RegisterForm/> : <LoginForm ssoLogin={configuration?.ssoLogin}/>}
{
configuration?.registerEnabled &&
<Button
type='link'
block
style={{marginTop: '1em'}}
onClick={toggleWantRegister}
>{wantRegister ? t`Log in` : t`Create an account`}
</Button>
}
</Card.Grid>,
2025-10-31 22:52:45 +01:00
<Card.Grid key="ads" style={{width: md ? '100%' : '50%'}} hoverable={false}>
2025-10-31 13:46:17 +01:00
<TextPage resource='ads.md'/>
</Card.Grid>
2025-10-31 22:52:45 +01:00
]
2025-10-31 13:46:17 +01:00
if (md) {
2025-10-31 22:52:45 +01:00
grid.reverse()
2025-10-31 13:46:17 +01:00
}
2024-12-30 23:50:15 +01:00
return (
<Card title={wantRegister ? t`Register` : t`Log in`} style={{width: '100%'}}>
2025-10-31 13:46:17 +01:00
{grid}
2024-12-30 23:50:15 +01:00
</Card>
)
}