|
1 | 1 | "use client" |
2 | 2 | import { Copy, Pen } from "lucide-react" |
| 3 | +import { useRouter } from "next/navigation" |
3 | 4 | import { toast } from "sonner" |
4 | 5 | import { Badge } from "@/components/ui/badge" |
5 | 6 | import { Button } from "@/components/ui/button" |
| 7 | +import { setGroupHide } from "@/server/actions/groups" |
6 | 8 | import type { TgGroup } from "@/server/trpc/types" |
7 | 9 |
|
8 | 10 | export function GroupRow({ row: r }: { row: TgGroup }) { |
9 | | - // const trpc = useTRPC() |
10 | | - // const { mutateAsync: hideMutate } = useMutation(trpc.tg.groups.setHide.mutationOptions()) |
11 | | - // |
12 | | - // async function toggleHide() { |
13 | | - // const ok = await hideMutate({ telegramId: r.telegramId, hide: !r.hide }).catch(() => false) |
14 | | - // if (!ok) toast.error("The field cannot be modified") |
15 | | - // |
16 | | - // toast.success("Hide option toggled!") |
17 | | - // invalidate() |
18 | | - // } |
| 11 | + const router = useRouter() |
| 12 | + |
| 13 | + async function toggleHide() { |
| 14 | + const ok = await setGroupHide(r.telegramId, !r.hide).catch(() => false) |
| 15 | + if (!ok) toast.error("The field cannot be modified") |
| 16 | + |
| 17 | + toast.success("Hide option toggled!") |
| 18 | + router.refresh() |
| 19 | + } |
19 | 20 |
|
20 | 21 | return ( |
21 | 22 | <div className="grid gap-4 items-center grid-cols-5 border-b py-2 w-full"> |
@@ -55,13 +56,7 @@ export function GroupRow({ row: r }: { row: TgGroup }) { |
55 | 56 | </div> |
56 | 57 | <div className="flex items-center justify-start gap-2"> |
57 | 58 | <p>{r.hide ? <Badge className="bg-yellow-800">HIDDEN</Badge> : <Badge variant="secondary">Visibile</Badge>}</p> |
58 | | - <Button |
59 | | - type="button" |
60 | | - variant="outline" |
61 | | - size="icon-sm" |
62 | | - className={!r.link ? "hidden" : ""} |
63 | | - onClick={() => null /*toggleHide*/} |
64 | | - > |
| 59 | + <Button type="button" variant="outline" size="icon-sm" className={!r.link ? "hidden" : ""} onClick={toggleHide}> |
65 | 60 | <Pen /> |
66 | 61 | </Button> |
67 | 62 | </div> |
|
0 commit comments