diff --git a/surfsense_web/atoms/chat/hitl-edit-panel.atom.ts b/surfsense_web/atoms/chat/hitl-edit-panel.atom.ts index ede6a0134..455402503 100644 --- a/surfsense_web/atoms/chat/hitl-edit-panel.atom.ts +++ b/surfsense_web/atoms/chat/hitl-edit-panel.atom.ts @@ -15,6 +15,7 @@ interface HitlEditPanelState { toolName: string; extraFields?: ExtraField[]; onSave: ((title: string, content: string, extraFieldValues?: Record) => void) | null; + onClose: (() => void) | null; } const initialState: HitlEditPanelState = { @@ -24,6 +25,7 @@ const initialState: HitlEditPanelState = { toolName: "", extraFields: undefined, onSave: null, + onClose: null, }; export const hitlEditPanelAtom = atom(initialState); @@ -41,6 +43,7 @@ export const openHitlEditPanelAtom = atom( toolName: string; extraFields?: ExtraField[]; onSave: (title: string, content: string, extraFieldValues?: Record) => void; + onClose?: () => void; } ) => { if (!get(hitlEditPanelAtom).isOpen) { @@ -53,6 +56,7 @@ export const openHitlEditPanelAtom = atom( toolName: payload.toolName, extraFields: payload.extraFields, onSave: payload.onSave, + onClose: payload.onClose ?? null, }); set(rightPanelTabAtom, "hitl-edit"); set(rightPanelCollapsedAtom, false); @@ -60,6 +64,8 @@ export const openHitlEditPanelAtom = atom( ); export const closeHitlEditPanelAtom = atom(null, (get, set) => { + const current = get(hitlEditPanelAtom); + current.onClose?.(); set(hitlEditPanelAtom, initialState); set(rightPanelTabAtom, "sources"); const prev = get(preHitlCollapsedAtom); diff --git a/surfsense_web/components/tool-ui/gmail/create-draft.tsx b/surfsense_web/components/tool-ui/gmail/create-draft.tsx index 7571c4a48..611824672 100644 --- a/surfsense_web/components/tool-ui/gmail/create-draft.tsx +++ b/surfsense_web/components/tool-ui/gmail/create-draft.tsx @@ -245,6 +245,7 @@ function ApprovalCard({ bcc: extras.bcc ?? pendingEdits?.bcc ?? args.bcc ?? "", }); }, + onClose: () => setIsPanelOpen(false), }); }} > @@ -352,7 +353,7 @@ function ApprovalCard({ size="sm" className="rounded-lg gap-1.5" onClick={handleApprove} - disabled={!canApprove} + disabled={!canApprove || isPanelOpen} > Approve @@ -363,6 +364,7 @@ function ApprovalCard({ size="sm" variant="ghost" className="rounded-lg text-muted-foreground" + disabled={isPanelOpen} onClick={() => { setDecided("reject"); onDecision({ type: "reject", message: "User rejected the action." }); diff --git a/surfsense_web/components/tool-ui/gmail/send-email.tsx b/surfsense_web/components/tool-ui/gmail/send-email.tsx index 740566fb0..cd4725c5a 100644 --- a/surfsense_web/components/tool-ui/gmail/send-email.tsx +++ b/surfsense_web/components/tool-ui/gmail/send-email.tsx @@ -247,6 +247,7 @@ function ApprovalCard({ bcc: extras.bcc ?? pendingEdits?.bcc ?? args.bcc ?? "", }); }, + onClose: () => setIsPanelOpen(false), }); }} > @@ -352,7 +353,7 @@ function ApprovalCard({ size="sm" className="rounded-lg gap-1.5" onClick={handleApprove} - disabled={!canApprove} + disabled={!canApprove || isPanelOpen} > Send @@ -363,6 +364,7 @@ function ApprovalCard({ size="sm" variant="ghost" className="rounded-lg text-muted-foreground" + disabled={isPanelOpen} onClick={() => { setDecided("reject"); onDecision({ type: "reject", message: "User rejected the action." }); diff --git a/surfsense_web/components/tool-ui/gmail/update-draft.tsx b/surfsense_web/components/tool-ui/gmail/update-draft.tsx index a62b36549..15c72852e 100644 --- a/surfsense_web/components/tool-ui/gmail/update-draft.tsx +++ b/surfsense_web/components/tool-ui/gmail/update-draft.tsx @@ -328,6 +328,7 @@ function ApprovalCard({ bcc: extras.bcc ?? currentBcc, }); }, + onClose: () => setIsPanelOpen(false), }); }} > @@ -440,6 +441,7 @@ function ApprovalCard({ size="sm" className="rounded-lg gap-1.5" onClick={handleApprove} + disabled={isPanelOpen} > Approve @@ -450,6 +452,7 @@ function ApprovalCard({ size="sm" variant="ghost" className="rounded-lg text-muted-foreground" + disabled={isPanelOpen} onClick={() => { setDecided("reject"); onDecision({ diff --git a/surfsense_web/components/tool-ui/google-calendar/create-event.tsx b/surfsense_web/components/tool-ui/google-calendar/create-event.tsx index abd67e01a..93117c170 100644 --- a/surfsense_web/components/tool-ui/google-calendar/create-event.tsx +++ b/surfsense_web/components/tool-ui/google-calendar/create-event.tsx @@ -304,6 +304,7 @@ function ApprovalCard({ attendees: extras.attendees ?? pendingEdits?.attendees ?? attendeesList.join(", "), }); }, + onClose: () => setIsPanelOpen(false), }); }} > @@ -446,7 +447,7 @@ function ApprovalCard({ size="sm" className="rounded-lg gap-1.5" onClick={handleApprove} - disabled={!canApprove} + disabled={!canApprove || isPanelOpen} > Approve @@ -457,6 +458,7 @@ function ApprovalCard({ size="sm" variant="ghost" className="rounded-lg text-muted-foreground" + disabled={isPanelOpen} onClick={() => { setDecided("reject"); onDecision({ type: "reject", message: "User rejected the action." }); diff --git a/surfsense_web/components/tool-ui/google-calendar/update-event.tsx b/surfsense_web/components/tool-ui/google-calendar/update-event.tsx index 014293a18..5da4dd2f2 100644 --- a/surfsense_web/components/tool-ui/google-calendar/update-event.tsx +++ b/surfsense_web/components/tool-ui/google-calendar/update-event.tsx @@ -347,6 +347,7 @@ function ApprovalCard({ attendees: extras.attendees ?? proposedAttendeesStr, }); }, + onClose: () => setIsPanelOpen(false), }); }} > @@ -462,6 +463,7 @@ function ApprovalCard({ size="sm" className="rounded-lg gap-1.5" onClick={handleApprove} + disabled={isPanelOpen} > Approve @@ -472,6 +474,7 @@ function ApprovalCard({ size="sm" variant="ghost" className="rounded-lg text-muted-foreground" + disabled={isPanelOpen} onClick={() => { setDecided("reject"); onDecision({ type: "reject", message: "User rejected the action." }); diff --git a/surfsense_web/components/tool-ui/google-drive/create-file.tsx b/surfsense_web/components/tool-ui/google-drive/create-file.tsx index 0bb5cfd29..716d4ff5a 100644 --- a/surfsense_web/components/tool-ui/google-drive/create-file.tsx +++ b/surfsense_web/components/tool-ui/google-drive/create-file.tsx @@ -249,6 +249,7 @@ function ApprovalCard({ setIsPanelOpen(false); setPendingEdits({ name: newName, content: newContent }); }, + onClose: () => setIsPanelOpen(false), }); }} > @@ -376,7 +377,7 @@ function ApprovalCard({ size="sm" className="rounded-lg gap-1.5" onClick={handleApprove} - disabled={!canApprove} + disabled={!canApprove || isPanelOpen} > Approve @@ -387,6 +388,7 @@ function ApprovalCard({ size="sm" variant="ghost" className="rounded-lg text-muted-foreground" + disabled={isPanelOpen} onClick={() => { setDecided("reject"); onDecision({ type: "reject", message: "User rejected the action." }); diff --git a/surfsense_web/components/tool-ui/linear/create-linear-issue.tsx b/surfsense_web/components/tool-ui/linear/create-linear-issue.tsx index 61e8a5f60..cb5b0e652 100644 --- a/surfsense_web/components/tool-ui/linear/create-linear-issue.tsx +++ b/surfsense_web/components/tool-ui/linear/create-linear-issue.tsx @@ -259,6 +259,7 @@ function ApprovalCard({ setIsPanelOpen(false); setPendingEdits({ title: newTitle, description: newDescription }); }, + onClose: () => setIsPanelOpen(false), }); }} > @@ -488,7 +489,7 @@ function ApprovalCard({ size="sm" className="rounded-lg gap-1.5" onClick={handleApprove} - disabled={!canApprove} + disabled={!canApprove || isPanelOpen} > Approve @@ -499,6 +500,7 @@ function ApprovalCard({ size="sm" variant="ghost" className="rounded-lg text-muted-foreground" + disabled={isPanelOpen} onClick={() => { setDecided("reject"); onDecision({ type: "reject", message: "User rejected the action." }); diff --git a/surfsense_web/components/tool-ui/linear/update-linear-issue.tsx b/surfsense_web/components/tool-ui/linear/update-linear-issue.tsx index 6578dbb1d..46bc168a4 100644 --- a/surfsense_web/components/tool-ui/linear/update-linear-issue.tsx +++ b/surfsense_web/components/tool-ui/linear/update-linear-issue.tsx @@ -325,6 +325,7 @@ function ApprovalCard({ })); setHasPanelEdits(true); }, + onClose: () => setIsPanelOpen(false), }); }} > @@ -599,6 +600,7 @@ function ApprovalCard({ size="sm" className="rounded-lg gap-1.5" onClick={handleApprove} + disabled={isPanelOpen} > Approve @@ -609,6 +611,7 @@ function ApprovalCard({ size="sm" variant="ghost" className="rounded-lg text-muted-foreground" + disabled={isPanelOpen} onClick={() => { setDecided("reject"); onDecision({ type: "reject", message: "User rejected the action." }); diff --git a/surfsense_web/components/tool-ui/notion/create-notion-page.tsx b/surfsense_web/components/tool-ui/notion/create-notion-page.tsx index e10b22d5e..84375af0a 100644 --- a/surfsense_web/components/tool-ui/notion/create-notion-page.tsx +++ b/surfsense_web/components/tool-ui/notion/create-notion-page.tsx @@ -228,6 +228,7 @@ function ApprovalCard({ setIsPanelOpen(false); setPendingEdits({ title: newTitle, content: newContent }); }, + onClose: () => setIsPanelOpen(false), }); }} > @@ -346,7 +347,7 @@ function ApprovalCard({ size="sm" className="rounded-lg gap-1.5" onClick={handleApprove} - disabled={!selectedAccountId || !isTitleValid} + disabled={!selectedAccountId || !isTitleValid || isPanelOpen} > Approve @@ -357,6 +358,7 @@ function ApprovalCard({ size="sm" variant="ghost" className="rounded-lg text-muted-foreground" + disabled={isPanelOpen} onClick={() => { setDecided("reject"); onDecision({ type: "reject", message: "User rejected the action." }); diff --git a/surfsense_web/components/tool-ui/notion/update-notion-page.tsx b/surfsense_web/components/tool-ui/notion/update-notion-page.tsx index b1cce42ee..4e12c6953 100644 --- a/surfsense_web/components/tool-ui/notion/update-notion-page.tsx +++ b/surfsense_web/components/tool-ui/notion/update-notion-page.tsx @@ -203,6 +203,7 @@ function ApprovalCard({ setIsPanelOpen(false); setPendingEdits({ content: newContent }); }, + onClose: () => setIsPanelOpen(false), }); }} > @@ -278,6 +279,7 @@ function ApprovalCard({ size="sm" className="rounded-lg gap-1.5" onClick={handleApprove} + disabled={isPanelOpen} > Approve @@ -288,6 +290,7 @@ function ApprovalCard({ size="sm" variant="ghost" className="rounded-lg text-muted-foreground" + disabled={isPanelOpen} onClick={() => { setDecided("reject"); onDecision({ type: "reject", message: "User rejected the action." });