import { EllipsisVertical, RefreshCcw, Trash, Edit, Copy } from "lucide-react";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "../ui/dropdown-menu";
import { Button } from "../ui/button";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "../ui/alert-dialog";
import { useEffect, useState } from "react";
import { useFetcher, useNavigate } from "@remix-run/react";
import { EditSpaceDialog } from "./edit-space-dialog.client";
import { toast } from "~/hooks/use-toast";
interface SpaceOptionsProps {
id: string;
name?: string;
description?: string | null;
}
export const SpaceOptions = ({ id, name, description }: SpaceOptionsProps) => {
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
const [resetSpace, setResetSpace] = useState(false);
const [editDialogOpen, setEditDialogOpen] = useState(false);
const deleteFetcher = useFetcher();
const resetFetcher = useFetcher();
const navigate = useNavigate();
const handleDelete = () => {
deleteFetcher.submit(null, {
method: "DELETE",
action: `/api/v1/spaces/${id}`,
encType: "application/json",
});
setDeleteDialogOpen(false);
};
useEffect(() => {
if (deleteFetcher.state === "idle" && deleteFetcher.data) {
navigate("/home/space");
}
}, [deleteFetcher.state, deleteFetcher.data, navigate]);
const handleReset = () => {
resetFetcher.submit(null, {
method: "POST",
action: `/api/v1/spaces/${id}/reset`,
encType: "application/json",
});
setResetSpace(false);
};
const handleEditSuccess = () => {
// Revalidate the page data to show updated space info
// revalidator.revalidate();
};
const handleCopy = async () => {
try {
await navigator.clipboard.writeText(id);
toast({
title: "Copied",
description: "Space ID copied to clipboard",
});
} catch (err) {
console.error("Failed to copy:", err);
toast({
title: "Error",
description: "Failed to copy ID",
variant: "destructive",
});
}
};
return (
<>
setEditDialogOpen(true)}>
setResetSpace(true)}>
setDeleteDialogOpen(true)}>
Delete space
Are you sure you want to delete this space? This action cannot be
undone.
Cancel
Continue
Delete space
Are you sure you want to reset this space? This is create
categorise all facts again in this space
Cancel
Continue
{/* Edit Space Dialog */}
>
);
};