import { useState } from "react"; import Image from "next/image"; import Link from "next/link"; import { useTheme } from "next-themes"; import { Settings, Check, Plus, Download } from "lucide-react"; import { RiContrastFill } from "react-icons/ri"; import { useSession } from "next-auth/react"; import { useParams } from "next/navigation"; import { ChevronDown, ChevronLeft, Edit } from "lucide-react"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuPortal, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { ProjectWithCommits } from "@/actions/projects"; import ProIcon from "@/assets/pro.svg"; import { Input } from "@/components/ui/input"; import { useQueryClient } from "@tanstack/react-query"; import Loading from "@/components/loading"; import { toast } from "sonner"; export const ProjectSettings = ({ project, }: { project?: ProjectWithCommits | null; }) => { const queryClient = useQueryClient(); const { repoId, owner } = useParams(); const { theme, setTheme } = useTheme(); const { data: session } = useSession(); const [open, setOpen] = useState(false); const [projectName, setProjectName] = useState( project?.cardData?.title || "New DeepSite website", ); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const handleRenameProject = async () => { setIsLoading(true); setError(null); try { const response = await fetch(`/api/projects/${repoId}/rename`, { method: "PUT", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ newTitle: projectName }), }).then(async (response) => { if (response.ok) { return response.json(); } }); if (response?.success) { setOpen(false); queryClient.setQueryData( ["project"], (oldProject: ProjectWithCommits) => ({ ...oldProject, cardData: { ...oldProject.cardData, title: projectName, }, }), ); } else { setError("Could not rename the project. Please try again."); } // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (err: any) { setError(err.message || "An error occurred"); } setIsLoading(false); }; const handleDownload = async () => { try { toast.info("Preparing download..."); const response = await fetch(`/api/projects/${repoId}/download`, { headers: { Accept: "application/zip", }, }); if (!response.ok) { throw new Error("Failed to download project"); } const blob = await response.blob(); const url = window.URL.createObjectURL(blob); const link = document.createElement("a"); link.href = url; link.download = `${session?.user?.username}-${repoId}.zip`; document.body.appendChild(link); link.click(); document.body.removeChild(link); window.URL.revokeObjectURL(url); toast.success("Download started!"); } catch (error) { toast.error("Failed to download project"); } }; return ( <> Go to Projects {!session?.user?.isPro && ( <> Pro Subscribe to Pro )} New Project {project && ( <> setOpen(true)}> Rename the project Project settings handleDownload()}> Download project )} Appearance setTheme("light")}> Light {theme === "light" && } setTheme("dark")}> Dark {theme === "dark" && } setTheme("system")}> System {theme === "system" && } Rename your Project Update the name of your project below.
{error &&

{error}

}

The URL of your project will remain the same after changing the name, only the displayed name will be updated.

setProjectName(e.target.value)} />
); };