"use client" import { useMemo, useState } from "react" import { Button } from "@/components/ui/button" import { useContactsStore } from "@/lib/contacts/contacts-store" import { useContactsList } from "@/lib/contacts/use-contacts-list" import { useMergeDuplicates } from "@/lib/api/hooks/use-contact-mutations" import { findDuplicatePairs, type DuplicateMatchReason } from "@/lib/contacts/duplicate-detection" import { fullContactDisplayName, type MergeSuggestion } from "@/lib/contacts/types" import { avatarColor, senderInitial } from "@/lib/sender-display" import { AddCoordinatesView } from "./add-coordinates-view" import { CONTACTS_HEADING_TEXT, CONTACTS_MUTED_TEXT, CONTACTS_PAGE_CARD_CLASS, CONTACTS_PAGE_INFO_BANNER_CLASS, CONTACTS_PAGE_INFO_BANNER_ICON_CLASS, CONTACTS_PAGE_LINK_BTN_CLASS, CONTACTS_PAGE_SECTION_TITLE_CLASS, CONTACTS_PAGE_TAB_ACTIVE_CLASS, CONTACTS_PAGE_TAB_INACTIVE_CLASS, CONTACTS_PRIMARY_BTN_CLASS, } from "@/lib/contacts-chrome-classes" import { cn } from "@/lib/utils" type SubView = "merge" | "coordinates" const REASON_LABELS: Record = { email: "Même adresse e-mail", phone: "Même numéro de téléphone", name: "Nom similaire", } export function MergeDuplicatesView() { const [subView, setSubView] = useState("merge") const { contacts } = useContactsList() const ignoredMergePairs = useContactsStore((s) => s.ignoredMergePairs) const ignoreMergePair = useContactsStore((s) => s.ignoreMergePair) const mergeDuplicatesMutation = useMergeDuplicates() const mergeSuggestions = useMemo( () => findDuplicatePairs(contacts, new Set(ignoredMergePairs)), [contacts, ignoredMergePairs] ) const [mergingAll, setMergingAll] = useState(false) function handleMerge(_suggestion: MergeSuggestion) { mergeDuplicatesMutation.mutate({ bookId: "default" }) } function handleIgnore(suggestion: MergeSuggestion) { ignoreMergePair(suggestion.contactA.id, suggestion.contactB.id) } function handleMergeAll() { setMergingAll(true) mergeDuplicatesMutation.mutate( { bookId: "default" }, { onSettled: () => setMergingAll(false) }, ) } return (
🧹

Des méthodes simples pour nettoyer vos contacts

Obtenez de l'aide pour fusionner les contacts en double, ajouter des informations utiles, et bien encore

{subView === "merge" && (

Fusionner les doublons ({mergeSuggestions.length})

{mergeSuggestions.length > 0 && ( )}
{mergeSuggestions.length === 0 && (

Aucun doublon détecté

)}
{mergeSuggestions.map((suggestion) => ( handleMerge(suggestion)} onIgnore={() => handleIgnore(suggestion)} /> ))}
)} {subView === "coordinates" && }
) } function MergeSuggestionCard({ suggestion, onMerge, onIgnore, }: { suggestion: MergeSuggestion onMerge: () => void onIgnore: () => void }) { const { contactA, contactB, reason } = suggestion return (

{REASON_LABELS[reason]}

) } function ContactMiniCard({ contact }: { contact: import("@/lib/contacts/types").FullContact }) { const displayName = fullContactDisplayName(contact) const name = displayName || contact.emails[0]?.value || "?" const color = avatarColor(name) const initial = senderInitial(name) return (
{contact.avatarUrl ? ( {name} ) : (
{initial}
)}

{name}

{contact.emails[0] && (

{contact.emails[0].value}

)} {contact.phones[0] && (

{contact.phones[0].value} ({contact.phones[0].label})

)}
) }