-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d5ec7b
commit c11b726
Showing
1 changed file
with
31 additions
and
3 deletions.
There are no files selected for viewing
34 changes: 31 additions & 3 deletions
34
app/(dashboard)/u/[username]/community/_components/unblock-button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,33 @@ | ||
import React from "react"; | ||
import { onUnblock } from "@/actions/block"; | ||
import { Button } from "@/components/ui/button"; | ||
import { useTransition } from "react"; | ||
import { toast } from "sonner"; | ||
|
||
export const UnblockButton = () => { | ||
return <div>UnblockButton</div>; | ||
interface UnblockButtonProps { | ||
userId: string; | ||
} | ||
|
||
export const UnblockButton = ({ userId }: UnblockButtonProps) => { | ||
const [isPending, startTransition] = useTransition(); | ||
|
||
const onClick = () => { | ||
startTransition(() => { | ||
onUnblock(userId) | ||
.then((result) => | ||
toast.success(`User ${result.blocked.username} unblocked`) | ||
) | ||
.catch(() => toast.error("Something went wrong")); | ||
}); | ||
}; | ||
return ( | ||
<Button | ||
disabled={isPending} | ||
onClick={onClick} | ||
variant="link" | ||
size="sm" | ||
className="text-blue-500 w-full" | ||
> | ||
Unblcok | ||
</Button> | ||
); | ||
}; |