PR fixes
This commit is contained in:
@@ -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>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user