-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ [open-formulieren/open-forms#4929] Refactor cosign <Routes> to not…
… require any props Split the state up in the components used to render each route/path, which allows localizing the state. For the synchronization between routes, React context is used.
- Loading branch information
1 parent
1c2f8e6
commit a902951
Showing
4 changed files
with
59 additions
and
72 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import {useContext, useState} from 'react'; | ||
import {useNavigate} from 'react-router-dom'; | ||
|
||
import {ConfigContext} from 'Context'; | ||
import {destroy} from 'api'; | ||
import {CosignSummary} from 'components/Summary'; | ||
import useFormContext from 'hooks/useFormContext'; | ||
|
||
import {useCosignContext} from './Context'; | ||
|
||
/** | ||
* Fetch the submission summary data and display it, together with the controls to | ||
* confirm the submission and buttons to log out. | ||
*/ | ||
const CosignCheck = () => { | ||
const navigate = useNavigate(); | ||
const config = useContext(ConfigContext); | ||
const form = useFormContext(); | ||
const {onCosignComplete} = useCosignContext(); | ||
|
||
const [submission, setSubmission] = useState(null); | ||
const [summaryData, setSummaryData] = useState([]); | ||
|
||
const onDestroySession = async () => { | ||
await destroy(`${config.baseUrl}authentication/${submission.id}/session`); | ||
setSubmission(null); | ||
setSummaryData([]); | ||
navigate('/'); | ||
}; | ||
|
||
return ( | ||
<CosignSummary | ||
form={form} | ||
submission={submission} | ||
summaryData={summaryData} | ||
onSubmissionLoaded={submission => setSubmission(submission)} | ||
onDataLoaded={({summaryData}) => setSummaryData(summaryData)} | ||
onCosignComplete={onCosignComplete} | ||
onDestroySession={onDestroySession} | ||
/> | ||
); | ||
}; | ||
|
||
CosignCheck.propTypes = {}; | ||
|
||
export default CosignCheck; |
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