diff --git a/.changeset/rotten-lions-chew.md b/.changeset/rotten-lions-chew.md new file mode 100644 index 00000000000..7f013398c93 --- /dev/null +++ b/.changeset/rotten-lions-chew.md @@ -0,0 +1,5 @@ +--- +"@graphcommerce/magento-customer": patch +--- + +feat(GCOM-1318): dismiss login page and go back to previous page asap when logging in diff --git a/packages/magento-customer/hooks/useAccountSignInUpForm.tsx b/packages/magento-customer/hooks/useAccountSignInUpForm.tsx index 41907a85776..a27dd625235 100644 --- a/packages/magento-customer/hooks/useAccountSignInUpForm.tsx +++ b/packages/magento-customer/hooks/useAccountSignInUpForm.tsx @@ -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 @@ -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 } }