Created
February 20, 2020 05:28
-
-
Save jsmanifest/45f19ccb4404ab40d625ed7806cb6955 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import React from 'react' | |
import { useSelector, useDispatch } from 'react-redux' | |
import { Modal } from 'components/common' | |
import SigninSignup from './modalComponents/SigninSignup' | |
import { toggle } from './appModalSlice' | |
import { selectModal } from './selectors' | |
import * as modalComponents from './modalComponents' | |
function AppModal() { | |
const modal = useSelector(selectModal) | |
const dispatchRedux = useDispatch() | |
const isLoggedIn = true | |
function closeModal() { | |
if (isLoggedIn) { | |
dispatchRedux(toggle({ opened: false, context: '' })) | |
} | |
} | |
let Component: React.ElementType<any> = modalComponents[modal.context] | |
if (!Component) { | |
if (!isLoggedIn) { | |
Component = SigninSignup | |
} else { | |
Component = 'div' | |
} | |
} | |
return ( | |
<Modal opened={modal.opened || !isLoggedIn} onClose={closeModal}> | |
<> | |
<Component {...modal} closeModal={closeModal} /> | |
</> | |
</Modal> | |
) | |
} | |
export default AppModal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment