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