about summary refs log tree commit diff
path: root/src/components/PolicyUpdateOverlay/context.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/PolicyUpdateOverlay/context.tsx')
-rw-r--r--src/components/PolicyUpdateOverlay/context.tsx32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/components/PolicyUpdateOverlay/context.tsx b/src/components/PolicyUpdateOverlay/context.tsx
new file mode 100644
index 000000000..68ae7bbd8
--- /dev/null
+++ b/src/components/PolicyUpdateOverlay/context.tsx
@@ -0,0 +1,32 @@
+import {createContext, type ReactNode, useContext} from 'react'
+
+import {Provider as PortalProvider} from '#/components/PolicyUpdateOverlay/Portal'
+import {
+  type PolicyUpdateState,
+  usePolicyUpdateState,
+} from '#/components/PolicyUpdateOverlay/usePolicyUpdateState'
+
+const Context = createContext<PolicyUpdateState>({
+  completed: true,
+  complete: () => {},
+})
+
+export function usePolicyUpdateStateContext() {
+  const context = useContext(Context)
+  if (!context) {
+    throw new Error(
+      'usePolicyUpdateStateContext must be used within a PolicyUpdateProvider',
+    )
+  }
+  return context
+}
+
+export function Provider({children}: {children?: ReactNode}) {
+  const state = usePolicyUpdateState()
+
+  return (
+    <PortalProvider>
+      <Context.Provider value={state}>{children}</Context.Provider>
+    </PortalProvider>
+  )
+}