2.35 Property Status Architecture — Single-Word Pill Mapping, lost_reason Values & Win-Back Chip
Single-word pill mapping · lost_reason values · is_win_back WIN BACK chip · occupancy-collision note · i18n lookup pattern · chat update gap
Single-word pill mapping · lost_reason values · is_win_back WIN BACK chip · occupancy-collision note · i18n lookup pattern · chat update gap
asset_status drives the Current vs Past section divider — it is never shown as a pill. For Past properties the single-word pill label and colour come from lost_reason. Pills render at 10px in a flex-wrap row on a compact card — labels are deliberately short single words (DIY, REPO, etc.). is_win_back is an independent boolean rendered as a separate outlined ↺ WIN BACK chip (blue border, transparent fill), placed after the reason pill. This mapping applies to both the Universal Inbox PropertySection and the props-attributes hero card (TemporaryFullPropertyCard) — they share the same semantic mapping. Pill labels and tooltips are looked up from an i18n labels dictionary keyed on the raw DB value — never hardcoded in JSX.
§1 Architecture Overview
How the three DB columns map to UI elements in the Universal Inbox property card.
§2 Data Model — tbl_assets
Three columns are relevant to the status pill system. management_status drives the lifecycle (lead → managed → lost → won_back) but is not shown in the inbox pill — it's used internally by the AI and compliance layers.
| Column | Type | Migration | Purpose | UI role |
|---|---|---|---|---|
asset_status |
varchar(20) |
V001 (original) | Coarse lifecycle: Instructed, Farming, Lost | Section grouping only — drives Current / Past divider, never shown as a pill |
lost_reason |
varchar(50) NULL |
V004/01_alter_tbl_assets.sql |
Reason the asset left management. Only set when asset_status = Lost |
Pill label + colour for Past properties |
is_win_back |
BOOLEAN DEFAULT false |
ad-hoc/20260325_add_is_win_back_flag.sql |
Flags a Lost asset with re-engagement potential | Separate action badge (↺ Win Back) — NOT a status pill |
management_status |
varchar(20) |
V004/01 comment update | Fine-grained lifecycle: lead, onboarding, managed, offboarding, lost, won_back | Not shown in inbox — used by AI strategy layer |
lost_reason is a free varchar(50). New values (self_managing, new_agent) are functional from deploy — no DDL required. The column comment in V004 is the canonical value list; code is the authoritative mapping.
§3 Current vs Past Grouping — isCurrentStatus()
The Universal Inbox property list renders two sections: Current properties on top, Past below. The divider is determined client-side by isCurrentStatus() in PropertySection.tsx:
// src/app/dashboard-v2/_components/inbox/PropertySection.tsx
function isCurrentStatus(status: string | null): boolean {
const s = (status ?? '').toLowerCase();
return s === 'instructed' || s === 'farming' || s === '';
}
| asset_status value | isCurrentStatus() | Section |
|---|---|---|
Instructed | true | CURRENT |
Farming | true | CURRENT |
"" / null | true (fallback) | CURRENT |
Lost | false | PAST |
| anything else | false | PAST |
assetStatusBadge() is called for all cards but only delegates to lostReasonBadge() when status.toLowerCase() === 'lost'. Current-section pills (INSTRUCTED, FARMING) are hardcoded — they do not use lost_reason.
function assetStatusBadge(status: string | null, lost_reason?: string | null) {
const s = (status ?? '').toLowerCase();
if (s === 'instructed') return { bg: 'var(--t-success-alpha)', fg: 'var(--t-success)', label: 'INSTRUCTED' };
if (s === 'farming') return { bg: 'var(--t-info-alpha)', fg: 'var(--t-info)', label: 'FARMING' };
if (s === 'lost') return lostReasonBadge(lost_reason); // ← pill driven by lost_reason
return { bg: 'var(--t-bg-subtle)', fg: 'var(--t-text-muted)', label: status?.toUpperCase() ?? '' };
}
§4 Pill Colour Mapping — All lost_reason Values
Source: lostReasonBadge() in PropertySection.tsx, shared by TemporaryFullPropertyCard. All labels are single words — pills render at ~10px font in a flex-wrap row on a compact card; multi-word labels cause layout overflow.
RAIA (Real estate Artificial Intelligence Agent) property cards also show a physical occupancy pill (e.g. OCCUPIED) driven by the occupancy_status field — independent of lost_reason. If owner_moved_in were labelled OCCUPIED it would visually collide with the occupancy pill and create ambiguity. The label is therefore MOVED IN to unambiguously signal the landlord themselves moved in, rather than a tenant occupancy state.
| lost_reason DB value | Pill label | Colour | Background | Foreground | Notes |
|---|---|---|---|---|---|
owner_sold |
SOLD | Green | var(--t-success-alpha) |
var(--t-success) |
Landlord sold the property — clean exit, no fault |
owner_moved_in |
MOVED IN | Amber | rgba(251,191,36,0.15) |
#b45309 |
Landlord occupied property themselves. Label is MOVED IN (not OCCUPIED) to avoid collision with the physical occupancy pill — see note above. |
self_managing |
DIY | Blue | var(--t-info-alpha) |
var(--t-info) |
Landlord chose to self-manage. Pill shows DIY — concise, unambiguous. The full reason (e.g. "Owner decided to Self-Manage (DIY)") belongs in the property history diary/notes, NOT the pill label. |
competitor_won |
COMPETITOR | Red | var(--t-danger-alpha) |
var(--t-danger) |
Lost to a competitor agent |
new_agent (deprecated — folded) |
COMPETITOR | Red | var(--t-danger-alpha) |
var(--t-danger) |
new_agent is deprecated at the display layer. It renders identically to competitor_won — same COMPETITOR pill. Staff should use competitor_won going forward; new_agent records in the DB continue to display correctly. |
fee_dispute |
DISPUTE | Red | var(--t-danger-alpha) |
var(--t-danger) |
Left over fee disagreement |
service_complaint |
COMPLAINT | Red | var(--t-danger-alpha) |
var(--t-danger) |
Explicit service complaint — highest churn risk signal |
deceased |
DECEASED | Grey | rgba(0,0,0,0.08) |
#6b7280 |
Landlord deceased — estate/probate scenario |
repossessed |
REPO | Dark red | rgba(127,29,29,0.12) |
#991b1b |
Property repossessed by lender. Label shortened to REPO — fits compact pill row. |
other |
OTHER | Grey | rgba(0,0,0,0.08) |
#6b7280 |
Catch-all — unclassified reason |
null / unknown |
LOST | Grey | rgba(0,0,0,0.08) |
#1a1a1a |
Default fallback — reason not recorded |
Single-word label rationale
Pills are rendered at approximately 10px font size in a flex-wrap row on a compact property card. Multi-word labels (e.g. "SELF MANAGING", "FEE DISPUTE", "REPOSSESSED") overflow the pill boundary or force unwanted line breaks at smaller viewports. All labels are therefore reduced to a single word or tight abbreviation: DIY, DISPUTE, COMPLAINT, REPO, LOST. The full human-readable reason is stored in the property history diary/notes and surfaced in tooltips — not in the pill itself.
ManagementMenu.tsx dropdown values
The staff dropdown in ManagementMenu.tsx lists options in alphabetical order (sorted by the LOST_REASON_OPTIONS array). new_agent remains in the dropdown for backwards compatibility but is labelled as deprecated in UI copy. competitor_won is the preferred value:
// src/components/ManagementMenu.tsx
const LOST_REASON_OPTIONS = [
"competitor_won",
"deceased",
"fee_dispute",
"new_agent", // deprecated — maps to COMPETITOR pill (same as competitor_won)
"other",
"owner_moved_in",
"owner_sold",
"repossessed",
"self_managing",
"service_complaint"
];
lost_reason is varchar(50) with no CHECK constraint. Any string can be stored. The pill mapping in PropertySection.tsx falls through to the grey "LOST" default for unrecognised values. Add new values to both LOST_REASON_OPTIONS (dropdown) and lostReasonBadge() (pill switch) — neither auto-syncs.
§5 WIN BACK — Outlined Chip, Not a Status Pill
is_win_back can be true on any lost property regardless of lost_reason. A service_complaint property can be flagged for win-back; a deceased one generally won't be. The flag is toggled independently by staff via the ManagementMenu.
The WIN BACK chip renders as a separate outlined chip placed immediately after the lost_reason pill — it is never folded into the status pill. Visual spec: blue border (#4f46e5), transparent fill, blue label text, ↺ prefix glyph, tooltip "Targeted for win-back". This card can therefore simultaneously show:
- Section: PAST
- Status pill: DIY
- WIN BACK chip: ↺ WIN BACK
DB definition
-- ad-hoc/20260325_add_is_win_back_flag.sql
ALTER TABLE tbl_assets
ADD COLUMN IF NOT EXISTS is_win_back BOOLEAN DEFAULT FALSE;
-- Filtered index for efficient win-back queue queries
CREATE INDEX IF NOT EXISTS idx_assets_win_back
ON tbl_assets(asset_status, is_win_back)
WHERE asset_status = 'Lost' AND is_win_back = TRUE;
API passthrough
The inbox context API (src/app/api/inbox/conversations/[id]/context/route.ts) passes lost_reason raw to the frontend. is_win_back follows the same pattern — no server-side transformation. The PropertyItem interface declares both as nullable:
// PropertySection.tsx — PropertyItem interface
export interface PropertyItem {
asset_id: string;
asset_status: string | null;
lost_reason?: string | null; // raw DB value
is_win_back?: boolean | null; // raw DB boolean
// ...
}
§6 i18n Lookup Pattern — Labels Dictionary
Pill labels and tooltip strings are never hardcoded in JSX. They are resolved at render time via a labels dictionary keyed on the raw DB value. This means adding a new locale requires adding one dictionary — no JSX changes.
// src/lib/i18n/lostReasonLabels.ts
// ─── Lookup module — add new locales here, never in JSX ───────────────────
type LostReasonKey =
| 'owner_sold' | 'owner_moved_in' | 'self_managing'
| 'competitor_won' | 'new_agent' // new_agent folded → COMPETITOR
| 'fee_dispute' | 'service_complaint'
| 'deceased' | 'repossessed' | 'other';
interface LabelEntry { pill: string; tooltip: string; }
const en: Record<LostReasonKey, LabelEntry> = {
owner_sold: { pill: 'SOLD', tooltip: 'Landlord sold the property' },
owner_moved_in: { pill: 'MOVED IN', tooltip: 'Landlord moved in themselves' },
self_managing: { pill: 'DIY', tooltip: 'Owner decided to self-manage (DIY)' },
competitor_won: { pill: 'COMPETITOR', tooltip: 'Lost to a competitor agent' },
new_agent: { pill: 'COMPETITOR', tooltip: 'Went to another agent (deprecated value)' },
fee_dispute: { pill: 'DISPUTE', tooltip: 'Left over a fee disagreement' },
service_complaint: { pill: 'COMPLAINT', tooltip: 'Explicit service complaint' },
deceased: { pill: 'DECEASED', tooltip: 'Landlord deceased — estate/probate' },
repossessed: { pill: 'REPO', tooltip: 'Property repossessed by lender' },
other: { pill: 'OTHER', tooltip: 'Unclassified reason' },
};
// Fallback for null / unknown values
const FALLBACK: LabelEntry = { pill: 'LOST', tooltip: 'Reason not recorded' };
const locales: Record<string, Record<string, LabelEntry>> = { en };
export function getLostReasonLabel(
dbValue: string | null | undefined,
locale = 'en'
): LabelEntry {
const dict = locales[locale] ?? locales['en'];
return dict[dbValue ?? ''] ?? FALLBACK;
}
// PropertySection.tsx (or TemporaryFullPropertyCard.tsx)
const { pill, tooltip } = getLostReasonLabel(property.lost_reason);
// <span title={tooltip}>{pill}</span>
Future locales (e.g. fr, ar) simply add an entry to locales. The WIN BACK chip label and tooltip follow the same pattern via a separate getWinBackLabel(locale) helper in the same module.
§7 Chat-Based Updates — Architecture & Gap (ADR-137)
The planned future state allows staff to update lost_reason via the Staff Aigent chat: "We lost this property because of bad service" → AI extracts intent → writes lost_reason = 'service_complaint' to tbl_assets.
ADR-137 documents the constraint: the Staff Aigent currently has no tool that can write directly to tbl_assets. All asset mutations go through the ManagementMenu UI (PATCH /api/assets/:id). Until ADR-137 is resolved with a set_asset_lost_reason tool or equivalent, chat-based lost_reason updates are not available.
Planned architecture (not yet live)
Staff chat: "We lost 123 Main St — bad service"
↓
Staff Aigent NLU: extracts { asset_ref, lost_reason: 'service_complaint' }
↓
Tool call: set_asset_lost_reason(asset_id, lost_reason) ← MISSING (ADR-137)
↓
PATCH /api/assets/:id { lost_reason: 'service_complaint' }
↓
tbl_assets updated → inbox pill updates on next load
| Component | Status | Notes |
|---|---|---|
| ManagementMenu UI dropdown | ✅ Live | Staff select lost_reason from dropdown in sidebar |
| PATCH /api/assets/:id endpoint | ✅ Live | Accepts lost_reason field |
| inbox context API passthrough | ✅ Live | context/route.ts returns raw lost_reason |
| Pill rendering (lostReasonBadge) | ✅ Live | All 10 values + null fallback mapped (single-word labels; new_agent folded into COMPETITOR) |
Chat → set_asset_lost_reason tool | ❌ Not built | ADR-137 — write tool pending |
| NLU intent extraction for lost_reason | ❌ Not built | Depends on write tool existing first |
§8 Code File References
| File | What it does |
|---|---|
src/lib/i18n/lostReasonLabels.ts |
i18n lookup module — getLostReasonLabel() resolves pill label + tooltip from DB value; getWinBackLabel() for WIN BACK chip copy |
src/app/dashboard-v2/_components/inbox/PropertySection.tsx |
lostReasonBadge(), assetStatusBadge(), isCurrentStatus(), PropertyItem interface |
src/components/TemporaryFullPropertyCard.tsx |
Props-attributes hero card — uses same lostReasonBadge() semantic mapping as the inbox PropertySection |
src/components/ManagementMenu.tsx |
LOST_REASON_OPTIONS — dropdown array, also the authoritative list of staff-selectable values |
src/app/api/inbox/conversations/[id]/context/route.ts |
Returns lost_reason raw from DB to the inbox context panel |
03_technology/04_datastores/database/ddl/live-supabase/V004/01_alter_tbl_assets.sql |
Adds lost_reason varchar(50) NULL column and management_status comment update |
03_technology/04_datastores/database/ad-hoc/20260325_add_is_win_back_flag.sql |
Adds is_win_back BOOLEAN DEFAULT false column + filtered index |
§9 References & External Sources
| Source | Type | Notes |
|---|---|---|
V004/01_alter_tbl_assets.sql |
DDL migration | Authoritative column definition for lost_reason. DB comment lists canonical values. |
20260325_add_is_win_back_flag.sql |
Ad-hoc migration | is_win_back column + filtered index definition. |
PropertySection.tsx |
Frontend — React | Single source of truth for pill colour mapping and grouping logic. |
ManagementMenu.tsx |
Frontend — React | Authoritative list of staff-selectable lost_reason values via LOST_REASON_OPTIONS. |
| ADR-137 | Architecture decision | Documents the write tool gap for chat-based asset mutations. |