redone player/user structure. player can only be in one lobby; realtime with trpc subscriptions and redis
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
"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";
|
||||
import { appRoutes } from "@/config/app.routes";
|
||||
|
||||
function DeleteLobbyDialog({ lobbyId }: { lobbyId: string }) {
|
||||
const [loading, setLoading] = React.useState(false);
|
||||
const { mutateAsync } = api.lobby.delete.useMutation();
|
||||
const router = useRouter();
|
||||
const handleConfirm = async () => {
|
||||
setLoading(true);
|
||||
const result = await mutateAsync({ lobbyId });
|
||||
if (result) {
|
||||
router.push(appRoutes.home);
|
||||
router.refresh();
|
||||
} else toast.error("Something went wrong");
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<AlertDialog>
|
||||
<Button asChild variant={"destructive"}>
|
||||
<AlertDialogTrigger>Delete Lobby</AlertDialogTrigger>
|
||||
</Button>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
This action cannot be undone. You will permanently delete this
|
||||
lobby!
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction onClick={handleConfirm} disabled={loading}>
|
||||
Delete Lobby
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default DeleteLobbyDialog;
|
||||
Reference in New Issue
Block a user