Skip to content

Commit

Permalink
#1273 - on edit disallowed toast closes
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Feb 15, 2024
1 parent 5c8c395 commit db4765b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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([
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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');
Expand All @@ -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],
Expand Down
18 changes: 18 additions & 0 deletions packages/openchs-android/src/views/common/AvniToast.js
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -372,7 +373,8 @@ class SubjectDashboardProfileTab extends AbstractComponent {
</View>
{displayGeneralEncounterInfo && <SubjectDashboardGeneralTab {...this.props}/>}
<Separator height={110} backgroundColor={Colors.GreyContentBackground}/>
{editFormRuleResponse.isEditDisallowed() && ToastAndroid.show(editFormRuleResponse.getMessageKey(), ToastAndroid.SHORT)}
{editFormRuleResponse.isEditDisallowed() &&
<AvniToast message={this.I18n.t(editFormRuleResponse.getMessageKey())} onAutoClose={() => this.dispatchAction(Actions.ON_EDIT_ERROR_SHOWN)}/>}
</View>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -256,7 +257,8 @@ class SubjectDashboardProgramsTab extends AbstractComponent {
primaryAction={this.getPrimaryEnrolmentContextAction(hasExitPrivilege)}/>
</View>
</TouchableOpacity>
{this.state.editFormRuleResponse.isEditDisallowed() && ToastAndroid.show(this.state.editFormRuleResponse.getMessageKey(), ToastAndroid.SHORT)}
{this.state.editFormRuleResponse.isEditDisallowed() &&
<AvniToast message={this.I18n.t(this.state.editFormRuleResponse.getMessageKey())} onAutoClose={() => this.dispatchAction(Actions.ON_EDIT_ERROR_SHOWN)}/>}
</View>);
}

Expand Down

0 comments on commit db4765b

Please sign in to comment.