"use client" // Adds a party (a person or an organization), then opens it. "This is me" links a person to the // member's own account, so the platform's export or erasure of that member reaches the party. import type { ProjectSlugs } from "@conusai-kit/ui" import { describeError, useWrite } from "@conusai-kit/ui/data" import { CheckField, FormLayout, type FormValues, PageSection, SelectField, serviceNotice, TextField, usePageNavigation, } from "@conusai-kit/ui/patterns" import { type ReactElement, useState } from "react" export interface PartyFormLabels { readonly heading: string readonly kind: string readonly person: string readonly organization: string readonly displayName: string readonly legalName: string readonly country: string readonly countryHint: string readonly linkSelf: string readonly submit: string readonly busy: string /** The text of each business refusal by problem code (`businessRefusalNotices` of `@conusai-kit/business/refusals`). */ readonly refusals: Readonly> } export function PartyForm({ slugs, listHref, labels, }: { slugs: ProjectSlugs listHref: string labels: PartyFormLabels }): ReactElement { const navigation = usePageNavigation() const create = useWrite, { partyId: string }>("crm.party.create") const [requestId] = useState(() => crypto.randomUUID()) const [kind, setKind] = useState("organization") const submit = async ({ displayName, legalName, country = "", linkSelf }: FormValues): Promise => { const created = await create.mutate({ ...slugs, kind, displayName, ...(legalName ? { legalName } : {}), country: country.toUpperCase(), ...(kind === "person" && linkSelf === "on" ? { linkSelf: true } : {}), requestId, }) navigation.navigate(`${listHref}/${encodeURIComponent(created.partyId)}`) } return ( serviceNotice(error, labels.refusals)?.text ?? describeError(error)} > {kind === "person" ? : null} ) }