1
1
import { useActor } from "@xstate/react"
2
- import { FullScreenLoader } from "components/Loader/FullScreenLoader"
3
- import { SignInLayout } from "components/SignInLayout/SignInLayout"
4
- import React , { useContext } from "react"
2
+ import { FC , useContext } from "react"
5
3
import { Helmet } from "react-helmet-async"
4
+ import { useTranslation } from "react-i18next"
6
5
import { Navigate , useLocation } from "react-router-dom"
7
- import { LoginErrors , SignInForm } from "../../components/SignInForm/SignInForm"
8
- import { pageTitle } from "../../util/page"
9
6
import { retrieveRedirect } from "../../util/redirect"
10
7
import { XServiceContext } from "../../xServices/StateContext"
8
+ import { LoginPageView } from "./LoginPageView"
11
9
12
- interface LocationState {
13
- isRedirect : boolean
14
- }
15
-
16
- export const LoginPage : React . FC = ( ) => {
10
+ export const LoginPage : FC = ( ) => {
17
11
const location = useLocation ( )
18
12
const xServices = useContext ( XServiceContext )
19
13
const [ authState , authSend ] = useActor ( xServices . authXService )
20
- const isLoading = authState . hasTag ( "loading" )
21
14
const redirectTo = retrieveRedirect ( location . search )
22
- const locationState = location . state
23
- ? ( location . state as LocationState )
24
- : null
25
- const isRedirected = locationState ? locationState . isRedirect : false
26
- const { authError, getUserError, checkPermissionsError, getMethodsError } =
27
- authState . context
28
-
29
- const onSubmit = async ( {
30
- email,
31
- password,
32
- } : {
33
- email : string
34
- password : string
35
- } ) => {
36
- authSend ( { type : "SIGN_IN" , email, password } )
37
- }
15
+ const commonTranslation = useTranslation ( "common" )
16
+ const loginPageTranslation = useTranslation ( "loginPage" )
38
17
39
18
if ( authState . matches ( "signedIn" ) ) {
40
19
return < Navigate to = { redirectTo } replace />
@@ -44,28 +23,17 @@ export const LoginPage: React.FC = () => {
44
23
return (
45
24
< >
46
25
< Helmet >
47
- < title > { pageTitle ( "Login" ) } </ title >
26
+ < title >
27
+ { loginPageTranslation . t ( "signInTo" ) } { commonTranslation . t ( "coder" ) }
28
+ </ title >
48
29
</ Helmet >
49
- { authState . hasTag ( "loading" ) ? (
50
- < FullScreenLoader />
51
- ) : (
52
- < SignInLayout >
53
- < SignInForm
54
- authMethods = { authState . context . methods }
55
- redirectTo = { redirectTo }
56
- isLoading = { isLoading }
57
- loginErrors = { {
58
- [ LoginErrors . AUTH_ERROR ] : authError ,
59
- [ LoginErrors . GET_USER_ERROR ] : isRedirected
60
- ? getUserError
61
- : null ,
62
- [ LoginErrors . CHECK_PERMISSIONS_ERROR ] : checkPermissionsError ,
63
- [ LoginErrors . GET_METHODS_ERROR ] : getMethodsError ,
64
- } }
65
- onSubmit = { onSubmit }
66
- />
67
- </ SignInLayout >
68
- ) }
30
+ < LoginPageView
31
+ context = { authState . context }
32
+ isLoading = { authState . hasTag ( "loading" ) }
33
+ onSignIn = { ( { email, password } ) => {
34
+ authSend ( { type : "SIGN_IN" , email, password } )
35
+ } }
36
+ />
69
37
</ >
70
38
)
71
39
}
0 commit comments