🐛 fix: link created opportunity to the current agent#697
Merged
Conversation
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
approved these changes
Jun 17, 2026
need4deed
left a comment
Contributor
There was a problem hiding this comment.
Approving: agent-link fix reviewed (uses agentId from /me; submit gated on agentId). LGTM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The rewritten
NewOpportunityform (from #693) builds its payload withbuildCreatePayload, which hardcodes: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) carriesagent_id.This supersedes #696 (closed), which fixed the same class of bug on the pre-rewrite version of this file.
Fix
useGetCurrentAgent(GET /agent/me).agent.idintobuildCreatePayload, settingagent_idon the payload.disabled={isPending || agentLoading || !agent}) and bail inonSubmitif there's no agent id, so we never create an unlinked opportunity under a race.submitted_by_idis left asnull— 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