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

Replacement plan creation UI changes #1127

Merged
merged 5 commits into from
Jun 10, 2024
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
29 changes: 17 additions & 12 deletions src/api/plan.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import {
getAuthHeaderConfig,
findStatusWithCode,
isUserAgrologist,
canUserAddAttachments
} from '../utils'
import * as API from '../constants/api'
import RUPSchema from '../components/rangeUsePlanPage/schema'
import { getNetworkStatus } from '../utils/helper/network'
import { deleteFromQueue } from './delete'
canUserAddAttachments,
} from '../utils';
import * as API from '../constants/api';
import RUPSchema from '../components/rangeUsePlanPage/schema';
import { getNetworkStatus } from '../utils/helper/network';
import { deleteFromQueue } from './delete';
import {
saveGrazingSchedules,
saveInvasivePlantChecklist,
Expand Down Expand Up @@ -109,13 +109,13 @@ export const savePlan = async (plan, user = {}) => {
}),
);

await saveGrazingSchedules(planId, grazingSchedules, newPastures)
await saveInvasivePlantChecklist(planId, invasivePlantChecklist)
await saveManagementConsiderations(planId, managementConsiderations)
await saveMinisterIssues(planId, ministerIssues, newPastures)
await saveAdditionalRequirements(planId, additionalRequirements)
await saveGrazingSchedules(planId, grazingSchedules, newPastures);
await saveInvasivePlantChecklist(planId, invasivePlantChecklist);
await saveManagementConsiderations(planId, managementConsiderations);
await saveMinisterIssues(planId, ministerIssues, newPastures);
await saveAdditionalRequirements(planId, additionalRequirements);
if (isUserAgrologist(user) && canUserAddAttachments(plan, user)) {
await saveAttachments(planId, files)
await saveAttachments(planId, files);
}

return planId;
Expand Down Expand Up @@ -247,6 +247,11 @@ export const updateStatus = async ({ planId, note, statusId }) => {
);
};

export const createReplacementPlan = async (planId) => {
return (await axios.put(API.REPLACEMENT_PLAN(planId), getAuthHeaderConfig()))
.data.replacementPlan;
};

export const updateConfirmation = async ({
user,
planId,
Expand Down
15 changes: 13 additions & 2 deletions src/components/common/Banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,26 @@ const defaultProps = {
noDefaultHeight: false,
};

const Banner = ({ header, content, style, noDefaultHeight, contentLine2 }) => (
const Banner = ({
header,
content,
style,
noDefaultHeight,
contentLine2,
isReplacementPlan,
}) => (
<div className="banner" style={style}>
<div
className={classnames('banner__container', {
'banner__container--no-default-height': noDefaultHeight,
banner__container__highlighted: isReplacementPlan,
})}
>
<div>
<h1 className="banner__header">{header}</h1>
<h1 className="banner__header">
{header}
{isReplacementPlan ? ' (Replacement Plan)' : ''}
</h1>
<div className="banner__content">{content}</div>
{contentLine2 && (
<>
Expand Down
2 changes: 0 additions & 2 deletions src/components/emailTemplatePage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ const EmailTemplatePage = () => {
<TextField
label="From Email"
variant="outlined"
fullWidth
value={selectedTemplate.fromEmail}
onChange={(event) =>
setSelectedTemplate({
Expand All @@ -124,7 +123,6 @@ const EmailTemplatePage = () => {
<TextField
label="Subject"
variant="outlined"
fullWidth
value={selectedTemplate.subject}
onChange={(event) => {
setSelectedTemplate({
Expand Down
1 change: 1 addition & 0 deletions src/components/rangeUsePlanPage/ActionBtns.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const ActionBtns = ({
...permissionsOptions,
};

console.log(permissions);
return (
<>
<div className="rup__actions__btns__buttons">
Expand Down
31 changes: 18 additions & 13 deletions src/components/rangeUsePlanPage/PlanForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import { Attachments, AttachmentsHeader } from './attachments';
import EditableProvider from '../../providers/EditableProvider';
import { isUUID } from 'uuid-v4';
import { useUser } from '../../providers/UserProvider';
import { canUserAttachMaps, canUserAddAttachments, canUserConsiderManagement, canUserAddAdditionalReqs } from '../../utils';
import {
canUserAttachMaps,
canUserAddAttachments,
canUserConsiderManagement,
canUserAddAdditionalReqs,
} from '../../utils';

const PlanForm = ({
plan,
Expand Down Expand Up @@ -98,26 +103,26 @@ const PlanForm = ({
<EditableProvider editable={canUserAddAttachments(plan, user)}>
<Element name={ELEMENT_ID.ATTACHMENTS} id={ELEMENT_ID.ATTACHMENTS}>
<AttachmentsHeader />
<Attachments
planId={plan.id}
attachments={plan.files}
propertyName="decisionAttachments"
label="Decision Material"
/>
<EditableProvider editable={canUserAttachMaps(plan, user)}>
<Attachments
planId={plan.id}
attachments={plan.files}
propertyName="decisionAttachments"
label="Decision Material"
/>
<Attachments
planId={plan.id}
attachments={plan.files}
propertyName="mapAttachments"
label="Map"
/>
<Attachments
planId={plan.id}
attachments={plan.files}
propertyName="otherAttachments"
label="Other"
/>
</EditableProvider>
<Attachments
planId={plan.id}
attachments={plan.files}
propertyName="otherAttachments"
label="Other"
/>
</Element>
</EditableProvider>
)}
Expand Down
1 change: 0 additions & 1 deletion src/components/rangeUsePlanPage/manageAgentsPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ const ManageAgentsPage = ({ match }) => {
{...params}
label="Select user"
variant="outlined"
fullWidth
className={classes.autocomplete}
/>
)}
Expand Down
10 changes: 8 additions & 2 deletions src/components/rangeUsePlanPage/pageForAH/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import PlanForm from '../PlanForm';
import { createAmendment, savePlan } from '../../../api';
import { canUserEditThisPlan, isPlanAmendment } from '../../../utils';
import NetworkStatus from '../../common/NetworkStatus';
import permissions from '../../../constants/permissions';

// Agreement Holder page
class PageForAH extends Component {
Expand Down Expand Up @@ -172,7 +173,7 @@ class PageForAH extends Component {
const { isSavingAsDraft, isSubmitting, isCreatingAmendment } = this.state;
const { openConfirmationModal, plan, user, clientAgreements } = this.props;
const { confirmations, status } = plan;

console.log(permissions + '****************************');
return (
<ActionBtns
permissions={{
Expand Down Expand Up @@ -265,7 +266,12 @@ class PageForAH extends Component {
fetchPlan={fetchPlan}
/>

<Banner noDefaultHeight header={bannerHeader} content={bannerContent} />
<Banner
noDefaultHeight
header={bannerHeader}
content={bannerContent}
isReplacementPlan={plan.replacementOf != null}
/>

<StickyHeader>
<div className="rup__actions__background">
Expand Down
7 changes: 6 additions & 1 deletion src/components/rangeUsePlanPage/pageForStaff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,12 @@ class PageForStaff extends Component {
content={strings.SUBMIT_PLAN_CONFIRM_CONTENT}
/>

<Banner header={bannerHeader} content={bannerContent} noDefaultHeight />
<Banner
header={bannerHeader}
content={bannerContent}
noDefaultHeight
isReplacementPlan={plan.replacementOf != null}
/>

<StickyHeader>
<div className="rup__actions__background">
Expand Down
23 changes: 23 additions & 0 deletions src/components/selectRangeUsePlanPage/CreateReplacementPlan.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useHistory } from 'react-router-dom';
import React from 'react';
import { MenuItem } from '@material-ui/core';
import { createReplacementPlan } from '../../api';
import { RANGE_USE_PLAN } from '../../constants/routes';

const CreateReplacementPlan = ({ planId }) => {
const history = useHistory();
return (
<MenuItem
onClick={async (e) => {
e.stopPropagation();
const replacementPlan = await createReplacementPlan(planId);
console.log(replacementPlan);
history.push(`${RANGE_USE_PLAN}/${replacementPlan.id}`);
}}
>
Create Replacement Plan
</MenuItem>
);
};

export default CreateReplacementPlan;
24 changes: 20 additions & 4 deletions src/components/selectRangeUsePlanPage/ExtensionColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ export default function ExtensionColumn({ user, currentPage, agreement }) {
return <div>Staff Rejected</div>;
case PLAN_EXTENSION_STATUS.DISTRICT_MANAGER_REJECTED:
return <div>District Manager Rejected</div>;
case PLAN_EXTENSION_STATUS.REPLACEMENT_PLAN_CREATED:
return <div>Replacement Plan Created</div>;
case PLAN_EXTENSION_STATUS.REPLACEMENT_PLAN_ACTIVE:
return <div>Active Replacement Plan</div>;
case PLAN_EXTENSION_STATUS.AWAITING_EXTENSION:
if (
agreement.plan?.extensionReceivedVotes ===
Expand Down Expand Up @@ -205,6 +209,7 @@ export default function ExtensionColumn({ user, currentPage, agreement }) {

const renderExtensionForStaff = (user, agreement) => {
if (isUserStaff(user)) {
console.log(agreement.plan?.extensionStatus);
switch (agreement.plan?.extensionStatus) {
case PLAN_EXTENSION_STATUS.AWAITING_VOTES:
if (
Expand Down Expand Up @@ -253,6 +258,10 @@ export default function ExtensionColumn({ user, currentPage, agreement }) {
return <div>District Manager Rejected</div>;
case PLAN_EXTENSION_STATUS.AWAITING_EXTENSION:
return <div>Awaiting Extension</div>;
case PLAN_EXTENSION_STATUS.REPLACEMENT_PLAN_CREATED:
return <div>Replacement Plan Created</div>;
case PLAN_EXTENSION_STATUS.REPLACEMENT_PLAN_ACTIVE:
return <div>Active Replacement Plan</div>;
case PLAN_EXTENSION_STATUS.EXTENDED:
return (
<div>
Expand Down Expand Up @@ -302,11 +311,14 @@ export default function ExtensionColumn({ user, currentPage, agreement }) {
} else {
if (
agreement.plan?.planExtensionRequests.filter((request) => {
return request.userId === user.id && request.requestedExtension;
}).length === 0
return (
request.userId === user.id &&
request.requestedExtension === true
);
}).length !== 0
)
return <>Rejected</>;
return <>Requested</>;
return <>Requested</>;
return <>-</>;
}
case PLAN_EXTENSION_STATUS.AGREEMENT_HOLDER_REJECTED:
return <div>Agreement Holder Rejected</div>;
Expand All @@ -316,6 +328,10 @@ export default function ExtensionColumn({ user, currentPage, agreement }) {
return <div>District Manager Rejected</div>;
case PLAN_EXTENSION_STATUS.AWAITING_EXTENSION:
return <div>Awaiting Extension</div>;
case PLAN_EXTENSION_STATUS.REPLACEMENT_PLAN_CREATED:
return <div>Replacement Plan Created</div>;
case PLAN_EXTENSION_STATUS.REPLACEMENT_PLAN_ACTIVE:
return <div>Active Replacement Plan</div>;
case PLAN_EXTENSION_STATUS.EXTENDED:
return (
<div>
Expand Down
1 change: 0 additions & 1 deletion src/components/selectRangeUsePlanPage/NewPlanButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const NewPlanButton = ({ agreement }) => {

return (
<Button
fullWidth
variant="contained"
disableElevation
color="primary"
Expand Down
62 changes: 28 additions & 34 deletions src/components/selectRangeUsePlanPage/PlanActions.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import React from 'react';
import { Button } from '@material-ui/core';
import ClickAwayListener from '@material-ui/core/ClickAwayListener';
import Grow from '@material-ui/core/Grow';
import MenuList from '@material-ui/core/MenuList';
import Paper from '@material-ui/core/Paper';
import Popper from '@material-ui/core/Popper';
import MenuItem from '@material-ui/core/MenuItem';
import MenuList from '@material-ui/core/MenuList';
import { Button } from '@material-ui/core';
import { RANGE_USE_PLAN } from '../../constants/routes';
import KeyboardArrowDown from '@material-ui/icons/KeyboardArrowDown';
import React from 'react';
import * as strings from '../../constants/strings';
import EditIcon from '@material-ui/icons/Edit';
import ViewIcon from '@material-ui/icons/Visibility';
import { Link } from 'react-router-dom';
import { PLAN_EXTENSION_STATUS } from '../../constants/variables';
import CreateReplacementPlan from './CreateReplacementPlan';
import NewPlanMenuItem from './NewPlanMenuItem';
import KeyboardArrowDown from '@material-ui/icons/KeyboardArrowDown';
import ViewPlanMenuItem from './ViewPlanMenuItem';

export default function PlanActions({
agreement,
Expand All @@ -35,7 +33,6 @@ export default function PlanActions({

setOpen(false);
};

return (
<div>
<Button
Expand Down Expand Up @@ -69,34 +66,31 @@ export default function PlanActions({
<ClickAwayListener onClickAway={handleClose}>
<MenuList autoFocusItem={open} id="menu-list-grow">
{planId && (
<MenuItem
fullWidth
variant="outlined"
component={Link}
to={{
pathname: `${RANGE_USE_PLAN}/${planId}`,
state: {
page: currentPage,
prevSearch: location.search,
},
}}
>
{canEdit ? (
<>
<EditIcon fontSize="small" />
{strings.EDIT}
</>
) : (
<>
<ViewIcon fontSize="small" />
{strings.VIEW}
</>
)}
</MenuItem>
<ViewPlanMenuItem
planId={planId}
currentPage={currentPage}
menuText={canEdit ? strings.EDIT : strings.VIEW}
/>
)}
{canCreatePlan && !planId && (
<NewPlanMenuItem agreement={agreement} />
)}
{[
PLAN_EXTENSION_STATUS.AGREEMENT_HOLDER_REJECTED,
PLAN_EXTENSION_STATUS.STAFF_REJECTED,
PLAN_EXTENSION_STATUS.DISTRICT_MANAGER_REJECTED,
].includes(agreement.plan?.extensionStatus) && (
<CreateReplacementPlan planId={planId} />
)}
{[PLAN_EXTENSION_STATUS.REPLACEMENT_PLAN_CREATED].includes(
agreement.plan?.extensionStatus,
) && (
<ViewPlanMenuItem
planId={agreement.plan?.replacementPlanId}
currentPage={currentPage}
menuText={'View Replacement Plan'}
/>
)}
</MenuList>
</ClickAwayListener>
</Paper>
Expand Down
Loading
Loading