Skip to content

Commit

Permalink
CM-909: added possibility to suspend a program
Browse files Browse the repository at this point in the history
  • Loading branch information
sniedzielski committed Jun 7, 2024
1 parent 044ada9 commit 8286877
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,22 @@ export function deleteBenefitPlan(benefitPlan, clientMutationLabel) {
);
}

export function closeBenefitPlan(benefitPlan, clientMutationLabel) {
const benefitPlanUuids = `ids: ["${benefitPlan?.id}"]`;
const mutation = formatMutation('closeBenefitPlan', benefitPlanUuids, clientMutationLabel);
const requestedDateTime = new Date();
return graphql(
mutation.payload,
[REQUEST(ACTION_TYPE.MUTATION), SUCCESS(ACTION_TYPE.CLOSE_BENEFIT_PLAN), ERROR(ACTION_TYPE.MUTATION)],
{
actionType: ACTION_TYPE.CLOSE_BENEFIT_PLAN,
clientMutationId: mutation.clientMutationId,
clientMutationLabel,
requestedDateTime,
},
);
}

function dateTimeToDate(date) {
return date.split('T')[0];
}
Expand Down
27 changes: 26 additions & 1 deletion src/pages/BenefitPlanPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import { connect } from 'react-redux';
import _ from 'lodash';
import { withTheme, withStyles } from '@material-ui/core/styles';
import DeleteIcon from '@material-ui/icons/Delete';
import PauseIcon from '@material-ui/icons/Pause';
import { RIGHT_BENEFICIARY_SEARCH, RIGHT_BENEFIT_PLAN_UPDATE } from '../constants';
import {
fetchBenefitPlan, deleteBenefitPlan, updateBenefitPlan, clearBenefitPlan, createBenefitPlan,
fetchBenefitPlan, deleteBenefitPlan, closeBenefitPlan, updateBenefitPlan, clearBenefitPlan, createBenefitPlan,
} from '../actions';
import BenefitPlanHeadPanel from '../components/BenefitPlanHeadPanel';
import BenefitPlanTabPanel from '../components/BenefitPlanTabPanel';
Expand All @@ -38,6 +39,7 @@ function BenefitPlanPage({
benefitPlan,
fetchBenefitPlan,
deleteBenefitPlan,
closeBenefitPlan,
updateBenefitPlan,
coreConfirm,
clearConfirm,
Expand Down Expand Up @@ -147,6 +149,13 @@ function BenefitPlanPage({
}),
);

const stopBenefitPlanCallback = () => closeBenefitPlan(
benefitPlan,
formatMessageWithValues(intl, 'socialProtection', 'benefitPlan.delete.mutationLabel', {
id: benefitPlan?.id,
}),
);

const openDeleteBenefitPlanConfirmDialog = () => {
setConfirmedAction(() => deleteBenefitPlanCallback);
coreConfirm(
Expand All @@ -158,6 +167,17 @@ function BenefitPlanPage({
);
};

const openStopBenefitPlanConfirmDialog = () => {
setConfirmedAction(() => stopBenefitPlanCallback);
coreConfirm(
formatMessageWithValues(intl, 'socialProtection', 'benefitPlan.suspend.confirm.title', {
code: benefitPlan?.code,
name: benefitPlan?.name,
}),
formatMessage(intl, 'socialProtection', 'benefitPlan.suspend.confirm.message'),
);
};

const getBenefitPlanPanels = () => {
const panels = [];
if (benefitPlan?.id && benefitPlan?.beneficiaryDataSchema) {
Expand All @@ -174,6 +194,10 @@ function BenefitPlanPage({
doIt: openDeleteBenefitPlanConfirmDialog,
icon: <DeleteIcon />,
tooltip: formatMessage(intl, 'socialProtection', 'deleteButtonTooltip'),
}, {
doIt: openStopBenefitPlanConfirmDialog,
icon: <PauseIcon />,
tooltip: formatMessage(intl, 'socialProtection', 'stopButtonTooltip'),
},
];

Expand Down Expand Up @@ -231,6 +255,7 @@ const mapDispatchToProps = (dispatch) => bindActionCreators({
fetchBenefitPlan,
clearBenefitPlan,
deleteBenefitPlan,
closeBenefitPlan,
updateBenefitPlan,
coreConfirm,
clearConfirm,
Expand Down
1 change: 1 addition & 0 deletions src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const ACTION_TYPE = {
GET_BENEFIT_PLAN: 'BENEFIT_PLAN_BENEFIT_PLAN',
CREATE_BENEFIT_PLAN: 'BENEFIT_PLAN_CREATE_BENEFIT_PLAN',
DELETE_BENEFIT_PLAN: 'BENEFIT_PLAN_DELETE_BENEFIT_PLAN',
CLOSE_BENEFIT_PLAN: 'BENEFIT_PLAN_CLOSE_BENEFIT_PLAN',
UPDATE_BENEFIT_PLAN: 'BENEFIT_PLAN_UPDATE_BENEFIT_PLAN',
BENEFIT_PLAN_CODE_FIELDS_VALIDATION: 'BENEFIT_PLAN_CODE_FIELDS_VALIDATION',
BENEFIT_PLAN_NAME_FIELDS_VALIDATION: 'BENEFIT_PLAN_NAME_FIELDS_VALIDATION',
Expand Down
4 changes: 4 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
{
"socialProtection.benefitPlan.delete.confirm.title": "Delete benefit plan {code} {name}",
"socialProtection.benefitPlan.delete.confirm.message": "Are you sure you want to delete the benefit plan?",
"socialProtection.benefitPlan.suspend.confirm.title": "Suspend benefit plan {code} {name}",
"socialProtection.benefitPlan.suspend.confirm.message": "Are you sure you want to suspend the benefit plan?",
"socialProtection.benefitPlan.delete.mutationLabel": "Delete benefit plan {id}",
"socialProtection.benefitPlan.update.mutationLabel": "Update benefit plan {id}",
"socialProtection.benefitPlan.create.mutationLabel": "Create benefit plan {id}",
"socialProtection.downloadBeneficiaries.mutationLabel": "Download beneficiaries",
"socialProtection.benefitPlan.editButtonTooltip": "Edit",
"socialProtection.benefitPlan.deleteButtonTooltip": "Delete",
"socialProtection.benefitPlan.stopButtonTooltip": "Suspend",
"socialProtection.stopButtonTooltip": "Suspend",
"socialProtection.benefitPlan.searcherResultsTitle": "{benefitPlansTotalCount} Benefit Plans",
"socialProtection.beneficiaries.searcherResultsTitle": "{beneficiariesTotalCount} Beneficiaries",
"socialProtection.beneficiaries.members.searcherResultsTitle": "{individualsTotalCount} Individuals Found",
Expand Down

0 comments on commit 8286877

Please sign in to comment.