mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React from 'react'
2
3import * as Dialog from '#/components/Dialog'
4import {DialogControlProps} from '#/components/Dialog'
5import {VerifyEmailIntentDialog} from '#/components/intents/VerifyEmailIntentDialog'
6
7interface Context {
8 verifyEmailDialogControl: DialogControlProps
9 verifyEmailState: {code: string} | undefined
10 setVerifyEmailState: (state: {code: string} | undefined) => void
11}
12
13const Context = React.createContext({} as Context)
14export const useIntentDialogs = () => React.useContext(Context)
15
16export function Provider({children}: {children: React.ReactNode}) {
17 const verifyEmailDialogControl = Dialog.useDialogControl()
18 const [verifyEmailState, setVerifyEmailState] = React.useState<
19 {code: string} | undefined
20 >()
21
22 const value = React.useMemo(
23 () => ({
24 verifyEmailDialogControl,
25 verifyEmailState,
26 setVerifyEmailState,
27 }),
28 [verifyEmailDialogControl, verifyEmailState, setVerifyEmailState],
29 )
30
31 return (
32 <Context.Provider value={value}>
33 {children}
34 <VerifyEmailIntentDialog />
35 </Context.Provider>
36 )
37}