Skip to content

Commit

Permalink
temp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
devinleighsmith committed Nov 20, 2023
1 parent 5ca8e92 commit 9cfa05c
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ export interface ICompensationRequisitionTrayContainerProps {
compensationRequisitionId?: number;
onClose: () => void;
View: React.FunctionComponent<React.PropsWithChildren<CompensationRequisitionTrayViewProps>>;
onUpdate: () => void;
}

export const CompensationRequisitionTrayContainer: React.FunctionComponent<
React.PropsWithChildren<ICompensationRequisitionTrayContainerProps>
> = ({ compensationRequisitionId, onClose, View }) => {
> = ({ compensationRequisitionId, onClose, View, onUpdate }) => {
const { getSystemConstant } = useSystemConstants();
const { file, project, setProject, setProjectLoading, setStaleFile, setStaleLastUpdatedBy } =
const { file, project, setProject, setProjectLoading, setStaleLastUpdatedBy } =
useContext(SideBarContext);

const [editMode, setEditMode] = useState(false);
Expand Down Expand Up @@ -87,7 +88,7 @@ export const CompensationRequisitionTrayContainer: React.FunctionComponent<
onUpdate={() => {
fetchCompensationReq();
setStaleLastUpdatedBy(true);
setStaleFile(true);
onUpdate();
}}
></View>
) : null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import axios, { AxiosError } from 'axios';
import React, { useCallback, useContext } from 'react';
import React, { useCallback, useContext, useEffect } from 'react';

Check warning on line 2 in source/frontend/src/features/mapSideBar/acquisition/tabs/compensation/list/CompensationListContainer.tsx

View workflow job for this annotation

GitHub Actions / build-frontend

'useEffect' is defined but never used
import { toast } from 'react-toastify';

import { FileTypes } from '@/constants';
import { PopoutContext } from '@/features/mapSideBar/context/popoutContext';
import { SideBarContext } from '@/features/mapSideBar/context/sidebarContext';
import CompensationRequisitionRouter from '@/features/mapSideBar/router/CompensationRequisitionRouter';
import { useAcquisitionProvider } from '@/hooks/repositories/useAcquisitionProvider';
import { useCompensationRequisitionRepository } from '@/hooks/repositories/useRequisitionCompensationRepository';
import { getDeleteModalProps, useModalContext } from '@/hooks/useModalContext';
Expand Down Expand Up @@ -44,6 +46,10 @@ export const CompensationListContainer: React.FunctionComponent<
await getAcquisitionCompensationRequisitions(fileId);
}, [getAcquisitionCompensationRequisitions, fileId]);

const { setRouterComponent, popoutUpdated } = useContext(PopoutContext);

setRouterComponent(CompensationRequisitionRouter);

const onUpdateTotalCompensation = async (
totalAllowableCompensation: number | null,
): Promise<number | null> => {
Expand Down Expand Up @@ -121,10 +127,10 @@ export const CompensationListContainer: React.FunctionComponent<
};

React.useEffect(() => {
if (compensations === undefined || staleFile) {
if (compensations === undefined || popoutUpdated) {
fetchData();
}
}, [fetchData, staleFile, compensations]);
}, [fetchData, popoutUpdated, compensations]);

return (
<View
Expand Down
57 changes: 57 additions & 0 deletions source/frontend/src/features/mapSideBar/context/popoutContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import * as React from 'react';
import { useState } from 'react';

export interface IPopoutContext {
showActionBar: boolean;
setShowActionBar: (showActionBar: boolean) => void;
RouterComponent: React.FunctionComponent<IMapSidebarPopoutRouterProps> | null;
setRouterComponent: (
routerComponent: React.FunctionComponent<IMapSidebarPopoutRouterProps>,
) => void;
popoutUpdated: boolean;
setPopoutUpdated: (popoutUpdated: boolean) => void;
}

export interface IMapSidebarPopoutRouterProps {
setShowActionBar: (showActionBar: boolean) => void;
onUpdate: () => void;
}

export const PopoutContext = React.createContext<IPopoutContext>({
showActionBar: false,
setShowActionBar: (showActionBar: boolean) => {
throw Error('setShowActionBar function not defined');
},
RouterComponent: null,
setRouterComponent: (routerComponent: React.FunctionComponent<IMapSidebarPopoutRouterProps>) => {
throw Error('setRouterComponent function not defined');
},
popoutUpdated: false,
setPopoutUpdated: (popoutUpdated: boolean) => {
throw Error('setPopoutUpdated function not defined');
},
});

export const PopoutContextProvider = (props: {
children: React.ReactChild | React.ReactChild[] | React.ReactNode;
}) => {
const [showActionBar, setShowActionBar] = useState(false);
const [popoutUpdated, setPopoutUpdated] = useState(false);
const [RouterComponent, setRouterComponent] =
useState<React.FunctionComponent<IMapSidebarPopoutRouterProps> | null>(null);

return (
<PopoutContext.Provider
value={{
showActionBar: showActionBar,
setShowActionBar: setShowActionBar,
RouterComponent: RouterComponent,
setRouterComponent: setRouterComponent,
popoutUpdated: popoutUpdated,
setPopoutUpdated: setPopoutUpdated,
}}
>
{props.children}
</PopoutContext.Provider>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ import AppRoute from '@/utils/AppRoute';

import { CompensationRequisitionTrayContainer } from '../acquisition/tabs/compensation/CompensationRequisitionTrayContainer';
import { CompensationRequisitionTrayView } from '../acquisition/tabs/compensation/CompensationRequisitionTrayView';

interface ICompensationRequisitionRouterProps {
setShowActionBar: (show: boolean) => void;
}
import { IMapSidebarPopoutRouterProps } from '../context/popoutContext';

export const CompensationRequisitionRouter: React.FunctionComponent<
React.PropsWithChildren<ICompensationRequisitionRouterProps>
React.PropsWithChildren<IMapSidebarPopoutRouterProps>
> = React.memo(props => {
const location = useLocation();
const history = useHistory();
Expand Down Expand Up @@ -45,6 +42,7 @@ export const CompensationRequisitionRouter: React.FunctionComponent<
compensationRequisitionId={Number(match.params.id)}
onClose={onClose}
View={CompensationRequisitionTrayView}
onUpdate={props.onUpdate}
/>
)}
claim={Claims.COMPENSATION_REQUISITION_VIEW}
Expand Down
31 changes: 31 additions & 0 deletions source/frontend/src/features/mapSideBar/router/MapRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import queryString from 'query-string';
import { memo, useEffect, useMemo } from 'react';
import { matchPath, Switch, useHistory, useLocation } from 'react-router-dom';

import { ReactComponent as RealEstateAgent } from '@/assets/images/real-estate-agent.svg';
import { SideBarType } from '@/components/common/mapFSM/machineDefinition/types';
import { useMapStateMachine } from '@/components/common/mapFSM/MapStateMachineContext';
import Claims from '@/constants/claims';
Expand All @@ -13,12 +14,17 @@ import AppRoute from '@/utils/AppRoute';
import AcquisitionContainer from '../acquisition/AcquisitionContainer';
import AcquisitionView from '../acquisition/AcquisitionView';
import AddAcquisitionContainer from '../acquisition/add/AddAcquisitionContainer';
import AcquisitionHeader from '../acquisition/common/AcquisitionHeader';
import LeaseContainer from '../lease/LeaseContainer';
import AddProjectContainer from '../project/add/AddProjectContainer';
import ProjectContainer from '../project/ProjectContainer';
import ProjectContainerView from '../project/ProjectContainerView';
import AddResearchContainer from '../research/add/AddResearchContainer';
import ResearchContainer from '../research/ResearchContainer';
import MapContentContainer from '../shared/MapContentContainer';
import MapContentView from '../shared/MapContentView';
import SidebarFooter from '../shared/SidebarFooter';
import CompensationRequisitionRouter from './CompensationRequisitionRouter';

interface IMapRouterProps {}

Expand Down Expand Up @@ -162,6 +168,31 @@ export const MapRouter: React.FunctionComponent<IMapRouterProps> = memo(props =>
key={'Acquisition'}
title={'Acquisition File'}
/>
<AppRoute
path={`/mapview/sidebar/new_acq/:id`}
customRender={({ match }) => (
<MapContentContainer
Header={AcquisitionHeader}
Footer={SidebarFooter}
PopupRouter={CompensationRequisitionRouter}
View={MapContentView}
onClose={onClose}
title={'Acquisition File'}
icon={
<RealEstateAgent
title="Acquisition file Icon"
width="2.6rem"
height="2.6rem"
fill="currentColor"
className="mr-2"
/>
}
/>
)}
claim={Claims.ACQUISITION_VIEW}
key={'new_acq'}
title={'Acquisition File'}
/>
<AppRoute
path={`/mapview/sidebar/property/:propertyId`}
customRender={({ match }) => (
Expand Down
114 changes: 114 additions & 0 deletions source/frontend/src/features/mapSideBar/shared/MapContentContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { FormikProps } from 'formik';
import * as React from 'react';
import { useCallback, useRef, useState } from 'react';
import { useHistory, useLocation, useRouteMatch } from 'react-router-dom';

import { useQuery } from '@/hooks/use-query';
import { Api_LastUpdatedBy } from '@/models/api/File';

import { IMapSidebarPopoutRouterProps } from '../context/popoutContext';
import { IMapContentViewProps } from './MapContentView';
import { ISidebarFooterProps } from './SidebarFooter';

interface IMapContentContainerProps {
View: React.FunctionComponent<React.PropsWithChildren<IMapContentViewProps>>;
Header: React.FunctionComponent<React.PropsWithChildren<IHeaderContainerProps>>;
Footer: React.FunctionComponent<ISidebarFooterProps>;
PopupRouter: React.FunctionComponent<React.PropsWithChildren<IMapSidebarPopoutRouterProps>>;
onClose: (() => void) | undefined;
title: React.ReactNode;
icon: React.ReactNode | React.FunctionComponent<React.PropsWithChildren<unknown>>;
}

export interface IHeaderContainerProps {
lastUpdatedBy: Api_LastUpdatedBy | null;
onClose: (() => void) | undefined;
}

export interface IBodyContainerProps {
formikRef: React.RefObject<FormikProps<any>>;
}

export interface IFooterContainerProps {
formikRef: React.RefObject<FormikProps<any>>;
onSave: () => Promise<void>;
onCancel: () => void;
}

export const MapContentContainer: React.FunctionComponent<
React.PropsWithChildren<IMapContentContainerProps>
> = ({ View, Header, Footer, PopupRouter, title, icon, onClose, ...props }) => {
const formikRef = useRef<FormikProps<any>>(null);
const [isValid, setIsValid] = useState<boolean>(true);
const [showConfirmModal, setShowConfirmModal] = useState<boolean>(false);

Check warning on line 43 in source/frontend/src/features/mapSideBar/shared/MapContentContainer.tsx

View workflow job for this annotation

GitHub Actions / build-frontend

'showConfirmModal' is assigned a value but never used

const location = useLocation();

Check warning on line 45 in source/frontend/src/features/mapSideBar/shared/MapContentContainer.tsx

View workflow job for this annotation

GitHub Actions / build-frontend

'location' is assigned a value but never used
const history = useHistory();
const match = useRouteMatch();

Check warning on line 47 in source/frontend/src/features/mapSideBar/shared/MapContentContainer.tsx

View workflow job for this annotation

GitHub Actions / build-frontend

'match' is assigned a value but never used
const query = useQuery();
const isEditing = query.get('edit') === 'true';

const setIsEditing = (value: boolean) => {
if (value) {
query.set('edit', value.toString());
} else {
query.delete('edit');
}
history.push({ search: query.toString() });
};

const handleSaveClick = async () => {
await formikRef?.current?.validateForm();
if (!formikRef?.current?.isValid) {
setIsValid(false);
} else {
setIsValid(true);
}

if (formikRef !== undefined) {
formikRef.current?.setSubmitting(true);
formikRef.current?.submitForm();
}
};

const handleCancelClick = () => {
if (formikRef !== undefined) {
if (formikRef.current?.dirty) {
setShowConfirmModal(true);
} else {
handleCancelConfirm();
}
} else {
handleCancelConfirm();
}
};

const handleCancelConfirm = () => {
if (formikRef !== undefined) {
formikRef.current?.resetForm();
}
setShowConfirmModal(false);
setIsEditing(false);
};

const close = useCallback(() => onClose && onClose(), [onClose]);

return (
<View
title={title}
icon={icon}
Header={Header}
Footer={Footer}
formikRef={formikRef}
isEditing={isEditing}
onCancel={handleCancelClick}
onClose={close}
onSave={handleSaveClick}
isFormValid={isValid}
>
{props.children}
</View>
);
};

export default MapContentContainer;
51 changes: 51 additions & 0 deletions source/frontend/src/features/mapSideBar/shared/MapContentView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { FormikProps } from 'formik';
import * as React from 'react';
import { useContext } from 'react';

import { SideBarContext } from '../context/sidebarContext';
import MapSideBarLayout from '../layout/MapSideBarLayout';
import { IHeaderContainerProps } from './MapContentContainer';
import { ISidebarFooterProps } from './SidebarFooter';

export interface IMapContentViewProps {
title: React.ReactNode;
Header: React.FunctionComponent<React.PropsWithChildren<IHeaderContainerProps>>;
Footer: React.FunctionComponent<React.PropsWithChildren<ISidebarFooterProps>>;
icon: React.ReactNode | React.FunctionComponent<React.PropsWithChildren<unknown>>;
isEditing: boolean;
formikRef: React.RefObject<FormikProps<any>>;
isFormValid: boolean;
onClose: (() => void) | undefined;
onSave: () => Promise<void>;
onCancel: () => void;
}

export const MapContentView: React.FunctionComponent<IMapContentViewProps> = ({
Header,
Footer,
title,
icon,
isEditing,
formikRef,
isFormValid,
onClose,
onCancel,
onSave,
}) => {
const { file, lastUpdatedBy } = useContext(SideBarContext);

Check warning on line 35 in source/frontend/src/features/mapSideBar/shared/MapContentView.tsx

View workflow job for this annotation

GitHub Actions / build-frontend

'file' is assigned a value but never used

return (
<MapSideBarLayout
title={title}
icon={icon}
header={Header && <Header lastUpdatedBy={lastUpdatedBy} onClose={onClose} />}
footer={
isEditing && (
<Footer onCancel={onCancel} onSave={onSave} displayRequiredFieldError={isFormValid} />
)
}
></MapSideBarLayout>
);
};

export default MapContentView;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styled from 'styled-components';

import { Button } from '@/components/common/buttons/Button';

interface ISidebarFooterProps {
export interface ISidebarFooterProps {
isOkDisabled?: boolean;
onSave: () => void;
showEdit?: boolean;
Expand Down
Loading

0 comments on commit 9cfa05c

Please sign in to comment.