From 9a4c1e4d16567abe051501870b631b487b1a6e3b Mon Sep 17 00:00:00 2001 From: Arturas Mickiewicz Date: Wed, 17 Jun 2026 13:42:58 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20fix:=20link=20created=20oppo?= =?UTF-8?q?rtunity=20to=20the=20current=20agent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The rewritten NewOpportunity form hardcoded agent_id: null in buildCreatePayload, so opportunities created by an agent were never linked to them. Fetch the current agent (GET /agent/me), pass its id into the payload, and gate submit until the agent is loaded. Co-Authored-By: Claude Opus 4.8 --- .../Dashboard/NewOpportunity/NewOpportunity.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/Dashboard/NewOpportunity/NewOpportunity.tsx b/src/components/Dashboard/NewOpportunity/NewOpportunity.tsx index 8607dae1..65550be4 100644 --- a/src/components/Dashboard/NewOpportunity/NewOpportunity.tsx +++ b/src/components/Dashboard/NewOpportunity/NewOpportunity.tsx @@ -37,6 +37,7 @@ import { AvailabilityGrid } from "@/components/forms/AvailabilityGrid/Availabili import { LanguageFields } from "@/components/forms/LanguageFields"; import { apiPathOpportunity, DashboardRoutes, MAX_DESCRIPTION_LENGTH } from "@/config/constants"; import { useMutationQuery } from "@/hooks"; +import { useGetCurrentAgent } from "@/hooks/useGetCurrentAgent"; import { zodResolver } from "@hookform/resolvers/zod"; import { Heading2, Heading4 } from "@/components/styled/text"; import { ShootingStarIcon, ArrowLeftIcon } from "@phosphor-icons/react"; @@ -129,6 +130,7 @@ function buildCreatePayload( apiSkills: ApiLanguageOption[], lang: string, t: TFunction, + agentId: number, ): OpportunityFormDataWithAgentSubmitter { const isEvent = headerData.volunteerType === VolunteerStateTypeType.EVENTS; const isAccompanying = headerData.volunteerType === VolunteerStateTypeType.ACCOMPANYING; @@ -173,7 +175,7 @@ function buildCreatePayload( category: "", category_id: "", language: lang as `${Lang}`, - agent_id: null, + agent_id: agentId, submitted_by_id: null, last_edited_time_notion: null, }; @@ -390,6 +392,7 @@ export function NewOpportunity() { const lang = i18n.language; const locale = lang === "de" ? de : enUS; const router = useRouter(); + const { agent, isLoading: agentLoading } = useGetCurrentAgent(); const volunteerTypeLabelMap = createVolunteerTypeLabelMap(t); const { data: apiLanguages = [] } = useApiLanguages(); @@ -471,6 +474,8 @@ export function NewOpportunity() { }); const onSubmit = (headerData: HeaderFormData) => { + // Don't create an opportunity that isn't linked to its agent. + if (!agent?.id) return; const payload = buildCreatePayload( headerData, detailsMethods.getValues(), @@ -480,6 +485,7 @@ export function NewOpportunity() { apiSkills, lang, t, + agent.id, ); createOpportunity(payload); }; @@ -586,7 +592,7 @@ export function NewOpportunity() { backgroundcolor="var(--color-aubergine)" textColor="var(--color-white)" onClick={handleHeaderSubmit(onSubmit)} - disabled={isPending} + disabled={isPending || agentLoading || !agent} /> From a6fa8671ddcaff0410ab93f5886c553a5a75e0bb Mon Sep 17 00:00:00 2001 From: Arturas Mickiewicz Date: Wed, 17 Jun 2026 13:47:06 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20use=20agen?= =?UTF-8?q?tId=20from=20/me=20instead=20of=20the=20full=20agent=20fetch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit agent_id only needs the id, which useGetCurrentAgent exposes as `agentId` straight from GET /me. Gating on the full `agent` object waited on (and could be blocked by) the secondary GET /agent/:id request. Gate on `agentId` instead. Co-Authored-By: Claude Opus 4.8 --- .../Dashboard/NewOpportunity/NewOpportunity.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/Dashboard/NewOpportunity/NewOpportunity.tsx b/src/components/Dashboard/NewOpportunity/NewOpportunity.tsx index 65550be4..d5228be9 100644 --- a/src/components/Dashboard/NewOpportunity/NewOpportunity.tsx +++ b/src/components/Dashboard/NewOpportunity/NewOpportunity.tsx @@ -392,7 +392,7 @@ export function NewOpportunity() { const lang = i18n.language; const locale = lang === "de" ? de : enUS; const router = useRouter(); - const { agent, isLoading: agentLoading } = useGetCurrentAgent(); + const { agentId } = useGetCurrentAgent(); const volunteerTypeLabelMap = createVolunteerTypeLabelMap(t); const { data: apiLanguages = [] } = useApiLanguages(); @@ -475,7 +475,7 @@ export function NewOpportunity() { const onSubmit = (headerData: HeaderFormData) => { // Don't create an opportunity that isn't linked to its agent. - if (!agent?.id) return; + if (!agentId) return; const payload = buildCreatePayload( headerData, detailsMethods.getValues(), @@ -485,7 +485,7 @@ export function NewOpportunity() { apiSkills, lang, t, - agent.id, + agentId, ); createOpportunity(payload); }; @@ -592,7 +592,7 @@ export function NewOpportunity() { backgroundcolor="var(--color-aubergine)" textColor="var(--color-white)" onClick={handleHeaderSubmit(onSubmit)} - disabled={isPending || agentLoading || !agent} + disabled={isPending || !agentId} />