Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions public/locales/de/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions public/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 29 additions & 0 deletions src/app/[lang]/dashboard/profile/page.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<CenteredWrapper>
<Paragraph>{t("dashboard.profile.loading")}</Paragraph>
</CenteredWrapper>
);
}

if (!agentId) {
return (
<CenteredWrapper>
<Paragraph>{t("dashboard.profile.notSetUp")}</Paragraph>
</CenteredWrapper>
);
}

return <AgentProfileController entityId={String(agentId)} />;
}
23 changes: 16 additions & 7 deletions src/hooks/useGetCurrentAgent.ts
Original file line number Diff line number Diff line change
@@ -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<ApiAgentGet>({
queryKey: ["agent", "me"],
apiPath: apiPathAgentMe,
const { data: user, isLoading: userLoading } = useGetQuery<ApiUserGet & { agentId?: number }>({
queryKey: ["user"],
apiPath: apiPathMe,
staleTime: cacheTTL,
enabled: isLoggedIn,
addLang: false,
});

return { agent: data, isLoading };
const agentId = user?.agentId;

const { data: agent, isLoading: agentLoading } = useGetQuery<ApiAgentGet>({
queryKey: ["agent", String(agentId)],
apiPath: `${apiPathAgent}/${agentId}`,
staleTime: cacheTTL,
enabled: !!agentId,
addLang: false,
});

return { agent, agentId, isLoading: userLoading || (!!agentId && agentLoading) };
};
Loading