fix: read vertical from URL using window instead of searchParams
This commit is contained in:
+17
-12
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect, useMemo, Suspense } from "react";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { useSearchParams, useRouter, usePathname } from "next/navigation";
|
||||
import Image from "next/image";
|
||||
import { motion } from "framer-motion";
|
||||
import PaymentButton from "@/components/stripe/PaymentButton";
|
||||
@@ -217,6 +217,8 @@ const fadeUp = { hidden: { opacity: 0, y: 20 }, visible: { opacity: 1, y: 0 } };
|
||||
|
||||
function DemosContent() {
|
||||
const searchParams = useSearchParams();
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const [lang, setLang] = useState<Language>("es");
|
||||
const [selected, setSelected] = useState<Vertical>("real-estate");
|
||||
const [contactOpen, setContactOpen] = useState(false);
|
||||
@@ -240,19 +242,22 @@ function DemosContent() {
|
||||
const [formSubmitted, setFormSubmitted] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const type = searchParams.get("type");
|
||||
const vertical = searchParams.get("vertical");
|
||||
const name = searchParams.get("name");
|
||||
if (type && ["real-estate", "restaurant", "clinic", "home-services"].includes(type)) {
|
||||
setSelected(type as Vertical);
|
||||
if (typeof window === "undefined") return;
|
||||
// Read directly from URL
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const urlVertical = params.get("vertical");
|
||||
const urlType = params.get("type");
|
||||
const urlName = params.get("name");
|
||||
|
||||
if (urlVertical && ["real-estate", "restaurant", "clinic", "home-services"].includes(urlVertical)) {
|
||||
setSelected(urlVertical as Vertical);
|
||||
} else if (urlType && ["real-estate", "restaurant", "clinic", "home-services"].includes(urlType)) {
|
||||
setSelected(urlType as Vertical);
|
||||
}
|
||||
if (vertical && ["real-estate", "restaurant", "clinic", "home-services"].includes(vertical)) {
|
||||
setSelected(vertical as Vertical);
|
||||
if (urlName) {
|
||||
setBusinessName(decodeURIComponent(urlName));
|
||||
}
|
||||
if (name) {
|
||||
setBusinessName(decodeURIComponent(name));
|
||||
}
|
||||
}, [searchParams]);
|
||||
}, []);
|
||||
|
||||
const t = contentByLang[lang];
|
||||
const v = verticals[selected][lang];
|
||||
|
||||
Reference in New Issue
Block a user