Skip to content

Commit

Permalink
[New #18] Added rejected, completed and published buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
LaChope committed Dec 13, 2023
1 parent bd85599 commit a7b6f9d
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 19 deletions.
8 changes: 5 additions & 3 deletions js/components/HelpIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -19,8 +19,10 @@ const HelpIcon = (props) => {
return <FaCheck className={'ok-icon ' + props.className}/>;
case "remove":
return <FaTimes className={'remove-icon ' + props.className}/>;
case "progress":
return <FaTasks className={'progress-icon ' + props.className}/>;
case "to-do":
return <FaTasks className={'to-do-icon ' + props.className}/>;
case "envelope":
return <FaEnvelope className={'publish-icon' + props.className}/>
default:
return null;
}
Expand Down
13 changes: 8 additions & 5 deletions js/components/record/Record.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,16 @@ class Record extends React.Component {
_renderRoleSpecificButtons() {
return <>
{EXTENSIONS === EXTENSION_CONSTANTS.SUPPLIER &&
<>
<Button className="mx-1" variant='danger' size='sm'>{this.i18n('reject')}</Button>
<Button className="mx-1" variant='success' size='sm'>{this.i18n('accept')}</Button>
</>
<Button className="mx-1" variant='danger' size='sm'
onClick={this.props.handlers.onReject}>
{this.i18n('reject')}
</Button>
}
{EXTENSIONS === EXTENSION_CONSTANTS.OPERATOR &&
<Button className="mx-1" variant='success' size='sm'>{this.i18n('complete')}</Button>}
<Button className="mx-1" variant='success' size='sm'
onClick={this.props.handlers.onComplete}>
{this.i18n('complete')}
</Button>}
</>;
}

Expand Down
27 changes: 25 additions & 2 deletions js/components/record/RecordController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 <Record
Expand Down
14 changes: 11 additions & 3 deletions js/components/record/RecordRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import withI18n from "../../i18n/withI18n";
import RecordValidator from "../../validation/RecordValidator";
import {LoaderSmall} from "../Loader";
import PropTypes from "prop-types";
import {ROLE} from "../../constants/DefaultConstants";
import {RECORD_PHASE, ROLE} from "../../constants/DefaultConstants";

let RecordRow = (props) => {
const record = props.record,
Expand All @@ -18,7 +18,15 @@ let RecordRow = (props) => {
deleteButton = props.disableDelete ? null :
<Button variant='warning' size='sm' title={props.i18n('records.delete-tooltip')}
onClick={() => props.onDelete(record)}>{props.i18n('delete')}{props.deletionLoading &&
<LoaderSmall/>}</Button>;
<LoaderSmall/>}</Button>,
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 <tr>
{isAdmin &&
Expand All @@ -41,7 +49,7 @@ let RecordRow = (props) => {
</td>
{ isAdmin &&
<td className='report-row content-center'>
<HelpIcon text={completionTooltip} glyph={isComplete ? 'ok' : 'progress'}/>
<HelpIcon text={completionTooltip} glyph={getGlyph()}/>
</td>
}
<td className='report-row actions'>
Expand Down
5 changes: 4 additions & 1 deletion js/components/record/Records.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ class Records extends React.Component {
onClick={onCreateWithFormTemplate}>{this.i18n('records.create-tile')}</Button>
: null}
{showPublishButton ?
<Button className="mx-1" variant='success' size='sm'>{this.i18n('publish')}</Button>
<Button className="mx-1" variant='success' size='sm'
onClick={this.props.handlers.onPublish}>
{this.i18n('publish')}
</Button>
: null}
</div>
{showAlert && recordDeleted.status === ACTION_STATUS.ERROR &&
Expand Down
26 changes: 24 additions & 2 deletions js/components/record/RecordsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
})

};

render() {
const {formTemplatesLoaded, recordsLoaded, recordDeleted, recordsDeleting, currentUser} = this.props;
const formTemplate = extractQueryParam(this.props.location.search, "formTemplate");
Expand All @@ -62,7 +82,8 @@ class RecordsController extends React.Component {
const handlers = {
onEdit: this._onEditRecord,
onCreate: this._onAddRecord,
onDelete: this._onDeleteRecord
onDelete: this._onDeleteRecord,
onPublish: this._onPublishRecords
};
return <Records recordsLoaded={recordsLoaded} showAlert={this.state.showAlert} handlers={handlers}
recordDeleted={recordDeleted} recordsDeleting={recordsDeleting} currentUser={currentUser}
Expand All @@ -86,6 +107,7 @@ function mapStateToProps(state) {
function mapDispatchToProps(dispatch) {
return {
deleteRecord: bindActionCreators(deleteRecord, dispatch),
updateRecord: bindActionCreators(updateRecord, dispatch),
loadRecords: bindActionCreators(loadRecords, dispatch),
loadFormTemplates: bindActionCreators(loadFormTemplates, dispatch),
transitionToWithOpts: bindActionCreators(transitionToWithOpts, dispatch)
Expand Down
8 changes: 8 additions & 0 deletions js/constants/DefaultConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,11 @@ export const EXTENSION_CONSTANTS = {
SUPPLIER: "supplier",
OPERATOR: "operator"
}

export const RECORD_PHASE = {
OPEN: 'open',
VALID: 'valid',
COMPLETED: 'completed',
PUBLISHED: 'published',
REJECTED: 'rejected'
}
1 change: 0 additions & 1 deletion js/i18n/cs.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export default {
'actions': 'Akce',
'required': 'Políčka označená * jsou povinná',
'reject': 'Odmítnout',
'accept':'Přijmout',
'complete': 'Dokončit',
'publish': 'Publikovat',

Expand Down
1 change: 0 additions & 1 deletion js/i18n/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export default {
'actions': 'Actions',
'required': 'Fields marked with * are required',
'reject': 'Reject',
'accept':'Accept',
'complete': 'Complete',
'publish': 'Publish',

Expand Down
4 changes: 3 additions & 1 deletion js/utils/EntityFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import * as Utils from "./Utils";
import * as RecordState from "../model/RecordState";
import * as Vocabulary from "../constants/Vocabulary";
import {RECORD_PHASE} from "../constants/DefaultConstants";

export function initNewUser() {
return {
Expand Down Expand Up @@ -30,7 +31,8 @@ export function initNewPatientRecord() {
formTemplate: '',
complete: false,
isNew: true,
state: RecordState.createRecordState()
state: RecordState.createRecordState(),
phase: RECORD_PHASE.OPEN
}
}

Expand Down

0 comments on commit a7b6f9d

Please sign in to comment.