chore: [app dir bootstrapping 9]: replace useSearchParams with useCompatSearchParams hook (#12056)
Co-authored-by: zomars <[email protected]>
This commit is contained in:
1 parent
3534e3c224
commit
28acbe549a
53 files changed
+254
-97
No files matched your search
@@ -1,10 +1,10 @@
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useSearchParams } from "next/navigation";
|
||||
import { useEffect, useRef, useState, useCallback } from "react";
|
||||
|
||||
import type { Message } from "./embed";
|
||||
import { sdkActionManager } from "./sdk-event";
|
||||
import type { EmbedThemeConfig, UiConfig, EmbedNonStylesConfig, BookerLayouts, EmbedStyles } from "./types";
|
||||
import { useCompatSearchParams } from "./useCompatSearchParams";
|
||||
|
||||
type SetStyles = React.Dispatch<React.SetStateAction<EmbedStyles>>;
|
||||
type setNonStylesConfig = React.Dispatch<React.SetStateAction<EmbedNonStylesConfig>>;
|
||||
@@ -208,7 +208,7 @@ const useUrlChange = (callback: (newUrl: string) => void) => {
|
||||
};
|
||||
|
||||
export const useEmbedTheme = () => {
|
||||
const searchParams = useSearchParams();
|
||||
const searchParams = useCompatSearchParams();
|
||||
const [theme, setTheme] = useState(
|
||||
embedStore.theme || (searchParams?.get("theme") as typeof embedStore.theme)
|
||||
);
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// this file is copied from '@calcom/lib/hooks/useCompatSearchParams.tsx'
|
||||
import { ReadonlyURLSearchParams, useParams, useSearchParams } from "next/navigation";
|
||||
|
||||
export const useCompatSearchParams = () => {
|
||||
const _searchParams = useSearchParams() ?? new URLSearchParams();
|
||||
const params = useParams() ?? {};
|
||||
|
||||
const searchParams = new URLSearchParams(_searchParams.toString());
|
||||
Object.getOwnPropertyNames(params).forEach((key) => {
|
||||
searchParams.delete(key);
|
||||
|
||||
const param = params[key];
|
||||
const paramArr = typeof param === "string" ? param.split("/") : param;
|
||||
|
||||
paramArr.forEach((p) => {
|
||||
searchParams.append(key, p);
|
||||
});
|
||||
});
|
||||
|
||||
return new ReadonlyURLSearchParams(searchParams);
|
||||
};
|
||||
Reference in new issue
Block a user