fix: correct agent profile save mutations and cache invalidation#419
fix: correct agent profile save mutations and cache invalidation#419
Conversation
#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>
|
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. |
|
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. |
Summary
Fixes two broken save hooks in the agent profile that caused edits to silently fail or not refresh the UI:
Contact details (#392):
useUpdateAgentContactwas 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]whereentityIdis the agent's own ID, so the profile never refreshed after saving.Organisation details (#354):
useUpdateOrganizationwas callingPATCH /api/organization/:operatorwhereoperatoris a free-text string (e.g. "Bayern Rotes Kreuz"), not a numeric ID — every save was a 404 that silently failed.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.PATCH /api/agent/:agentIdwhich acceptsaboutandwebsite. The organisation's numeric ID is not exposed in the current agent API response, so theaddressfield cannot yet be saved — this needs a separate BE change to expose the org ID.Test plan
🤖 Generated with Claude Code