fix: fixed redirecting on project select
This commit is contained in:
@ -1,14 +1,16 @@
|
||||
"use client";
|
||||
|
||||
import React, { useMemo, useState } from "react";
|
||||
import { useMemo, useState } from "react";
|
||||
import { usePathname, useRouter } from "next/navigation";
|
||||
import { ProjectsCrud, useProjectsCrud } from "@/hooks/cruds/useProjectsCrud";
|
||||
import useProjectsList from "@/hooks/lists/useProjectsList";
|
||||
import useIsMobile from "@/hooks/utils/useIsMobile";
|
||||
import { ProjectSchema } from "@/lib/client";
|
||||
import makeContext from "@/lib/contextFactory/contextFactory";
|
||||
|
||||
type ProjectsContextState = {
|
||||
selectedProject: ProjectSchema | null;
|
||||
setSelectedProjectId: React.Dispatch<React.SetStateAction<number | null>>;
|
||||
setSelectedProjectId: (id: number | null) => void;
|
||||
refetchProjects: () => void;
|
||||
projects: ProjectSchema[];
|
||||
projectsCrud: ProjectsCrud;
|
||||
@ -17,6 +19,9 @@ type ProjectsContextState = {
|
||||
|
||||
const useProjectsContextState = (): ProjectsContextState => {
|
||||
const { projects, refetch: refetchProjects, queryKey } = useProjectsList();
|
||||
const isMobile = useIsMobile();
|
||||
const pathname = usePathname();
|
||||
const router = useRouter();
|
||||
|
||||
const [selectedProjectId, setSelectedProjectId] = useState<number | null>(
|
||||
null
|
||||
@ -38,11 +43,16 @@ const useProjectsContextState = (): ProjectsContextState => {
|
||||
|
||||
const projectsCrud = useProjectsCrud({ queryKey });
|
||||
|
||||
const handleSetSelectedProjectId = (id: number | null) => {
|
||||
if (!isMobile && pathname !== "/deals") router.push("/deals");
|
||||
setSelectedProjectId(id);
|
||||
};
|
||||
|
||||
return {
|
||||
projects,
|
||||
selectedProject,
|
||||
refetchProjects,
|
||||
setSelectedProjectId,
|
||||
setSelectedProjectId: handleSetSelectedProjectId,
|
||||
projectsCrud,
|
||||
modulesSet,
|
||||
};
|
||||
|
||||
@ -1,19 +1,14 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useMemo } from "react";
|
||||
import { usePathname, useRouter } from "next/navigation";
|
||||
import { useMemo } from "react";
|
||||
import { Group, Stack, Text } from "@mantine/core";
|
||||
import { useProjectsContext } from "@/app/deals/contexts/ProjectsContext";
|
||||
import ThemeIcon from "@/components/ui/ThemeIcon/ThemeIcon";
|
||||
import useIsMobile from "@/hooks/utils/useIsMobile";
|
||||
import linksData from "../data/linksData";
|
||||
import NavbarClickable from "./NavbarClickable";
|
||||
|
||||
const NavbarLinks = () => {
|
||||
const isMobile = useIsMobile();
|
||||
const pathname = usePathname();
|
||||
const router = useRouter();
|
||||
const { modulesSet, selectedProject } = useProjectsContext();
|
||||
const { modulesSet } = useProjectsContext();
|
||||
const filteredLinks = useMemo(
|
||||
() =>
|
||||
linksData.filter(
|
||||
@ -22,10 +17,6 @@ const NavbarLinks = () => {
|
||||
[modulesSet]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isMobile && pathname !== "/deals") router.push("/deals");
|
||||
}, [selectedProject]);
|
||||
|
||||
return (
|
||||
<Stack gap={"xs"}>
|
||||
{filteredLinks.map((linkData, index) => (
|
||||
|
||||
Reference in New Issue
Block a user