From ba90a86d80ce1a2c67870d2caa0cee50b6292097 Mon Sep 17 00:00:00 2001 From: Nadav Nir Date: Wed, 17 Jun 2026 11:00:22 +0200 Subject: [PATCH] fix: read addressStreet/addressPostcode directly from API response MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now that BE PR #694 exposes addressStreet and addressPostcode in agentDetails, initialize the edit form from those fields instead of parsing the serialized address string. Display shows "—" when no address is set (BE no longer returns "Berlin" as a fallback). Closes https://github.com/need4deed-org/fe/issues/657 Depends on https://github.com/need4deed-org/be/pull/694 Co-Authored-By: Claude Sonnet 4.6 --- .../OrganisationDetails/OrganisationDetails.tsx | 7 +++---- .../OrganisationDetailsDisplay.tsx | 2 +- .../sections/OrganisationDetails/formatters.ts | 5 ----- src/components/Dashboard/Profile/types/agent.ts | 12 +++++++++++- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/components/Dashboard/Profile/sections/OrganisationDetails/OrganisationDetails.tsx b/src/components/Dashboard/Profile/sections/OrganisationDetails/OrganisationDetails.tsx index 2d5e2ca2..8b110c1d 100644 --- a/src/components/Dashboard/Profile/sections/OrganisationDetails/OrganisationDetails.tsx +++ b/src/components/Dashboard/Profile/sections/OrganisationDetails/OrganisationDetails.tsx @@ -9,7 +9,7 @@ import { useTranslation } from "react-i18next"; import { FormContainer } from "../shared/styles"; import { EditableSectionProps, EditableSectionRef } from "../shared/types"; import { useEditingChangeNotifier } from "../shared/useEditingChangeNotifier"; -import { apiLanguagesToFormValues, parseAddress, toLanguagesForForm } from "./formatters"; +import { apiLanguagesToFormValues, toLanguagesForForm } from "./formatters"; import { OrganisationDetailsDisplay } from "./OrganisationDetailsDisplay"; import { OrganisationDetailsEdit } from "./OrganisationDetailsEdit"; import { createOrganisationDetailsSchema, OrganisationDetailsFormData } from "./organisationDetailsSchema"; @@ -33,14 +33,13 @@ export const OrganisationDetails = forwardRef(functio const languagesForForm = toLanguagesForForm(apiLanguages, i18n.language); const schema = createOrganisationDetailsSchema(t); - const { street, postcode } = parseAddress(details?.address || ""); const initialFormValues = { ...details, website: details?.website || "", operator: details?.operator || agent.operator || "", clientLanguages: apiLanguagesToFormValues(details?.clientLanguages), - addressStreet: street, - addressPostcode: postcode, + addressStreet: details?.addressStreet ?? "", + addressPostcode: details?.addressPostcode ?? "", }; const methods = useForm({ diff --git a/src/components/Dashboard/Profile/sections/OrganisationDetails/OrganisationDetailsDisplay.tsx b/src/components/Dashboard/Profile/sections/OrganisationDetails/OrganisationDetailsDisplay.tsx index 487ce674..98c3a779 100644 --- a/src/components/Dashboard/Profile/sections/OrganisationDetails/OrganisationDetailsDisplay.tsx +++ b/src/components/Dashboard/Profile/sections/OrganisationDetails/OrganisationDetailsDisplay.tsx @@ -37,7 +37,7 @@ export const OrganisationDetailsDisplay = ({ rawClientLanguages, address }: Prop mode="display" type="text" label={t(`${i18nPrefix}.address`)} - value={address ?? ""} + value={address || "—"} setValue={() => {}} /> ): string => langs?.map((lang) => lang.title).join(", ") ?? ""; - -export function parseAddress(formatted: string): { street: string; postcode: string } { - const match = formatted.match(/^(.+),\s*(\d{5})/); - return match ? { street: match[1].trim(), postcode: match[2] } : { street: "", postcode: "" }; -} diff --git a/src/components/Dashboard/Profile/types/agent.ts b/src/components/Dashboard/Profile/types/agent.ts index dbb6186a..5e6145db 100644 --- a/src/components/Dashboard/Profile/types/agent.ts +++ b/src/components/Dashboard/Profile/types/agent.ts @@ -1,6 +1,16 @@ +import { AgentDetails, ApiAgentGet } from "need4deed-sdk"; + export { AgentEngagementStatusType as AgentEngagementStatus, AgentTrustType as AgentTrustLevel, AgentVolunteerSearchType as AgentVolunteerSearch, } from "need4deed-sdk"; -export type { ApiAgentGet as ApiAgentProfileGet } from "need4deed-sdk"; + +type AgentDetailsExtended = AgentDetails & { + addressStreet?: string | null; + addressPostcode?: string | null; +}; + +export type ApiAgentProfileGet = Omit & { + agentDetails: AgentDetailsExtended; +};