Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions apps/web/src/project/components/delete-project-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { Label } from "@/components/ui/label";
import { Input } from "@/components/ui/input";
import { useState } from "react";

const REQUIRED_CONFIRMATION_TEXT = "DELETE";

export function DeleteProjectDialog({
isOpen,
Expand All @@ -25,6 +28,8 @@ export function DeleteProjectDialog({
const count = projectNames.length;
const isSingle = count === 1;
const singleName = isSingle ? projectNames[0] : null;

const [confirmationInput, setConfirmationInput] = useState<string>("");

return (
<Dialog open={isOpen} onOpenChange={onOpenChange}>
Comment on lines +32 to 35
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

confirmationInput is never reset when the dialog closes — the confirmation guard is bypassed on re-use.

When the dialog is closed (via Cancel, backdrop click, or Escape) and then reopened, confirmationInput retains its previous value. If the user previously typed "DELETE" and confirmed a deletion, the state still holds "DELETE" when the dialog opens for the next project, causing the delete button to be immediately enabled and completely bypassing the guard.

The fix is to intercept onOpenChange locally and reset the state whenever the dialog transitions to closed:

🛡️ Proposed fix
  const [confirmationInput, setConfirmationInput] = useState<string>("");
+
+  const handleOpenChange = (open: boolean) => {
+    if (!open) setConfirmationInput("");
+    onOpenChange(open);
+  };

  return (
-   <Dialog open={isOpen} onOpenChange={onOpenChange}>
+   <Dialog open={isOpen} onOpenChange={handleOpenChange}>
      ...
-         <Button variant="outline" onClick={() => onOpenChange(false)}>
+         <Button variant="outline" onClick={() => handleOpenChange(false)}>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/web/src/project/components/delete-project-dialog.tsx` around lines 32 -
35, The dialog's confirmationInput state (confirmationInput,
setConfirmationInput) is not reset when the Dialog (Dialog component using
isOpen and onOpenChange) closes, so reopening bypasses the "DELETE" guard; fix
by wrapping the passed onOpenChange with a local handler (e.g.,
handleOpenChange) that calls setConfirmationInput("") whenever open becomes
false and then forwards the event to the original onOpenChange prop, and pass
that handler into Dialog's onOpenChange.

Expand Down Expand Up @@ -59,12 +64,15 @@ export function DeleteProjectDialog({
</AlertDescription>
</Alert>
<div className="flex flex-col gap-3">
<Label className="text-xs font-semibold text-slate-500">
Type "DELETE" to confirm
<Label htmlFor="confirmation-input" className="text-xs font-semibold text-slate-500">
{`Type "${REQUIRED_CONFIRMATION_TEXT}" to confirm`}
</Label>
<Input
id={"confirmation-input"}
onChange={(e) => {setConfirmationInput(e.target.value)}}
value={confirmationInput}
type="text"
placeholder="DELETE"
placeholder={REQUIRED_CONFIRMATION_TEXT}
size="lg"
variant="destructive"
/>
Expand All @@ -74,7 +82,7 @@ export function DeleteProjectDialog({
<Button variant="outline" onClick={() => onOpenChange(false)}>
Cancel
</Button>
<Button variant="destructive" onClick={onConfirm}>
<Button variant="destructive" onClick={onConfirm} disabled={confirmationInput !== REQUIRED_CONFIRMATION_TEXT}>
Delete project
</Button>
</DialogFooter>
Expand Down