diff --git a/services/web/frontend/js/features/outline/components/outline-pane.js b/services/web/frontend/js/features/outline/components/outline-pane.js index 741edd2e7b..ae27057d48 100644 --- a/services/web/frontend/js/features/outline/components/outline-pane.js +++ b/services/web/frontend/js/features/outline/components/outline-pane.js @@ -19,7 +19,9 @@ function OutlinePane({ }) { const { t } = useTranslation() - const { projectId } = useEditorContext() + const { projectId } = useEditorContext({ + projectId: PropTypes.string.isRequired + }) const storageKey = `file_outline.expanded.${projectId}` const [expanded, setExpanded] = useState(() => { diff --git a/services/web/frontend/js/features/preview/components/preview-error.js b/services/web/frontend/js/features/preview/components/preview-error.js index 365650e0ac..950ed5c2da 100644 --- a/services/web/frontend/js/features/preview/components/preview-error.js +++ b/services/web/frontend/js/features/preview/components/preview-error.js @@ -8,10 +8,15 @@ import { useEditorContext } from '../../../shared/context/editor-context' import { startFreeTrial } from '../../../main/account-upgrade' function PreviewError({ name }) { - const { isProjectOwner } = useEditorContext() + const { isProjectOwner } = useEditorContext({ + isProjectOwner: PropTypes.bool + }) const { exposedSettings: { enableSubscriptions } - } = useApplicationContext() + } = useApplicationContext({ + exposedSettings: PropTypes.shape({ enableSubscriptions: PropTypes.bool }) + .isRequired + }) const { t } = useTranslation() let errorTitle diff --git a/services/web/frontend/js/shared/context/application-context.js b/services/web/frontend/js/shared/context/application-context.js index 016474bf32..0993e3ca98 100644 --- a/services/web/frontend/js/shared/context/application-context.js +++ b/services/web/frontend/js/shared/context/application-context.js @@ -4,6 +4,17 @@ import ExposedSettings from '../../main/exposed-settings' export const ApplicationContext = createContext() +ApplicationContext.Provider.propTypes = { + value: PropTypes.shape({ + user: PropTypes.shape({ + id: PropTypes.string.isRequired + }), + exposedSettings: PropTypes.shape({ + enableSubscriptions: PropTypes.bool + }) + }) +} + export function ApplicationProvider({ children }) { const applicationContextValue = { user: window.user, @@ -20,7 +31,13 @@ ApplicationProvider.propTypes = { children: PropTypes.any } -export function useApplicationContext() { - const applicationContext = useContext(ApplicationContext) - return applicationContext +export function useApplicationContext(propTypes) { + const data = useContext(ApplicationContext) + PropTypes.checkPropTypes( + propTypes, + data, + 'data', + 'ApplicationContext.Provider' + ) + return data } diff --git a/services/web/frontend/js/shared/context/editor-context.js b/services/web/frontend/js/shared/context/editor-context.js index 73b4e0ca30..15f9ac6729 100644 --- a/services/web/frontend/js/shared/context/editor-context.js +++ b/services/web/frontend/js/shared/context/editor-context.js @@ -4,6 +4,19 @@ import usePersistedState from '../../infrastructure/persisted-state-hook' export const EditorContext = createContext() +EditorContext.Provider.propTypes = { + value: PropTypes.shape({ + cobranding: PropTypes.shape({ + logoImgUrl: PropTypes.string.isRequired, + brandVariationName: PropTypes.string.isRequired, + brandVariationHomeUrl: PropTypes.string.isRequired + }), + loading: PropTypes.bool, + projectId: PropTypes.string.isRequired, + isProjectOwner: PropTypes.bool + }) +} + export function EditorProvider({ children, loading, @@ -70,7 +83,8 @@ EditorProvider.propTypes = { setChatIsOpenAngular: PropTypes.func.isRequired } -export function useEditorContext() { - const editorContext = useContext(EditorContext) - return editorContext +export function useEditorContext(propTypes) { + const data = useContext(EditorContext) + PropTypes.checkPropTypes(propTypes, data, 'data', 'EditorContext.Provider') + return data } diff --git a/services/web/test/frontend/helpers/render-with-context.js b/services/web/test/frontend/helpers/render-with-context.js index a83057af94..b61e93aa83 100644 --- a/services/web/test/frontend/helpers/render-with-context.js +++ b/services/web/test/frontend/helpers/render-with-context.js @@ -7,7 +7,7 @@ import { ChatProvider } from '../../../frontend/js/features/chat/context/chat-co export function renderWithEditorContext( children, - { user = { id: '123abd' }, projectId } = {} + { user = { id: '123abd' }, projectId = 'project123' } = {} ) { window.user = user || window.user window.project_id = projectId != null ? projectId : window.project_id