Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor unverified & guest modal #248

Open
pattruong opened this issue Apr 13, 2021 · 0 comments
Open

Refactor unverified & guest modal #248

pattruong opened this issue Apr 13, 2021 · 0 comments
Labels
dx Developer Experience: improves our ability to work or collaborate refactor Clean up and/or improve past implementations

Comments

@pattruong
Copy link
Member

pattruong commented Apr 13, 2021

Overview

const triggerUnverifiedModal = useCallback(() => {
  open()
  setModalAlert(false)
  setContent('unverified')
}, [open, setModalAlert, setContent])

Currently unverified modal and guest modal is commonly used but takes up a lot of boilerplate

Boilerplate

const {
  isSuccess,
  isPending,
  open,
  content,
  setContent,
  setModalAlert,
  reset,
} = useModal()

const triggerUnverifiedModal = useCallback(() => {
  open()
  setModalAlert(false)
  setContent('unverified')
}, [open, setModalAlert, setContent])

const goToCreate = () => {
  if (isVerified) {
    history.push(`${url}/new`)
  } else if (isAuthenticated) {
    triggerUnverifiedModal()
  } else {
    open()
    setContent('login', 'You must be logged in to create a recipe')
  }
}

useEffect(() => {
  if (!isPending && isSuccess && content === 'login' && isVerified) {
    // need to clear modal settings so that going back
    // to this page doesn't retrigger this effect
    reset()
    history.push(`${url}/new`)
  }
}, [isPending, isSuccess, content, isVerified, url, history, reset])

Changes we want

  • make it so you can just get const { triggerUnverifiedModal, triggerGuestModal } = useModal() and not have to reconstruct the functions each time
  • investigate if we can simplify the isSuccess status to not have to do so many low level checks — content check & reset()
  • Example of complex isSuccess status check
useEffect(() => {
  if (!isPending && isSuccess && content === 'login' && isVerified) {
    // need to clear modal settings so that going back
    // to this page doesn't retrigger this effect
    reset()
    history.push(`${url}/new`)
  }
}, [isPending, isSuccess, content, isVerified, url, history, reset])
@pattruong pattruong added dx Developer Experience: improves our ability to work or collaborate refactor Clean up and/or improve past implementations labels Apr 13, 2021
@pattruong pattruong added this to the alpha v0.3 milestone Apr 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dx Developer Experience: improves our ability to work or collaborate refactor Clean up and/or improve past implementations
Projects
None yet
Development

No branches or pull requests

1 participant