Skip to content

Commit

Permalink
allow paste and replace non active plans (#1142)
Browse files Browse the repository at this point in the history
Co-authored-by: Brijesh <[email protected]>
  • Loading branch information
brijesh-amin and Brijesh authored Jul 5, 2024
1 parent 0e508fa commit 04f9c53
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/components/selectRangeUsePlanPage/CopyPlanMenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import React from 'react';
import { MenuItem } from '@material-ui/core';
import { saveDataInLocalStorage } from '../../utils';

const CopyPlanMenuItem = ({ planId, agreementId, menuText }) => {
const CopyPlanMenuItem = ({ planId, agreementId, menuText, handleClose }) => {
return (
<MenuItem
onClick={async (e) => {
saveDataInLocalStorage('copyPlanInfo', { planId, agreementId });
e.stopPropagation();
handleClose(e);
}}
>
{menuText}
Expand Down
32 changes: 24 additions & 8 deletions src/components/selectRangeUsePlanPage/PastePlanMenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ import {
getDataFromLocalStorage,
} from '../../utils';
import useConfirm from '../../providers/ConfrimationModalProvider';
import { PLAN_PASTE_CONFIRMATION_QUESTION } from '../../constants/strings';
import {
PLAN_PASTE_CONFIRMATION_QUESTION,
PLAN_PASTE_REPLACE_CONFIRMATION_QUESTION,
} from '../../constants/strings';
import * as API from '../../constants/api';
import { useToast } from '../../providers/ToastProvider';
import { useHistory } from 'react-router-dom';

const PastePlanMenuItem = ({ agreementId, menuText, currentPage }) => {
const PastePlanMenuItem = ({
agreement,
menuText,
currentPage,
isReplacingPlan,
}) => {
const history = useHistory();
const { errorToast } = useToast();
const confirm = useConfirm();
Expand All @@ -27,16 +35,24 @@ const PastePlanMenuItem = ({ agreementId, menuText, currentPage }) => {
return;
}
const choice = await confirm({
contentText: PLAN_PASTE_CONFIRMATION_QUESTION(
sourcePlan.agreementId,
agreementId,
),
contentText: isReplacingPlan
? PLAN_PASTE_REPLACE_CONFIRMATION_QUESTION(
sourcePlan.agreementId,
agreement.id,
)
: PLAN_PASTE_CONFIRMATION_QUESTION(
sourcePlan.agreementId,
agreement.id,
),
});
if (choice) {
try {
const response = await axios.put(
API.COPY_PLAN(sourcePlan.planId, agreementId),
{},
API.COPY_PLAN(sourcePlan.planId),
{
agreementId: agreement.id,
destinationPlanId: agreement.plan?.id,
},
getAuthHeaderConfig(),
);
history.push({
Expand Down
17 changes: 16 additions & 1 deletion src/components/selectRangeUsePlanPage/PlanActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import CreateReplacementPlan from './CreateReplacementPlan';
import NewPlanMenuItem from './NewPlanMenuItem';
import ViewPlanMenuItem from './ViewPlanMenuItem';
import PastePlanMenuItem from './PastePlanMenuItem';
import { getDataFromLocalStorage, isPlanActive } from '../../utils';

export default function PlanActions({
agreement,
Expand Down Expand Up @@ -76,6 +77,7 @@ export default function PlanActions({
)}
{planId && (
<CopyPlanMenuItem
handleClose={handleClose}
planId={planId}
agreementId={agreement.id}
menuText={'Copy'}
Expand All @@ -86,11 +88,24 @@ export default function PlanActions({
)}
{canCreatePlan && !planId && (
<PastePlanMenuItem
agreementId={agreement.id}
isReplacingPlan={false}
agreement={agreement}
menuText={'Paste'}
currentPage={currentPage}
/>
)}
{canCreatePlan &&
planId &&
!isPlanActive(agreement.plan) &&
getDataFromLocalStorage('copyPlanInfo')?.agreementId !==
agreement.id && (
<PastePlanMenuItem
isReplacingPlan={true}
agreement={agreement}
menuText={'Paste & Replace'}
currentPage={currentPage}
/>
)}
{[
PLAN_EXTENSION_STATUS.AGREEMENT_HOLDER_REJECTED,
PLAN_EXTENSION_STATUS.STAFF_REJECTED,
Expand Down
3 changes: 1 addition & 2 deletions src/constants/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ export const REPLACEMENT_PLAN = (planId) =>
export const REJECT_VOTE = (planId) => `/v1/plan/${planId}/extension/reject`;
export const UPDATE_CONFIRMATION = (planId, confirmationId) =>
`/v1/plan/${planId}/confirmation/${confirmationId}`;
export const COPY_PLAN = (planId, agreementId) =>
`/v1/plan/${planId}/copy/${agreementId}`;
export const COPY_PLAN = (planId) => `/v1/plan/${planId}/copy`;
export const DISCARD_AMENDMENT = (planId) =>
`v1/plan/${planId}/discard-amendment`;

Expand Down
6 changes: 6 additions & 0 deletions src/constants/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,3 +351,9 @@ export const PLAN_PASTE_CONFIRMATION_QUESTION = (
destinationAgreement,
) =>
`Are you sure you want to paste content of ${sourceAgreement} and create a new plan ${destinationAgreement}?`;

export const PLAN_PASTE_REPLACE_CONFIRMATION_QUESTION = (
sourceAgreement,
destinationAgreement,
) =>
`Are you sure you want to paste content of ${sourceAgreement} and replace the plan ${destinationAgreement}? Please note - This will delete the current plan.`;

0 comments on commit 04f9c53

Please sign in to comment.