-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deseng 448: Engagement Edit Screen Reorder/Redesign (#2352)
* 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
1 parent
ec35a55
commit 70f74ab
Showing
12 changed files
with
165 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...ponents/engagement/form/EngagementFormTabs/AdditionalDetails/AdditionalDetailsContext.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
}; |
41 changes: 41 additions & 0 deletions
41
.../components/engagement/form/EngagementFormTabs/AdditionalDetails/AdditionalTabContent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...rmTabs/Settings/EngagementInformation.tsx → ...ditionalDetails/EngagementInformation.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
met-web/src/components/engagement/form/EngagementFormTabs/AdditionalDetails/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 0 additions & 25 deletions
25
met-web/src/components/engagement/form/EngagementFormTabs/Links/index.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
8 changes: 4 additions & 4 deletions
8
met-web/src/components/engagement/form/EngagementFormTabs/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters