-
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] Move analytics tool config load…
…ing into own component Instead of hooking this up to the Form component, we can instead wrap the context provider and let it fetch the config by itself. This way, we slim down the Form component, and get a small performance boost since loading the analytics tool config is not immediately relevant. Since context is used, only when the config loading is resolved will the consumers be re-rendered, which at this point is mostly the AbortButton component. We deliberately don't show a loader when the config is being retrieved as this would block the entire page without good reason and we have a faster time-to-interact this way.
- Loading branch information
1 parent
f530400
commit 0f1e874
Showing
5 changed files
with
53 additions
and
31 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
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,40 @@ | ||
import PropTypes from 'prop-types'; | ||
import React, {useContext} from 'react'; | ||
import {useIntl} from 'react-intl'; | ||
import {useAsync} from 'react-use'; | ||
|
||
import {ConfigContext} from 'Context'; | ||
import {get} from 'api'; | ||
|
||
const AnalyticsToolsConfigContext = React.createContext({ | ||
govmetricSourceIdFormFinished: '', | ||
govmetricSourceIdFormAborted: '', | ||
govmetricSecureGuidFormFinished: '', | ||
govmetricSecureGuidFormAborted: '', | ||
enableGovmetricAnalytics: false, | ||
}); | ||
|
||
AnalyticsToolsConfigContext.displayName = 'AnalyticsToolsConfigContext'; | ||
|
||
const AnalyticsToolsConfigProvider = ({children}) => { | ||
const {locale} = useIntl(); | ||
const {baseUrl} = useContext(ConfigContext); | ||
|
||
const {value} = useAsync(async () => { | ||
return await get(`${baseUrl}analytics/analytics-tools-config-info`); | ||
}, [locale]); | ||
|
||
return ( | ||
<AnalyticsToolsConfigContext.Provider value={value}> | ||
{children} | ||
</AnalyticsToolsConfigContext.Provider> | ||
); | ||
}; | ||
|
||
AnalyticsToolsConfigProvider.propTypes = { | ||
children: PropTypes.node, | ||
}; | ||
|
||
export const useAnalyticsToolsConfig = () => useContext(AnalyticsToolsConfigContext); | ||
|
||
export default AnalyticsToolsConfigProvider; |
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