Skip to content

Commit

Permalink
Deseng 448: Engagement Edit Screen Reorder/Redesign (#2352)
Browse files Browse the repository at this point in the history
* DEDENG-448 : Re-arranging tabs in edit engagement form

* DEDENG-448 : Re-arranging tabs in edit engagement form- Deleting unused files

* Updated Changelog

* DESENG-448: Moving Consent under Additional Details tab

* Fixing a Sonarcube suggestion to use usememo
  • Loading branch information
ratheesh-aot authored Jan 11, 2024
1 parent ec35a55 commit 70f74ab
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 63 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
## January 10, 2024

- **Task** Custom Consent per Engagement [🎟️DESENG-456](https://apps.itsm.gov.bc.ca/jira/browse/DESENG-456)
- **Task** Engagement Edit Screen Reorder/Redesign [🎟️DESENG-448](https://apps.itsm.gov.bc.ca/jira/browse/DESENG-448)
- Added new tab Addional Details and moved metadata inside that
- Moved public url section inside Settings tab
- Changed Engagement Details to Engagement Core
- Removed Links tab

## January 9, 2024

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import React, { createContext, useContext, useState, useMemo } from 'react';
import { ActionContext } from '../../ActionContext';
import { EngagementTabsContext } from '../EngagementTabsContext';
import { useAppDispatch } from 'hooks';
import { openNotification } from 'services/notificationService/notificationSlice';
import { SubmissionStatus } from 'constants/engagementStatus';

export interface AdditionalDetailsContextState {
initialConsentMessage: string;
setInitialConsentMessage: (richContent: string) => void;
consentMessage: string;
setConsentMessage: (richContent: string) => void;
handleSaveAdditional: () => void;
updatingAdditional: boolean;
hasBeenOpened: boolean;
}

export const AdditionalDetailsContext = createContext<AdditionalDetailsContextState>({
initialConsentMessage: '',
setInitialConsentMessage: () => {
return;
},
consentMessage: '',
setConsentMessage: () => {
return;
},
handleSaveAdditional: () => {
return;
},
updatingAdditional: false,
hasBeenOpened: false,
});

export const AdditionalDetailsContextProvider = ({ children }: { children: React.ReactNode }) => {
const { handleUpdateEngagementRequest, savedEngagement } = useContext(ActionContext);
const { engagementFormData } = useContext(EngagementTabsContext);
const dispatch = useAppDispatch();

const [updatingAdditional, setUpdatingAdditional] = useState(false);
const [consentMessage, setConsentMessage] = useState(savedEngagement?.consent_message || '');
const [initialConsentMessage, setInitialConsentMessage] = useState(savedEngagement?.consent_message || '');

const handleUpdateEngagementAdditional = () => {
return handleUpdateEngagementRequest({
...engagementFormData,
consent_message: consentMessage,
});
};

const handleSaveAdditional = async () => {
try {
if (!savedEngagement.id) {
dispatch(openNotification({ text: 'Must create engagement first', severity: 'error' }));
return;
}
setUpdatingAdditional(true);
await handleUpdateEngagementAdditional();
setUpdatingAdditional(false);
dispatch(openNotification({ text: 'Engagement additional details saved', severity: 'success' }));
} catch (error) {
setUpdatingAdditional(false);
dispatch(openNotification({ text: 'Error saving engagement additional details', severity: 'error' }));
}
};

const hasBeenOpened = [SubmissionStatus.Closed, SubmissionStatus.Open].includes(
savedEngagement.engagement_status.id,
);

const contextValue = useMemo(
() => ({
initialConsentMessage,
setInitialConsentMessage,
consentMessage,
setConsentMessage,
handleSaveAdditional,
updatingAdditional,
hasBeenOpened,
}),
[initialConsentMessage, consentMessage, updatingAdditional, hasBeenOpened],
);

return <AdditionalDetailsContext.Provider value={contextValue}>{children}</AdditionalDetailsContext.Provider>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React, { useContext } from 'react';
import { Divider, Grid } from '@mui/material';
import { MetPaper, PrimaryButton } from 'components/common';
import ConsentMessage from './ConsentMessage';
import EngagementInformation from './EngagementInformation';

import { AdditionalDetailsContext } from './AdditionalDetailsContext';

const AdditionalTabContent = () => {
const { handleSaveAdditional, updatingAdditional } = useContext(AdditionalDetailsContext);

return (
<MetPaper elevation={1}>
<Grid
container
direction="row"
justifyContent="flex-start"
alignItems="flex-start"
spacing={2}
sx={{ padding: '2em' }}
>
<Grid item xs={12}>
<EngagementInformation />
</Grid>
<Grid item xs={12}>
<Divider />
</Grid>
<Grid item xs={12}>
<ConsentMessage />
</Grid>
<Grid item xs={12}>
<PrimaryButton loading={updatingAdditional} onClick={handleSaveAdditional}>
Save
</PrimaryButton>
</Grid>
</Grid>
</MetPaper>
);
};

export default AdditionalTabContent;
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { useContext } from 'react';
import { Box, Grid } from '@mui/material';
import { MetHeader4 } from 'components/common';
import { EngagementSettingsContext } from './EngagementSettingsContext';
import { AdditionalDetailsContext } from './AdditionalDetailsContext';
import RichTextEditor from 'components/common/RichTextEditor';

const ConsentMessage = () => {
const { consentMessage, setConsentMessage } = useContext(EngagementSettingsContext);
const { initialConsentMessage, setConsentMessage } = useContext(AdditionalDetailsContext);

const handleRichContentChange = (newState: string) => {
setConsentMessage(newState);
Expand All @@ -20,7 +20,7 @@ const ConsentMessage = () => {
<Box display="flex" flexDirection="column" justifyContent="space-between">
<RichTextEditor
handleEditorStateChange={handleRichContentChange}
initialRawEditorState={consentMessage || ''}
initialRawEditorState={initialConsentMessage || ''}
/>
</Box>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import React, { useContext } from 'react';
import { Grid, MenuItem, TextField, Select, SelectChangeEvent } from '@mui/material';
import { MetLabel, MetHeader4 } from 'components/common';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import AdditionalTabContent from './AdditionalTabContent';
import { AdditionalDetailsContextProvider } from './AdditionalDetailsContext';

const EngagementAdditionalDetails = () => {
return (
<AdditionalDetailsContextProvider>
<AdditionalTabContent />
</AdditionalDetailsContextProvider>
);
};

export default EngagementAdditionalDetails;
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import EngagementForm from './EngagementForm';
import { MetTab, MetTabList, MetTabPanel } from '../StyledTabComponents';
import { EngagementFormTabValues, ENGAGEMENT_FORM_TABS } from './constants';
import EngagementUserManagement from './UserManagement/EngagementUserManagement';
import EngagementLinks from './Links';
import EngagementAdditionalDetails from './AdditionalDetails';
import EngagementSettings from './Settings';

const FormTabs = () => {
const [value, setValue] = React.useState<EngagementFormTabValues>(ENGAGEMENT_FORM_TABS.DETAILS);
const [value, setValue] = React.useState<EngagementFormTabValues>(ENGAGEMENT_FORM_TABS.CORE);

return (
<Box sx={{ width: '100%', typography: 'body1' }}>
Expand All @@ -24,24 +24,24 @@ const FormTabs = () => {
}}
variant="scrollable"
>
<MetTab label="Engagement Details" value={ENGAGEMENT_FORM_TABS.DETAILS} />
<MetTab label="Engagement Core" value={ENGAGEMENT_FORM_TABS.CORE} />
<MetTab label="Additional Details" value={ENGAGEMENT_FORM_TABS.ADDITIONAL} />
<MetTab label="User Management" value={ENGAGEMENT_FORM_TABS.USER_MANAGEMENT} />
<MetTab label="Settings" value={ENGAGEMENT_FORM_TABS.SETTINGS} />
<MetTab label="URL (links)" value={ENGAGEMENT_FORM_TABS.LINKS} />
</MetTabList>
</Box>
<MetTabPanel value={ENGAGEMENT_FORM_TABS.DETAILS}>
<MetTabPanel value={ENGAGEMENT_FORM_TABS.CORE}>
<EngagementForm />
</MetTabPanel>
<MetTabPanel value={ENGAGEMENT_FORM_TABS.ADDITIONAL}>
<EngagementAdditionalDetails />
</MetTabPanel>
<MetTabPanel value={ENGAGEMENT_FORM_TABS.USER_MANAGEMENT}>
<EngagementUserManagement />
</MetTabPanel>
<MetTabPanel value={ENGAGEMENT_FORM_TABS.SETTINGS}>
<EngagementSettings />
</MetTabPanel>
<MetTabPanel value={ENGAGEMENT_FORM_TABS.LINKS}>
<EngagementLinks />
</MetTabPanel>
</TabContext>
</Box>
);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { SubmissionStatus } from 'constants/engagementStatus';
export interface EngagementSettingsContextState {
isInternal: boolean;
setIsInternal: (isInternal: boolean) => void;
consentMessage: string;
setConsentMessage: (richContent: string) => void;
sendReport: boolean;
setSendReport: (sendReport: boolean) => void;
handleSaveSettings: () => void;
Expand All @@ -22,10 +20,6 @@ export const EngagementSettingsContext = createContext<EngagementSettingsContext
setIsInternal: () => {
return;
},
consentMessage: '',
setConsentMessage: () => {
return;
},
sendReport: false,
setSendReport: () => {
return;
Expand All @@ -47,7 +41,6 @@ export const EngagementSettingsContextProvider = ({ children }: { children: Reac
const [isInternal, setIsInternal] = useState(savedIsInternal);
const [sendReport, setSendReport] = useState(Boolean(settings.send_report));
const [updatingSettings, setUpdatingSettings] = useState(false);
const [consentMessage, setConsentMessage] = useState(savedEngagement?.consent_message || '');

const handleUpdateEngagementMetadata = () => {
return handleUpdateEngagementMetadataRequest({
Expand All @@ -60,7 +53,6 @@ export const EngagementSettingsContextProvider = ({ children }: { children: Reac
return handleUpdateEngagementRequest({
...engagementFormData,
is_internal: isInternal,
consent_message: consentMessage,
});
};

Expand Down Expand Up @@ -97,8 +89,6 @@ export const EngagementSettingsContextProvider = ({ children }: { children: Reac
value={{
isInternal,
sendReport,
consentMessage,
setConsentMessage,
setIsInternal,
setSendReport,
handleSaveSettings,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React, { useContext } from 'react';
import { Divider, Grid } from '@mui/material';
import { MetPaper, PrimaryButton } from 'components/common';
import EngagementInformation from './EngagementInformation';
import ConsentMessage from './ConsentMessage';
import InternalEngagement from './InternalEngagement';
import SendReport from './SendReport';
import { EngagementSettingsContext } from './EngagementSettingsContext';
import { PublicUrls } from './PublicUrls';

const EngagementSettingsForm = () => {
const { handleSaveSettings, updatingSettings } = useContext(EngagementSettingsContext);
Expand All @@ -20,12 +19,6 @@ const EngagementSettingsForm = () => {
spacing={2}
sx={{ padding: '2em' }}
>
<Grid item xs={12}>
<EngagementInformation />
</Grid>
<Grid item xs={12}>
<Divider />
</Grid>
<Grid item xs={12}>
<InternalEngagement />
</Grid>
Expand All @@ -36,15 +29,15 @@ const EngagementSettingsForm = () => {
<SendReport />
</Grid>
<Grid item xs={12}>
<Divider />
<PrimaryButton loading={updatingSettings} onClick={handleSaveSettings}>
Save
</PrimaryButton>
</Grid>
<Grid item xs={12}>
<ConsentMessage />
<Divider />
</Grid>
<Grid item xs={12}>
<PrimaryButton loading={updatingSettings} onClick={handleSaveSettings}>
Save
</PrimaryButton>
<PublicUrls />
</Grid>
</Grid>
</MetPaper>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export type EngagementFormTabValues = 'details' | 'settings' | 'User Management' | 'links';
export type EngagementFormTabValues = 'core' | 'settings' | 'User Management' | 'additional';

export const ENGAGEMENT_FORM_TABS: { [x: string]: EngagementFormTabValues } = {
DETAILS: 'details',
SETTINGS: 'settings',
CORE: 'core',
ADDITIONAL: 'additional',
USER_MANAGEMENT: 'User Management',
LINKS: 'links',
SETTINGS: 'settings',
};

export const ENGAGEMENT_UPLOADER_HEIGHT = '360px';
Expand Down

0 comments on commit 70f74ab

Please sign in to comment.