"use client"; import { useState } from "react"; import { Plus, Trash2, Tags, Building2 } from "lucide-react"; import { Card, CardContent } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Skeleton } from "@/components/ui/skeleton"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { useTagMappings, usePaperclipCompanies, useAddTagMapping, useDeleteTagMapping, } from "@/lib/api/settings"; import { APPEAL_SUBTYPES } from "@/lib/practice-area"; import { toast } from "sonner"; const TAG_SUGGESTIONS = APPEAL_SUBTYPES.filter((s) => s.value !== "unknown"); export function PaperclipTab() { const { data: mappings, isPending: loadingMappings } = useTagMappings(); const { data: companies, isPending: loadingCompanies } = usePaperclipCompanies(); const addMapping = useAddTagMapping(); const deleteMapping = useDeleteTagMapping(); const [tag, setTag] = useState(""); const [tagLabel, setTagLabel] = useState(""); const [companyId, setCompanyId] = useState(""); function handleTagInput(value: string) { setTag(value); const match = TAG_SUGGESTIONS.find((s) => s.value === value); if (match) setTagLabel(match.label); } function handleAdd() { if (!tag || !companyId) { toast.error("יש לבחור תגית וחברה"); return; } const company = companies?.find((c) => c.id === companyId); addMapping.mutate( { tag, tag_label: tagLabel, company_id: companyId, company_name: company?.name ?? "", }, { onSuccess: () => { toast.success("מיפוי נוסף בהצלחה"); setTag(""); setTagLabel(""); setCompanyId(""); }, onError: (err) => toast.error(`שגיאה: ${err.message}`), }, ); } function handleDelete(id: string, tag: string) { deleteMapping.mutate(id, { onSuccess: () => toast.success(`מיפוי "${tag}" נמחק`), onError: (err) => toast.error(`שגיאה: ${err.message}`), }); } return (

חברות ב-Paperclip

{loadingCompanies ? ( ) : !companies?.length ? (

לא נמצאו חברות

) : (
{companies.map((c) => (
{c.name} {c.prefix}
))}
)}

מיפוי תגיות {mappings?.length ?? 0}

handleTagInput(e.target.value)} placeholder="סוג ערר או תגית חופשית" className="w-[220px]" /> {TAG_SUGGESTIONS.map((s) => ( ))}
setTagLabel(e.target.value)} placeholder="שם לתצוגה" className="w-[160px]" />
{loadingMappings ? ( ) : !mappings?.length ? (

אין מיפויים. הוסף מיפוי כדי שתיקים חדשים ישויכו אוטומטית לפרויקט בחברה הנכונה.

) : (
{mappings.map((m) => ( ))}
Tag Label Company
{m.tag} {m.tag_label} {m.company_name}
)}
); }