Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -33,14 +33,13 @@ export const OrganisationDetails = forwardRef<EditableSectionRef, Props>(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<OrganisationDetailsFormData>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const OrganisationDetailsDisplay = ({ rawClientLanguages, address }: Prop
mode="display"
type="text"
label={t(`${i18nPrefix}.address`)}
value={address ?? ""}
value={address || "—"}
setValue={() => {}}
/>
<EditableField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,3 @@ export const apiLanguagesToFormValues = (langs?: Array<{ id: number; title: stri

export const clientLanguagesToDisplay = (langs?: Array<{ id: number; title: string }>): 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: "" };
}
12 changes: 11 additions & 1 deletion src/components/Dashboard/Profile/types/agent.ts
Original file line number Diff line number Diff line change
@@ -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<ApiAgentGet, "agentDetails"> & {
agentDetails: AgentDetailsExtended;
};
Loading