diff --git a/frontend/src/components/university/modules/GenericModule.js b/frontend/src/components/university/modules/GenericModule.js index 1a633b884910a5c04be139da1e6423f79a8c31cf..6a3f015a6db0d9af59fb92c8a09d0d4664a7c2a3 100644 --- a/frontend/src/components/university/modules/GenericModule.js +++ b/frontend/src/components/university/modules/GenericModule.js @@ -12,6 +12,7 @@ import green from '@material-ui/core/colors/green'; import MyComponent from '../../MyComponent'; import isModerationRequired from '../../../utils/isModerationRequired'; +import Alert from './editors/Alert'; import { serverModerationStatusFetchData, @@ -81,16 +82,44 @@ class GenericModule extends MyComponent { pendingModerationOpen: false, rawModelDataForEditor: this.props.rawModelData, forceSave: false, + alert: { open: false } }; - handleOpenEditor = () => { - this.setState({ editorOpen: true }); + handleOpenEditor = (force = false) => { + 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 = () => { this.setState({ editorOpen: false, dataToSave: null }); }; + handleCloseAlert = () => { + this.setState({ alert: { open: false } }) + } + handleCloseHistory = () => { this.setState({ historyOpen: false }); }; @@ -107,6 +136,8 @@ class GenericModule extends MyComponent { this.setState({ pendingModerationOpen: false }); } + + handleEditPendingModeration = (rawModelData) => { this.setState({ rawModelDataForEditor: rawModelData, @@ -170,6 +201,10 @@ class GenericModule extends MyComponent { return (
+ ({ + multilineButton: { + display: 'block', + marginLeft: 'auto', + marginRight: 'auto', + }, + button: {} +}) + class Alert extends React.Component { render() { + const { classes } = this.props; return ( - {this.props.title} - - - {this.props.description} - - - - { - this.props.info ? - - : -
- - -
- } -
+ { + this.props.open ? +
+ {this.props.title} + + + {this.props.description} + + + + { + this.props.info ? + + : +
+ + +
+ } +
+
+ : +
+ }
); } @@ -50,6 +80,7 @@ Alert.defaultProps = { agreeText: "OK", disagreeText: "Annuler", infoText: "J'ai compris", + multilineButtons: false, handleClose: () => { Console.log("Missing function for closing alert.") }, handleResponse: () => { Console.log("Missing function for handling post close.") } } @@ -64,7 +95,10 @@ Alert.propTypes = { description: PropTypes.string, handleClose: PropTypes.func.isRequired, handleResponse: PropTypes.func.isRequired, + multilineButtons: PropTypes.bool.isRequired, }; -export default Alert; \ No newline at end of file +export default compose( + withStyles(styles, { withTheme: true }), +)(Alert);