forked from sqlpad/sqlpad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInviteUserForm.js
More file actions
89 lines (83 loc) · 2.32 KB
/
Copy pathInviteUserForm.js
File metadata and controls
89 lines (83 loc) · 2.32 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
import React, { useState } from 'react';
import { Link } from 'react-router-dom';
import Button from '../common/Button';
import FormExplain from '../common/FormExplain.js';
import Input from '../common/Input';
import message from '../common/message';
import Select from '../common/Select';
import Spacer from '../common/Spacer.js';
import fetchJson from '../utilities/fetch-json.js';
function InviteUserForm({ onInvited }) {
const [email, setEmail] = useState(null);
const [role, setRole] = useState(null);
const [isInviting, setIsInviting] = useState(null);
const onInviteClick = async event => {
event.preventDefault();
event.stopPropagation();
const user = {
email,
role
};
setIsInviting(true);
const json = await fetchJson('POST', '/api/users', user);
setIsInviting(false);
if (json.error) {
message.error('Add user failed: ' + json.error.toString());
return false;
}
setEmail(null);
setRole(null);
onInvited();
};
return (
<div>
<p>
Users may only sign up if they have first been added. Once added, invite
them to continue the sign-up process on the{' '}
<Link to={'/signup'}>signup page</Link>.
</p>
<form onSubmit={onInviteClick}>
<label>
Email
<Input
name="email"
type="email"
value={email || ''}
error={!email}
onChange={e => setEmail(e.target.value)}
/>
</label>
<Spacer size={2} />
<label>
role
<Select
name="role"
value={role || ''}
onChange={event => setRole(event.target.value)}
error={!role}
>
<option value="" />
<option value="editor">Editor</option>
<option value="admin">Admin</option>
</Select>
<FormExplain>
Admins can manage database connections and users
</FormExplain>
</label>
<Spacer size={3} />
<div>
<Button
htmlType="submit"
className="w-100"
type="primary"
onClick={onInviteClick}
disabled={isInviting}
>
Add user
</Button>
</div>
</form>
</div>
);
}
export default InviteUserForm;