PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.2.8
Yatra – Travel Booking & Tour Operator Software v3.0.2.8
3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 All 83 releases
yatra / resources / js / hooks / useNavigate.ts

useNavigate.ts in Yatra – Travel Booking & Tour Operator Software 3.0.2.8, at resources/js/hooks/useNavigate.ts

71 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Primary sidebar navigation: replaces the query string with a clean Yatra URL (drops action, id, etc.)
3 * so it matches {@link getUrl} in Layout and avoids full page reloads.
4 */
5 export function navigateMenu(subpage: string, tab?: string): void {
6 const pathname = window.location.pathname;
7 const page =
8 new URLSearchParams(window.location.search).get("page") || "yatra";
9 const sp = new URLSearchParams();
10 sp.set("page", page);
11
12 if (subpage === "dashboard") {
13 // Match Layout getUrl("dashboard"): only ?page=yatra
14 } else {
15 sp.set("subpage", subpage);
16 if (tab !== undefined && tab !== null && tab !== "") {
17 sp.set("tab", tab);
18 }
19 }
20
21 const newUrl = `${pathname}?${sp.toString()}`;
22 window.history.pushState({}, "", newUrl);
23 window.dispatchEvent(new PopStateEvent("popstate"));
24 }
25
26 /**
27 * Navigation hook for updating URL parameters
28 */
29 export const useNavigate = () => {
30 const navigate = (params: {
31 subpage?: string;
32 tab?: string;
33 action?: string;
34 tabMode?: "specific" | "recurring";
35 id?: number | string;
36 trip_id?: number | string;
37 [key: string]: string | number | undefined;
38 }) => {
39 const urlParams = new URLSearchParams(window.location.search);
40
41 const setParam = (key: string, value?: string | number) => {
42 if (value === undefined || value === null) {
43 urlParams.delete(key);
44 } else {
45 urlParams.set(key, value.toString());
46 }
47 };
48
49 const standardKeys = ["subpage", "tab", "action", "id"];
50
51 standardKeys.forEach((key) => {
52 if (Object.prototype.hasOwnProperty.call(params, key)) {
53 setParam(key, params[key]);
54 }
55 });
56
57 // Handle custom parameters (like trip_id, tab_mode)
58 Object.keys(params).forEach((key) => {
59 if (!standardKeys.includes(key)) {
60 setParam(key, params[key]);
61 }
62 });
63
64 const newUrl = `${window.location.pathname}?${urlParams.toString()}`;
65 window.history.pushState({}, "", newUrl);
66 window.dispatchEvent(new PopStateEvent("popstate"));
67 };
68
69 return { navigate, navigateMenu };
70 };
71