RAIA™ Specification

3.40 Universal Contact Components

Every person in RAIA (Real estate Artificial Intelligence Agent) — landlord, tenant, supplier, guarantor — has contact details: phone numbers, email addresses, WhatsApp, social media. Instead of each page drawing its own version of those details, there is now one shared set of "contact cards". Any page that needs to show a person’s phone number, social links, or communication activity drops in the same card. Fix the card once, and every page that uses it gets better. Add a new channel type (say, Signal) once, and it appears everywhere the card is used.

← Back to Developer Hub TEXTBOOK SPECIFICATION
In Plain English

Every person in RAIA (Real estate Artificial Intelligence Agent) — landlord, tenant, supplier, guarantor — has contact details: phone numbers, email addresses, WhatsApp, social media. Instead of each page drawing its own version of those details, there is now one shared set of "contact cards". Any page that needs to show a person’s phone number, social links, or communication activity drops in the same card. Fix the card once, and every page that uses it gets better. Add a new channel type (say, Signal) once, and it appears everywhere the card is used.

One set of contact cards — ContactCard, ContactChannelsCard, ContactSocialCard, ContactActivityCard — consumed by every role-specific detail panel (Landlord, Tenant, Supplier). This page covers the component API, the PersonContact / ContactChannel type system, the SWR hooks and API endpoints that feed them, and the migration path away from the deprecated per-role implementations. Verified against 03_technology/11_frontend/portal/src/components/contact/.

Phase 2 Shipped Landlord + Tenant Live Supplier Pending Phase 3 Type-Safe SSOT
4
Universal cards — ContactCard, ContactChannelsCard, ContactSocialCard, ContactActivityCard
2
SWR hooks — useContactChannels + useContactActivity, with abort + retry baked in
13
Built-in channel types — email, phone, whatsapp, sms, telegram, wechat, website, facebook, instagram, tiktok, linkedin, x, twitter
3
Role extensions — LandlordContact, TenantContact, SupplierContact extend PersonContact

Section A One Set of Contact Cards for Everyone

Imagine a paper filing system where every drawer in the office has its own way of writing a person’s phone number — some in blue ink, some in red, some on sticky notes, some on cards. When someone changes their number, you have to remember which drawers have copies. That is what the portal used to be like: the Landlord page had one way of showing contact details, the Tenant page had a different way, and adding anything new meant editing both.

The universal contact components are one shared box of index cards. Every page that needs to show contact details pulls from the same box. A change to the card — a new icon, a new field, a new channel type — appears everywhere automatically.

UNIVERSAL CONTACT COMPONENTS — ONE BOX, MANY PAGES /api/persons/[id]/channels tbl_persons_channels → ContactChannel[] /api/persons/[id]/comms-activity tbl_conversations → ContactActivityData Parent panels (SSR) Tier-1 email / phone / lang useContactChannels SWR hook · abort · retry useContactActivity SWR hook · window=90d|365d|hot props (no fetch) channels, email, phone ContactCard avatar + name + role pill ContactChannelsCard email / phone / messaging ContactSocialCard facebook / instagram / x ContactActivityCard comms chart (threads) LandlordDetailPanel landlord centre · dashboard-v2 TenantDetailPanel tenant centre · dashboard-v2 SupplierDetailPanel Phase 3 — pending tbl_suppliers

The Four Cards

CardWhat it showsWhere you see it
ContactCard Avatar (or initials), full name, role pill (Landlord / Tenant / Landlord+Tenant / Contact), up to N channel icons List rows, search results, related-contact pickers — anywhere a compact person chip is needed
ContactChannelsCard Email, phone, WhatsApp / Telegram capability badges, preferred channel, preferred language Landlord and Tenant detail panels — the “Communication” section
ContactSocialCard Facebook, Instagram, TikTok, LinkedIn, X / Twitter links — renders nothing if no social channels exist Landlord and Tenant detail panels — the “Social Media” section
ContactActivityCard Communication activity chart — how many threads or messages arrived on each channel over a time window Landlord and Tenant detail panels — the “Communication activity” section
Why This Matters

Before Phase 2, contact rendering was copy-pasted: LandlordCommsSection, CompactPersonCard, CommsActivitySection, LandlordSocialSection each implemented their own version. Fixing a bug meant remembering to fix it in every file. The universal components replace all four — one source of truth for how a person’s contact details look, behave, and fetch data.

Section B What You See in the Portal

Open any landlord or tenant detail panel. The contact sections look and behave identically:

  • Communication — email, phone, plus WhatsApp / Telegram chips on the primary phone when those messaging apps are linked.
  • Social Media — only appears if the person actually has social channels on file. If the section is missing, that means none are recorded — it is not hidden by a bug.
  • Communication activity — a small chart showing which channels the person actually uses. “Honest empty” — if there are no conversations yet, the card says so plainly instead of drawing an empty chart.

Editing Communication Channels

Click the pencil icon on the Communication card. The view swaps to ContactChannelsEdit — the edit counterpart. You can:

  1. 1
    Add a new channel

    Pick a type (email, phone, whatsapp, telegram, wechat, sms, website, or a social platform) and enter the value. Phone numbers are split into dial code + national number for you; the database stores them in E.164 format.

  2. 2
    Mark one channel of each type as primary

    There can be many emails and many phones, but exactly one primary of each. The primary is what outbound automations use by default.

  3. 3
    Save

    Save writes through to tbl_persons_channels. The card refreshes itself via the mutate() function on the channels hook — no full-page reload.

WhatsApp & Telegram Badges

The little WA / TG chips on a phone number tell you whether that phone is reachable on WhatsApp and / or Telegram. They are synthesised — there is no has_whatsapp column in the database. The API looks for a companion whatsapp channel row whose digits match the phone row’s digits; if one exists, the chip is active.

Why a phone might show no chips

If a phone shows greyed-out chips, the person either has no WhatsApp / Telegram row on file, or the WhatsApp row’s digits do not match the phone row’s digits. Clean the data by re-entering both rows through the edit UI — the matching is purely on digits, so +44 7700 900123 and 07700 900123 will not match. Save both as E.164.

Section C Component Overview

Universal Contact Components — Architecture Data Layer PersonContact LandlordContact TenantContact ContactChannel Components (portal/src) ContactCard.tsx ContactChannelsCard.tsx ContactSocialCard.tsx ContactActivityCard.tsx UI Surfaces RHS Context Panel Person Profile Page Conversation Sidebar
Developer Section — verified against portal/src/components/contact/ @ e9272660

All universal contact components live in 03_technology/11_frontend/portal/src/components/contact/ and are re-exported from a single barrel file. Always import from the barrel — never deep-import a single file.

import {
  ContactCard,
  ContactChannelsCard,
  ContactChannelsEdit,
  ContactSocialCard,
  ContactActivityCard,
  useContactChannels,
  useContactActivity,
} from "@/components/contact";

import type {
  PersonContact,
  ContactChannel,
  LandlordContact,
  TenantContact,
  SupplierContact,
  ContactActivityData,
} from "@/components/contact";
ComponentLinesFetches?Purpose
ContactCard.tsx165No — receives person propCompact person chip: avatar + name + role pill + channel icons
ContactChannelsCard.tsx391No — receives channels + Tier-1 fallbacksRead-only view of comms channels with WA/TG badges
ContactChannelsEdit.tsx551Save only (POST/PUT)Edit counterpart — add / remove / set primary channel
ContactSocialCard.tsx104No — receives channelsSocial links grid; returns null when empty
ContactActivityCard.tsx203Yes — useContactActivity(personId)Communication activity chart (threads or messages)

Type System

The SSOT for all contact shapes is components/contact/types.ts. Three layers:

1. ContactChannel — one row in tbl_persons_channels

export interface ContactChannel {
  channel_id?: string;             // absent when synthesised from Tier-1
  channel_type: ContactChannelType; // "email" | "phone" | "whatsapp" | ... | string
  channel_value: string;
  is_primary: boolean;
  label?: string | null;           // "Work Email", "Mobile"
  has_whatsapp?: boolean;          // synthesised by API from companion row
  has_telegram?: boolean;          // synthesised by API from companion row
}

The channel_type union is closed at the built-ins (email, phone, whatsapp, sms, telegram, wechat, website, facebook, instagram, tiktok, linkedin, x, twitter) but open via string so future channel types do not require a type-level migration.

has_whatsapp / has_telegram are NOT columns

These flags exist only on the TypeScript type. The API route synthesises them by checking whether a companion whatsapp or telegram row exists with the same digits as the phone row. Do not write them into tbl_persons_channels — there is no column to receive them. Do not trust them as authoritative on the server; recompute on every read.

2. PersonContact — the universal person shape

export interface PersonContact {
  person_id: string;
  full_name: string;
  avatar_url: string | null;
  first_name?: string | null;
  last_name?: string | null;
  role?: string | null;             // "LANDLORD" | "TENANT" | "BOTH" | "UNKNOWN"
  priority?: string | null;         // "High" | "Medium" | "Low" | null
  complaint_count?: number | null;
  email?: string | null;            // Tier-1 fallback when channels[] empty
  phone?: string | null;            // Tier-1 fallback when channels[] empty
  channels?: ContactChannel[];      // may be empty
}

Tier-1 fallback rule: when channels is empty, consumers must fall back to person.email and person.phone. These come from tbl_persons directly. This is how the cards stay useful for legacy contacts that have no tbl_persons_channels rows yet.

3. Role-specific extensions

export interface LandlordContact extends PersonContact {
  rental_properties?: RentalProperty[];
  services?: LandlordServiceRef[];
  kyc_checks?: KycCheck[];
  comm_preferred?: string | null;   // manual override only — ADR-170
  preferred_language?: string | null;
}

export interface TenantContact extends PersonContact {
  tenancy_id?: string | null;
  current_address?: string | null;
  tenancy_start_date?: string | null;
  tenancy_end_date?: string | null;
}

export interface SupplierContact extends PersonContact {
  // Phase 3 BLOCKED — tbl_suppliers does not exist.
  // supplier_type / organisation_name have no DDL backing.
  supplier_type?: string | null;
  organisation_name?: string | null;
}
Supplier extension is a placeholder

SupplierContact is defined in the type file but cannot be persisted — tbl_suppliers does not exist in the schema. Do not write code that depends on supplier_type or organisation_name surviving a round-trip. Either add the DDL or re-map to tbl_persons.occupation / tbl_persons.employment.

Data Fetching & API Endpoints

Two SWR-style hooks ship with the components. Both are thin wrappers around fetch with abort-signal handling and an mutate() retry.

useContactChannels(personId)

// Endpoint: GET /api/persons/[personId]/channels
// Response: { channels: ContactChannel[] }
const { channels, isLoading, error, mutate } = useContactChannels(personId);

The API route (src/app/api/persons/[personId]/channels/route.ts) is staff-only, org-scoped, and synthesises the has_whatsapp / has_telegram flags on phone rows by matching digits against companion messaging rows. Ordering is is_primary DESC, channel_type ASC.

useContactActivity(personId, window = "all")

// Endpoint: GET /api/persons/[personId]/comms-activity?window=90d|365d|hot
// Response: ContactActivityData
const { activity, isLoading, error } = useContactActivity(personId, "all");

The activity route queries tbl_conversations for the person. Per the spec (COMMS_ACTIVITY_CHARTS_SPEC.md §8.4), it returns an honest empty when zero rows match — empty_reason is set, channels and series are empty arrays, and the card renders a plain-text empty state rather than a blank chart.

WindowMeaningBacked by
90dLast 90 daystbl_conversations realtime
365dLast 12 monthstbl_conversations realtime
hotHot window (current burst)ADR-298 — uses realtime; no rollup needed at P1
allAll time (default)tbl_conversations realtime

Usage: Landlord Detail Panel

LandlordDetailPanel.tsx composes the universal components in place of the deprecated per-role implementations:

import {
  ContactChannelsCard,
  ContactChannelsEdit,
  ContactSocialCard,
  ContactActivityCard,
} from "@/components/contact";

// inside the detail panel render:
{editingComms ? (
  <ContactChannelsEdit
    personId={landlord.person_id}
    channels={landlord.channels ?? []}
    email={landlord.email}
    phone={landlord.phone}
    preferredChannel={landlord.preferred_channel}
    preferredLanguage={landlord.preferred_language}
    onSaved={() => { setEditingComms(false); onLandlordUpdated?.(); }}
    onCancel={() => setEditingComms(false)}
    showMessagingToggles
    showPreferences
  />
) : (
  <ContactChannelsCard
    channels={landlord.channels ?? []}
    email={landlord.email}
    phone={landlord.phone}
    showMessagingBadges
    preferredChannel={landlord.preferred_channel}
    preferredLanguage={landlord.preferred_language}
    langOther={landlord.lang_other}
    onEdit={() => setEditingComms(true)}
  />
)}

<ContactSocialCard channels={landlord.channels ?? []} />
<ContactActivityCard personId={landlord.person_id} window="all" />

Notes:

  • showMessagingToggles and showPreferences are landlord-specific features. The Tenant panel leaves them off.
  • onLandlordUpdated?.() triggers the parent’s refetch — the panels keep ownership of the data, the cards just render it.
  • The window="all" prop is explicit on Landlord, default on Tenant — both hit the same endpoint with the same default.

Usage: Tenant Detail Panel

import {
  ContactChannelsCard,
  ContactSocialCard,
  ContactActivityCard,
} from "@/components/contact";

<ContactChannelsCard
  channels={channels}
  email={tenant.email}
  phone={tenant.phone}
  showMessagingBadges
  preferredChannel={tenant.preferred_channel}
  preferredLanguage={tenant.preferred_language}
  langOther={tenant.lang_other}
/>

<ContactSocialCard channels={channels} />
<ContactActivityCard personId={tenant.person_id} />

The Tenant panel passes the same shape with no edit callback — tenant comms editing is handled elsewhere. Everything else is identical to Landlord.

Testing Guide

Three layers of coverage, in increasing order of cost and confidence:

1. Unit tests — Vitest

Live in portal/src/__tests__/components/contact/:

  • ContactCard.test.tsx
  • ContactChannelsCard.test.tsx
  • ContactSocialCard.test.tsx
  • ContactActivityCard.test.tsx

Run with:

cd 03_technology/11_frontend/portal
npx vitest run src/__tests__/components/contact/

The unit suite covers the load-bearing behaviours: section titles, Tier-1 fallback (email/phone props used when channels[] is empty), empty-state rendering, WA/TG chip visibility when showMessagingBadges is on / off, and the pencil button rendering only when onEdit is provided.

2. E2E tests — Playwright

Live in portal/e2e/:

  • landlord-contact-view.spec.ts — exercises Landlord RHS detail panel
  • tenant-contact-view.spec.ts — exercises Tenant RHS detail panel
  • contact-components.spec.ts — cross-cutting checks

Run with:

BASE_URL=https://app.estateaigents.com \
ORG_ID=a0450010-0778-4000-8000-000000000010 \
COOKIE='...' \
npx playwright test e2e/landlord-contact-view.spec.ts --reporter=line

E2E expectations: the Landlord RHS shows “Communication”, “Social Media” (if channels exist), and “Communication activity” sections, with the pencil toggling into ContactChannelsEdit. Tenant view asserts the same minus edit.

3. Smoke — after any deploy

# Open any landlord and tenant on staging, check:
#  - "Communication" section renders with email + phone
#  - "Social Media" section appears only when social channels exist
#  - "Communication activity" shows the chart OR an "honest empty" message
#  - Pencil icon toggles into edit mode without a full-page reload

Migration from Deprecated Components

Phase 2 (commits 2b5d466e → a16a78e3) replaced four landlord-specific components with the universal set. If you find a panel still using the old names, migrate it:

DeprecatedReplacementNotes
CompactPersonCardContactCardSame props shape; rename import, drop any custom role pill logic (now built in)
LandlordCommsSection (view half)ContactChannelsCardPass channels + Tier-1 email / phone; use onEdit to flip to edit mode
LandlordCommsSection (edit half)ContactChannelsEditRequires personId, onCancel, onSaved. Gate landlord extras with showMessagingToggles / showPreferences
LandlordSocialSectionContactSocialCardReturns null when empty — no need to wrap in a conditional
CommsActivitySectionContactActivityCardPass personId for SWR-fetch or activity for pre-fetched data
Migration checklist for a new consumer (e.g. Supplier panel)

1. Import from @/components/contact (barrel only). 2. Build a PersonContact-shaped object in your data layer — at minimum person_id, full_name, avatar_url, plus channels[] or Tier-1 email/phone. 3. Render <ContactChannelsCard />, <ContactSocialCard />, <ContactActivityCard /> in that order. 4. Add an onEdit handler only if your panel supports inline editing. 5. Add Vitest coverage for the Tier-1 fallback path (empty channels).

References & External Sources

SourceTypeNotes
portal/src/components/contact/types.ts Code SSOT for PersonContact, ContactChannel, role extensions
portal/src/components/contact/index.ts Code Barrel export — always import from here
portal/src/app/api/persons/[personId]/channels/route.ts Code Staff-only endpoint; synthesises has_whatsapp / has_telegram via digit match
portal/src/app/api/persons/[personId]/comms-activity/route.ts Code Honest-empty per COMMS_ACTIVITY_CHARTS_SPEC.md §8.4; ADR-298 window mapping
portal/src/components/ui/charts/COMMS_ACTIVITY_CHARTS_SPEC.md Spec Universal chart primitives consumed by ContactActivityCard
ADR-170 ADR comm_preferred is manual override only — never auto-derive
ADR-298 ADR Comms-activity window mapping; realtime over rollup at P1
Commits 2b5d466e, 3e57076f, a16a78e3, e9272660 Git Phase 1 → 2 → 4 progression; unit + E2E test coverage landed in e9272660