Skip to content

Commit

Permalink
Add login error box for login page.
Browse files Browse the repository at this point in the history
  • Loading branch information
yildirayunlu committed Jan 25, 2021
1 parent 7365108 commit 485710b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/containers/auth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export const Auth: React.FC<IAuthProps> = ({
logout,
}) => {
const [auth, setAuth] = React.useState(false);
const [loginError, setLoginError] = React.useState(false);

const dispatch = useDispatch();

// check auth
Expand All @@ -33,10 +35,13 @@ export const Auth: React.FC<IAuthProps> = ({
const onSubmit = async (values: ILoginForm) => {
login &&
login(values)
.then(() => setAuth(true))
.catch(() => console.log("login error"));
.then(() => {
setAuth(true);
setLoginError(false);
})
.catch(() => setLoginError(true));
};
return <LoginPage onSubmit={onSubmit} />;
return <LoginPage onSubmit={onSubmit} isLoginError={loginError} />;
}

// set user identity
Expand Down
27 changes: 25 additions & 2 deletions src/pages/login/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
import React from "react";
import { Row, Col, Layout, Card, Typography, Form, Input, Button } from "antd";
import {
Row,
Col,
Layout,
Card,
Typography,
Form,
Input,
Button,
Alert,
} from "antd";
export interface ILoginForm {
username: string;
password: string;
}

export interface ILoginPageProps {
onSubmit?: ((values: ILoginForm) => void) | undefined;
isLoginError?: boolean;
}

export const LoginPage: React.FC<ILoginPageProps> = ({ onSubmit }) => {
export const LoginPage: React.FC<ILoginPageProps> = ({
isLoginError,
onSubmit,
}) => {
const { Title } = Typography;

const [form] = Form.useForm();
Expand All @@ -25,6 +39,15 @@ export const LoginPage: React.FC<ILoginPageProps> = ({ onSubmit }) => {
}}
>
<Col xl={6} lg={8} md={12} sm={18} xs={22}>
{isLoginError && (
<Alert
type="error"
message="Login Error"
description="Invalid username or password"
style={{ marginBottom: 20 }}
/>
)}

<Card>
<Title level={2} style={{ textAlign: "center" }}>
Login
Expand Down

0 comments on commit 485710b

Please sign in to comment.