"use client"; import { useState } from "react"; import { useTableControls } from "@/components/ui/use-table-controls"; import { TableControls, SortableTh } from "@/components/ui/table-controls"; import { RowActionsMenu, RowActionsItem, RowActionsDestructiveItem, RowActionsSeparator } from "@/components/ui/row-actions-menu"; import { DeleteConfirmDialog } from "@/components/ui/delete-confirm-dialog"; import { ConfirmDialog } from "@/components/ui/confirm-dialog"; import { AddTermButton, EditTermButton, type TermRow } from "./terms-form"; import { deleteTerm, toggleTermActive } from "./actions"; const CHIPS = ["Active", "Inactive"]; function TermActionsMenu({ term, categoryNames }: { term: TermRow; categoryNames: string[] }) { const [editOpen, setEditOpen] = useState(false); const [deleteOpen, setDeleteOpen] = useState(false); const [toggleOpen, setToggleOpen] = useState(false); return ( <> setEditOpen(true)}>Edit setToggleOpen(true)}> {term.isActive ? "Deactivate" : "Activate"} setDeleteOpen(true)}>Delete deleteTerm(term.id)} /> toggleTermActive(term.id)} /> ); } export function TermsTable({ terms, categoryNames }: { terms: TermRow[]; categoryNames: string[] }) { const { search, setSearch, sortKey, sortDir, toggleSort, activeFilters, toggleFilter, filtered } = useTableControls({ rows: terms, defaultSortKey: "categoryName", searchText: (t) => [t.categoryName, t.text, t.isActive ? "active" : "inactive"].join(" "), chipMatch: (t, chip) => { if (chip.toLowerCase() === "active") return t.isActive; if (chip.toLowerCase() === "inactive") return !t.isActive; return false; }, sortValue: (t, key) => { if (key === "isActive") return t.isActive ? "Active" : "Inactive"; if (key === "isDefault") return t.isDefault ? "Yes" : "No"; const val = t[key as keyof TermRow]; return typeof val === "string" || typeof val === "boolean" ? val : String(val ?? ""); }, }); return (

Terms & Conditions

Categories & clauses that populate the PO Terms & Conditions editor

toggleSort(k as keyof TermRow)}>Category toggleSort(k as keyof TermRow)}>Clause toggleSort(k as keyof TermRow)}>Default toggleSort(k as keyof TermRow)}>Status {filtered.length === 0 && ( )} {filtered.map((term) => ( ))}
No clauses yet. Add one to populate the PO Terms & Conditions editor.
{term.categoryName} {term.text} {term.isDefault ? Default : } {term.isActive ? "Active" : "Inactive"}
); }