|
@@ -5,6 +5,7 @@ import ProjectSearchLoading from "./ProjectSearchLoading"; |
|
|
import { fetchUserAbilities, fetchUserStaff } from "@/app/utils/fetchUtil"; |
|
|
import { fetchUserAbilities, fetchUserStaff } from "@/app/utils/fetchUtil"; |
|
|
import { authOptions } from "@/config/authConfig"; |
|
|
import { authOptions } from "@/config/authConfig"; |
|
|
import { getServerSession } from "next-auth"; |
|
|
import { getServerSession } from "next-auth"; |
|
|
|
|
|
import { VIEW_ALL_PROJECTS } from "@/middleware"; |
|
|
|
|
|
|
|
|
interface SubComponents { |
|
|
interface SubComponents { |
|
|
Loading: typeof ProjectSearchLoading; |
|
|
Loading: typeof ProjectSearchLoading; |
|
@@ -15,11 +16,15 @@ const ProjectSearchWrapper: React.FC & SubComponents = async () => { |
|
|
const userStaff = await fetchUserStaff() |
|
|
const userStaff = await fetchUserStaff() |
|
|
const teamId = userStaff?.teamId |
|
|
const teamId = userStaff?.teamId |
|
|
const projects = await fetchProjects(); |
|
|
const projects = await fetchProjects(); |
|
|
|
|
|
|
|
|
|
|
|
const abilities = await fetchUserAbilities() |
|
|
|
|
|
const isViewAllProjectRight = [VIEW_ALL_PROJECTS].some((ability) => abilities.includes(ability)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let filteredProjects = projects |
|
|
let filteredProjects = projects |
|
|
if (teamId) { |
|
|
|
|
|
|
|
|
if (!isViewAllProjectRight) { |
|
|
filteredProjects = projects.filter(project => project.teamId === teamId) |
|
|
filteredProjects = projects.filter(project => project.teamId === teamId) |
|
|
} |
|
|
} |
|
|
const abilities = await fetchUserAbilities() |
|
|
|
|
|
|
|
|
|
|
|
return <ProjectSearch projects={filteredProjects} projectCategories={projectCategories} abilities={abilities}/>; |
|
|
return <ProjectSearch projects={filteredProjects} projectCategories={projectCategories} abilities={abilities}/>; |
|
|
}; |
|
|
}; |
|
|