"use client"; import React from "react"; import { Button } from "@/components/ui/button"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog"; import { api } from "@/trpc/react"; import { toast } from "sonner"; import { useRouter } from "next/navigation"; function LobbyMembershipDialog({ lobbyId, join, }: { lobbyId: string; join: boolean; }) { const [loading, setLoading] = React.useState(false); const { mutateAsync } = api.lobby.membership.useMutation(); const router = useRouter(); const handleConfirm = async () => { setLoading(true); const result = await mutateAsync({ lobbyId, join }); if (result) { if (!join) router.push("/"); else toast.success("Successfully joined the lobby."); } else toast.error("Something went wrong"); setLoading(false); }; const labelText = join ? "join" : "leave"; return ( {labelText} Lobby You are about to {labelText} the lobby. Cancel {labelText} ); } export default LobbyMembershipDialog;