UNPKG

@fakel/rest-admin

Version:

An application that makes it easier to work with your API

32 lines (31 loc) 1.61 kB
import React from 'react'; import Space from 'antd/lib/space'; import Card from 'antd/lib/card'; import { Redirect, useHistory } from 'react-router-dom'; import { PasswordInput, SimpleForm, TextInput } from '../../components'; import LoginButtton from '../../components/Buttons/LoginButton'; import { useLogin } from '../../hooks/useLogin'; import { useLocaleStore } from '../../hooks/useLocaleStore'; export var LoginPage = function (props) { var _a = useLogin(), login = _a.login, isAuthorized = _a.isAuthorized, loading = _a.loading; var i18Store = useLocaleStore(); var history = useHistory(); var handleSubmit = function (values) { login(values).then(function () { if (isAuthorized) { history.push('/'); } }); }; return !isAuthorized ? (React.createElement(Space, { style: { width: '100vw', height: '100vh', display: 'flex', justifyContent: 'center', alignItems: 'center', } }, React.createElement(Card, { title: i18Store.i18nProvider.translate('auth.sign_in'), style: { width: '100%' } }, React.createElement(SimpleForm, { handleSubmit: handleSubmit, initialValue: { username: '', password: '' }, actions: React.createElement(LoginButtton, { message: "auth.sign_in", loading: loading }) }, React.createElement(TextInput, { name: "username", placeholder: "Username" }), React.createElement(PasswordInput, { name: "password", placeholder: "Password" }))))) : (React.createElement(Redirect, { to: "/" })); };