Save the username and password, show an alert to prove it.
This commit is contained in:
parent
9ff63d96fd
commit
c6400d58d3
|
@ -22,7 +22,9 @@ const App = () => {
|
||||||
//setUsers(data)
|
//setUsers(data)
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
const doLogin = (username: string, password: string) => {
|
||||||
|
alert("I be authin '" + username)
|
||||||
|
};
|
||||||
const loadAuth = () => {
|
const loadAuth = () => {
|
||||||
const auth = localStorage.getItem("auth");
|
const auth = localStorage.getItem("auth");
|
||||||
if (!auth) return;
|
if (!auth) return;
|
||||||
|
@ -40,7 +42,7 @@ const App = () => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
{state ? <p>{state.username}</p> : <AuthModal doLogin={() => alert("login")}></AuthModal>}
|
{state ? <p>{state.username}</p> : <AuthModal doLogin={doLogin}></AuthModal>}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,13 +2,16 @@ import Button from "react-bootstrap/Button"
|
||||||
import Form from "react-bootstrap/Form"
|
import Form from "react-bootstrap/Form"
|
||||||
import Modal from "react-bootstrap/Modal"
|
import Modal from "react-bootstrap/Modal"
|
||||||
|
|
||||||
import React from "react"
|
import React, {useState} from "react"
|
||||||
|
|
||||||
type AuthProps = {
|
type AuthProps = {
|
||||||
doLogin: () => void;
|
doLogin: (email: string, password: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const AuthModal: React.FC<AuthProps> = ({ doLogin }) => {
|
const AuthModal: React.FC<AuthProps> = ({ doLogin }) => {
|
||||||
|
const [email, setEmail] = useState("");
|
||||||
|
const [password, setPassword] = useState("");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="modal show"
|
className="modal show"
|
||||||
|
@ -23,7 +26,7 @@ const AuthModal: React.FC<AuthProps> = ({ doLogin }) => {
|
||||||
<Form>
|
<Form>
|
||||||
<Form.Group className="mb-3" controlId="formBasicEmail">
|
<Form.Group className="mb-3" controlId="formBasicEmail">
|
||||||
<Form.Label>Email address</Form.Label>
|
<Form.Label>Email address</Form.Label>
|
||||||
<Form.Control type="email" placeholder="Enter email" />
|
<Form.Control type="email" placeholder="Enter email" onChange={e => setEmail(e.target.value)}/>
|
||||||
<Form.Text className="text-muted">
|
<Form.Text className="text-muted">
|
||||||
We'll never share your email with anyone else.
|
We'll never share your email with anyone else.
|
||||||
</Form.Text>
|
</Form.Text>
|
||||||
|
@ -31,13 +34,13 @@ const AuthModal: React.FC<AuthProps> = ({ doLogin }) => {
|
||||||
|
|
||||||
<Form.Group className="mb-3" controlId="formBasicPassword">
|
<Form.Group className="mb-3" controlId="formBasicPassword">
|
||||||
<Form.Label>Password</Form.Label>
|
<Form.Label>Password</Form.Label>
|
||||||
<Form.Control type="password" placeholder="Password" />
|
<Form.Control type="password" placeholder="Password" onChange={e => setPassword(e.target.value)}/>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
</Form>
|
</Form>
|
||||||
</Modal.Body>
|
</Modal.Body>
|
||||||
|
|
||||||
<Modal.Footer>
|
<Modal.Footer>
|
||||||
<Button variant="primary" onClick={doLogin}>Login</Button>
|
<Button variant="primary" onClick={() => {doLogin(email, password)}}>Login</Button>
|
||||||
</Modal.Footer>
|
</Modal.Footer>
|
||||||
</Modal.Dialog>
|
</Modal.Dialog>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue