diff --git a/src/components/selectRangeUsePlanPage/CopyPlanMenuItem.js b/src/components/selectRangeUsePlanPage/CopyPlanMenuItem.js index 222293e7..42ff49ee 100644 --- a/src/components/selectRangeUsePlanPage/CopyPlanMenuItem.js +++ b/src/components/selectRangeUsePlanPage/CopyPlanMenuItem.js @@ -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 ( { saveDataInLocalStorage('copyPlanInfo', { planId, agreementId }); e.stopPropagation(); + handleClose(e); }} > {menuText} diff --git a/src/components/selectRangeUsePlanPage/PastePlanMenuItem.js b/src/components/selectRangeUsePlanPage/PastePlanMenuItem.js index c53a4658..9339ba04 100644 --- a/src/components/selectRangeUsePlanPage/PastePlanMenuItem.js +++ b/src/components/selectRangeUsePlanPage/PastePlanMenuItem.js @@ -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(); @@ -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({ diff --git a/src/components/selectRangeUsePlanPage/PlanActions.js b/src/components/selectRangeUsePlanPage/PlanActions.js index 4de12285..5d26c29f 100644 --- a/src/components/selectRangeUsePlanPage/PlanActions.js +++ b/src/components/selectRangeUsePlanPage/PlanActions.js @@ -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, @@ -76,6 +77,7 @@ export default function PlanActions({ )} {planId && ( )} + {canCreatePlan && + planId && + !isPlanActive(agreement.plan) && + getDataFromLocalStorage('copyPlanInfo')?.agreementId !== + agreement.id && ( + + )} {[ PLAN_EXTENSION_STATUS.AGREEMENT_HOLDER_REJECTED, PLAN_EXTENSION_STATUS.STAFF_REJECTED, diff --git a/src/constants/api.js b/src/constants/api.js index 1a4cab3b..be70eb0d 100644 --- a/src/constants/api.js +++ b/src/constants/api.js @@ -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`; diff --git a/src/constants/strings.js b/src/constants/strings.js index 8a2ae296..928a4520 100644 --- a/src/constants/strings.js +++ b/src/constants/strings.js @@ -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.`;