-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathUserFormBase.tsx
More file actions
135 lines (129 loc) · 4.2 KB
/
Copy pathUserFormBase.tsx
File metadata and controls
135 lines (129 loc) · 4.2 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import * as React from 'react';
import "./UserForm.css"
import { NameField } from './helpers/NameField';
import { EmailField } from './helpers/EmailField';
import { PasswordField } from './helpers/PasswordField';
import { RoleField } from './helpers/RoleField';
import { ProfilePictureField } from './helpers/ProfilePictureField';
import { Button } from '@rmwc/button';
interface IState {
first_name: string,
last_name: string,
email: string,
password: string,
profile_pic_url: string,
role: string[],
isCreate: boolean,
profile_picture_b64: string,
}
interface IProps {
initialState: IState
onPost: (state: IState) => any,
postLabel: string
}
export class UserFormBase extends React.Component<IProps, IState> {
constructor(props: IProps) {
super(props);
this.state = props.initialState;
}
public render() {
let password = this.state.isCreate &&
<div>
<PasswordField
value={this.state.password}
onChange={this.handlePasswordChange}
label="Temporary Password"
required={this.state.isCreate}
/>
<br/>
</div>;
return (
<form onSubmit={(e) => {
e.preventDefault();
this.props.onPost(this.state);
}} autoComplete="false">
<button disabled={true} className="UserFormDisableAutoSubmitButton" type="submit">Hidden button to disable implicit submit</button>
<div>
<NameField
value={this.state.first_name}
onChange={this.handleFirstNameChange}
label="First Name"
required={true}
/>
<br/>
<NameField
value={this.state.last_name}
onChange={this.handleLastNameChange}
label="Last Name"
required={true}
/>
<br/>
<EmailField
value={this.state.email}
onChange={this.handleEmailChange}
label="Email"
required={true}
/>
<br/>
{password}
<RoleField
role={this.state.role}
onInteraction={this.handleRoleChange}
label="Role"
required={true}
/>
<br/>
<img
style={{marginLeft: "20px", marginTop:"5px"}}
src={this.state.profile_picture_b64 ||
this.state.profile_pic_url}
height={200}
/>
<br/>
<ProfilePictureField
onPFPChange={this.handlePFPChange}
onPFPURLChange={this.handlePFPURLChange}
/>
</div>
<Button type='submit'>
{this.props.postLabel}
</Button>
</form>
)
}
private handleFirstNameChange = (first_name: string) => {
this.setState({
first_name
})
}
private handleLastNameChange = (last_name: string) => {
this.setState({
last_name
})
}
private handleEmailChange = (email: string) => {
this.setState({
email
})
}
private handlePasswordChange = (password: string) => {
this.setState({
password
})
}
private handleRoleChange = (role: string[]) => {
this.setState({
role
})
}
private handlePFPChange = (profile_picture_b64: string) => {
this.setState({
profile_picture_b64
})
}
private handlePFPURLChange = (profile_pic_url: string) => {
this.setState({
profile_pic_url
})
}
}