feat: add address book, fix email layout, update dependencies

- Address book with JMAP sync and local fallback (contacts CRUD,
  search/filter, composer autocomplete, i18n for 8 languages)
- Fix email layout: remove horizontal scroll, left-side clipping,
  and empty spaces from blocked external images in newsletters
- Update all dependencies to latest compatible versions
- Expand i18n from 3 to 8 languages (added ES, IT, DE, NL, PT)
- Upgrade Next.js to 16.1.6 for security patches
This commit is contained in:
Matthieu MALVACHE
2026-02-16 17:25:20 +01:00
committed by Matthieu MALVACHE
parent 5d60fe5186
commit 8a5bc9b88d
27 changed files with 2927 additions and 968 deletions
+153
View File
@@ -0,0 +1,153 @@
"use client";
import { useTranslations } from "next-intl";
import { Mail, Phone, Building, MapPin, StickyNote, Pencil, Trash2, BookUser } from "lucide-react";
import { Avatar } from "@/components/ui/avatar";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
import type { ContactCard } from "@/lib/jmap/types";
import { getContactDisplayName, getContactPrimaryEmail } from "@/stores/contact-store";
interface ContactDetailProps {
contact: ContactCard | null;
onEdit: () => void;
onDelete: () => void;
className?: string;
}
export function ContactDetail({ contact, onEdit, onDelete, className }: ContactDetailProps) {
const t = useTranslations("contacts");
if (!contact) {
return (
<div className={cn("flex flex-col items-center justify-center h-full text-muted-foreground", className)}>
<BookUser className="w-16 h-16 mb-4 opacity-20" />
<p className="text-sm">{t("detail.no_contact_selected")}</p>
</div>
);
}
const name = getContactDisplayName(contact);
const email = getContactPrimaryEmail(contact);
const emails = contact.emails ? Object.values(contact.emails) : [];
const phones = contact.phones ? Object.values(contact.phones) : [];
const orgs = contact.organizations ? Object.values(contact.organizations) : [];
const addresses = contact.addresses ? Object.values(contact.addresses) : [];
const notes = contact.notes ? Object.values(contact.notes) : [];
return (
<div className={cn("flex flex-col h-full overflow-y-auto", className)}>
<div className="px-6 py-6 border-b border-border">
<div className="flex items-start justify-between">
<div className="flex items-center gap-4">
<Avatar name={name} email={email} size="lg" />
<div>
<h2 className="text-xl font-semibold">{name || "—"}</h2>
{orgs.length > 0 && orgs[0].name && (
<p className="text-sm text-muted-foreground">{orgs[0].name}</p>
)}
</div>
</div>
<div className="flex gap-2">
<Button variant="outline" size="sm" onClick={onEdit}>
<Pencil className="w-4 h-4 mr-1" />
{t("form.edit_title")}
</Button>
<Button variant="outline" size="sm" onClick={onDelete} className="text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300 hover:bg-red-50 dark:hover:bg-red-950">
<Trash2 className="w-4 h-4" />
</Button>
</div>
</div>
</div>
<div className="px-6 py-4 space-y-6">
{emails.length > 0 && (
<Section icon={Mail} title={t("detail.emails")}>
{emails.map((e, i) => (
<div key={i} className="flex items-center gap-2">
<a href={`mailto:${e.address}`} className="text-sm text-primary hover:underline">
{e.address}
</a>
{e.contexts && (
<ContextBadge contexts={e.contexts} />
)}
</div>
))}
</Section>
)}
{phones.length > 0 && (
<Section icon={Phone} title={t("detail.phones")}>
{phones.map((p, i) => (
<div key={i} className="flex items-center gap-2">
<a href={`tel:${p.number}`} className="text-sm text-primary hover:underline">
{p.number}
</a>
{p.contexts && (
<ContextBadge contexts={p.contexts} />
)}
</div>
))}
</Section>
)}
{orgs.length > 0 && (
<Section icon={Building} title={t("detail.organizations")}>
{orgs.map((o, i) => (
<div key={i} className="text-sm">
{o.name}
{o.units && o.units.length > 0 && (
<span className="text-muted-foreground"> {o.units.map(u => u.name).join(", ")}</span>
)}
</div>
))}
</Section>
)}
{addresses.length > 0 && (
<Section icon={MapPin} title={t("detail.addresses")}>
{addresses.map((a, i) => (
<div key={i} className="text-sm">
{[a.street, a.locality, a.region, a.postcode, a.country].filter(Boolean).join(", ")}
{a.contexts && (
<ContextBadge contexts={a.contexts} />
)}
</div>
))}
</Section>
)}
{notes.length > 0 && (
<Section icon={StickyNote} title={t("detail.notes")}>
{notes.map((n, i) => (
<p key={i} className="text-sm whitespace-pre-wrap">{n.note}</p>
))}
</Section>
)}
</div>
</div>
);
}
function Section({ icon: Icon, title, children }: { icon: React.ComponentType<{ className?: string }>; title: string; children: React.ReactNode }) {
return (
<div>
<div className="flex items-center gap-2 mb-2">
<Icon className="w-4 h-4 text-muted-foreground" />
<h3 className="text-sm font-medium text-muted-foreground">{title}</h3>
</div>
<div className="space-y-1 pl-6">{children}</div>
</div>
);
}
function ContextBadge({ contexts }: { contexts: Record<string, boolean> }) {
const labels = Object.keys(contexts).filter(k => contexts[k]);
if (labels.length === 0) return null;
return (
<span className="text-xs px-1.5 py-0.5 rounded bg-muted text-muted-foreground">
{labels.join(", ")}
</span>
);
}
+304
View File
@@ -0,0 +1,304 @@
"use client";
import { useState } from "react";
import { useTranslations } from "next-intl";
import { X, Plus } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import type { ContactCard } from "@/lib/jmap/types";
interface EmailEntry {
address: string;
context: "work" | "private" | "";
}
interface PhoneEntry {
number: string;
context: "work" | "private" | "";
}
interface ContactFormProps {
contact?: ContactCard | null;
onSave: (data: Partial<ContactCard>) => Promise<void>;
onCancel: () => void;
}
export function ContactForm({ contact, onSave, onCancel }: ContactFormProps) {
const t = useTranslations("contacts.form");
const isEditing = !!contact;
const givenInit = contact?.name?.components?.find(c => c.kind === "given")?.value || "";
const surnameInit = contact?.name?.components?.find(c => c.kind === "surname")?.value || "";
const [givenName, setGivenName] = useState(givenInit);
const [surname, setSurname] = useState(surnameInit);
const [emails, setEmails] = useState<EmailEntry[]>(() => {
if (contact?.emails) {
return Object.values(contact.emails).map(e => ({
address: e.address,
context: e.contexts?.work ? "work" : e.contexts?.private ? "private" : "",
}));
}
return [{ address: "", context: "" }];
});
const [phones, setPhones] = useState<PhoneEntry[]>(() => {
if (contact?.phones) {
return Object.values(contact.phones).map(p => ({
number: p.number,
context: p.contexts?.work ? "work" : p.contexts?.private ? "private" : "",
}));
}
return [];
});
const [organization, setOrganization] = useState(
contact?.organizations ? Object.values(contact.organizations)[0]?.name || "" : ""
);
const [note, setNote] = useState(
contact?.notes ? Object.values(contact.notes)[0]?.note || "" : ""
);
const [isSaving, setIsSaving] = useState(false);
const [error, setError] = useState<string | null>(null);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setError(null);
if (!givenName.trim() && !surname.trim()) {
setError(t("name_required"));
return;
}
const validEmails = emails.filter(e => e.address.trim());
for (const entry of validEmails) {
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(entry.address.trim())) {
setError(t("email_invalid"));
return;
}
}
const emailsMap: Record<string, { address: string; contexts?: Record<string, boolean> }> = {};
validEmails.forEach((entry, i) => {
const obj: { address: string; contexts?: Record<string, boolean> } = { address: entry.address.trim() };
if (entry.context) {
obj.contexts = { [entry.context]: true };
}
emailsMap[`e${i}`] = obj;
});
const validPhones = phones.filter(p => p.number.trim());
const phonesMap: Record<string, { number: string; contexts?: Record<string, boolean> }> = {};
validPhones.forEach((entry, i) => {
const obj: { number: string; contexts?: Record<string, boolean> } = { number: entry.number.trim() };
if (entry.context) {
obj.contexts = { [entry.context]: true };
}
phonesMap[`p${i}`] = obj;
});
const nameComponents = [];
if (givenName.trim()) {
nameComponents.push({ kind: "given" as const, value: givenName.trim() });
}
if (surname.trim()) {
nameComponents.push({ kind: "surname" as const, value: surname.trim() });
}
const data: Partial<ContactCard> = {
name: { components: nameComponents, isOrdered: true },
emails: Object.keys(emailsMap).length > 0 ? emailsMap : undefined,
phones: Object.keys(phonesMap).length > 0 ? phonesMap : undefined,
organizations: organization.trim()
? { o0: { name: organization.trim() } }
: undefined,
notes: note.trim()
? { n0: { note: note.trim() } }
: undefined,
};
setIsSaving(true);
try {
await onSave(data);
} catch (err) {
setError(err instanceof Error ? err.message : t("save_failed"));
} finally {
setIsSaving(false);
}
};
return (
<form onSubmit={handleSubmit} className="flex flex-col h-full">
<div className="px-6 py-4 border-b border-border">
<h2 className="text-lg font-semibold">
{isEditing ? t("edit_title") : t("create_title")}
</h2>
</div>
<div className="flex-1 overflow-y-auto px-6 py-4 space-y-4">
{error && (
<div className="text-sm text-red-600 dark:text-red-400 bg-red-50 dark:bg-red-950 px-3 py-2 rounded">
{error}
</div>
)}
<div className="grid grid-cols-2 gap-3">
<div>
<label className="text-sm text-muted-foreground mb-1 block">{t("given_name")}</label>
<Input
value={givenName}
onChange={(e) => setGivenName(e.target.value)}
placeholder={t("given_name")}
autoFocus
/>
</div>
<div>
<label className="text-sm text-muted-foreground mb-1 block">{t("surname")}</label>
<Input
value={surname}
onChange={(e) => setSurname(e.target.value)}
placeholder={t("surname")}
/>
</div>
</div>
<div>
<label className="text-sm text-muted-foreground mb-1 block">{t("email")}</label>
<div className="space-y-2">
{emails.map((entry, i) => (
<div key={i} className="flex items-center gap-2">
<Input
type="email"
value={entry.address}
onChange={(e) => {
const next = [...emails];
next[i] = { ...next[i], address: e.target.value };
setEmails(next);
}}
placeholder={t("email_placeholder")}
className="flex-1"
/>
<select
value={entry.context}
onChange={(e) => {
const next = [...emails];
next[i] = { ...next[i], context: e.target.value as EmailEntry["context"] };
setEmails(next);
}}
className="text-sm bg-transparent border rounded px-2 py-2 text-foreground"
>
<option value=""></option>
<option value="work">{t("context_work")}</option>
<option value="private">{t("context_private")}</option>
</select>
{emails.length > 1 && (
<Button
type="button"
variant="ghost"
size="icon"
onClick={() => setEmails(emails.filter((_, j) => j !== i))}
className="h-8 w-8"
>
<X className="w-3 h-3" />
</Button>
)}
</div>
))}
<Button
type="button"
variant="ghost"
size="sm"
onClick={() => setEmails([...emails, { address: "", context: "" }])}
>
<Plus className="w-3 h-3 mr-1" />
{t("add_email")}
</Button>
</div>
</div>
<div>
<label className="text-sm text-muted-foreground mb-1 block">{t("phone")}</label>
<div className="space-y-2">
{phones.map((entry, i) => (
<div key={i} className="flex items-center gap-2">
<Input
type="tel"
value={entry.number}
onChange={(e) => {
const next = [...phones];
next[i] = { ...next[i], number: e.target.value };
setPhones(next);
}}
placeholder={t("phone_placeholder")}
className="flex-1"
/>
<select
value={entry.context}
onChange={(e) => {
const next = [...phones];
next[i] = { ...next[i], context: e.target.value as PhoneEntry["context"] };
setPhones(next);
}}
className="text-sm bg-transparent border rounded px-2 py-2 text-foreground"
>
<option value=""></option>
<option value="work">{t("context_work")}</option>
<option value="private">{t("context_private")}</option>
</select>
<Button
type="button"
variant="ghost"
size="icon"
onClick={() => setPhones(phones.filter((_, j) => j !== i))}
className="h-8 w-8"
>
<X className="w-3 h-3" />
</Button>
</div>
))}
<Button
type="button"
variant="ghost"
size="sm"
onClick={() => setPhones([...phones, { number: "", context: "" }])}
>
<Plus className="w-3 h-3 mr-1" />
{t("add_phone")}
</Button>
</div>
</div>
<div>
<label className="text-sm text-muted-foreground mb-1 block">{t("organization")}</label>
<Input
value={organization}
onChange={(e) => setOrganization(e.target.value)}
placeholder={t("organization_placeholder")}
/>
</div>
<div>
<label className="text-sm text-muted-foreground mb-1 block">{t("note")}</label>
<textarea
value={note}
onChange={(e) => setNote(e.target.value)}
placeholder={t("note_placeholder")}
className="w-full min-h-[80px] rounded border bg-transparent px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground resize-y outline-none focus:ring-2 focus:ring-ring"
/>
</div>
</div>
<div className="flex items-center justify-end gap-2 px-6 py-4 border-t border-border">
<Button type="button" variant="outline" onClick={onCancel} disabled={isSaving}>
{t("cancel")}
</Button>
<Button type="submit" disabled={isSaving}>
{isSaving ? (isEditing ? t("updating") : t("creating")) : t("save")}
</Button>
</div>
</form>
);
}
+44
View File
@@ -0,0 +1,44 @@
"use client";
import { Avatar } from "@/components/ui/avatar";
import { cn } from "@/lib/utils";
import type { ContactCard } from "@/lib/jmap/types";
import { getContactDisplayName, getContactPrimaryEmail } from "@/stores/contact-store";
interface ContactListItemProps {
contact: ContactCard;
isSelected: boolean;
onClick: () => void;
}
export function ContactListItem({ contact, isSelected, onClick }: ContactListItemProps) {
const name = getContactDisplayName(contact);
const email = getContactPrimaryEmail(contact);
const org = contact.organizations
? Object.values(contact.organizations)[0]?.name
: undefined;
return (
<button
onClick={onClick}
className={cn(
"w-full flex items-center gap-3 px-4 py-3 text-left transition-colors",
"hover:bg-muted",
isSelected && "bg-accent text-accent-foreground"
)}
>
<Avatar name={name} email={email} size="sm" />
<div className="flex-1 min-w-0">
<div className="text-sm font-medium truncate">
{name || email || "—"}
</div>
{email && name && (
<div className="text-xs text-muted-foreground truncate">{email}</div>
)}
{org && (
<div className="text-xs text-muted-foreground truncate">{org}</div>
)}
</div>
</button>
);
}
+110
View File
@@ -0,0 +1,110 @@
"use client";
import { useMemo } from "react";
import { useTranslations } from "next-intl";
import { Search, Plus, BookUser, Info } from "lucide-react";
import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button";
import { ContactListItem } from "./contact-list-item";
import { cn } from "@/lib/utils";
import type { ContactCard } from "@/lib/jmap/types";
import { getContactDisplayName } from "@/stores/contact-store";
interface ContactListProps {
contacts: ContactCard[];
selectedContactId: string | null;
searchQuery: string;
onSearchChange: (query: string) => void;
onSelectContact: (id: string) => void;
onCreateNew: () => void;
supportsSync: boolean;
className?: string;
}
export function ContactList({
contacts,
selectedContactId,
searchQuery,
onSearchChange,
onSelectContact,
onCreateNew,
supportsSync,
className,
}: ContactListProps) {
const t = useTranslations("contacts");
const filtered = useMemo(() => {
if (!searchQuery) return contacts;
const lower = searchQuery.toLowerCase();
return contacts.filter((c) => {
const name = getContactDisplayName(c).toLowerCase();
const emails = c.emails
? Object.values(c.emails).map((e) => e.address.toLowerCase())
: [];
return (
name.includes(lower) || emails.some((e) => e.includes(lower))
);
});
}, [contacts, searchQuery]);
const sorted = useMemo(() => {
return [...filtered].sort((a, b) => {
const nameA = getContactDisplayName(a).toLowerCase();
const nameB = getContactDisplayName(b).toLowerCase();
return nameA.localeCompare(nameB);
});
}, [filtered]);
return (
<div className={cn("flex flex-col h-full", className)}>
<div className="px-4 py-3 border-b border-border space-y-3">
<div className="flex items-center justify-between">
<h2 className="text-lg font-semibold">{t("title")}</h2>
<Button size="sm" onClick={onCreateNew}>
<Plus className="w-4 h-4 mr-1" />
{t("create_new")}
</Button>
</div>
<div className="relative">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground" />
<Input
placeholder={t("search_placeholder")}
value={searchQuery}
onChange={(e) => onSearchChange(e.target.value)}
className="pl-9"
/>
</div>
{!supportsSync && (
<div className="flex items-start gap-2 text-xs text-muted-foreground bg-muted rounded px-3 py-2">
<Info className="w-3.5 h-3.5 mt-0.5 flex-shrink-0" />
<span>{t("local_mode")}</span>
</div>
)}
</div>
<div className="flex-1 overflow-y-auto">
{sorted.length === 0 ? (
<div className="flex flex-col items-center justify-center h-full text-muted-foreground px-4">
<BookUser className="w-12 h-12 mb-3 opacity-30" />
<p className="text-sm">
{searchQuery ? t("empty_search") : t("empty_state")}
</p>
</div>
) : (
<div className="divide-y divide-border">
{sorted.map((contact) => (
<ContactListItem
key={contact.id}
contact={contact}
isSelected={contact.id === selectedContactId}
onClick={() => onSelectContact(contact.id)}
/>
))}
</div>
)}
</div>
</div>
);
}