-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.tsx
70 lines (65 loc) · 1.91 KB
/
index.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
import React, { useState } from "react";
import { Input, Button } from "@nextui-org/react";
import useFetchWithMsal from "../../hooks/useFetchWithMsal.jsx";
import { loginRequest } from "../../authConfig.js";
const CreateUserForm = () => {
const BASE_URL = process.env.REACT_APP_BASE_URL;
const [netID, setNetID] = useState<string>("");
const [roles, setRoles] = useState<string>("");
const [permissions, setPermissions] = useState<string>("");
const { execute } = useFetchWithMsal(loginRequest);
const handleCreateUser = async () => {
try {
execute(
"PUT",
`${BASE_URL}/default/api/v1/create_user?netid=${netID}&permStr=${permissions}&roleStr=${roles}`,
null
).then((response) => {
console.log(response);
});
} catch (error) {
console.log(error);
}
};
const handleSubmit = (event) => {
if (netID !== "" && roles !== "") {
handleCreateUser();
event.preventDefault();
setNetID("");
setRoles("");
setPermissions("");
}
};
return (
<div>
<p>Create User</p>
<form onSubmit={handleSubmit}>
<div className="flex flex-col m-2">
<div className="mb-2">
<Input
placeholder="NetID"
value={netID}
onChange={(event) => setNetID(event.target.value)}
/>
</div>
<div className="mb-2">
<Input
placeholder="Roles"
value={roles}
onChange={(event) => setRoles(event.target.value)}
/>
</div>
<div className="mb-2">
<Input
placeholder="Permissions"
value={permissions}
onChange={(event) => setPermissions(event.target.value)}
/>
</div>
<Button type="submit">Submit</Button>
</div>
</form>
</div>
);
};
export default CreateUserForm;