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