fix(registratura): remove parentheses from institution-only contacts, add live contact sync
- Fix display format: institutions without a person name no longer show as "(Company)" — now shows just "Company" - Three-case formatting: name+company → "Name (Company)", only company → "Company", only name → "Name" - Registry table now resolves sender/recipient live from address book via contactMap — edits in address book reflect immediately in registry - New contacts created via quick-contact are added to contactMap on the fly Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useState, useMemo, useCallback } from "react";
|
import { useState, useEffect, useMemo, useCallback } from "react";
|
||||||
import { BookOpen, Plus } from "lucide-react";
|
import { BookOpen, Plus } from "lucide-react";
|
||||||
import { NotificationPreferences } from "./notification-preferences";
|
import { NotificationPreferences } from "./notification-preferences";
|
||||||
import {
|
import {
|
||||||
@@ -76,6 +76,21 @@ export function RegistraturaModule() {
|
|||||||
const contactStorage = useStorage("address-book");
|
const contactStorage = useStorage("address-book");
|
||||||
const tagStorageService = useStorageService();
|
const tagStorageService = useStorageService();
|
||||||
|
|
||||||
|
// ── Live contact map for table display (contactId → { name, company }) ──
|
||||||
|
const [contactMap, setContactMap] = useState<Map<string, { name: string; company: string }>>(new Map());
|
||||||
|
useEffect(() => {
|
||||||
|
contactStorage.exportAll().then((all) => {
|
||||||
|
const map = new Map<string, { name: string; company: string }>();
|
||||||
|
for (const [key, value] of Object.entries(all)) {
|
||||||
|
if (key.startsWith("contact:") && value) {
|
||||||
|
const c = value as { id?: string; name?: string; company?: string };
|
||||||
|
if (c.id) map.set(c.id, { name: c.name ?? "", company: c.company ?? "" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setContactMap(map);
|
||||||
|
});
|
||||||
|
}, [contactStorage]);
|
||||||
|
|
||||||
const [viewMode, setViewMode] = useState<ViewMode>("list");
|
const [viewMode, setViewMode] = useState<ViewMode>("list");
|
||||||
const [editingEntry, setEditingEntry] = useState<RegistryEntry | null>(null);
|
const [editingEntry, setEditingEntry] = useState<RegistryEntry | null>(null);
|
||||||
const [viewingEntry, setViewingEntry] = useState<RegistryEntry | null>(null);
|
const [viewingEntry, setViewingEntry] = useState<RegistryEntry | null>(null);
|
||||||
@@ -121,6 +136,12 @@ export function RegistraturaModule() {
|
|||||||
updatedAt: now,
|
updatedAt: now,
|
||||||
};
|
};
|
||||||
await contactStorage.set(`contact:${contact.id}`, contact);
|
await contactStorage.set(`contact:${contact.id}`, contact);
|
||||||
|
// Update live contact map
|
||||||
|
setContactMap((prev) => {
|
||||||
|
const next = new Map(prev);
|
||||||
|
next.set(contact.id, { name: contact.name, company: contact.company });
|
||||||
|
return next;
|
||||||
|
});
|
||||||
return contact;
|
return contact;
|
||||||
} catch {
|
} catch {
|
||||||
return undefined;
|
return undefined;
|
||||||
@@ -539,6 +560,7 @@ export function RegistraturaModule() {
|
|||||||
onDelete={handleDelete}
|
onDelete={handleDelete}
|
||||||
onClose={handleCloseViaReply}
|
onClose={handleCloseViaReply}
|
||||||
onReply={handleConex}
|
onReply={handleConex}
|
||||||
|
contactMap={contactMap}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{!loading && (
|
{!loading && (
|
||||||
|
|||||||
@@ -86,6 +86,14 @@ import {
|
|||||||
} from "../services/deadline-service";
|
} from "../services/deadline-service";
|
||||||
import { getDeadlineType } from "../services/deadline-catalog";
|
import { getDeadlineType } from "../services/deadline-catalog";
|
||||||
|
|
||||||
|
/** Format a contact for display: "Name (Company)" / "Company" / "Name" */
|
||||||
|
function formatContactLabel(c: { name: string; company: string }): string {
|
||||||
|
const name = c.name?.trim();
|
||||||
|
const company = c.company?.trim();
|
||||||
|
if (name && company) return `${name} (${company})`;
|
||||||
|
return name || company || "";
|
||||||
|
}
|
||||||
|
|
||||||
interface RegistryEntryFormProps {
|
interface RegistryEntryFormProps {
|
||||||
initial?: RegistryEntry;
|
initial?: RegistryEntry;
|
||||||
/** Pre-fill as reply to this entry — sets threadParentId, flips direction (used by "Inchide") */
|
/** Pre-fill as reply to this entry — sets threadParentId, flips direction (used by "Inchide") */
|
||||||
@@ -666,8 +674,7 @@ export function RegistryEntryForm({
|
|||||||
|
|
||||||
const hasExactMatch = suggestions.some(
|
const hasExactMatch = suggestions.some(
|
||||||
(c) =>
|
(c) =>
|
||||||
c.name.toLowerCase() === currentValue.toLowerCase() ||
|
formatContactLabel(c).toLowerCase() === currentValue.toLowerCase(),
|
||||||
`${c.name} (${c.company})`.toLowerCase() === currentValue.toLowerCase(),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const showCreateButton =
|
const showCreateButton =
|
||||||
@@ -1067,7 +1074,7 @@ export function RegistryEntryForm({
|
|||||||
"sender",
|
"sender",
|
||||||
sender,
|
sender,
|
||||||
(c) => {
|
(c) => {
|
||||||
setSender(c.company ? `${c.name} (${c.company})` : c.name);
|
setSender(formatContactLabel(c));
|
||||||
setSenderContactId(c.id);
|
setSenderContactId(c.id);
|
||||||
setSenderFocused(false);
|
setSenderFocused(false);
|
||||||
},
|
},
|
||||||
@@ -1108,7 +1115,7 @@ export function RegistryEntryForm({
|
|||||||
"recipient",
|
"recipient",
|
||||||
recipient,
|
recipient,
|
||||||
(c) => {
|
(c) => {
|
||||||
setRecipient(c.company ? `${c.name} (${c.company})` : c.name);
|
setRecipient(formatContactLabel(c));
|
||||||
setRecipientContactId(c.id);
|
setRecipientContactId(c.id);
|
||||||
setRecipientFocused(false);
|
setRecipientFocused(false);
|
||||||
},
|
},
|
||||||
@@ -1203,7 +1210,7 @@ export function RegistryEntryForm({
|
|||||||
"assignee",
|
"assignee",
|
||||||
assignee,
|
assignee,
|
||||||
(c) => {
|
(c) => {
|
||||||
setAssignee(c.company ? `${c.name} (${c.company})` : c.name);
|
setAssignee(formatContactLabel(c));
|
||||||
setAssigneeContactId(c.id);
|
setAssigneeContactId(c.id);
|
||||||
setAssigneeFocused(false);
|
setAssigneeFocused(false);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -39,6 +39,19 @@ import { DEFAULT_DOC_TYPE_LABELS, EXTERNAL_STATUS_LABELS } from "../types";
|
|||||||
import { getOverdueDays } from "../services/registry-service";
|
import { getOverdueDays } from "../services/registry-service";
|
||||||
import { cn } from "@/shared/lib/utils";
|
import { cn } from "@/shared/lib/utils";
|
||||||
|
|
||||||
|
/** Format a contact for display: "Name (Company)" / "Company" / "Name" */
|
||||||
|
function formatContactLabel(c: { name?: string; company?: string }): string {
|
||||||
|
const name = (c.name ?? "").trim();
|
||||||
|
const company = (c.company ?? "").trim();
|
||||||
|
if (name && company) return `${name} (${company})`;
|
||||||
|
return name || company || "";
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ContactInfo {
|
||||||
|
name: string;
|
||||||
|
company: string;
|
||||||
|
}
|
||||||
|
|
||||||
interface RegistryTableProps {
|
interface RegistryTableProps {
|
||||||
entries: RegistryEntry[];
|
entries: RegistryEntry[];
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
@@ -48,6 +61,8 @@ interface RegistryTableProps {
|
|||||||
onClose: (entry: RegistryEntry) => void;
|
onClose: (entry: RegistryEntry) => void;
|
||||||
/** Create a new entry linked as reply (conex) to this entry */
|
/** Create a new entry linked as reply (conex) to this entry */
|
||||||
onReply?: (entry: RegistryEntry) => void;
|
onReply?: (entry: RegistryEntry) => void;
|
||||||
|
/** Live contact data map: contactId → { name, company } for live sync */
|
||||||
|
contactMap?: Map<string, ContactInfo>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Column definitions ──
|
// ── Column definitions ──
|
||||||
@@ -185,6 +200,7 @@ export function RegistryTable({
|
|||||||
onDelete,
|
onDelete,
|
||||||
onClose,
|
onClose,
|
||||||
onReply,
|
onReply,
|
||||||
|
contactMap,
|
||||||
}: RegistryTableProps) {
|
}: RegistryTableProps) {
|
||||||
const [visibleCols, setVisibleCols] = useState<Set<ColumnId>>(
|
const [visibleCols, setVisibleCols] = useState<Set<ColumnId>>(
|
||||||
() => DEFAULT_VISIBLE,
|
() => DEFAULT_VISIBLE,
|
||||||
@@ -416,16 +432,22 @@ export function RegistryTable({
|
|||||||
)}
|
)}
|
||||||
{visibleCols.has("sender") && (
|
{visibleCols.has("sender") && (
|
||||||
<td className="px-3 py-2 max-w-[130px] truncate text-xs">
|
<td className="px-3 py-2 max-w-[130px] truncate text-xs">
|
||||||
{entry.sender || (
|
{(() => {
|
||||||
|
const live = entry.senderContactId && contactMap?.get(entry.senderContactId);
|
||||||
|
return (live ? formatContactLabel(live) : entry.sender) || (
|
||||||
<span className="text-muted-foreground">—</span>
|
<span className="text-muted-foreground">—</span>
|
||||||
)}
|
);
|
||||||
|
})()}
|
||||||
</td>
|
</td>
|
||||||
)}
|
)}
|
||||||
{visibleCols.has("recipient") && (
|
{visibleCols.has("recipient") && (
|
||||||
<td className="px-3 py-2 max-w-[130px] truncate text-xs">
|
<td className="px-3 py-2 max-w-[130px] truncate text-xs">
|
||||||
{entry.recipient || (
|
{(() => {
|
||||||
|
const live = entry.recipientContactId && contactMap?.get(entry.recipientContactId);
|
||||||
|
return (live ? formatContactLabel(live) : entry.recipient) || (
|
||||||
<span className="text-muted-foreground">—</span>
|
<span className="text-muted-foreground">—</span>
|
||||||
)}
|
);
|
||||||
|
})()}
|
||||||
</td>
|
</td>
|
||||||
)}
|
)}
|
||||||
{visibleCols.has("assignee") && (
|
{visibleCols.has("assignee") && (
|
||||||
|
|||||||
Reference in New Issue
Block a user