Merge branch 'develop' into feature/tracking
This commit is contained in:
@@ -3,6 +3,7 @@ import NextLink from "next/link"
|
||||
import { usePathname, useSearchParams } from "next/navigation"
|
||||
import { useCallback, useMemo } from "react"
|
||||
|
||||
import { useCheckIfExternalLink } from "@/hooks/useCheckIfExternalLink"
|
||||
import { trackClick } from "@/utils/tracking"
|
||||
|
||||
import { linkVariants } from "./variants"
|
||||
@@ -46,22 +47,40 @@ export default function Link({
|
||||
})
|
||||
|
||||
const fullUrl = useMemo(() => {
|
||||
const search =
|
||||
keepSearchParams && searchParams.size ? `?${searchParams}` : ""
|
||||
return `${href}${search}`
|
||||
if (!keepSearchParams || !searchParams.size) return href
|
||||
|
||||
const delimiter = href.includes("?") ? "&" : "?"
|
||||
return `${href}${delimiter}${searchParams}`
|
||||
}, [href, searchParams, keepSearchParams])
|
||||
|
||||
// TODO: Remove this check (and hook) and only return <Link /> when current web is deleted
|
||||
const isExternal = useCheckIfExternalLink(href)
|
||||
|
||||
const trackClickById = useCallback(() => {
|
||||
if (trackingId) {
|
||||
trackClick(trackingId)
|
||||
}
|
||||
}, [trackingId])
|
||||
|
||||
return (
|
||||
const linkProps = {
|
||||
href: fullUrl,
|
||||
className: classNames,
|
||||
}
|
||||
|
||||
return isExternal ? (
|
||||
<a
|
||||
{...linkProps}
|
||||
{...props}
|
||||
onClick={(e) => {
|
||||
if (onClick) {
|
||||
onClick(e)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<NextLink
|
||||
scroll={scroll}
|
||||
prefetch={prefetch}
|
||||
className={classNames}
|
||||
onClick={(e) => {
|
||||
if (onClick) {
|
||||
onClick(e)
|
||||
@@ -70,9 +89,9 @@ export default function Link({
|
||||
trackClickById()
|
||||
}
|
||||
}}
|
||||
href={fullUrl}
|
||||
id={trackingId}
|
||||
{...props}
|
||||
{...linkProps}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user