Merged in chore/remove-unused-code (pull request #2229)
Remove unused code * Remove unused scandic-web files * Remove unused exports Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -1,63 +0,0 @@
|
||||
"use client"
|
||||
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation"
|
||||
import { useCallback, useEffect } from "react"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { BookingErrorCodeEnum } from "@/constants/booking"
|
||||
import { useEnterDetailsStore } from "@/stores/enter-details"
|
||||
|
||||
import { toast } from "@/components/TempDesignSystem/Toasts"
|
||||
|
||||
export function usePaymentFailedToast() {
|
||||
const updateSearchParams = useEnterDetailsStore(
|
||||
(state) => state.actions.updateSeachParamString
|
||||
)
|
||||
const intl = useIntl()
|
||||
const searchParams = useSearchParams()
|
||||
const pathname = usePathname()
|
||||
const router = useRouter()
|
||||
|
||||
const getErrorMessage = useCallback(
|
||||
(errorCode: string | null) => {
|
||||
switch (errorCode) {
|
||||
case BookingErrorCodeEnum.TransactionCancelled:
|
||||
return intl.formatMessage({
|
||||
defaultMessage: "You have now cancelled your payment.",
|
||||
})
|
||||
default:
|
||||
return intl.formatMessage({
|
||||
defaultMessage:
|
||||
"We had an issue processing your booking. Please try again. No charges have been made.",
|
||||
})
|
||||
}
|
||||
},
|
||||
[intl]
|
||||
)
|
||||
|
||||
const errorCode = searchParams.get("errorCode")
|
||||
const errorMessage = getErrorMessage(errorCode)
|
||||
|
||||
useEffect(() => {
|
||||
if (!errorCode) return
|
||||
|
||||
const toastType =
|
||||
errorCode === BookingErrorCodeEnum.TransactionCancelled
|
||||
? "warning"
|
||||
: "error"
|
||||
toast[toastType](errorMessage)
|
||||
|
||||
const queryParams = new URLSearchParams(searchParams.toString())
|
||||
queryParams.delete("errorCode")
|
||||
|
||||
updateSearchParams(queryParams.toString())
|
||||
router.push(`${pathname}?${queryParams.toString()}`)
|
||||
}, [
|
||||
searchParams,
|
||||
pathname,
|
||||
errorCode,
|
||||
errorMessage,
|
||||
router,
|
||||
updateSearchParams,
|
||||
])
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
import { useCallback, useEffect } from "react"
|
||||
import { useMediaQuery } from "usehooks-ts"
|
||||
|
||||
import type { StepEnum } from "@/types/enums/step"
|
||||
|
||||
export default function useScrollToActiveSection(
|
||||
step: StepEnum,
|
||||
steps: StepEnum[],
|
||||
isActive: boolean
|
||||
) {
|
||||
const isMobile = useMediaQuery("(max-width: 767px)")
|
||||
|
||||
const handleScroll = useCallback(() => {
|
||||
if (!isMobile) {
|
||||
return
|
||||
}
|
||||
|
||||
const currentElement = document.querySelector<HTMLElement>(
|
||||
`[data-step="${step}"]`
|
||||
)
|
||||
const prevOpenElement =
|
||||
document.querySelector<HTMLElement>(`[data-open="true"]`)
|
||||
|
||||
const currentStepIndex = steps.indexOf(step)
|
||||
const prevStep = prevOpenElement
|
||||
? (Number(prevOpenElement?.dataset.step) as StepEnum)
|
||||
: null
|
||||
const prevStepIndex = prevStep ? steps.indexOf(prevStep) : null
|
||||
|
||||
if (currentElement) {
|
||||
const BOOKING_WIDGET_OFFSET = 71
|
||||
|
||||
const prevElementContent = prevOpenElement?.querySelector("header + div")
|
||||
|
||||
let collapsedSpace = 0
|
||||
if (
|
||||
prevElementContent &&
|
||||
prevStepIndex &&
|
||||
prevStepIndex < currentStepIndex
|
||||
) {
|
||||
collapsedSpace = prevElementContent.clientHeight
|
||||
}
|
||||
|
||||
const currentElementTop =
|
||||
currentElement.getBoundingClientRect().top + window.scrollY
|
||||
|
||||
const scrollTarget = Math.round(
|
||||
currentElementTop - BOOKING_WIDGET_OFFSET - collapsedSpace
|
||||
)
|
||||
|
||||
window.scrollTo({
|
||||
top: scrollTarget,
|
||||
behavior: "smooth",
|
||||
})
|
||||
}
|
||||
}, [step, steps, isMobile])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isActive) return
|
||||
handleScroll()
|
||||
}, [isActive, handleScroll])
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
"use client"
|
||||
import { useEffect } from "react"
|
||||
|
||||
export function useHandleKeyPress(callback: (event: KeyboardEvent) => void) {
|
||||
useEffect(() => {
|
||||
window.addEventListener("keydown", callback)
|
||||
return () => {
|
||||
window.removeEventListener("keydown", callback)
|
||||
}
|
||||
}, [callback])
|
||||
}
|
||||
Reference in New Issue
Block a user