diff --git a/public/locales/de/translations.json b/public/locales/de/translations.json index 22136abf..13435b62 100644 --- a/public/locales/de/translations.json +++ b/public/locales/de/translations.json @@ -954,6 +954,7 @@ "clientLanguages": "Sprachen der Klient:innen", "cancel": "Abbrechen", "saveChanges": "Änderungen speichern", + "saveSuccess": "Organisationsdetails erfolgreich aktualisiert", "validation": { "required": "Dieses Feld ist erforderlich", "websiteInvalid": "Webseite muss mit http:// oder https:// beginnen", diff --git a/public/locales/en/translations.json b/public/locales/en/translations.json index fed0d78f..3675044a 100644 --- a/public/locales/en/translations.json +++ b/public/locales/en/translations.json @@ -953,6 +953,7 @@ "clientLanguages": "Client languages", "cancel": "Cancel", "saveChanges": "Save changes", + "saveSuccess": "Organisation details updated successfully", "validation": { "required": "This field is required", "websiteInvalid": "Website must start with http:// or https://", diff --git a/src/components/Dashboard/Profile/sections/ContactDetails/agent/AgentContactDetails.tsx b/src/components/Dashboard/Profile/sections/ContactDetails/agent/AgentContactDetails.tsx index 00a58ada..ec72e2e4 100644 --- a/src/components/Dashboard/Profile/sections/ContactDetails/agent/AgentContactDetails.tsx +++ b/src/components/Dashboard/Profile/sections/ContactDetails/agent/AgentContactDetails.tsx @@ -30,7 +30,7 @@ export const AgentContactDetails = forwardRef(function ref, ) { const { t } = useTranslation(); - const { mutate: updateAgent, isPending } = useUpdateAgentContact(String(agent?.representative?.id)); + const { mutate: updateAgent, isPending } = useUpdateAgentContact(String(agent?.representative?.id), String(agent?.id)); const [isEditing, setIsEditing] = useState(false); useEditingChangeNotifier(isEditing, onEditingChange); diff --git a/src/components/Dashboard/Profile/sections/OrganisationDetails/OrganisationDetails.tsx b/src/components/Dashboard/Profile/sections/OrganisationDetails/OrganisationDetails.tsx index def55a28..3148bff2 100644 --- a/src/components/Dashboard/Profile/sections/OrganisationDetails/OrganisationDetails.tsx +++ b/src/components/Dashboard/Profile/sections/OrganisationDetails/OrganisationDetails.tsx @@ -24,7 +24,7 @@ export const OrganisationDetails = forwardRef(functio ) { const { t, i18n } = useTranslation(); const [isEditing, setIsEditing] = useState(false); - const { mutate: updateOrganization /*, isPending */ } = useUpdateOrganization(String(agent?.operator)); + const { mutate: updateOrganization /*, isPending */ } = useUpdateOrganization(String(agent?.id)); useEditingChangeNotifier(isEditing, onEditingChange); const { data: apiLanguages } = useApiLanguages(); @@ -56,12 +56,15 @@ export const OrganisationDetails = forwardRef(functio }; const onSubmit = (values: OrganisationDetailsFormData) => { - updateOrganization(values as unknown as ApiAgentProfileGet, { - onSuccess: () => { - reset(values); - setIsEditing(false); + updateOrganization( + { about: values.about, website: values.website }, + { + onSuccess: () => { + reset(values); + setIsEditing(false); + }, }, - }); + ); }; return ( diff --git a/src/hooks/useUpdateAgentContact.ts b/src/hooks/useUpdateAgentContact.ts index 657932ab..e638f8b8 100644 --- a/src/hooks/useUpdateAgentContact.ts +++ b/src/hooks/useUpdateAgentContact.ts @@ -4,11 +4,11 @@ import { useMutationQuery } from "@/hooks"; import { ApiRepresentativeGet } from "need4deed-sdk"; import { DeepPartial } from "ts-type-safe"; -export const useUpdateAgentContact = (personId: string) => { +export const useUpdateAgentContact = (personId: string, agentId: string) => { return useMutationQuery, ApiAgentProfileGet>({ apiPath: `${apiPathPerson}${personId}`, method: "patch", successMessage: "dashboard.agentProfile.contactDetails.saveSuccess", - queryKeyToInvalidate: ["agent", personId], + queryKeyToInvalidate: ["agent", agentId], }); }; diff --git a/src/hooks/useUpdateOrganizationDetails.ts b/src/hooks/useUpdateOrganizationDetails.ts index ca845c95..e66f20bc 100644 --- a/src/hooks/useUpdateOrganizationDetails.ts +++ b/src/hooks/useUpdateOrganizationDetails.ts @@ -1,14 +1,16 @@ import { ApiAgentProfileGet } from "@/components/Dashboard/Profile/types"; -import { apiPathOrganization } from "@/config/constants"; +import { apiPathAgent } from "@/config/constants"; import { useMutationQuery } from "@/hooks"; -import { ApiRepresentativeGet } from "need4deed-sdk"; -import { DeepPartial } from "ts-type-safe"; +import { ApiAgentPatch } from "need4deed-sdk"; -export const useUpdateOrganization = (organizationId: string) => { - return useMutationQuery, ApiAgentProfileGet>({ - apiPath: `${apiPathOrganization}${organizationId}`, +// Patches agent-level org details (about, website) via the agent endpoint. +// Note: address and district require the organization's numeric ID which is not +// currently exposed in the agent API response — those fields need a BE change. +export const useUpdateOrganization = (agentId: string) => { + return useMutationQuery, ApiAgentProfileGet>({ + apiPath: `${apiPathAgent}/${agentId}`, method: "patch", - successMessage: "__dashboard.agentProfile.contactDetails.saveSuccess", - queryKeyToInvalidate: ["organization", organizationId], + successMessage: "dashboard.agentProfile.organisationDetails.saveSuccess", + queryKeyToInvalidate: ["agent", agentId], }); };