diff --git a/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.component.js b/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.component.js index e07af82ad..e9c49596f 100644 --- a/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.component.js +++ b/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.component.js @@ -42,6 +42,7 @@ const CommunicatorDialog = ({ addOrRemoveBoard, copyBoard, deleteMyBoard, + updateMyBoard, setRootBoard, publishBoard, showNotification @@ -124,6 +125,7 @@ const CommunicatorDialog = ({ addOrRemoveBoard={addOrRemoveBoard} copyBoard={copyBoard} deleteMyBoard={deleteMyBoard} + updateMyBoard={updateMyBoard} publishBoard={publishBoard} setRootBoard={setRootBoard} selectedIds={communicatorBoardsIds} @@ -202,6 +204,7 @@ CommunicatorDialog.propTypes = { onSearch: PropTypes.func, addOrRemoveBoard: PropTypes.func.isRequired, deleteMyBoard: PropTypes.func.isRequired, + updateMyBoard: PropTypes.func.isRequired, copyBoard: PropTypes.func.isRequired, setRootBoard: PropTypes.func.isRequired, publishBoard: PropTypes.func.isRequired, diff --git a/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js b/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js index 0c9d883e1..3fe5e88b4 100644 --- a/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js +++ b/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.container.js @@ -20,7 +20,8 @@ import { replaceBoard, createBoard, updateBoard, - updateApiObjectsNoChild + updateApiObjectsNoChild, + updateApiBoard } from '../../Board/Board.actions'; import messages from './CommunicatorDialog.messages'; @@ -476,6 +477,18 @@ class CommunicatorDialogContainer extends React.Component { showNotification(intl.formatMessage(messages.boardDeleted)); } + async updateMyBoard(board) { + const { updateBoard, updateApiBoard, userData } = this.props; + updateBoard(board); + + // Loggedin user? + if ('name' in userData && 'email' in userData) { + try { + await updateApiBoard(board); + } catch (err) {} + } + } + render() { const limit = this.state.page * BOARDS_PAGE_LIMIT; const communicatorBoardsIds = this.props.communicatorBoards.map(b => b.id); @@ -487,6 +500,7 @@ class CommunicatorDialogContainer extends React.Component { communicatorBoardsIds, addOrRemoveBoard: this.addOrRemoveBoard.bind(this), deleteMyBoard: this.deleteMyBoard.bind(this), + updateMyBoard: this.updateMyBoard.bind(this), publishBoard: this.publishBoard.bind(this), setRootBoard: this.setRootBoard.bind(this), copyBoard: this.copyBoard.bind(this), @@ -541,7 +555,8 @@ const mapDispatchToProps = { updateBoard, addBoardCommunicator, upsertCommunicator, - updateApiObjectsNoChild + updateApiObjectsNoChild, + updateApiBoard }; export default connect( diff --git a/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.messages.js b/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.messages.js index c8ad572ad..0aa76ae5f 100644 --- a/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.messages.js +++ b/src/components/Communicator/CommunicatorDialog/CommunicatorDialog.messages.js @@ -109,6 +109,10 @@ export default defineMessages({ id: 'cboard.components.CommunicatorDialog.boardInfoDate', defaultMessage: 'Last edited' }, + boardDescription: { + id: 'cboard.components.CommunicatorDialog.boardDescription', + defaultMessage: 'Description' + }, boardPublished: { id: 'cboard.components.CommunicatorDialog.boardPublished', defaultMessage: @@ -156,6 +160,15 @@ export default defineMessages({ defaultMessage: 'This action will delete the board and it cannot be recovered. Do you want to proceed?' }, + publishBoard: { + id: 'cboard.components.CommunicatorDialog.publishBoard', + defaultMessage: 'Board Description' + }, + publishBoardDescription: { + id: 'cboard.components.CommunicatorDialog.publishBoardDescription', + defaultMessage: + 'Please provide a short description about the content of the board and what is the board intended for.' + }, accept: { id: 'cboard.components.CommunicatorDialog.accept', defaultMessage: 'Accept' diff --git a/src/components/Communicator/CommunicatorDialog/CommunicatorDialogBoardItem.component.js b/src/components/Communicator/CommunicatorDialog/CommunicatorDialogBoardItem.component.js index e99e5b689..d85206ae9 100644 --- a/src/components/Communicator/CommunicatorDialog/CommunicatorDialogBoardItem.component.js +++ b/src/components/Communicator/CommunicatorDialog/CommunicatorDialogBoardItem.component.js @@ -21,13 +21,20 @@ import DialogActions from '@material-ui/core/DialogActions'; import Button from '@material-ui/core/Button'; import Typography from '@material-ui/core/Typography'; import Tooltip from '@material-ui/core/Tooltip'; +import TextField from '@material-ui/core/TextField'; import CircularProgress from '@material-ui/core/CircularProgress'; +import Slide from '@material-ui/core/Slide'; +import DialogContentText from '@material-ui/core/DialogContentText'; import IconButton from '../../UI/IconButton'; import { TAB_INDEXES } from './CommunicatorDialog.constants'; import messages from './CommunicatorDialog.messages'; import { isCordova } from '../../../cordova-util'; +const Transition = React.forwardRef(function Transition(props, ref) { + return ; +}); + class CommunicatorDialogBoardItem extends React.Component { constructor(props) { super(props); @@ -37,7 +44,9 @@ class CommunicatorDialogBoardItem extends React.Component { loading: false, openBoardInfo: false, openDeleteBoard: false, - openCopyBoard: false + openPublishBoard: false, + openCopyBoard: false, + publishDialogValue: '' }; } @@ -61,6 +70,33 @@ class CommunicatorDialogBoardItem extends React.Component { }); } + handleBoardDescriptionChange = event => { + const { value: publishDialogValue } = event.target; + this.setState({ publishDialogValue }); + }; + + async handleBoardPublishOpen(board) { + console.log(board); + if (!board.isPublic && !board.description) { + this.setState({ + openPublishBoard: true + }); + } else { + this.setState({ loading: true }); + try { + if (this.state.publishDialogValue) { + board.description = this.state.publishDialogValue; + } + await this.props.publishBoard(board); + } catch (err) { + } finally { + this.setState({ + loading: false + }); + } + } + } + handleBoardCopyOpen() { this.setState({ openCopyBoard: true @@ -97,11 +133,35 @@ class CommunicatorDialogBoardItem extends React.Component { } } + async handleBoardPublish(board) { + this.setState({ + openPublishBoard: false, + loading: true + }); + + try { + if (this.state.publishDialogValue) { + const newBoard = { + ...board, + description: this.state.publishDialogValue + }; + this.props.updateMyBoard(newBoard); + } + await this.props.publishBoard(board); + } catch (err) { + } finally { + this.setState({ + loading: false + }); + } + } + handleDialogClose() { this.setState({ openBoardInfo: false, openCopyBoard: false, - openDeleteBoard: false + openDeleteBoard: false, + openPublishBoard: false }); } @@ -118,8 +178,7 @@ class CommunicatorDialogBoardItem extends React.Component { userData, communicator, activeBoardId, - addOrRemoveBoard, - publishBoard + addOrRemoveBoard } = this.props; const title = board.name || board.id; const displayActions = @@ -135,7 +194,11 @@ class CommunicatorDialogBoardItem extends React.Component { return (
- {!!boardCaption && {title}} + {!!boardCaption && ( + + {title} + + )} {!boardCaption && (
@@ -250,6 +313,10 @@ class CommunicatorDialogBoardItem extends React.Component { {intl.formatMessage(messages.boardInfoAuthor)}:{' '} {board.author} + + {intl.formatMessage(messages.boardDescription)}:{' '} + {board.description} + {intl.formatMessage(messages.boardInfoDate)}:{' '} {moment(board.lastEdited).format('DD/MM/YYYY')} @@ -332,11 +399,56 @@ class CommunicatorDialogBoardItem extends React.Component { : intl.formatMessage(messages.menuPublishOption) } onClick={() => { - publishBoard(board); + this.handleBoardPublishOpen(board); }} > {board.isPublic ? : } + + + {intl.formatMessage(messages.publishBoard)} + + + + {intl.formatMessage(messages.publishBoardDescription)} + + + + + + + +