fix: revert to older version

This commit is contained in:
Mohamed Marrouchi
2025-05-28 16:26:32 +01:00
parent 4692339bea
commit 0c31d3047e
4 changed files with 9 additions and 52 deletions

View File

@@ -21,7 +21,6 @@ import { useTranslate } from "@/hooks/useTranslate";
import { Title } from "@/layout/content/Title";
import { EntityType, RouterType } from "@/services/types";
import { normalizeDate } from "@/utils/date";
import { extractQueryParamsUrl } from "@/utils/URL";
import { getAvatarSrc } from "../helpers/mapMessages";
import { useChat } from "../hooks/ChatContext";
@@ -75,10 +74,7 @@ export const SubscribersList = (props: {
<Conversation
onClick={() => {
chat.setSubscriberId(subscriber.id);
push({
pathname: `/${RouterType.INBOX}/subscribers/${subscriber.id}`,
query: extractQueryParamsUrl(window.location.href),
});
push(`/${RouterType.INBOX}/subscribers/${subscriber.id}`);
}}
className="changeColor"
key={subscriber.id}

View File

@@ -26,7 +26,7 @@ import { AssignedTo } from "./types";
export const Inbox = () => {
const { t } = useTranslate();
const { onSearch, searchPayload, searchText } = useSearch<ISubscriber>({
const { onSearch, searchPayload } = useSearch<ISubscriber>({
$or: ["first_name", "last_name"],
});
const [channels, setChannels] = useState<string[]>([]);
@@ -48,7 +48,6 @@ export const Inbox = () => {
<Sidebar position="left">
<Grid paddingX={1} paddingTop={1}>
<Search
value={searchText}
onClearClick={() => onSearch("")}
className="changeColor"
onChange={(v) => onSearch(v)}

View File

@@ -7,8 +7,7 @@
*/
import { debounce } from "@mui/material";
import { useRouter } from "next/router";
import { ChangeEvent, useCallback, useEffect, useState } from "react";
import { ChangeEvent, useState } from "react";
import {
TBuildInitialParamProps,
@@ -53,38 +52,13 @@ const buildNeqInitialParams = <T,>({
);
export const useSearch = <T,>(params: TParamItem<T>) => {
const router = useRouter();
const [searchText, setSearchText] = useState<string>(
(router.query.search as string) || "",
const [searchText, setSearchText] = useState<string>("");
const onSearch = debounce(
(e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement> | string) => {
setSearchText(typeof e === "string" ? e : e.target.value);
},
300,
);
useEffect(() => {
if (router.query.search !== searchText) {
setSearchText((router.query.search as string) || "");
}
}, [router.query.search]);
const updateQueryParams = useCallback(
debounce(async (newSearchText: string) => {
await router.replace(
{
pathname: router.pathname,
query: { ...router.query, search: newSearchText || undefined },
},
undefined,
{ shallow: true },
);
}, 300),
[router],
);
const onSearch = (
e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement> | string,
) => {
const newSearchText = typeof e === "string" ? e : e.target.value;
setSearchText(newSearchText);
updateQueryParams(newSearchText);
};
const {
$eq: eqInitialParams,
$iLike: iLikeParams,
@@ -93,7 +67,6 @@ export const useSearch = <T,>(params: TParamItem<T>) => {
} = params;
return {
searchText,
onSearch,
searchPayload: {
where: {

View File

@@ -6,8 +6,6 @@
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/
import qs from "qs";
export const buildURL = (baseUrl: string, relativePath: string): string => {
try {
return new URL(relativePath).toString();
@@ -39,12 +37,3 @@ export const isAbsoluteUrl = (value: string = ""): boolean => {
return false;
}
};
// todo: in the future we might need to extract this logic into a hook
export const extractQueryParamsUrl = (fullUrl: string): string => {
const extractedQueryParams = qs.parse(new URL(fullUrl).search, {
ignoreQueryPrefix: true,
});
return qs.stringify(extractedQueryParams);
};