Created
March 18, 2023 15:49
-
-
Save florianwalther-private/005569f7debfc3f58c143ed66f622cc6 to your computer and use it in GitHub Desktop.
AuthModalsProvider
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
interface AuthModalsContext { | |
showLoginModal: () => void, | |
showSignUpModal: () => void, | |
showResetPasswordModal: () => void, | |
} | |
export const AuthModalsContext = createContext<AuthModalsContext>({ | |
showLoginModal: () => { throw new Error("AuthModalContext not implemented") }, | |
showSignUpModal: () => { throw new Error("AuthModalContext not implemented") }, | |
showResetPasswordModal: () => { throw new Error("AuthModalContext not implemented") }, | |
}); | |
interface AuthModalProps { | |
children: ReactNode, | |
} | |
export default function AuthModalsProvider({ children }: AuthModalProps) { | |
const [showLoginModal, setShowLoginModal] = useState(false); | |
const [showSignUpModal, setShowSignUpModal] = useState(false); | |
const [showResetPasswordModal, setShowResetPasswordModal] = useState(false); | |
const [value] = useState({ | |
showLoginModal: () => setShowLoginModal(true), | |
showSignUpModal: () => setShowSignUpModal(true), | |
showResetPasswordModal: () => setShowResetPasswordModal(true), | |
}); | |
return ( | |
<AuthModalsContext.Provider value={value}> | |
{children} | |
{showLoginModal && | |
<LoginModal | |
onDismiss={() => setShowLoginModal(false)} | |
onSignUpInsteadClicked={() => { | |
setShowLoginModal(false); | |
setShowSignUpModal(true); | |
}} | |
onForgotPasswordClicked={() => { | |
setShowLoginModal(false); | |
setShowResetPasswordModal(true); | |
}} | |
/> | |
} | |
{showSignUpModal && | |
<SignUpModal | |
onDismiss={() => setShowSignUpModal(false)} | |
onLoginInsteadClicked={() => { | |
setShowSignUpModal(false); | |
setShowLoginModal(true); | |
}} | |
/> | |
} | |
{showResetPasswordModal && | |
<ResetPasswordModal | |
onDismiss={() => setShowResetPasswordModal(false)} | |
onSignUpClicked={() => { | |
setShowResetPasswordModal(false); | |
setShowSignUpModal(true); | |
}} | |
/> | |
} | |
</AuthModalsContext.Provider> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment