Commit 7e66e534 authored by Florent Chehab's avatar Florent Chehab
Browse files

Alert when trying to edit and there is an alement pending moderation

parent 19b1cd5e
...@@ -12,6 +12,7 @@ import green from '@material-ui/core/colors/green'; ...@@ -12,6 +12,7 @@ import green from '@material-ui/core/colors/green';
import MyComponent from '../../MyComponent'; import MyComponent from '../../MyComponent';
import isModerationRequired from '../../../utils/isModerationRequired'; import isModerationRequired from '../../../utils/isModerationRequired';
import Alert from './editors/Alert';
import { import {
serverModerationStatusFetchData, serverModerationStatusFetchData,
...@@ -81,16 +82,44 @@ class GenericModule extends MyComponent { ...@@ -81,16 +82,44 @@ class GenericModule extends MyComponent {
pendingModerationOpen: false, pendingModerationOpen: false,
rawModelDataForEditor: this.props.rawModelData, rawModelDataForEditor: this.props.rawModelData,
forceSave: false, forceSave: false,
alert: { open: false }
}; };
handleOpenEditor = () => { handleOpenEditor = (force = false) => {
this.setState({ editorOpen: true }); if (force || this.props.rawModelData.pending_moderation.length == 0) {
this.setState({ editorOpen: true });
} else {
this.setState({
alert: {
open: true,
info: false,
title: "Une version est en attente de modération",
description: "Vous vous apprêter à éditer le module tel qu'il est présenté sur la page principale. Toutefois, il conseillé d'éditer le module à partir de la version en attente de modération car cette dernière sera écrasée par votre contribution.",
agreeText: "Ok, je vais voir la version en attente de modération",
disagreeText: "Je ne veux pas me baser sur le travail en attente de modération",
handleResponse: (agree) => {
if (agree) {
this.handleOpenPendingModeration();
} else {
this.handleOpenEditor(true);
}
},
multilineButtons: true,
}
})
}
}; };
handleCloseEditor = () => { handleCloseEditor = () => {
this.setState({ editorOpen: false, dataToSave: null }); this.setState({ editorOpen: false, dataToSave: null });
}; };
handleCloseAlert = () => {
this.setState({ alert: { open: false } })
}
handleCloseHistory = () => { handleCloseHistory = () => {
this.setState({ historyOpen: false }); this.setState({ historyOpen: false });
}; };
...@@ -107,6 +136,8 @@ class GenericModule extends MyComponent { ...@@ -107,6 +136,8 @@ class GenericModule extends MyComponent {
this.setState({ pendingModerationOpen: false }); this.setState({ pendingModerationOpen: false });
} }
handleEditPendingModeration = (rawModelData) => { handleEditPendingModeration = (rawModelData) => {
this.setState({ this.setState({
rawModelDataForEditor: rawModelData, rawModelDataForEditor: rawModelData,
...@@ -170,6 +201,10 @@ class GenericModule extends MyComponent { ...@@ -170,6 +201,10 @@ class GenericModule extends MyComponent {
return ( return (
<div> <div>
<Alert
{...this.state.alert}
handleClose={this.handleCloseAlert}
/>
<this.props.editor <this.props.editor
open={this.state.editorOpen} open={this.state.editorOpen}
handleCloseEditor={this.handleCloseEditor} handleCloseEditor={this.handleCloseEditor}
......
...@@ -7,36 +7,66 @@ import DialogContent from '@material-ui/core/DialogContent'; ...@@ -7,36 +7,66 @@ import DialogContent from '@material-ui/core/DialogContent';
import DialogContentText from '@material-ui/core/DialogContentText'; import DialogContentText from '@material-ui/core/DialogContentText';
import DialogTitle from '@material-ui/core/DialogTitle'; import DialogTitle from '@material-ui/core/DialogTitle';
import withStyles from '@material-ui/core/styles/withStyles';
import compose from 'recompose/compose';
const styles = theme => ({
multilineButton: {
display: 'block',
marginLeft: 'auto',
marginRight: 'auto',
},
button: {}
})
class Alert extends React.Component { class Alert extends React.Component {
render() { render() {
const { classes } = this.props;
return ( return (
<Dialog <Dialog
open={this.props.open} open={this.props.open}
> >
<DialogTitle>{this.props.title}</DialogTitle> {
<DialogContent> this.props.open ?
<DialogContentText style={{whiteSpace: 'pre-wrap'}}> <div>
{this.props.description} <DialogTitle>{this.props.title}</DialogTitle>
</DialogContentText> <DialogContent>
</DialogContent> <DialogContentText style={{ whiteSpace: 'pre-wrap' }}>
<DialogActions> {this.props.description}
{ </DialogContentText>
this.props.info ? </DialogContent>
<Button onClick={() => { this.props.handleClose(); this.props.handleResponse() }} color="primary"> <DialogActions>
{this.props.infoText} {
</Button> this.props.info ?
: <Button onClick={() => { this.props.handleClose(); this.props.handleResponse() }} color="primary">
<div> {this.props.infoText}
<Button onClick={() => { this.props.handleClose(); this.props.handleResponse(false) }} color="primary"> </Button>
{this.props.disagreeText} :
</Button> <div>
<Button onClick={() => { this.props.handleClose(); this.props.handleResponse(true) }} color="primary" autoFocus> <Button
{this.props.agreeText} onClick={() => { this.props.handleClose(); this.props.handleResponse(false) }}
</Button> color='secondary'
</div> className={this.props.multilineButtons ? classes.multilineButton : classes.button}
} >
</DialogActions> {this.props.disagreeText}
</Button>
<Button
onClick={() => { this.props.handleClose(); this.props.handleResponse(true) }}
className={this.props.multilineButtons ? classes.multilineButton : classes.button}
variant='outlined'
color="primary"
autoFocus
>
{this.props.agreeText}
</Button>
</div>
}
</DialogActions>
</div>
:
<div></div>
}
</Dialog > </Dialog >
); );
} }
...@@ -50,6 +80,7 @@ Alert.defaultProps = { ...@@ -50,6 +80,7 @@ Alert.defaultProps = {
agreeText: "OK", agreeText: "OK",
disagreeText: "Annuler", disagreeText: "Annuler",
infoText: "J'ai compris", infoText: "J'ai compris",
multilineButtons: false,
handleClose: () => { Console.log("Missing function for closing alert.") }, handleClose: () => { Console.log("Missing function for closing alert.") },
handleResponse: () => { Console.log("Missing function for handling post close.") } handleResponse: () => { Console.log("Missing function for handling post close.") }
} }
...@@ -64,7 +95,10 @@ Alert.propTypes = { ...@@ -64,7 +95,10 @@ Alert.propTypes = {
description: PropTypes.string, description: PropTypes.string,
handleClose: PropTypes.func.isRequired, handleClose: PropTypes.func.isRequired,
handleResponse: PropTypes.func.isRequired, handleResponse: PropTypes.func.isRequired,
multilineButtons: PropTypes.bool.isRequired,
}; };
export default Alert; export default compose(
\ No newline at end of file withStyles(styles, { withTheme: true }),
)(Alert);
Markdown is supported
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