diff --git a/packages/openchs-android/src/action/individual/IndividualRegistrationDetailsActions.js b/packages/openchs-android/src/action/individual/IndividualRegistrationDetailsActions.js index 55d604650..1d88e1d0a 100644 --- a/packages/openchs-android/src/action/individual/IndividualRegistrationDetailsActions.js +++ b/packages/openchs-android/src/action/individual/IndividualRegistrationDetailsActions.js @@ -59,6 +59,10 @@ class IndividualRegistrationDetailsActions { return newState; } + static onEditErrorShown(state) { + return {...state, editFormRuleResponse: EditFormRuleResponse.createEditAllowedResponse()} + } + static onDeleteRelative(state, action, context) { context.get(IndividualRelationshipService).deleteRelative(action.individualRelative); const relatives = context.get(IndividualRelationshipService).getRelatives(state.individual); @@ -152,7 +156,8 @@ const IndividualRegistrationDetailsActionsNames = { ON_TOGGLE: "IRDA.ON_TOGGLE", ON_SUBJECT_PROGRAM_ELIGIBILITY_CHECK: "IRDA.ON_SUBJECT_PROGRAM_ELIGIBILITY_CHECK", ON_DISPLAY_INDICATOR_TOGGLE: "IRDA.ON_DISPLAY_INDICATOR_TOGGLE", - ON_EDIT_START: "IRDA.ON_EDIT_START" + ON_EDIT_START: "IRDA.ON_EDIT_START", + ON_EDIT_ERROR_SHOWN: "IRDA.ON_EDIT_ERROR_SHOWN" }; const IndividualRegistrationDetailsActionsMap = new Map([ @@ -163,6 +168,7 @@ const IndividualRegistrationDetailsActionsMap = new Map([ [IndividualRegistrationDetailsActionsNames.ON_SUBJECT_PROGRAM_ELIGIBILITY_CHECK, IndividualRegistrationDetailsActions.onSubjectProgramEligibilityCheck], [IndividualRegistrationDetailsActionsNames.ON_DISPLAY_INDICATOR_TOGGLE, IndividualRegistrationDetailsActions.onDisplayIndicatorToggle], [IndividualRegistrationDetailsActionsNames.ON_EDIT_START, IndividualRegistrationDetailsActions.onEditStart], + [IndividualRegistrationDetailsActionsNames.ON_EDIT_ERROR_SHOWN, IndividualRegistrationDetailsActions.onEditErrorShown], ]); export { diff --git a/packages/openchs-android/src/action/program/ProgramEnrolmentDashboardActions.js b/packages/openchs-android/src/action/program/ProgramEnrolmentDashboardActions.js index fa5bb7fed..e861ef30f 100644 --- a/packages/openchs-android/src/action/program/ProgramEnrolmentDashboardActions.js +++ b/packages/openchs-android/src/action/program/ProgramEnrolmentDashboardActions.js @@ -199,6 +199,10 @@ class ProgramEnrolmentDashboardActions { return state; } + static onEditErrorShown(state) { + return {...state, editFormRuleResponse: EditFormRuleResponse.createEditAllowedResponse()} + } + static onEditEnrolmentExit(state, action, context) { logEvent(firebaseEvents.EDIT_PROGRAM_EXIT); const enrolment = context.get(EntityService).findByUUID(state.enrolment.uuid, ProgramEnrolment.schema.name); @@ -324,7 +328,8 @@ const ProgramEnrolmentDashboardActionsNames = { HIDE_ENCOUNTER_SELECTOR: "PEDA.HIDE_ENCOUNTER_SELECTOR", ON_ENROLMENT_TOGGLE: "PEDA.ON_ENROLMENT_TOGGLE", ON_ENCOUNTER_TOGGLE: "PEDA.ON_Encounter_TOGGLE", - ON_PROGRAM_REJOIN: "PEDA.ON_PROGRAM_REJOIN" + ON_PROGRAM_REJOIN: "PEDA.ON_PROGRAM_REJOIN", + ON_EDIT_ERROR_SHOWN: "PEDA.ON_EDIT_ERROR_SHOWN" }; const ProgramEncounterTypeChoiceActionNames = new EntityTypeChoiceActionNames('PEDA'); @@ -339,6 +344,7 @@ const ProgramEnrolmentDashboardActionsMap = new Map([ [ProgramEnrolmentDashboardActionsNames.ON_EDIT_ENROLMENT, ProgramEnrolmentDashboardActions.onEditEnrolment], [ProgramEnrolmentDashboardActionsNames.ON_EXIT_ENROLMENT, ProgramEnrolmentDashboardActions.onExitEnrolment], [ProgramEnrolmentDashboardActionsNames.ON_EDIT_ENROLMENT_EXIT, ProgramEnrolmentDashboardActions.onEditEnrolmentExit], + [ProgramEnrolmentDashboardActionsNames.ON_EDIT_ERROR_SHOWN, ProgramEnrolmentDashboardActions.onEditErrorShown], [ProgramEnrolmentDashboardActionsNames.ON_ENROLMENT_CHANGE, ProgramEnrolmentDashboardActions.onEnrolmentChange], [ProgramEnrolmentDashboardActionsNames.LAUNCH_ENCOUNTER_SELECTOR, ProgramEnrolmentDashboardActions.launchEncounterSelector], [ProgramEnrolmentDashboardActionsNames.HIDE_ENCOUNTER_SELECTOR, ProgramEnrolmentDashboardActions.hideEncounterSelector], diff --git a/packages/openchs-android/src/views/common/AvniToast.js b/packages/openchs-android/src/views/common/AvniToast.js new file mode 100644 index 000000000..ecc6c0777 --- /dev/null +++ b/packages/openchs-android/src/views/common/AvniToast.js @@ -0,0 +1,18 @@ +import {Component} from "react"; +import {ToastAndroid} from "react-native"; +import PropTypes from "prop-types"; + +class AvniToast extends Component { + static propTypes = { + message: PropTypes.string.isRequired, + onAutoClose: PropTypes.func.isRequired + } + + render() { + const {message, onAutoClose} = this.props; + setTimeout(() => onAutoClose(), 1000); + return ToastAndroid.show(message, ToastAndroid.SHORT); + } +} + +export default AvniToast; diff --git a/packages/openchs-android/src/views/individual/SubjectDashboardProfileTab.js b/packages/openchs-android/src/views/individual/SubjectDashboardProfileTab.js index d57e48673..bfaa9de6d 100644 --- a/packages/openchs-android/src/views/individual/SubjectDashboardProfileTab.js +++ b/packages/openchs-android/src/views/individual/SubjectDashboardProfileTab.js @@ -39,6 +39,7 @@ import SubjectProgramEligibilityWidget from "./SubjectProgramEligibilityWidget"; import CustomActivityIndicator from "../CustomActivityIndicator"; import GroupSubjectService from "../../service/GroupSubjectService"; import UserInfoService from "../../service/UserInfoService"; +import AvniToast from "../common/AvniToast"; class SubjectDashboardProfileTab extends AbstractComponent { static propTypes = { @@ -372,7 +373,8 @@ class SubjectDashboardProfileTab extends AbstractComponent { {displayGeneralEncounterInfo && } - {editFormRuleResponse.isEditDisallowed() && ToastAndroid.show(editFormRuleResponse.getMessageKey(), ToastAndroid.SHORT)} + {editFormRuleResponse.isEditDisallowed() && + this.dispatchAction(Actions.ON_EDIT_ERROR_SHOWN)}/>} ); } diff --git a/packages/openchs-android/src/views/program/SubjectDashboardProgramsTab.js b/packages/openchs-android/src/views/program/SubjectDashboardProgramsTab.js index 780f98901..2f3c7c0fd 100644 --- a/packages/openchs-android/src/views/program/SubjectDashboardProgramsTab.js +++ b/packages/openchs-android/src/views/program/SubjectDashboardProgramsTab.js @@ -26,6 +26,7 @@ import ObservationsSectionOptions from "../common/ObservationsSectionOptions"; import Icon from 'react-native-vector-icons/SimpleLineIcons' import Separator from "../primitives/Separator"; import UserInfoService from "../../service/UserInfoService"; +import AvniToast from "../common/AvniToast"; class SubjectDashboardProgramsTab extends AbstractComponent { static propTypes = { @@ -256,7 +257,8 @@ class SubjectDashboardProgramsTab extends AbstractComponent { primaryAction={this.getPrimaryEnrolmentContextAction(hasExitPrivilege)}/> - {this.state.editFormRuleResponse.isEditDisallowed() && ToastAndroid.show(this.state.editFormRuleResponse.getMessageKey(), ToastAndroid.SHORT)} + {this.state.editFormRuleResponse.isEditDisallowed() && + this.dispatchAction(Actions.ON_EDIT_ERROR_SHOWN)}/>} ); }