diff --git a/src/app/[lang]/dashboard/agents/[id]/page.tsx b/src/app/[lang]/dashboard/agents/[id]/page.tsx
index ee1a7cf0..6e09830d 100644
--- a/src/app/[lang]/dashboard/agents/[id]/page.tsx
+++ b/src/app/[lang]/dashboard/agents/[id]/page.tsx
@@ -1,5 +1,6 @@
import ProfileLayout from "@/components/Dashboard/Profile/ProfileLayout";
-import { getServerUserRole } from "@/hooks/api/getUserRole";
+import { getServerAgent } from "@/hooks/api/getAgent";
+import { getServerUser } from "@/hooks/api/getUser";
import { RouteParams } from "@/types";
import { UserRole } from "need4deed-sdk";
import { cookies } from "next/headers";
@@ -10,9 +11,17 @@ export default async function DashboardAgentPage({ params }: RouteParams) {
const cookieStore = await cookies();
const cookieHeader = cookieStore.toString();
- const userRole = await getServerUserRole(cookieHeader);
+ const user = await getServerUser(cookieHeader);
+ const agent = await getServerAgent(cookieHeader, id);
+ const userRole = user?.role;
+ const personId = user?.personId;
+ const matchedPersonId = personId === agent?.representative?.id;
- if (!userRole || (userRole !== UserRole.COORDINATOR && userRole !== UserRole.ADMIN)) {
+ if (
+ !userRole ||
+ !personId ||
+ (userRole !== UserRole.COORDINATOR && userRole !== UserRole.ADMIN && !matchedPersonId)
+ ) {
redirect(`/dashboard/agents`);
}
return ;
diff --git a/src/components/Dashboard/Agents/AgentReadOnlyTableRow.tsx b/src/components/Dashboard/Agents/AgentReadOnlyTableRow.tsx
index 9f3b7113..b873f77f 100644
--- a/src/components/Dashboard/Agents/AgentReadOnlyTableRow.tsx
+++ b/src/components/Dashboard/Agents/AgentReadOnlyTableRow.tsx
@@ -1,5 +1,7 @@
import { ApiAgentGetList, OptionItem } from "need4deed-sdk";
import { ClickableRow, TableCell } from "@/components/core/common/Table";
+import { useTranslation } from "react-i18next";
+import { useRouter } from "next/navigation";
interface Props {
agent: ApiAgentGetList;
@@ -10,10 +12,17 @@ interface Props {
}
export function AgentReadOnlyTableRow({ agent, isLast, districtsList }: Props) {
+ const { i18n } = useTranslation();
+ const router = useRouter();
const { id, title, type, district } = agent;
const districtTitle = district?.id ? (districtsList?.find((d) => d.id === district.id)?.title ?? null) : null;
+
+ const handleGoToProfile = () => {
+ if (!id) return;
+ router.push(`/${i18n.language}/dashboard/agents/${id}`);
+ };
return (
-
+
{title}
{type}
{districtTitle || "—"}
diff --git a/src/hooks/api/getAgent.ts b/src/hooks/api/getAgent.ts
new file mode 100644
index 00000000..f32cfca5
--- /dev/null
+++ b/src/hooks/api/getAgent.ts
@@ -0,0 +1,27 @@
+import { fetchFn } from "@/hooks/api/utils";
+import { ApiAgentGet } from "need4deed-sdk";
+import { apiPathAgent } from "@/config/constants";
+
+export interface ApiResponse {
+ message: string;
+ data: T;
+ count: number;
+}
+
+export const getServerAgent = async (cookieHeader: string, id: string): Promise => {
+ try {
+ const urlPath = apiPathAgent.replace("/api/", "");
+ const response = await fetchFn>({
+ url: `${process.env.URL_API}/${urlPath}/${id}`,
+ options: {
+ method: "GET",
+ headers: { Cookie: cookieHeader },
+ cache: "no-store",
+ },
+ });
+ return response.data;
+ } catch (error) {
+ console.error("Failed to fetch server user role:", error);
+ return null;
+ }
+};
diff --git a/src/hooks/api/getUserRole.ts b/src/hooks/api/getUser.ts
similarity index 68%
rename from src/hooks/api/getUserRole.ts
rename to src/hooks/api/getUser.ts
index 512d8b04..f45db6e4 100644
--- a/src/hooks/api/getUserRole.ts
+++ b/src/hooks/api/getUser.ts
@@ -1,5 +1,5 @@
import { fetchFn } from "@/hooks/api/utils";
-import { UserRole } from "need4deed-sdk";
+import { ApiUserGet } from "need4deed-sdk";
import { apiPathMe } from "@/config/constants";
export interface ApiResponse {
@@ -8,10 +8,10 @@ export interface ApiResponse {
count: number;
}
-export const getServerUserRole = async (cookieHeader: string): Promise => {
+export const getServerUser = async (cookieHeader: string): Promise => {
try {
const urlPath = apiPathMe.replace("/api/", "");
- const response = await fetchFn>({
+ const response = await fetchFn>({
url: `${process.env.URL_API}/${urlPath}`,
options: {
method: "GET",
@@ -19,7 +19,7 @@ export const getServerUserRole = async (cookieHeader: string): Promise