2024-01-26 04:23:48 -05:00
|
|
|
import { createContext, FC, useContext, useState } from 'react'
|
2021-03-18 05:52:36 -04:00
|
|
|
|
2024-01-26 04:23:48 -05:00
|
|
|
const FileTreeCreateFormContext = createContext<
|
|
|
|
{ valid: boolean; setValid: (value: boolean) => void } | undefined
|
|
|
|
>(undefined)
|
2021-03-18 05:52:36 -04:00
|
|
|
|
|
|
|
export const useFileTreeCreateForm = () => {
|
|
|
|
const context = useContext(FileTreeCreateFormContext)
|
|
|
|
|
|
|
|
if (!context) {
|
|
|
|
throw new Error(
|
|
|
|
'useFileTreeCreateForm is only available inside FileTreeCreateFormProvider'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return context
|
|
|
|
}
|
|
|
|
|
2024-01-26 04:23:48 -05:00
|
|
|
const FileTreeCreateFormProvider: FC = ({ children }) => {
|
2021-03-18 05:52:36 -04:00
|
|
|
// is the form valid
|
|
|
|
const [valid, setValid] = useState(false)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<FileTreeCreateFormContext.Provider value={{ valid, setValid }}>
|
|
|
|
{children}
|
|
|
|
</FileTreeCreateFormContext.Provider>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-01-26 04:23:48 -05:00
|
|
|
export default FileTreeCreateFormProvider
|