Persist new defaultRole to server
parent
e2ac7f8bf0
commit
9daee3d802
|
@ -102,7 +102,13 @@ export const loadUsersAsync = url => async dispatch => {
|
||||||
export const loadOrganizationsAsync = url => async dispatch => {
|
export const loadOrganizationsAsync = url => async dispatch => {
|
||||||
try {
|
try {
|
||||||
const {data} = await getOrganizationsAJAX(url)
|
const {data} = await getOrganizationsAJAX(url)
|
||||||
dispatch(loadOrganizations(data))
|
|
||||||
|
const orgs = data.organizations.map(o => {
|
||||||
|
o.defaultRole = o.defaultRole || 'member'
|
||||||
|
return o
|
||||||
|
})
|
||||||
|
|
||||||
|
dispatch(loadOrganizations({organizations: orgs}))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
dispatch(errorThrown(error))
|
dispatch(errorThrown(error))
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,12 @@ class OrganizationsTable extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {organizations, onDeleteOrg, onRenameOrg} = this.props
|
const {
|
||||||
|
organizations,
|
||||||
|
onDeleteOrg,
|
||||||
|
onRenameOrg,
|
||||||
|
onChooseDefaultRole,
|
||||||
|
} = this.props
|
||||||
const {isCreatingOrganization} = this.state
|
const {isCreatingOrganization} = this.state
|
||||||
|
|
||||||
const tableTitle = `${organizations.length} Organization${organizations.length ===
|
const tableTitle = `${organizations.length} Organization${organizations.length ===
|
||||||
|
@ -78,6 +83,7 @@ class OrganizationsTable extends Component {
|
||||||
organization={org}
|
organization={org}
|
||||||
onDelete={onDeleteOrg}
|
onDelete={onDeleteOrg}
|
||||||
onRename={onRenameOrg}
|
onRename={onRenameOrg}
|
||||||
|
onChooseDefaultRole={onChooseDefaultRole}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
@ -98,5 +104,6 @@ OrganizationsTable.propTypes = {
|
||||||
onCreateOrg: func.isRequired,
|
onCreateOrg: func.isRequired,
|
||||||
onDeleteOrg: func.isRequired,
|
onDeleteOrg: func.isRequired,
|
||||||
onRenameOrg: func.isRequired,
|
onRenameOrg: func.isRequired,
|
||||||
|
onChooseDefaultRole: func.isRequired,
|
||||||
}
|
}
|
||||||
export default OrganizationsTable
|
export default OrganizationsTable
|
||||||
|
|
|
@ -4,7 +4,6 @@ import ConfirmButtons from 'shared/components/ConfirmButtons'
|
||||||
import Dropdown from 'shared/components/Dropdown'
|
import Dropdown from 'shared/components/Dropdown'
|
||||||
|
|
||||||
import {USER_ROLES} from 'src/admin/constants/dummyUsers'
|
import {USER_ROLES} from 'src/admin/constants/dummyUsers'
|
||||||
import {MEMBER_ROLE} from 'src/auth/Authorized'
|
|
||||||
|
|
||||||
class OrganizationsTableRow extends Component {
|
class OrganizationsTableRow extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
@ -14,7 +13,6 @@ class OrganizationsTableRow extends Component {
|
||||||
isEditing: false,
|
isEditing: false,
|
||||||
isDeleting: false,
|
isDeleting: false,
|
||||||
workingName: this.props.organization.name,
|
workingName: this.props.organization.name,
|
||||||
defaultRole: MEMBER_ROLE,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,11 +78,12 @@ class OrganizationsTableRow extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChooseDefaultRole = role => {
|
handleChooseDefaultRole = role => {
|
||||||
this.setState({defaultRole: role.name})
|
const {organization, onChooseDefaultRole} = this.props
|
||||||
|
onChooseDefaultRole(organization, role.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {workingName, isEditing, isDeleting, defaultRole} = this.state
|
const {workingName, isEditing, isDeleting} = this.state
|
||||||
const {organization} = this.props
|
const {organization} = this.props
|
||||||
|
|
||||||
const dropdownRolesItems = USER_ROLES.map(role => ({
|
const dropdownRolesItems = USER_ROLES.map(role => ({
|
||||||
|
@ -122,7 +121,7 @@ class OrganizationsTableRow extends Component {
|
||||||
<Dropdown
|
<Dropdown
|
||||||
items={dropdownRolesItems}
|
items={dropdownRolesItems}
|
||||||
onChoose={this.handleChooseDefaultRole}
|
onChoose={this.handleChooseDefaultRole}
|
||||||
selected={defaultRole}
|
selected={organization.defaultRole}
|
||||||
className="dropdown-stretch"
|
className="dropdown-stretch"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -151,9 +150,11 @@ OrganizationsTableRow.propTypes = {
|
||||||
organization: shape({
|
organization: shape({
|
||||||
id: string, // when optimistically created, organization will not have an id
|
id: string, // when optimistically created, organization will not have an id
|
||||||
name: string.isRequired,
|
name: string.isRequired,
|
||||||
|
defaultRole: string.isRequired,
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
onDelete: func.isRequired,
|
onDelete: func.isRequired,
|
||||||
onRename: func.isRequired,
|
onRename: func.isRequired,
|
||||||
|
onChooseDefaultRole: func.isRequired,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default OrganizationsTableRow
|
export default OrganizationsTableRow
|
||||||
|
|
|
@ -29,6 +29,11 @@ class OrganizationsPage extends Component {
|
||||||
deleteOrganizationAsync(organization)
|
deleteOrganizationAsync(organization)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleChooseDefaultRole = (organization, defaultRole) => {
|
||||||
|
const {actions: {updateOrganizationAsync}} = this.props
|
||||||
|
updateOrganizationAsync(organization, {...organization, defaultRole})
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {organizations} = this.props
|
const {organizations} = this.props
|
||||||
|
|
||||||
|
@ -38,6 +43,7 @@ class OrganizationsPage extends Component {
|
||||||
onCreateOrg={this.handleCreateOrganization}
|
onCreateOrg={this.handleCreateOrganization}
|
||||||
onDeleteOrg={this.handleDeleteOrganization}
|
onDeleteOrg={this.handleDeleteOrganization}
|
||||||
onRenameOrg={this.handleRenameOrganization}
|
onRenameOrg={this.handleRenameOrganization}
|
||||||
|
onChooseDefaultRole={this.handleChooseDefaultRole}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue