fix(SW-2463): scroll to payment error

This commit is contained in:
Christian Andolf
2025-04-30 10:52:53 +02:00
committed by Michael Zetterberg
parent 8b32abbefc
commit 0cd2e9c89f
3 changed files with 31 additions and 10 deletions

View File

@@ -1,5 +1,6 @@
"use client"
import { useSearchParams } from "next/navigation"
import { type PropsWithChildren, useEffect, useRef } from "react"
import { useIntl } from "react-intl"
@@ -16,6 +17,8 @@ import styles from "./bottomSheet.module.css"
export default function SummaryBottomSheet({ children }: PropsWithChildren) {
const intl = useIntl()
const scrollY = useRef(0)
const searchParams = useSearchParams()
const errorCode = searchParams.get("errorCode")
const { isSummaryOpen, toggleSummaryOpen, totalPrice, isSubmittingDisabled } =
useEnterDetailsStore((state) => ({
@@ -33,18 +36,21 @@ export default function SummaryBottomSheet({ children }: PropsWithChildren) {
} else {
document.body.style.position = ""
document.body.style.top = ""
window.scrollTo({
top: scrollY.current,
left: 0,
behavior: "instant",
})
if (!errorCode) {
window.scrollTo({
top: scrollY.current,
left: 0,
behavior: "instant",
})
}
}
return () => {
document.body.style.position = ""
document.body.style.top = ""
}
}, [isSummaryOpen])
}, [isSummaryOpen, errorCode])
return (
<div className={styles.wrapper} data-open={isSummaryOpen}>