From 3ca69dcd0f0d9c6c3a4182b87334bc883a7f9645 Mon Sep 17 00:00:00 2001
From: hamed <15238-genius.ha@users.noreply.drupalcode.org>
Date: Tue, 2 Dec 2025 15:38:42 +0330
Subject: [PATCH] refactor: enhance representation info fetching and pass it to
relevant components
---
app/panel/(layout)/layout.js | 31 +++++++++++++++++++++-
components/layoutPanel/userDetail/Head.js | 6 +++--
components/layoutPanel/userDetail/index.js | 4 +--
components/panel/Content.js | 23 +++++++++-------
services/response.js | 2 ++
5 files changed, 51 insertions(+), 15 deletions(-)
diff --git a/app/panel/(layout)/layout.js b/app/panel/(layout)/layout.js
index c15e8af..46793a5 100644
--- a/app/panel/(layout)/layout.js
+++ b/app/panel/(layout)/layout.js
@@ -2,6 +2,8 @@ import Content from "@/components/panel/Content";
import { defineAbilitiesFor } from "@/lib/ability";
import { getUser } from "@/lib/auth";
import { redirect } from "next/navigation";
+import { cookies } from "next/headers";
+import { fetchReq } from "@/lib/req";
async function LayoutPanel({ children }) {
const user = await getUser();
@@ -11,7 +13,34 @@ async function LayoutPanel({ children }) {
return redirect("/");
}
- return ;
+ let representationInfo = null;
+ const API_URL = process.env.NEXT_PUBLIC_API_URL;
+
+ try {
+ const cookieStore = cookies();
+ const userInfo = cookieStore.get("userInfo");
+ const accessToken = cookieStore.get("access_token");
+
+ if (userInfo && accessToken) {
+ const parsedUserInfo = JSON.parse(userInfo.value);
+ const representationUuid = parsedUserInfo?.representation_uuid;
+
+ if (representationUuid) {
+ representationInfo = await fetchReq(
+ `${API_URL}/api/v1/representation/${representationUuid}`,
+ {
+ headers: {
+ Authorization: `Bearer ${accessToken.value}`,
+ },
+ }
+ );
+ }
+ }
+ } catch (error) {
+ console.error("Error fetching representation info:", error);
+ }
+
+ return ;
}
export default LayoutPanel;
diff --git a/components/layoutPanel/userDetail/Head.js b/components/layoutPanel/userDetail/Head.js
index 4150779..e7d7b60 100644
--- a/components/layoutPanel/userDetail/Head.js
+++ b/components/layoutPanel/userDetail/Head.js
@@ -6,7 +6,9 @@ import { Button } from "@mui/material";
import Image from "next/image";
import React from "react";
-function Head({ data, loading }) {
+function Head({ data, loading, representationInfo }) {
+ const cityName = representationInfo?.city?.label || "اهواز";
+
return (
@@ -23,7 +25,7 @@ function Head({ data, loading }) {
- نماینده شهر اهواز
+ نماینده شهر {cityName}
diff --git a/components/layoutPanel/userDetail/index.js b/components/layoutPanel/userDetail/index.js
index b73f0bd..47ade43 100644
--- a/components/layoutPanel/userDetail/index.js
+++ b/components/layoutPanel/userDetail/index.js
@@ -2,14 +2,14 @@ import Head from "./Head";
import Date from "./Date";
import Activities from "./Activities";
-function UserDetail({ data, loading }) {
+function UserDetail({ data, loading, representationInfo }) {
return (
diff --git a/components/panel/Content.js b/components/panel/Content.js
index 5b785b9..a3766ed 100644
--- a/components/panel/Content.js
+++ b/components/panel/Content.js
@@ -8,7 +8,7 @@ import UserDetail from "@/components/layoutPanel/userDetail";
import { usePathname } from "next/navigation";
import BgGray from "@/components/layoutPanel/sidebar/BgGray";
-function Content({ children }) {
+function Content({ children, representationInfo }) {
const pathname = usePathname();
const [active, setActive] = useState(false);
const [open, setOpen] = useState(true);
@@ -32,14 +32,13 @@ function Content({ children }) {
@@ -53,7 +52,11 @@ function Content({ children }) {
{pathname.includes("dashboard") && (
-
+
)}
);
diff --git a/services/response.js b/services/response.js
index 3cb33b7..c42622b 100644
--- a/services/response.js
+++ b/services/response.js
@@ -123,4 +123,6 @@ export const request = {
Authorization: "",
},
}),
+ getRepresentationInfo: (uuid) =>
+ api.get(`api/v1/representation/${uuid}`, { requireAuth: true }),
};