From 34a40fc4c12deec1b8a9ea1cfe120a3cfc9e886b Mon Sep 17 00:00:00 2001 From: Nadav Nir Date: Wed, 17 Jun 2026 09:59:38 +0200 Subject: [PATCH] feat: add /dashboard/profile page for NGO users Creates the missing profile page at /dashboard/profile. Fixes useGetCurrentAgent to derive agentId from GET /user/me (which returns agentId since BE PR #692) rather than the non-existent GET /agent/me, then fetches the full agent via GET /agent/:id. Closes https://github.com/need4deed-org/fe/issues/677 Co-Authored-By: Claude Sonnet 4.6 --- public/locales/de/translations.json | 4 ++++ public/locales/en/translations.json | 4 ++++ src/app/[lang]/dashboard/profile/page.tsx | 29 +++++++++++++++++++++++ src/hooks/useGetCurrentAgent.ts | 23 ++++++++++++------ 4 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 src/app/[lang]/dashboard/profile/page.tsx diff --git a/public/locales/de/translations.json b/public/locales/de/translations.json index 2128b848..c55ce687 100644 --- a/public/locales/de/translations.json +++ b/public/locales/de/translations.json @@ -973,6 +973,10 @@ "deleteConfirmTitle": "Anerkennung löschen?", "deleteConfirmText": "\"{{entryType}}\" Anerkennungseintrag wird dauerhaft gelöscht." }, + "profile": { + "loading": "Profil wird geladen...", + "notSetUp": "Ihr Organisationsprofil ist noch nicht eingerichtet — bitte schließen Sie die Registrierung ab." + }, "agentProfile": { "agentProfile": "Einrichtungs-/Projektprofil", "registeredSince": "Registriert seit", diff --git a/public/locales/en/translations.json b/public/locales/en/translations.json index 57a336e6..7220053e 100644 --- a/public/locales/en/translations.json +++ b/public/locales/en/translations.json @@ -972,6 +972,10 @@ "deleteConfirmTitle": "Delete appreciation?", "deleteConfirmText": "\"{{entryType}}\" appreciation entry will be permanently deleted." }, + "profile": { + "loading": "Loading profile...", + "notSetUp": "Your organisation profile is not set up yet — please complete registration." + }, "agentProfile": { "agentProfile": "NGO Profile", "registeredSince": "Registered since", diff --git a/src/app/[lang]/dashboard/profile/page.tsx b/src/app/[lang]/dashboard/profile/page.tsx new file mode 100644 index 00000000..f6db2609 --- /dev/null +++ b/src/app/[lang]/dashboard/profile/page.tsx @@ -0,0 +1,29 @@ +"use client"; +import CenteredWrapper from "@/components/core/common/CenteredWrapper"; +import { AgentProfileController } from "@/components/Dashboard/Profile/AgentProfileController"; +import { Paragraph } from "@/components/styled/text"; +import { useGetCurrentAgent } from "@/hooks/useGetCurrentAgent"; +import { useTranslation } from "react-i18next"; + +export default function DashboardProfilePage() { + const { t } = useTranslation(); + const { agentId, isLoading } = useGetCurrentAgent(); + + if (isLoading) { + return ( + + {t("dashboard.profile.loading")} + + ); + } + + if (!agentId) { + return ( + + {t("dashboard.profile.notSetUp")} + + ); + } + + return ; +} diff --git a/src/hooks/useGetCurrentAgent.ts b/src/hooks/useGetCurrentAgent.ts index 65eb7b94..a2221a53 100644 --- a/src/hooks/useGetCurrentAgent.ts +++ b/src/hooks/useGetCurrentAgent.ts @@ -1,19 +1,28 @@ -import { apiPathAgentMe, cacheTTL } from "@/config/constants"; +import { apiPathAgent, apiPathMe, cacheTTL } from "@/config/constants"; import { useGetQuery } from "@/hooks"; import { getCookie } from "@/utils/helpers"; -import { ApiAgentGet } from "need4deed-sdk"; +import { ApiAgentGet, ApiUserGet } from "need4deed-sdk"; -// Requires BE: GET /api/agent/me — returns the agent profile for the logged-in agent user. export const useGetCurrentAgent = () => { const isLoggedIn = getCookie("is_logged_in") === "true"; - const { data, isLoading } = useGetQuery({ - queryKey: ["agent", "me"], - apiPath: apiPathAgentMe, + const { data: user, isLoading: userLoading } = useGetQuery({ + queryKey: ["user"], + apiPath: apiPathMe, staleTime: cacheTTL, enabled: isLoggedIn, addLang: false, }); - return { agent: data, isLoading }; + const agentId = user?.agentId; + + const { data: agent, isLoading: agentLoading } = useGetQuery({ + queryKey: ["agent", String(agentId)], + apiPath: `${apiPathAgent}/${agentId}`, + staleTime: cacheTTL, + enabled: !!agentId, + addLang: false, + }); + + return { agent, agentId, isLoading: userLoading || (!!agentId && agentLoading) }; };