Last active
December 27, 2017 17:28
-
-
Save srph/6d8a0c2aa4625f00c2405002f9ae99f4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import React, {Component} from 'react' | |
| export default class AssignedMembersWidget extends Component { | |
| state = { | |
| selection: [], | |
| fetching: false, | |
| error: '', | |
| loading: false | |
| } | |
| componentDidMount() { | |
| // Fetch selection... | |
| // Reacted for example purposes. | |
| } | |
| render() { | |
| return ( | |
| // Redacted for example purposes only. Assume we have: | |
| // - A loader here | |
| // {this.props.fetching && <Loader />} | |
| // - An error alert | |
| // {this.props.error && <Alert>{this.props.error}</Alert} | |
| // - A button to open or close popover | |
| // {<button onClick={this.onTogglePopover}>Open Popover</button>} | |
| // - A popover to choose users from (to assign them) | |
| // <Popover onClickMember={this.onAssignMember} /> | |
| // A list of existing users (and as well the way to unassign them) | |
| // {this.props.user.map(user => <User user={user} onClickMember={this.onUnassignMember} />)} | |
| ) | |
| } | |
| // | |
| // Other handlers... | |
| // | |
| onAssignMember = (user) => { | |
| if (this.props.async) { | |
| this.setState({ | |
| error: '', | |
| loading: true | |
| }) | |
| fetch('/api/issues/:id/assign', { method: 'POST', id: user.id }) | |
| .then(res => { | |
| const users = [...this.state.users, user] | |
| this.setState({ loading: false }) | |
| this.props.onAssignMember(users, user) | |
| }, err => { | |
| this.setState({ | |
| loading: false, | |
| error: err | |
| }) | |
| }) | |
| return | |
| } | |
| const users = [...this.props.users, user] | |
| this.props.onAssignMember(users, user) | |
| } | |
| onUnassignMember = (user) => { | |
| // Redacted for example purposes. | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment