"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 { AddDeliveryLocationButton, EditDeliveryLocationButton, type CompanyOption, type DeliveryLocationRow, } from "./delivery-location-form"; import { deleteDeliveryLocation, toggleDeliveryLocationActive } from "./actions"; const CHIPS = ["Active", "Inactive"]; function LocationActionsMenu({ companies, location }: { companies: CompanyOption[]; location: DeliveryLocationRow }) { const [editOpen, setEditOpen] = useState(false); const [deleteOpen, setDeleteOpen] = useState(false); const [toggleOpen, setToggleOpen] = useState(false); return ( <> setEditOpen(true)}>Edit setToggleOpen(true)}> {location.isActive ? "Deactivate" : "Activate"} setDeleteOpen(true)}>Delete deleteDeliveryLocation(location.id)} /> toggleDeliveryLocationActive(location.id)} /> ); } export function DeliveryLocationsTable({ locations, companies, }: { locations: DeliveryLocationRow[]; companies: CompanyOption[]; }) { const { search, setSearch, sortKey, sortDir, toggleSort, activeFilters, toggleFilter, filtered } = useTableControls({ rows: locations, defaultSortKey: "companyName", searchText: (l) => [l.companyName, l.address, l.isActive ? "active" : "inactive"].join(" "), chipMatch: (l, chip) => { if (chip.toLowerCase() === "active") return l.isActive; if (chip.toLowerCase() === "inactive") return !l.isActive; return false; }, sortValue: (l, key) => { if (key === "isActive") return l.isActive ? "Active" : "Inactive"; const val = l[key as keyof DeliveryLocationRow]; return typeof val === "string" || typeof val === "boolean" ? val : String(val ?? ""); }, }); return (

Delivery Locations

Destinations that populate the PO “Place of Delivery” dropdown

toggleSort(k as keyof DeliveryLocationRow)}>Company toggleSort(k as keyof DeliveryLocationRow)}>Address toggleSort(k as keyof DeliveryLocationRow)}>Status {filtered.length === 0 && ( )} {filtered.map((location) => ( ))}
No delivery locations yet. Add one to populate the Place of Delivery dropdown.
{location.companyName} {location.address} {location.isActive ? "Active" : "Inactive"}
); }