-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.tsx
86 lines (78 loc) · 2.27 KB
/
auth.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import * as React from "react";
import AppContext, { AppContextData } from "../../../react-context";
import { scenarioComponent, scenarioCallable } from "../../scenario-replays/decorators";
import { AuthPageMethods, AuthPageState } from "./types";
import * as logic from "./logic";
import { navigateTo } from "../../../router";
import { executeUITask } from "../../../utils/task-state";
import { login } from "../utils";
class AuthPage extends React.Component<{}, AuthPageState> implements AuthPageMethods {
static contextType = AppContext;
declare context: AppContextData;
state: AuthPageState = {
email: "",
password: "",
submitState: "pristine",
};
@scenarioCallable()
changeEmail(data: { value: string }) {
this.setState({ email: data.value });
}
@scenarioCallable()
changePassword(data: { value: string }) {
this.setState({ password: data.value });
}
@scenarioCallable()
async submit() {
if (!logic.isValid(this.state)) {
return;
}
await executeUITask(this, "submitState", async () => {
await login(this.context.backend, this.state.email, this.state.password);
});
navigateTo(this.context.history, "/todo");
}
render() {
if (this.state.submitState === "running") {
return "Logging in...";
}
if (this.state.submitState === "error") {
return "Error logging in...";
}
return (
<div>
Log in with any e-mail address and password. The dummy backend will accept any e-mail/password combination.
<div>
<label>
Email:
<br />
<input
type="email"
value={this.state.email}
onChange={(event) =>
this.changeEmail({
value: event.target.value,
})
}
/>
</label>
</div>
<div>
Password:
<br />
<input
type="password"
value={this.state.password}
onChange={(event) =>
this.changePassword({
value: event.target.value,
})
}
/>
</div>
<button onClick={() => this.submit()}>Login</button>
</div>
);
}
}
export default scenarioComponent()(AuthPage);