diff --git a/src/actions/RecordActions.js b/src/actions/RecordActions.js index 5024cbb9..ed524a14 100644 --- a/src/actions/RecordActions.js +++ b/src/actions/RecordActions.js @@ -1,5 +1,5 @@ import * as ActionConstants from "../constants/ActionConstants"; -import { ACTION_FLAG } from "../constants/DefaultConstants"; +import { ACTION_FLAG, FORM_ACTION_FLAG } from "../constants/DefaultConstants"; import { axiosBackend } from "./index"; import * as Utils from "../utils/Utils"; import { loadRecords } from "./RecordsActions"; @@ -115,7 +115,7 @@ export function createRecord(record) { }; } -export function updateRecord(record) { +export function updateRecord(record, formActionFlag) { return function (dispatch, getState) { dispatch(saveRecordPending(ACTION_FLAG.UPDATE_ENTITY)); return axiosBackend @@ -125,7 +125,13 @@ export function updateRecord(record) { .then(() => { dispatch(saveRecordSuccess(record, null, ACTION_FLAG.UPDATE_ENTITY)); dispatch(loadRecords()); - dispatch(publishMessage(successMessage("record.save-success"))); + if (formActionFlag === FORM_ACTION_FLAG.SAVE_FORM) { + dispatch(publishMessage(successMessage("record.save-success"))); + } else if (formActionFlag === FORM_ACTION_FLAG.COMPLETE_FORM) { + dispatch(publishMessage(successMessage("record.complete-success"))); + } else if (formActionFlag === FORM_ACTION_FLAG.REJECT_FORM) { + dispatch(publishMessage(successMessage("record.reject-success"))); + } }) .catch((error) => { dispatch(saveRecordError(error.response.data, record, ACTION_FLAG.UPDATE_ENTITY)); diff --git a/src/components/record/RecordController.jsx b/src/components/record/RecordController.jsx index 97fec719..9ef2b463 100644 --- a/src/components/record/RecordController.jsx +++ b/src/components/record/RecordController.jsx @@ -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, RECORD_PHASE } from "../../constants/DefaultConstants"; +import { ACTION_FLAG, ACTION_STATUS, FORM_ACTION_FLAG, RECORD_PHASE } from "../../constants/DefaultConstants"; import { connect } from "react-redux"; import { bindActionCreators } from "redux"; import { @@ -102,7 +102,7 @@ class RecordController extends React.Component { if (record.isNew) { trackPromise(this.props.createRecord(omit(record, "isNew"), currentUser), "record"); } else { - trackPromise(this.props.updateRecord(record, currentUser), "record"); + trackPromise(this.props.updateRecord(record, FORM_ACTION_FLAG.SAVE_FORM, currentUser), "record"); } }; @@ -132,7 +132,7 @@ class RecordController extends React.Component { _onComplete = () => { this._handlePhaseChange(RECORD_PHASE.COMPLETED, () => { this._handleRejectReason(null, () => { - this.props.updateRecord(this.state.record, this.props.currentUser); + this.props.updateRecord(this.state.record, FORM_ACTION_FLAG.COMPLETE_FORM, this.props.currentUser); this._transitionToRecords(); }); }); @@ -141,7 +141,7 @@ class RecordController extends React.Component { _onReject = (rejectionReason) => { this._handlePhaseChange(RECORD_PHASE.REJECTED, () => { this._handleRejectReason(rejectionReason, () => { - this.props.updateRecord(this.state.record, this.props.currentUser); + this.props.updateRecord(this.state.record, FORM_ACTION_FLAG.REJECT_FORM, this.props.currentUser); this._transitionToRecords(); }); }); diff --git a/src/constants/DefaultConstants.js b/src/constants/DefaultConstants.js index de26bf85..788b074b 100644 --- a/src/constants/DefaultConstants.js +++ b/src/constants/DefaultConstants.js @@ -73,6 +73,12 @@ export const ACTION_FLAG = { UPDATE_ENTITY: "UPDATE_ENTITY", }; +export const FORM_ACTION_FLAG = { + COMPLETE_FORM: "COMPLETE_FORM", + REJECT_FORM: "REJECT_FORM", + SAVE_FORM: "SAVE_FORM", +}; + export const ACTION_STATUS = { PENDING: "PENDING", SUCCESS: "SUCCESS", diff --git a/src/i18n/cs.js b/src/i18n/cs.js index 29296389..26a98e69 100644 --- a/src/i18n/cs.js +++ b/src/i18n/cs.js @@ -187,6 +187,8 @@ export default { "record.created-by-msg": "Vytvořil(a) {name} {date}.", "record.last-edited-msg": "Naposledy upravil(a) {name} {date}.", "record.save-success": "Záznam úspěšně uložen.", + "record.complete-success": "Formulář byl úspěšně dokončen.", + "record.reject-success": "Formulář byl úspěšně zamítnut.", "record.save-error": "Záznam se nepodařilo uložit. {error}", "record.save-error.user-not-assigned-to-institution": "Uživatel není přiřazen k žádné instituci.", "record.form.please-wait": "Nahrávám formulář, prosím, čekejte...", diff --git a/src/i18n/en.js b/src/i18n/en.js index ef095a16..870467f4 100644 --- a/src/i18n/en.js +++ b/src/i18n/en.js @@ -188,6 +188,8 @@ export default { "record.created-by-msg": "Created {date} by {name}.", "record.last-edited-msg": "Last modified {date} by {name}.", "record.save-success": "Form successfully saved.", + "record.complete-success": "Form successfully completed.", + "record.reject-success": "Form successfully rejected.", "record.save-error": "Unable to save record. {error}", "record.save-error.user-not-assigned-to-institution": "User is not assigned to any institution.", "record.form.please-wait": "Loading form, please wait...", diff --git a/tests/__tests__/actions/RecordActions.spec.jsx b/tests/__tests__/actions/RecordActions.spec.jsx index 8cede4d8..43866db9 100644 --- a/tests/__tests__/actions/RecordActions.spec.jsx +++ b/tests/__tests__/actions/RecordActions.spec.jsx @@ -4,7 +4,7 @@ import * as ActionConstants from "../../../src/constants/ActionConstants"; import MockAdapter from "axios-mock-adapter"; import { TEST_TIMEOUT } from "../../constants/DefaultTestConstants"; import { axiosBackend } from "../../../src/actions"; -import { ACTION_FLAG, ROLE } from "../../../src/constants/DefaultConstants"; +import { ACTION_FLAG, FORM_ACTION_FLAG, ROLE } from "../../../src/constants/DefaultConstants"; import { createRecord, deleteRecord, @@ -183,14 +183,14 @@ describe("Record asynchronous actions", function () { { type: ActionConstants.SAVE_RECORD_PENDING, actionFlag: ACTION_FLAG.UPDATE_ENTITY }, { type: ActionConstants.SAVE_RECORD_SUCCESS, key: null, actionFlag: ACTION_FLAG.UPDATE_ENTITY, record }, { type: ActionConstants.LOAD_RECORDS_PENDING }, - { type: ActionConstants.PUBLISH_MESSAGE, message: successMessage("record.save-success") }, + { type: ActionConstants.PUBLISH_MESSAGE, message: successMessage("record.complete-success") }, { type: ActionConstants.LOAD_RECORDS_SUCCESS, records }, ]; mockApi.onPut(`${API_URL}/rest/records/${record.key}`).reply(200, null, { location }); mockApi.onGet(`${API_URL}/rest/records`).reply(200, records, {}); - store.dispatch(updateRecord(record)); + store.dispatch(updateRecord(record, FORM_ACTION_FLAG.COMPLETE_FORM)); setTimeout(() => { expect(store.getActions()).toEqual(expectedActions);