Small fixes
This commit is contained in:
@@ -238,15 +238,15 @@ export function UrlsDataTable({ data }: UrlsDataTableProps) {
|
||||
const [columnVisibility, setColumnVisibility] = React.useState<VisibilityState>({})
|
||||
const router = useRouter()
|
||||
|
||||
function handleCopy(string: string) {
|
||||
const handleCopy = React.useCallback((string: string) => {
|
||||
navigator.clipboard.writeText(string).then(() => {
|
||||
toast.success("URL copied to clipboard")
|
||||
}).catch(() => {
|
||||
toast.error("Failed to copy URL")
|
||||
})
|
||||
}
|
||||
}, [])
|
||||
|
||||
async function handleDelete(id: string) {
|
||||
const handleDelete = React.useCallback(async (id: string) => {
|
||||
const res = await deleteUrl(id)
|
||||
|
||||
if (res.error) {
|
||||
@@ -255,49 +255,51 @@ export function UrlsDataTable({ data }: UrlsDataTableProps) {
|
||||
toast.success("URL deleted successfully")
|
||||
router.refresh()
|
||||
}
|
||||
}
|
||||
}, [router])
|
||||
|
||||
const actionRow: ColumnDef<UrlRecord> = {
|
||||
id: "actions",
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => {
|
||||
const urlRecord = row.original
|
||||
const tableColumns = React.useMemo(() => {
|
||||
const actionRow: ColumnDef<UrlRecord> = {
|
||||
id: "actions",
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => {
|
||||
const urlRecord = row.original
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" className="h-8 w-8 p-0">
|
||||
<span className="sr-only">Open menu</span>
|
||||
<MoreHorizontal className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuLabel>Actions</DropdownMenuLabel>
|
||||
<DropdownMenuItem
|
||||
onClick={() => {
|
||||
handleCopy(`${window.location.origin}/r/${urlRecord.slug}`)
|
||||
}}
|
||||
>
|
||||
<Copy className="mr-2 h-4 w-4" />
|
||||
Copy URL
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
className="text-red-600"
|
||||
onClick={() => {
|
||||
handleDelete(urlRecord.id)
|
||||
}}
|
||||
>
|
||||
<Trash2 className="mr-2 h-4 w-4" />
|
||||
Delete
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
)
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" className="h-8 w-8 p-0">
|
||||
<span className="sr-only">Open menu</span>
|
||||
<MoreHorizontal className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuLabel>Actions</DropdownMenuLabel>
|
||||
<DropdownMenuItem
|
||||
onClick={() => {
|
||||
handleCopy(`${window.location.origin}/r/${urlRecord.slug}`)
|
||||
}}
|
||||
>
|
||||
<Copy className="mr-2 h-4 w-4" />
|
||||
Copy URL
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
className="text-red-600"
|
||||
onClick={() => {
|
||||
handleDelete(urlRecord.id)
|
||||
}}
|
||||
>
|
||||
<Trash2 className="mr-2 h-4 w-4" />
|
||||
Delete
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const tableColumns = React.useMemo(() => [...columns, actionRow], [actionRow])
|
||||
return [...columns, actionRow]
|
||||
}, [handleCopy, handleDelete])
|
||||
|
||||
const table = useReactTable({
|
||||
data,
|
||||
|
||||
Reference in New Issue
Block a user