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; +};