Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #145 from alan-turing-institute/create-group-extra
Create group button in permission manager
- Loading branch information
Showing
5 changed files
with
92 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Box, Button, Form, FormField, TextInput } from "grommet"; | ||
import React from "react"; | ||
import { useNavigate, useParams } from "react-router-dom"; | ||
import { getBaseURL } from "./utils.js"; | ||
|
||
class CreateGroup extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
newGroupName: "", | ||
}; | ||
} | ||
|
||
async submitCreateGroup() { | ||
const requestOptions = { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Token ${localStorage.getItem("token")}`, | ||
}, | ||
body: JSON.stringify({ name: this.state.newGroupName }), | ||
}; | ||
|
||
await fetch(`${getBaseURL()}/groups/`, requestOptions); | ||
this.setState({ newGroupName: "" }); | ||
this.props.afterSubmit(); | ||
} | ||
|
||
render() { | ||
return ( | ||
<Form onSubmit={this.submitCreateGroup.bind(this)}> | ||
<Box gap="small" direction="row"> | ||
<FormField margin={{ left: "small" }}> | ||
<TextInput | ||
plain={true} | ||
value={this.state.newGroupName} | ||
name="new-group-name" | ||
onChange={(e) => this.setState({ newGroupName: e.target.value })} | ||
/> | ||
</FormField> | ||
<Button type="submit" label="Create group" /> | ||
</Box> | ||
</Form> | ||
); | ||
} | ||
} | ||
|
||
export default (props) => ( | ||
<CreateGroup {...props} params={useParams()} navigate={useNavigate()} /> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters