"use client" import { Checkbox } from "@/components/ui/checkbox" import { Label } from "@/components/ui/label" import { useContactBooks } from "@/lib/api/hooks/use-contact-queries" import type { WebhookContactsScope } from "@/lib/mail-automation/webhook-config" import { cn } from "@/lib/utils" export function WebhookContactsScopeEditor({ scope, onChange, enabled, className, }: { scope: WebhookContactsScope onChange: (scope: WebhookContactsScope) => void enabled: boolean className?: string }) { const { data: booksRaw, isLoading } = useContactBooks() const books = Array.isArray(booksRaw) ? booksRaw : booksRaw && typeof booksRaw === "object" && "address_books" in booksRaw ? (booksRaw as { address_books: { id: string; name: string }[] }).address_books ?? [] : [] if (!enabled) return null function toggleBook(bookId: string) { const ids = scope.book_ids.includes(bookId) ? scope.book_ids.filter((id) => id !== bookId) : [...scope.book_ids, bookId] onChange({ all_books: false, book_ids: ids }) } return (
Périmètre contacts — carnets {!scope.all_books && (
{isLoading ? (

Chargement…

) : books.length === 0 ? (

Aucun carnet configuré.

) : ( )}
)}
) }