diff --git a/.changeset/rotten-lions-chew.md b/.changeset/rotten-lions-chew.md new file mode 100644 index 0000000000..df0e168353 --- /dev/null +++ b/.changeset/rotten-lions-chew.md @@ -0,0 +1,5 @@ +--- +'@graphcommerce/magento-customer': patch +--- + +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 41907a8577..cedef10e84 100644 --- a/packages/magento-customer/hooks/useAccountSignInUpForm.tsx +++ b/packages/magento-customer/hooks/useAccountSignInUpForm.tsx @@ -1,3 +1,4 @@ +import { usePageContext } from '@graphcommerce/framer-next-pages' import { useQuery } from '@graphcommerce/graphql' import { useFormGqlQuery } from '@graphcommerce/react-hook-form' import { useRouter } from 'next/router' @@ -73,5 +74,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 } } diff --git a/packages/magento-customer/package.json b/packages/magento-customer/package.json index 09456dfc61..53f478cd6c 100644 --- a/packages/magento-customer/package.json +++ b/packages/magento-customer/package.json @@ -14,6 +14,7 @@ "peerDependencies": { "@graphcommerce/ecommerce-ui": "^8.0.0-canary.87", "@graphcommerce/eslint-config-pwa": "^8.0.0-canary.87", + "@graphcommerce/framer-next-pages": "^8.0.0-canary.87", "@graphcommerce/framer-utils": "^8.0.0-canary.87", "@graphcommerce/graphql": "^8.0.0-canary.87", "@graphcommerce/graphql-mesh": "^8.0.0-canary.87", diff --git a/yarn.lock b/yarn.lock index e8650e3186..42d9436482 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3591,6 +3591,7 @@ __metadata: peerDependencies: "@graphcommerce/ecommerce-ui": ^8.0.0-canary.87 "@graphcommerce/eslint-config-pwa": ^8.0.0-canary.87 + "@graphcommerce/framer-next-pages": ^8.0.0-canary.87 "@graphcommerce/framer-utils": ^8.0.0-canary.87 "@graphcommerce/graphql": ^8.0.0-canary.87 "@graphcommerce/graphql-mesh": ^8.0.0-canary.87