Skip to content

Commit

Permalink
Dismiss login page and go back to previous page asap when logging in
Browse files Browse the repository at this point in the history
  • Loading branch information
paales committed Jan 15, 2024
1 parent 1d87862 commit 2eca9da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/rotten-lions-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphcommerce/magento-customer": patch
---

feat(GCOM-1318): dismiss login page and go back to previous page asap when logging in
8 changes: 8 additions & 0 deletions packages/magento-customer/hooks/useAccountSignInUpForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
IsEmailAvailableQueryVariables,
} from './IsEmailAvailable.gql'
import { useCustomerSession } from './useCustomerSession'
import { useGo, usePageContext } from '@graphcommerce/framer-next-pages'
import { useShowBack } from '@graphcommerce/next-ui/Layout/components/LayoutHeaderBack'

export type UseFormIsEmailAvailableProps = {
onSubmitted?: (data: { email: string }) => void
Expand Down Expand Up @@ -73,5 +75,11 @@ export function useAccountSignInUpForm(props: UseFormIsEmailAvailableProps = {})
if (isValid && isSubmitSuccessful) mode = hasAccount ? 'signin' : 'signup'
}

const { closeSteps = 0 } = usePageContext() ?? {}
useEffect(() => {
// Automatically close the overlay if the user is signed in
if (mode === 'signedin' && closeSteps > 0) window.history.go(closeSteps * -1)
}, [mode, closeSteps])

return { mode, form, submit }
}

0 comments on commit 2eca9da

Please sign in to comment.