Skip to content
Snippets Groups Projects
Commit 8919b18b authored by john's avatar john
Browse files

attempt to automate team creation

parent 42ace9e9
No related branches found
No related tags found
No related merge requests found
import { each, filter, isEmpty } from 'lodash'
import Actions from 'pubsweet-client/src/actions'
import React from 'react'
import { bindActionCreators } from 'redux'
......@@ -6,14 +7,16 @@ import { connect } from 'react-redux'
import AddBook from './AddBook'
import BookList from './BookList'
import DashboardHeader from './DashboardHeader'
import { teamTypes } from '../utils/config'
import styles from './dashboard.local.scss'
export class Dashboard extends React.Component {
constructor (props) {
super(props)
this.createCollection = this.createCollection.bind(this)
this.removeCollection = this.removeCollection.bind(this)
this.createBook = this.createBook.bind(this)
this.makeTeamsForBook = this.makeTeamsForBook.bind(this)
this.removeBook = this.removeBook.bind(this)
this.toggleModal = this.toggleModal.bind(this)
this.state = {
......@@ -21,13 +24,35 @@ export class Dashboard extends React.Component {
}
}
componentWillMount () {
const { getTeams } = this.props.actions
getTeams()
}
/*
If a book has no teams, it is a new one.
Make the default teams for it automatically.
*/
componentDidUpdate () {
// console.log('did')
const { books, teams } = this.props
each(books, book => {
const teamsForBook = filter(teams, t => {
return t.object.id === book.id
})
if (isEmpty(teamsForBook)) this.makeTeamsForBook(book)
})
}
toggleModal () {
this.setState({
showModal: !this.state.showModal
})
}
createCollection (newTitle) {
createBook (newTitle) {
const { createCollection } = this.props.actions
const collection = {
......@@ -37,11 +62,32 @@ export class Dashboard extends React.Component {
createCollection(collection)
}
removeCollection (collection) {
removeBook (collection) {
const { deleteCollection } = this.props.actions
deleteCollection(collection)
}
makeTeamsForBook (book) {
const { createTeam } = this.props.actions
each(teamTypes, teamType => {
// TODO -- Review the idea that the name needs to be plural for some teams
// const name = teamType.name === 'Production Editor' ? teamType.name : teamType.name + 's'
//
// const newTeam = {
// members: [],
// name: name,
// object: {
// id: book.id,
// type: 'collection'
// },
// teamType: teamType
// }
//
// createTeam(newTeam)
})
}
render () {
const { books } = this.props
const { showModal } = this.state
......@@ -58,13 +104,13 @@ export class Dashboard extends React.Component {
<BookList
books={books}
container={this}
remove={this.removeCollection}
remove={this.removeBook}
/>
</div>
<AddBook
container={this}
create={this.createCollection}
create={this.createBook}
show={showModal}
toggle={this.toggleModal}
/>
......@@ -74,13 +120,15 @@ export class Dashboard extends React.Component {
}
Dashboard.propTypes = {
books: React.PropTypes.arrayOf(React.PropTypes.object),
actions: React.PropTypes.object.isRequired
actions: React.PropTypes.object.isRequired,
books: React.PropTypes.arrayOf(React.PropTypes.object), // TODO -- ??
teams: React.PropTypes.arrayOf(React.PropTypes.object)
}
function mapStateToProps (state, { params }) {
return {
books: state.collections
books: state.collections,
teams: state.teams
}
}
......
......@@ -3,7 +3,8 @@ import { AnnotationComponent } from 'substance'
class TrackChangeComponent extends AnnotationComponent {
didMount () {
this.context.editorSession.onUpdate('document', this.onTrackChangesUpdated, this)
const { editorSession } = this.context
editorSession.onUpdate('document', this.onTrackChangesUpdated, this)
}
render ($$) {
......
const teamTypes = CONFIG.authsome.teams
const chapter = {
dropdownValues: {
front: [
......@@ -23,4 +25,4 @@ const chapter = {
}
}
export { chapter }
export { chapter, teamTypes }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment