-
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: Moving Consent under Additional Details tab
1 parent
05121ea
commit 96c350a
Showing
6 changed files
with
134 additions
and
37 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
...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,85 @@ | ||
import React, { createContext, useContext, useState } 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, | ||
); | ||
|
||
return ( | ||
<AdditionalDetailsContext.Provider | ||
value={{ | ||
initialConsentMessage, | ||
setInitialConsentMessage, | ||
consentMessage, | ||
setConsentMessage, | ||
handleSaveAdditional, | ||
updatingAdditional, | ||
hasBeenOpened, | ||
}} | ||
> | ||
{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
22 changes: 5 additions & 17 deletions
22
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
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