Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OTC-757: Clearing pagination state if entered the FamiliesPage or Ins… #49

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ import EnrolledFamiliesReport from "./reports/EnrolledFamiliesReport";
import InsureeFamilyOverviewReport from "./reports/InsureeFamilyOverviewReport";

const ROUTE_INSUREE_FAMILIES = "insuree/families";
const ROUTE_INSUREE_FAMILY_OVERVIEW = "insuree/familyOverview";
const ROUTE_INSUREE_FAMILY_OVERVIEW = "insuree/families/familyOverview";
const ROUTE_INSUREE_FAMILY = "insuree/family";
const ROUTE_INSUREE_INSUREES = "insuree/insurees";
const ROUTE_INSUREE_INSUREE = "insuree/insuree";
const ROUTE_INSUREE_INSUREE = "insuree/insurees/insuree";

const DEFAULT_CONFIG = {
"translations": [{ key: "en", messages: messages_en }],
Expand Down
32 changes: 30 additions & 2 deletions src/pages/FamiliesPage.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import React, { Component } from "react";
import { bindActionCreators } from "redux";
import { connect } from "react-redux";
import { injectIntl } from "react-intl";
import { withTheme, withStyles } from "@material-ui/core/styles";
import { Fab } from "@material-ui/core";
import AddIcon from "@material-ui/icons/Add";
import { historyPush, withModulesManager, withHistory, withTooltip, formatMessage } from "@openimis/fe-core";
import {
historyPush,
withModulesManager,
withHistory,
withTooltip,
formatMessage,
clearCurrentPaginationPage,
} from "@openimis/fe-core";
import FamilySearcher from "../components/FamilySearcher";

import { RIGHT_FAMILY_ADD } from "../constants";
Expand All @@ -26,6 +34,21 @@ class FamiliesPage extends Component {
historyPush(this.props.modulesManager, this.props.history, "insuree.route.family");
};

componentDidMount = () => {
const moduleName = "insuree";
const { module } = this.props;
if (module !== moduleName) this.props.clearCurrentPaginationPage();
};

componentWillUnmount = () => {
const { location, history } = this.props;
const {
location: { pathname },
} = history;
const urlPath = location.pathname;
if (!pathname.includes(urlPath)) this.props.clearCurrentPaginationPage();
};

render() {
const { intl, classes, rights } = this.props;
return (
Expand All @@ -52,8 +75,13 @@ class FamiliesPage extends Component {

const mapStateToProps = (state) => ({
rights: !!state.core && !!state.core.user && !!state.core.user.i_user ? state.core.user.i_user.rights : [],
module: state.core?.savedPagination?.module,
});

const mapDispatchToProps = (dispatch) => bindActionCreators({ clearCurrentPaginationPage }, dispatch);

export default injectIntl(
withModulesManager(withHistory(connect(mapStateToProps)(withTheme(withStyles(styles)(FamiliesPage))))),
withModulesManager(
withHistory(connect(mapStateToProps, mapDispatchToProps)(withTheme(withStyles(styles)(FamiliesPage)))),
),
);
32 changes: 30 additions & 2 deletions src/pages/InsureesPage.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import React, { Component } from "react";
import { bindActionCreators } from "redux";
import { connect } from "react-redux";
import { injectIntl } from "react-intl";
import { withTheme, withStyles } from "@material-ui/core/styles";
import { Fab } from "@material-ui/core";
import AddIcon from "@material-ui/icons/Add";
import { historyPush, withModulesManager, withHistory, withTooltip, formatMessage } from "@openimis/fe-core";
import {
historyPush,
withModulesManager,
withHistory,
withTooltip,
formatMessage,
clearCurrentPaginationPage,
} from "@openimis/fe-core";
import InsureeSearcher from "../components/InsureeSearcher";

import { RIGHT_INSUREE_ADD } from "../constants";
Expand All @@ -23,6 +31,21 @@ class InsureesPage extends Component {
historyPush(this.props.modulesManager, this.props.history, "insuree.route.insuree");
};

componentDidMount = () => {
const moduleName = "insuree";
const { module } = this.props;
if (module !== moduleName) this.props.clearCurrentPaginationPage();
};

componentWillUnmount = () => {
const { location, history } = this.props;
const {
location: { pathname },
} = history;
const urlPath = location.pathname;
if (!pathname.includes(urlPath)) this.props.clearCurrentPaginationPage();
};

render() {
const { intl, classes, rights } = this.props;
return (
Expand All @@ -44,8 +67,13 @@ class InsureesPage extends Component {

const mapStateToProps = (state) => ({
rights: !!state.core && !!state.core.user && !!state.core.user.i_user ? state.core.user.i_user.rights : [],
module: state.core?.savedPagination?.module,
});

const mapDispatchToProps = (dispatch) => bindActionCreators({ clearCurrentPaginationPage }, dispatch);

export default injectIntl(
withModulesManager(withHistory(connect(mapStateToProps)(withTheme(withStyles(styles)(InsureesPage))))),
withModulesManager(
withHistory(connect(mapStateToProps, mapDispatchToProps)(withTheme(withStyles(styles)(InsureesPage)))),
),
);