import { Loader2, Pencil } from "lucide-react"; import { useEffect, useState } from "react"; import { toast } from "sonner"; import { CodeEditor } from "@/components/shared/code-editor"; import { Button } from "@/components/ui/button"; import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { api } from "@/utils/api"; interface Props { patchId: string; entityId: string; type: "application" | "compose"; onSuccess?: () => void; } export const EditPatchDialog = ({ patchId, entityId, type, onSuccess, }: Props) => { const { data: patch, isPending: isPatchLoading } = api.patch.one.useQuery( { patchId }, { enabled: !!patchId }, ); const [content, setContent] = useState(""); useEffect(() => { if (patch) { setContent(patch.content); } }, [patch]); const utils = api.useUtils(); const updatePatch = api.patch.update.useMutation(); const handleSave = () => { updatePatch .mutateAsync({ patchId, content }) .then(() => { toast.success("Patch saved"); utils.patch.byEntityId.invalidate({ id: entityId, type }); onSuccess?.(); }) .catch((err) => { toast.error(err.message); }); }; return ( Edit Patch {patch ? `Editing: ${patch.filePath}` : "Loading patch..."} {isPatchLoading ? (
) : (
setContent(value ?? "")} className="h-[400px] w-full" wrapperClassName="h-[400px]" lineWrapping />
)}
); };