Skip to content

fix: correct agent profile save mutations and cache invalidation#419

Open
nadavosa wants to merge 1 commit intodevelopfrom
fix/agent-profile-save-392-354
Open

fix: correct agent profile save mutations and cache invalidation#419
nadavosa wants to merge 1 commit intodevelopfrom
fix/agent-profile-save-392-354

Conversation

@nadavosa
Copy link
Copy Markdown
Collaborator

Summary

Fixes two broken save hooks in the agent profile that caused edits to silently fail or not refresh the UI:

Contact details (#392):

  • useUpdateAgentContact was invalidating ["agent", personId] (the representative's person ID) instead of ["agent", agentId] (the agent entity ID). The cache key used when fetching the profile is ["agent", entityId] where entityId is the agent's own ID, so the profile never refreshed after saving.

Organisation details (#354):

  • useUpdateOrganization was calling PATCH /api/organization/:operator where operator is a free-text string (e.g. "Bayern Rotes Kreuz"), not a numeric ID — every save was a 404 that silently failed.
  • The hook also used DeepPartial<ApiRepresentativeGet> (a person type) as the request body, had a double-underscore typo in the success message key, and invalidated the wrong cache key.
  • Fixed to call PATCH /api/agent/:agentId which accepts about and website. The organisation's numeric ID is not exposed in the current agent API response, so the address field cannot yet be saved — this needs a separate BE change to expose the org ID.

Test plan

  • Edit agent contact details (name, role, email, phone) — profile refreshes after save
  • Edit organisation details (about, website) — profile refreshes after save showing updated values
  • Confirm address field still displays correctly (read-only for now, pending BE change)

🤖 Generated with Claude Code

#354)

- useUpdateAgentContact: invalidated ["agent", personId] instead of the
  agent entity ID, so the profile cache never refreshed after saving contact
  details. Now accepts agentId separately and invalidates ["agent", agentId].
- useUpdateOrganization: was hitting /organization/:operator where operator
  is a text name string (not a numeric ID), so every save was a 404. Also
  used DeepPartial<ApiRepresentativeGet> (a person type) as the request body
  and had a double-underscore typo in the success message key. Fixed to hit
  /agent/:agentId (which accepts about/website) with the correct ApiAgentPatch
  type and proper cache invalidation. The org-level address field still needs
  the organization's numeric ID exposed in the API response — tracked separately.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lourooo
Copy link
Copy Markdown
Contributor

lourooo commented Apr 28, 2026

Great fixes, all bugs correctly identified and the solutions are well-aligned with the rest of the codebase.

One thing worth flagging: OrganisationDetailsFormData has fields like address, organizationType, operator, services, and clientLanguages marked as required in the schema, but ApiAgentPatch only accepts about and website.

A user could edit those fields, pass validation, and save but the data would silently not be persisted. Worth either making them read-only in edit mode or removing the required validation for anything not being sent to the API.

@Cy-fox
Copy link
Copy Markdown
Collaborator

Cy-fox commented Apr 28, 2026

Might be worth adding a quick guard before the mutation fires if agent?.id is missing. Right now the component uses String(agent?.id) which can happily turn undefined into the literal string "undefined", and the API call ends up hitting /agent/undefined. A small early return or a if (!id) check in the hook would keep things clean and avoid those weird requests showing up in the network tab.

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.

3 participants