Merged in fix/pathname-login (pull request #530)

fix: create useLazyPathname hook

Approved-by: Michael Zetterberg
This commit is contained in:
Christel Westerberg
2024-08-28 14:16:28 +00:00
committed by Michael Zetterberg
2 changed files with 23 additions and 3 deletions

View File

@@ -1,6 +1,5 @@
"use client"
import { usePathname } from "next/navigation"
import { PropsWithChildren, useEffect } from "react"
import { login } from "@/constants/routes/handleAuth"
@@ -8,6 +7,7 @@ import { login } from "@/constants/routes/handleAuth"
import Link from "@/components/TempDesignSystem/Link"
import { LinkProps } from "@/components/TempDesignSystem/Link/link"
import useLang from "@/hooks/useLang"
import { useLazyPathname } from "@/hooks/useLazyPathname"
import { trackLoginClick } from "@/utils/tracking"
import { TrackingPosition } from "@/types/components/tracking"
@@ -25,7 +25,11 @@ export default function LoginButton({
color?: LinkProps["color"]
}>) {
const lang = useLang()
const pathName = usePathname()
const pathName = useLazyPathname()
const href = pathName
? `${login[lang]}?redirectTo=${encodeURIComponent(pathName)}`
: login[lang]
useEffect(() => {
document
@@ -43,7 +47,7 @@ export default function LoginButton({
className={className}
id={trackingId}
color={color}
href={`${login[lang]}?redirectTo=${encodeURIComponent(pathName)}`}
href={href}
prefetch={false}
>
{children}