This commit is contained in:
Linus Flood
2024-10-21 09:53:40 +02:00
parent 827417ba40
commit 09777ee909
3 changed files with 40 additions and 33 deletions

View File

@@ -1,5 +1,4 @@
"use client"
import { useEffect, useState } from "react"
import { dt } from "@/lib/dt"
@@ -14,24 +13,6 @@ import styles from "./stay.module.css"
import type { StayCardProps } from "@/types/components/myPages/stays/stayCard"
const useCheckIfExternal = (bookingUrl: string) => {
const [isExternal, setIsExternal] = useState(false)
useEffect(() => {
if (typeof window !== "undefined") {
const hostName = window.location.hostname
const bookingURL = new URL(bookingUrl)
const hostsMatch = hostName === bookingURL.hostname
const langRouteRegex = /^\/[a-zA-Z]{2}\//
setIsExternal(!hostsMatch || !langRouteRegex.test(bookingURL.pathname))
}
}, [bookingUrl])
return isExternal
}
export default function StayCard({ stay }: StayCardProps) {
const lang = useLang()
@@ -45,13 +26,8 @@ export default function StayCard({ stay }: StayCardProps) {
const departDate = depart.format("DD MMM YYYY")
const departDateTime = depart.format("YYYY-MM-DD")
// TODO: Remove this check (and hook) and only return <Link /> when current web is deleted
const isExternal = useCheckIfExternal(bookingUrl)
const linkProps = {
href: bookingUrl,
className: styles.link,
children: (
return (
<Link href={bookingUrl} className={styles.link}>
<article className={styles.stay}>
<Image
className={styles.image}
@@ -76,8 +52,6 @@ export default function StayCard({ stay }: StayCardProps) {
</div>
</footer>
</article>
),
}
return isExternal ? <a {...linkProps} /> : <Link {...linkProps} />
</Link>
)
}