11import { 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"
53import { Helmet } from "react-helmet-async"
4+ import { useTranslation } from "react-i18next"
65import { Navigate , useLocation } from "react-router-dom"
7- import { LoginErrors , SignInForm } from "../../components/SignInForm/SignInForm"
8- import { pageTitle } from "../../util/page"
96import { retrieveRedirect } from "../../util/redirect"
107import { XServiceContext } from "../../xServices/StateContext"
8+ import { LoginPageView } from "./LoginPageView"
119
12- interface LocationState {
13- isRedirect : boolean
14- }
15-
16- export const LoginPage : React . FC = ( ) => {
10+ export const LoginPage : FC = ( ) => {
1711 const location = useLocation ( )
1812 const xServices = useContext ( XServiceContext )
1913 const [ authState , authSend ] = useActor ( xServices . authXService )
20- const isLoading = authState . hasTag ( "loading" )
2114 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" )
3817
3918 if ( authState . matches ( "signedIn" ) ) {
4019 return < Navigate to = { redirectTo } replace />
@@ -44,28 +23,17 @@ export const LoginPage: React.FC = () => {
4423 return (
4524 < >
4625 < Helmet >
47- < title > { pageTitle ( "Login" ) } </ title >
26+ < title >
27+ { loginPageTranslation . t ( "signInTo" ) } { commonTranslation . t ( "coder" ) }
28+ </ title >
4829 </ 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+ />
6937 </ >
7038 )
7139 }
0 commit comments