Skip to content

Commit 0c9084f

Browse files
committed
feat: scroll to top on thankyou page
1 parent c130feb commit 0c9084f

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

components/composite/StepComplete/index.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import PaymentSource from "@commercelayer/react-components/payment_source/Paymen
22
import PaymentSourceBrandIcon from "@commercelayer/react-components/payment_source/PaymentSourceBrandIcon"
33
import PaymentSourceBrandName from "@commercelayer/react-components/payment_source/PaymentSourceBrandName"
44
import PaymentSourceDetail from "@commercelayer/react-components/payment_source/PaymentSourceDetail"
5-
import { useContext, useEffect, useState } from "react"
5+
import { useContext, useEffect, useRef } from "react"
66
import { Trans, useTranslation } from "react-i18next"
77

88
import { OrderSummary } from "components/composite/OrderSummary"
@@ -59,13 +59,22 @@ export const StepComplete: React.FC<Props> = ({
5959
const { t } = useTranslation()
6060

6161
const ctx = useContext(AppContext)
62+
const topRef = useRef<HTMLDivElement | null>(null)
6263

6364
useEffect(() => {
6465
if (thankyouPageUrl != null) {
6566
window.location.href = thankyouPageUrl
6667
}
6768
}, [thankyouPageUrl])
6869

70+
useEffect(() => {
71+
if (topRef.current != null) {
72+
topRef.current.scrollIntoView({
73+
behavior: "smooth",
74+
})
75+
}
76+
}, [topRef.current])
77+
6978
if (!ctx) return null
7079

7180
const handleClick = () => {
@@ -77,7 +86,7 @@ export const StepComplete: React.FC<Props> = ({
7786
return (
7887
thankyouPageUrl == null && (
7988
<Base>
80-
<Top>
89+
<Top ref={topRef}>
8190
<Wrapper>
8291
<Logo
8392
logoUrl={logoUrl}

0 commit comments

Comments
 (0)