Commit e7605d90 authored by Steven's avatar Steven

fix: shortcut edit button opens create dialog instead of edit dialog

Fixed issue #5576 where clicking the edit button on a shortcut would
incorrectly open a create dialog instead of an edit dialog.

The root cause was an incorrect useEffect that was watching the shortcut
state itself instead of the initialShortcut prop. When the dialog was
opened for editing, the state wasn't properly reinitializing with the
existing shortcut data.

Changed the useEffect to:
- Watch initialShortcut as the dependency
- Reinitialize the shortcut state when initialShortcut changes
- Properly distinguishes between create (initialShortcut undefined) and
  edit (initialShortcut has data) modes
parent f9bf903e
......@@ -37,10 +37,14 @@ function CreateShortcutDialog({ open, onOpenChange, shortcut: initialShortcut, o
const isCreating = shortcut.name === "";
useEffect(() => {
if (shortcut.name) {
setShortcut(shortcut);
}
}, [shortcut.name, shortcut.title, shortcut.filter]);
setShortcut(
create(ShortcutSchema, {
name: initialShortcut?.name || "",
title: initialShortcut?.title || "",
filter: initialShortcut?.filter || "",
}),
);
}, [initialShortcut]);
const onShortcutTitleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setPartialState({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment