From 9e21e5d5173d40f3b45bb7a2d8798c77bf91f80d Mon Sep 17 00:00:00 2001 From: Max Chopart Date: Wed, 13 Dec 2023 13:02:08 +0100 Subject: [PATCH] [New #18] Added rejected, completed and published buttons --- js/components/HelpIcon.js | 8 ++++--- js/components/record/Record.js | 13 ++++++----- js/components/record/RecordController.js | 27 +++++++++++++++++++++-- js/components/record/RecordRow.js | 14 +++++++++--- js/components/record/Records.js | 5 ++++- js/components/record/RecordsController.js | 26 ++++++++++++++++++++-- js/constants/DefaultConstants.js | 8 +++++++ js/i18n/cs.js | 1 - js/i18n/en.js | 1 - js/utils/EntityFactory.js | 4 +++- 10 files changed, 88 insertions(+), 19 deletions(-) diff --git a/js/components/HelpIcon.js b/js/components/HelpIcon.js index d5ac3931..a7bfa4d4 100644 --- a/js/components/HelpIcon.js +++ b/js/components/HelpIcon.js @@ -3,7 +3,7 @@ import React from 'react'; import {OverlayTrigger, Tooltip} from 'react-bootstrap'; import PropTypes from "prop-types"; -import {FaQuestionCircle} from 'react-icons/fa'; +import {FaEnvelope, FaQuestionCircle} from 'react-icons/fa'; import {FaCheck} from 'react-icons/fa'; import {FaTimes} from 'react-icons/fa'; import {FaTasks} from "react-icons/fa"; @@ -19,8 +19,10 @@ const HelpIcon = (props) => { return ; case "remove": return ; - case "progress": - return ; + case "to-do": + return ; + case "envelope": + return default: return null; } diff --git a/js/components/record/Record.js b/js/components/record/Record.js index 1de24004..2711657e 100644 --- a/js/components/record/Record.js +++ b/js/components/record/Record.js @@ -121,13 +121,16 @@ class Record extends React.Component { _renderRoleSpecificButtons() { return <> {EXTENSIONS === EXTENSION_CONSTANTS.SUPPLIER && - <> - - - + } {EXTENSIONS === EXTENSION_CONSTANTS.OPERATOR && - } + } ; } diff --git a/js/components/record/RecordController.js b/js/components/record/RecordController.js index 3aa74e3d..d83045ec 100644 --- a/js/components/record/RecordController.js +++ b/js/components/record/RecordController.js @@ -6,7 +6,7 @@ import withI18n from '../../i18n/withI18n'; import Record from './Record'; import Routes from "../../constants/RoutesConstants"; import {transitionToWithOpts} from '../../utils/Routing'; -import {ACTION_FLAG, ACTION_STATUS} from "../../constants/DefaultConstants"; +import {ACTION_FLAG, ACTION_STATUS, RECORD_PHASE} from "../../constants/DefaultConstants"; import {connect} from "react-redux"; import {bindActionCreators} from "redux"; import { @@ -126,6 +126,27 @@ class RecordController extends React.Component { this.setState({record: update}); }; + _onComplete = () => { + this._handlePhaseChange(RECORD_PHASE.COMPLETED); + }; + + _onReject = () => { + this._handlePhaseChange(RECORD_PHASE.REJECTED); + }; + + _handlePhaseChange = (newPhase) => { + const currentUser = this.props.currentUser; + + this.setState((prevState) => { + const update = {...prevState.record}; + update.phase = newPhase; + return {record: update}; + }, () => { + const updatedRecord = this.state.record; + this.props.updateRecord(updatedRecord, currentUser); + }); + }; + _getLocalName() { if (EXTENSIONS.split(",").includes("kodi")) { // return name of the record based on answer of specific question return this._getKodiLocaLName(); @@ -158,7 +179,9 @@ class RecordController extends React.Component { const handlers = { onSave: this._onSave, onCancel: this._onCancel, - onChange: this._onChange + onChange: this._onChange, + onComplete: this._onComplete, + onReject: this._onReject }; return { const record = props.record, @@ -18,7 +18,15 @@ let RecordRow = (props) => { deleteButton = props.disableDelete ? null : ; + }, + recordPhase = props.record.phase; + + const getGlyph = () => { + if (recordPhase === RECORD_PHASE.OPEN) return "to-do"; + if (recordPhase === RECORD_PHASE.COMPLETED) return "ok"; + if (recordPhase === RECORD_PHASE.PUBLISHED) return "envelope"; + if (recordPhase === RECORD_PHASE.REJECTED) return "remove"; + } return {isAdmin && @@ -44,7 +52,7 @@ let RecordRow = (props) => { { isAdmin && - + } diff --git a/js/components/record/Records.js b/js/components/record/Records.js index e84656f3..6a6de6fa 100644 --- a/js/components/record/Records.js +++ b/js/components/record/Records.js @@ -66,7 +66,10 @@ class Records extends React.Component { onClick={onCreateWithFormTemplate}>{this.i18n('records.create-tile')} : null} {showPublishButton ? - + : null} diff --git a/js/components/record/RecordsController.js b/js/components/record/RecordsController.js index 16fe4905..f1c9f208 100644 --- a/js/components/record/RecordsController.js +++ b/js/components/record/RecordsController.js @@ -10,9 +10,10 @@ import {injectIntl} from "react-intl"; import withI18n from "../../i18n/withI18n"; import {connect} from "react-redux"; import {bindActionCreators} from "redux"; -import {deleteRecord} from "../../actions/RecordActions"; +import {deleteRecord, updateRecord} from "../../actions/RecordActions"; import {loadFormTemplates} from "../../actions/FormTemplatesActions"; import {extractQueryParam} from "../../utils/Utils" +import {RECORD_PHASE} from "../../constants/DefaultConstants"; class RecordsController extends React.Component { constructor(props) { @@ -53,6 +54,25 @@ class RecordsController extends React.Component { this.setState({showAlert: true}); }; + _onPublishRecords = async () => { + const currentUser = this.props.currentUser; + + this.setState({ + records: this.props.recordsLoaded.records + }, async () => { + const updatedRecords = this.state.records.map(async (record) => { + if (record.phase === RECORD_PHASE.COMPLETED) { + const updatedRecord = {...record, phase: RECORD_PHASE.PUBLISHED}; + await this.props.updateRecord(updatedRecord, currentUser); + return updatedRecord; + } + }); + + return await Promise.all(updatedRecords); + }) + + }; + _onExportRecords = (exportType) => { this.props.exportRecords(exportType); }; @@ -67,6 +87,7 @@ class RecordsController extends React.Component { onEdit: this._onEditRecord, onCreate: this._onAddRecord, onDelete: this._onDeleteRecord, + onPublish: this._onPublishRecords, onExport: this._onExportRecords }; return