Skip to content
Merged
Show file tree
Hide file tree
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
38 changes: 36 additions & 2 deletions src/apps/vault/ItemEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
"use client";

import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
Button,
Dialog,
DialogContent,
Expand Down Expand Up @@ -57,6 +65,7 @@ export function ItemEditor({
const [showGen, setShowGen] = useState(false);
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [confirmDiscardOpen, setConfirmDiscardOpen] = useState(false);

useEffect(() => {
if (!draft) return;
Expand Down Expand Up @@ -92,11 +101,21 @@ export function ItemEditor({
expiry !== (draft.secret.expiry ?? "") ||
cvv !== (draft.secret.cvv ?? "");

const requestClose = () => {
if (isDirty && !confirm("Discard your unsaved changes?")) return;
// The original close action that ran after the (now-removed) confirm guard.
// Both the not-dirty path and the Discard button call this.
const proceedClose = () => {
setConfirmDiscardOpen(false);
onClose();
};

const requestClose = () => {
if (isDirty) {
setConfirmDiscardOpen(true);
return;
}
proceedClose();
};

// TOTP secrets are base32 (RFC 4648: A–Z, 2–7, optional `=` padding). Flag a
// malformed seed up front instead of letting code generation silently fail.
const totpNorm = totpSecret.replace(/\s+/g, "").toUpperCase();
Expand Down Expand Up @@ -316,6 +335,21 @@ export function ItemEditor({
</Button>
</DialogFooter>
</DialogContent>

<AlertDialog open={confirmDiscardOpen} onOpenChange={setConfirmDiscardOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Discard unsaved changes?</AlertDialogTitle>
<AlertDialogDescription>
You have unsaved changes. If you close now, your edits will be lost.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Keep editing</AlertDialogCancel>
<AlertDialogAction onClick={proceedClose}>Discard</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</Dialog>
);
}
35 changes: 33 additions & 2 deletions src/apps/vault/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
*/

import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
Button,
Dialog,
DialogContent,
Expand Down Expand Up @@ -324,6 +332,7 @@ function UnlockedVault({
const [draft, setDraft] = useState<EditorDraft | null>(null);
const [showGen, setShowGen] = useState(false);
const [showChangePw, setShowChangePw] = useState(false);
const [confirmDeleteOpen, setConfirmDeleteOpen] = useState(false);

const selected = vault.index.find((m) => m.id === selectedId) ?? null;

Expand Down Expand Up @@ -380,13 +389,18 @@ function UnlockedVault({
setSelectedId(saved.id);
};

const onDeleteItem = async () => {
const onDeleteItem = () => {
if (!selected) return;
setConfirmDeleteOpen(true);
};

const confirmDelete = async () => {
if (!selected) return;
if (!confirm(`Delete “${selected.title}”? This cannot be undone.`)) return;
await deleteItem(zone, vault, selected.id);
onVaultChange(vault);
setSelectedId(null);
setSecret(null);
setConfirmDeleteOpen(false);
};

return (
Expand Down Expand Up @@ -506,6 +520,23 @@ function UnlockedVault({
}}
/>
)}

<AlertDialog open={confirmDeleteOpen} onOpenChange={setConfirmDeleteOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Delete item?</AlertDialogTitle>
<AlertDialogDescription>
{selected
? `Delete “${selected.title}”? This cannot be undone.`
: "This cannot be undone."}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction onClick={confirmDelete}>Delete</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
);
}
Expand Down
Loading