Skip to content

Commit

Permalink
OP-794: allow to add policy holder details after a new one is saved (#76
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jdolkowski committed Sep 1, 2023
1 parent fea6a6c commit 4698e5d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ export function fetchPickerPolicyHolders(params) {
return graphql(payload, "POLICYHOLDER_POLICYHOLDERS");
}

export function fetchPolicyHolder(modulesManager, policyHolderId) {
export function fetchPolicyHolder(modulesManager, policyHolderId, filters=[]) {
let filter = !!policyHolderId ? `id: "${policyHolderId}"` : "";
filters.push(filter)
const payload = formatPageQuery(
"policyHolder",
[filter],
filters,
POLICYHOLDER_FULL_PROJECTION(modulesManager)
);
return graphql(payload, "POLICYHOLDER_POLICYHOLDER");
Expand All @@ -136,6 +137,12 @@ export function fetchPolicyHolderInsurees(modulesManager, params) {
return graphql(payload, "POLICYHOLDER_POLICYHOLDERINSUREES");
}

export function clearPolicyHolderInsurees() {
return (dispatch) => {
dispatch({ type: "POLICYHOLDER_POLICYHOLDERINSUREES_CLEAR" });
};
}

export function fetchPickerPolicyHolderInsurees(modulesManager, params) {
const payload = formatPageQueryWithCount(
"policyHolderInsuree",
Expand Down
17 changes: 15 additions & 2 deletions src/components/PolicyHolderForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import {
formatMessageWithValues,
journalize,
Helmet,
decodeId,
} from "@openimis/fe-core";
import { fetchPolicyHolder, clearPolicyHolder } from "../actions";
import { fetchPolicyHolder, clearPolicyHolder, clearPolicyHolderInsurees } from "../actions";
import {
RIGHT_PORTALPOLICYHOLDER_SEARCH,
RIGHT_POLICYHOLDER_CREATE,
Expand Down Expand Up @@ -86,14 +87,22 @@ class PolicyHolderForm extends Component {
policyHolder: props.policyHolder,
policyHolderId: props.policyHolderId,
}));
const policyHolderRouteRef = this.props.modulesManager.getRef('policyHolder.route.policyHolder');
const decodedId = decodeId(this.props.policyHolder.id);
this.props.history.replace(`/${policyHolderRouteRef}/${decodedId}`);
}
if (prevProps.submittingMutation && !this.props.submittingMutation) {
this.props.journalize(this.props.mutation);
if (!this.props?.policyHolderId) {
this.props.fetchPolicyHolder(this.props.modulesManager, null, [`clientMutationId: "${this.props.mutation.clientMutationId}"`]);
}
}
}

componentWillUnmount() {
this.props.clearPolicyHolder();
//if different default tab under policyholder then it needs to be cleared according to default tab
this.props.clearPolicyHolderInsurees();
}

isMandatoryFieldsEmpty = () => {
Expand Down Expand Up @@ -199,7 +208,11 @@ const mapStateToProps = (state) => ({

const mapDispatchToProps = (dispatch) => {
return bindActionCreators(
{ fetchPolicyHolder, clearPolicyHolder, journalize },
{ fetchPolicyHolder,
clearPolicyHolder,
clearPolicyHolderInsurees,
journalize,
},
dispatch
);
};
Expand Down
10 changes: 10 additions & 0 deletions src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ function reducer(
fetchingPolicyHolderInsurees: false,
errorPolicyHolderInsurees: formatServerError(action.payload),
};
case "POLICYHOLDER_POLICYHOLDERINSUREES_CLEAR":
return {
...state,
fetchingPolicyHolderInsurees: false,
fetchedPolicyHolderInsurees: false,
policyHolderInsurees: [],
policyHolderInsureesPageInfo: {},
policyHolderInsureesTotalCount: 0,
errorPolicyHolderInsurees: null,
};
case "POLICYHOLDER_PICKERPOLICYHOLDERINSUREES_REQ":
return {
...state,
Expand Down

0 comments on commit 4698e5d

Please sign in to comment.