Skip to content

🐛 fix: link created opportunity to the current agent#697

Merged
arturasmckwcz merged 2 commits into
developfrom
arturas/link-agent-on-opportunity-create
Jun 17, 2026
Merged

🐛 fix: link created opportunity to the current agent#697
arturasmckwcz merged 2 commits into
developfrom
arturas/link-agent-on-opportunity-create

Conversation

@arturasmckwcz

Copy link
Copy Markdown
Collaborator

Problem

The rewritten NewOpportunity form (from #693) builds its payload with buildCreatePayload, which hardcodes:

agent_id: null,
submitted_by_id: null,

and the component never fetches the current agent. So every opportunity created through this screen is sent to POST /opportunity/ unlinked to any agent, even though the contract (OpportunityFormDataWithAgentSubmitter) carries agent_id.

This supersedes #696 (closed), which fixed the same class of bug on the pre-rewrite version of this file.

Fix

  • Fetch the logged-in agent via useGetCurrentAgent (GET /agent/me).
  • Pass agent.id into buildCreatePayload, setting agent_id on the payload.
  • Gate submit until the agent is loaded (disabled={isPending || agentLoading || !agent}) and bail in onSubmit if there's no agent id, so we never create an unlinked opportunity under a race.

submitted_by_id is left as null — its source/semantics aren't established here and the backend may derive it from the authenticated session. Happy to wire it up in a follow-up if it should come from the agent representative.

Testing

  • yarn typecheck
  • yarn lint ✅ (no new warnings)

🤖 Generated with Claude Code

arturasmckwcz and others added 2 commits June 17, 2026 13:42
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>

@need4deed need4deed left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving: agent-link fix reviewed (uses agentId from /me; submit gated on agentId). LGTM.

@arturasmckwcz arturasmckwcz merged commit 704b8a4 into develop Jun 17, 2026
1 check passed
@arturasmckwcz arturasmckwcz deleted the arturas/link-agent-on-opportunity-create branch June 17, 2026 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants