Open History to see the last commit
1import type {
2 ProjectScript,
3 ProjectScriptIcon,
4 ResolvedKeybindingsConfig,
5 T3ProjectFileScript,
6} from "@t3tools/contracts";
7import {
8 isAtomCommandInterrupted,
9 squashAtomCommandFailure,
10 type AtomCommandResult,
11} from "@t3tools/client-runtime/state/runtime";
12import {
13 BugIcon,
14 ChevronDownIcon,
15 DownloadIcon,
16 FlaskConicalIcon,
17 HammerIcon,
18 ListChecksIcon,
19 PlayIcon,
20 PlusIcon,
21 SettingsIcon,
22 WrenchIcon,
23} from "lucide-react";
24import React, { type FormEvent, type KeyboardEvent, useCallback, useMemo, useState } from "react";
25
26import {
27 keybindingValueForCommand,
28 decodeProjectScriptKeybindingRule,
29} from "~/lib/projectScriptKeybindings";
30import { keybindingFromKeyboardEvent } from "~/components/settings/KeybindingsSettings.logic";
31import {
32 commandForProjectScript,
33 nextProjectScriptId,
34 primaryProjectScript,
35} from "~/projectScripts";
36import { shortcutLabelForCommand } from "~/keybindings";
37import {
38 AlertDialog,
39 AlertDialogClose,
40 AlertDialogDescription,
41 AlertDialogFooter,
42 AlertDialogHeader,
43 AlertDialogPopup,
44 AlertDialogTitle,
45} from "./ui/alert-dialog";
46import { Button } from "./ui/button";
47import {
48 Dialog,
49 DialogDescription,
50 DialogFooter,
51 DialogHeader,
52 DialogPanel,
53 DialogPopup,
54 DialogTitle,
55} from "./ui/dialog";
56import { Group, GroupSeparator } from "./ui/group";
57import { Input } from "./ui/input";
58import { Label } from "./ui/label";
59import {
60 Menu,
61 MenuGroup,
62 MenuGroupLabel,
63 MenuItem,
64 MenuPopup,
65 MenuSeparator,
66 MenuShortcut,
67 MenuTrigger,
68} from "./ui/menu";
69import { Popover, PopoverPopup, PopoverTrigger } from "./ui/popover";
70import { Switch } from "./ui/switch";
71import { Textarea } from "./ui/textarea";
72import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
73import { cn } from "~/lib/utils";
74import {
75 THREAD_DETAILS_PANEL_CHEVRON_CLASS,
76 THREAD_DETAILS_PANEL_ICON_CLASS,
77 THREAD_DETAILS_PANEL_ROW_POPUP_CLASS,
78 THREAD_DETAILS_PANEL_ROW_CLASS,
79 THREAD_DETAILS_PANEL_SPLIT_GROUP_CLASS,
80 THREAD_DETAILS_PANEL_SPLIT_PRIMARY_CLASS,
81 THREAD_DETAILS_PANEL_SPLIT_SECONDARY_CLASS,
82 THREAD_DETAILS_PANEL_SPLIT_SEPARATOR_CLASS,
83} from "./chat/threadDetailsPanelStyles";
84
85const SCRIPT_ICONS: Array<{ id: ProjectScriptIcon; label: string }> = [
86 { id: "play", label: "Play" },
87 { id: "test", label: "Test" },
88 { id: "lint", label: "Lint" },
89 { id: "configure", label: "Configure" },
90 { id: "build", label: "Build" },
91 { id: "debug", label: "Debug" },
92];
93
94function ScriptIcon({
95 icon,
96 className = "size-3.5",
97}: {
98 icon: ProjectScriptIcon;
99 className?: string;
100}) {
101 if (icon === "test") return <FlaskConicalIcon className={className} />;
102 if (icon === "lint") return <ListChecksIcon className={className} />;
103 if (icon === "configure") return <WrenchIcon className={className} />;
104 if (icon === "build") return <HammerIcon className={className} />;
105 if (icon === "debug") return <BugIcon className={className} />;
106 return <PlayIcon className={className} />;
107}
108
109export interface NewProjectScriptInput {
110 name: string;
111 command: string;
112 icon: ProjectScriptIcon;
113 runOnWorktreeCreate: boolean;
114 keybinding: string | null;
115 /** Optional URL to open in the in-app preview when this script runs. */
116 previewUrl: string | null;
117 /** When true, automatically open the preview panel pointed at `previewUrl`. */
118 autoOpenPreview: boolean;
119}
120
121export type ProjectScriptActionResult = AtomCommandResult<void, unknown>;
122
123const NO_FILE_SCRIPTS: ReadonlyArray<T3ProjectFileScript> = [];
124
125interface ProjectScriptsControlProps {
126 displayMode?: "toolbar" | "panel";
127 scripts: ReadonlyArray<ProjectScript>;
128 /** Scripts declared in the project's checked-in t3.json, offered for import. */
129 fileScripts?: ReadonlyArray<T3ProjectFileScript>;
130 keybindings: ResolvedKeybindingsConfig;
131 preferredScriptId?: string | null;
132 onRunScript: (script: ProjectScript) => void;
133 onAddScript: (input: NewProjectScriptInput) => Promise<ProjectScriptActionResult>;
134 onUpdateScript: (
135 scriptId: string,
136 input: NewProjectScriptInput,
137 ) => Promise<ProjectScriptActionResult>;
138 onDeleteScript: (scriptId: string) => Promise<ProjectScriptActionResult>;
139}
140
141export default function ProjectScriptsControl({
142 displayMode = "toolbar",
143 scripts,
144 fileScripts = NO_FILE_SCRIPTS,
145 keybindings,
146 preferredScriptId = null,
147 onRunScript,
148 onAddScript,
149 onUpdateScript,
150 onDeleteScript,
151}: ProjectScriptsControlProps) {
152 const isPanel = displayMode === "panel";
153 const ActionGroup = isPanel ? "div" : Group;
154 const panelAnchorRef = React.useRef<HTMLDivElement | null>(null);
155 const addScriptFormId = React.useId();
156 const [editingScriptId, setEditingScriptId] = useState<string | null>(null);
157 const [actionsMenuOpen, setActionsMenuOpen] = useState({
158 scripts: false,
159 imports: false,
160 });
161 const [dialogOpen, setDialogOpen] = useState(false);
162 const [name, setName] = useState("");
163 const [command, setCommand] = useState("");
164 const [icon, setIcon] = useState<ProjectScriptIcon>("play");
165 const [iconPickerOpen, setIconPickerOpen] = useState(false);
166 const [runOnWorktreeCreate, setRunOnWorktreeCreate] = useState(false);
167 const [keybinding, setKeybinding] = useState("");
168 const [previewUrl, setPreviewUrl] = useState("");
169 const [autoOpenPreview, setAutoOpenPreview] = useState(false);
170 const [validationError, setValidationError] = useState<string | null>(null);
171 const [deleteConfirmOpen, setDeleteConfirmOpen] = useState(false);
172
173 const primaryScript = useMemo(() => {
174 if (preferredScriptId) {
175 const preferred = scripts.find((script) => script.id === preferredScriptId);
176 if (preferred) return preferred;
177 }
178 return primaryProjectScript(scripts);
179 }, [preferredScriptId, scripts]);
180 const importableScripts = useMemo(
181 () =>
182 fileScripts.filter(
183 (fileScript) =>
184 !scripts.some(
185 (script) =>
186 script.command === fileScript.command ||
187 script.name.toLowerCase() === fileScript.name.toLowerCase(),
188 ),
189 ),
190 [fileScripts, scripts],
191 );
192 const isEditing = editingScriptId !== null;
193 const dropdownItemClassName =
194 "data-highlighted:bg-transparent data-highlighted:text-foreground hover:bg-accent hover:text-accent-foreground focus-visible:bg-accent focus-visible:text-accent-foreground data-highlighted:hover:bg-accent data-highlighted:hover:text-accent-foreground data-highlighted:focus-visible:bg-accent data-highlighted:focus-visible:text-accent-foreground";
195
196 const captureKeybinding = (event: KeyboardEvent<HTMLInputElement>) => {
197 if (event.key === "Tab") return;
198 event.preventDefault();
199 if (event.key === "Backspace" || event.key === "Delete") {
200 setKeybinding("");
201 return;
202 }
203 const next = keybindingFromKeyboardEvent(event, navigator.platform);
204 if (!next) return;
205 setKeybinding(next);
206 };
207
208 const submitAddScript = async (event: FormEvent) => {
209 event.preventDefault();
210 const trimmedName = name.trim();
211 const trimmedCommand = command.trim();
212 if (trimmedName.length === 0) {
213 setValidationError("Name is required.");
214 return;
215 }
216 if (trimmedCommand.length === 0) {
217 setValidationError("Command is required.");
218 return;
219 }
220
221 setValidationError(null);
222 let payload: NewProjectScriptInput;
223 try {
224 const scriptIdForValidation =
225 editingScriptId ??
226 nextProjectScriptId(
227 trimmedName,
228 scripts.map((script) => script.id),
229 );
230 const keybindingRule = decodeProjectScriptKeybindingRule({
231 keybinding,
232 command: commandForProjectScript(scriptIdForValidation),
233 });
234 const trimmedPreviewUrl = previewUrl.trim();
235 payload = {
236 name: trimmedName,
237 command: trimmedCommand,
238 icon,
239 runOnWorktreeCreate,
240 keybinding: keybindingRule?.key ?? null,
241 previewUrl: trimmedPreviewUrl.length > 0 ? trimmedPreviewUrl : null,
242 autoOpenPreview: trimmedPreviewUrl.length > 0 ? autoOpenPreview : false,
243 } satisfies NewProjectScriptInput;
244 } catch (error) {
245 setValidationError(error instanceof Error ? error.message : "Failed to save action.");
246 return;
247 }
248
249 const result = editingScriptId
250 ? await onUpdateScript(editingScriptId, payload)
251 : await onAddScript(payload);
252 if (result._tag === "Failure") {
253 if (!isAtomCommandInterrupted(result)) {
254 const error = squashAtomCommandFailure(result);
255 setValidationError(error instanceof Error ? error.message : "Failed to save action.");
256 }
257 return;
258 }
259 setDialogOpen(false);
260 setIconPickerOpen(false);
261 };
262
263 const openAddDialog = () => {
264 setEditingScriptId(null);
265 setName("");
266 setCommand("");
267 setIcon("play");
268 setIconPickerOpen(false);
269 setRunOnWorktreeCreate(false);
270 setKeybinding("");
271 setPreviewUrl("");
272 setAutoOpenPreview(false);
273 setValidationError(null);
274 setDialogOpen(true);
275 };
276
277 const openEditDialog = (script: ProjectScript) => {
278 setActionsMenuOpen({ scripts: false, imports: false });
279 setEditingScriptId(script.id);
280 setName(script.name);
281 setCommand(script.command);
282 setIcon(script.icon);
283 setIconPickerOpen(false);
284 setRunOnWorktreeCreate(script.runOnWorktreeCreate);
285 setKeybinding(keybindingValueForCommand(keybindings, commandForProjectScript(script.id)) ?? "");
286 setPreviewUrl(script.previewUrl ?? "");
287 setAutoOpenPreview(script.autoOpenPreview ?? false);
288 setValidationError(null);
289 setDialogOpen(true);
290 };
291
292 const confirmDeleteScript = useCallback(() => {
293 if (!editingScriptId) return;
294 setDeleteConfirmOpen(false);
295 setDialogOpen(false);
296 void onDeleteScript(editingScriptId);
297 }, [editingScriptId, onDeleteScript]);
298
299 const importFileScript = async (fileScript: T3ProjectFileScript) => {
300 const payload: NewProjectScriptInput = {
301 name: fileScript.name,
302 command: fileScript.command,
303 icon: fileScript.icon ?? "play",
304 runOnWorktreeCreate: fileScript.runOnWorktreeCreate ?? false,
305 keybinding: null,
306 previewUrl: fileScript.previewUrl ?? null,
307 autoOpenPreview: fileScript.previewUrl ? (fileScript.autoOpenPreview ?? false) : false,
308 };
309 const result = await onAddScript(payload);
310 if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
311 // Surface the failure through the regular add dialog, prefilled so the
312 // user can adjust and retry.
313 const error = squashAtomCommandFailure(result);
314 setEditingScriptId(null);
315 setName(payload.name);
316 setCommand(payload.command);
317 setIcon(payload.icon);
318 setIconPickerOpen(false);
319 setRunOnWorktreeCreate(payload.runOnWorktreeCreate);
320 setKeybinding("");
321 setPreviewUrl(payload.previewUrl ?? "");
322 setAutoOpenPreview(payload.autoOpenPreview);
323 setValidationError(error instanceof Error ? error.message : "Failed to import action.");
324 setDialogOpen(true);
325 }
326 };
327
328 const importMenuItems = importableScripts.length > 0 && (
329 <>
330 {primaryScript && <MenuSeparator />}
331 <MenuGroup>
332 <MenuGroupLabel>From t3.json</MenuGroupLabel>
333 {importableScripts.map((fileScript) => (
334 <MenuItem
335 key={`${fileScript.name} ${fileScript.command}`}
336 className={dropdownItemClassName}
337 onClick={() => void importFileScript(fileScript)}
338 >
339 <ScriptIcon icon={fileScript.icon ?? "play"} className="size-4" />
340 <span className="truncate">{fileScript.name}</span>
341 <MenuShortcut className="ms-auto">
342 <DownloadIcon className="size-3.5" aria-label="Import" />
343 </MenuShortcut>
344 </MenuItem>
345 ))}
346 </MenuGroup>
347 </>
348 );
349
350 return (
351 <>
352 {primaryScript ? (
353 <ActionGroup
354 role="group"
355 aria-label="Project scripts"
356 {...(isPanel
357 ? { className: THREAD_DETAILS_PANEL_SPLIT_GROUP_CLASS, ref: panelAnchorRef }
358 : {})}
359 >
360 <Tooltip>
361 <TooltipTrigger
362 render={
363 <Button
364 size="xs"
365 variant={isPanel ? "ghost" : "outline"}
366 className={isPanel ? THREAD_DETAILS_PANEL_SPLIT_PRIMARY_CLASS : undefined}
367 aria-label={`Run ${primaryScript.name}`}
368 onClick={() => onRunScript(primaryScript)}
369 />
370 }
371 >
372 <ScriptIcon
373 icon={primaryScript.icon}
374 {...(isPanel ? { className: THREAD_DETAILS_PANEL_ICON_CLASS } : {})}
375 />
376 <span
377 className={cn(
378 "sr-only @3xl/header-actions:not-sr-only @3xl/header-actions:ml-0.5",
379 isPanel && "not-sr-only ml-0.5 truncate",
380 )}
381 >
382 {primaryScript.name}
383 </span>
384 </TooltipTrigger>
385 <TooltipPopup side="top">Run {primaryScript.name}</TooltipPopup>
386 </Tooltip>
387 {isPanel ? (
388 <span aria-hidden="true" className={THREAD_DETAILS_PANEL_SPLIT_SEPARATOR_CLASS} />
389 ) : (
390 <GroupSeparator className="hidden @3xl/header-actions:block" />
391 )}
392 <Menu
393 highlightItemOnHover={false}
394 open={actionsMenuOpen.scripts}
395 onOpenChange={(open) => setActionsMenuOpen({ scripts: open, imports: false })}
396 >
397 <MenuTrigger
398 render={
399 <Button
400 size={isPanel ? "sm" : "icon-xs"}
401 variant={isPanel ? "ghost" : "outline"}
402 className={isPanel ? THREAD_DETAILS_PANEL_SPLIT_SECONDARY_CLASS : undefined}
403 aria-label="Script actions"
404 />
405 }
406 >
407 <ChevronDownIcon
408 className={isPanel ? THREAD_DETAILS_PANEL_CHEVRON_CLASS : "size-4"}
409 />
410 </MenuTrigger>
411 <MenuPopup
412 align="end"
413 {...(isPanel ? { anchor: panelAnchorRef } : {})}
414 className={isPanel ? THREAD_DETAILS_PANEL_ROW_POPUP_CLASS : undefined}
415 >
416 {scripts.map((script) => {
417 const shortcutLabel = shortcutLabelForCommand(
418 keybindings,
419 commandForProjectScript(script.id),
420 );
421 return (
422 <MenuItem
423 key={script.id}
424 className={`group ${dropdownItemClassName}`}
425 onClick={() => onRunScript(script)}
426 >
427 <ScriptIcon icon={script.icon} className="size-4" />
428 <span className="truncate">
429 {script.runOnWorktreeCreate ? `${script.name} (setup)` : script.name}
430 </span>
431 <span className="relative ms-auto flex h-6 min-w-6 items-center justify-end">
432 {shortcutLabel && (
433 <MenuShortcut className="ms-0 transition-opacity group-hover:opacity-0 group-focus-visible:opacity-0">
434 {shortcutLabel}
435 </MenuShortcut>
436 )}
437 <Button
438 type="button"
439 variant="ghost"
440 size="icon-xs"
441 className="absolute right-0 top-1/2 size-6 -translate-y-1/2 opacity-0 pointer-events-none transition-opacity group-hover:opacity-100 group-hover:pointer-events-auto group-focus-visible:opacity-100 group-focus-visible:pointer-events-auto"
442 aria-label={`Edit ${script.name}`}
443 onPointerDown={(event) => {
444 event.preventDefault();
445 event.stopPropagation();
446 }}
447 onClick={(event) => {
448 event.preventDefault();
449 event.stopPropagation();
450 openEditDialog(script);
451 }}
452 >
453 <SettingsIcon className="size-3.5" />
454 </Button>
455 </span>
456 </MenuItem>
457 );
458 })}
459 {importMenuItems}
460 <MenuItem className={dropdownItemClassName} onClick={openAddDialog}>
461 <PlusIcon className="size-4" />
462 {isPanel ? "Add project script" : "Add action"}
463 </MenuItem>
464 </MenuPopup>
465 </Menu>
466 </ActionGroup>
467 ) : importableScripts.length > 0 ? (
468 <Menu
469 highlightItemOnHover={false}
470 open={actionsMenuOpen.imports}
471 onOpenChange={(open) => setActionsMenuOpen({ scripts: false, imports: open })}
472 >
473 <MenuTrigger render={<Button size="xs" variant="outline" aria-label="Project actions" />}>
474 <PlusIcon className="size-3.5" />
475 <span className="sr-only @3xl/header-actions:not-sr-only @3xl/header-actions:ml-0.5">
476 Add action
477 </span>
478 <ChevronDownIcon className="size-3.5" />
479 </MenuTrigger>
480 <MenuPopup align="end">
481 {importMenuItems}
482 <MenuItem className={dropdownItemClassName} onClick={openAddDialog}>
483 <PlusIcon className="size-4" />
484 Add action
485 </MenuItem>
486 </MenuPopup>
487 </Menu>
488 ) : (
489 <Tooltip>
490 <TooltipTrigger
491 render={
492 <Button
493 size="xs"
494 variant={isPanel ? "ghost" : "outline"}
495 className={isPanel ? THREAD_DETAILS_PANEL_ROW_CLASS : undefined}
496 aria-label={isPanel ? "Add project script" : "Add action"}
497 onClick={openAddDialog}
498 />
499 }
500 >
501 <PlusIcon className="size-3.5" />
502 <span
503 className={cn(
504 "sr-only @3xl/header-actions:not-sr-only @3xl/header-actions:ml-0.5",
505 isPanel && "not-sr-only ml-0.5",
506 )}
507 >
508 {isPanel ? "Add project script" : "Add action"}
509 </span>
510 </TooltipTrigger>
511 <TooltipPopup side="top">{isPanel ? "Add project script" : "Add action"}</TooltipPopup>
512 </Tooltip>
513 )}
514
515 <Dialog
516 onOpenChange={(open) => {
517 setDialogOpen(open);
518 if (!open) {
519 setIconPickerOpen(false);
520 }
521 }}
522 onOpenChangeComplete={(open) => {
523 if (open) return;
524 setEditingScriptId(null);
525 setName("");
526 setCommand("");
527 setIcon("play");
528 setRunOnWorktreeCreate(false);
529 setKeybinding("");
530 setPreviewUrl("");
531 setAutoOpenPreview(false);
532 setValidationError(null);
533 }}
534 open={dialogOpen}
535 >
536 <DialogPopup>
537 <DialogHeader>
538 <DialogTitle>{isEditing ? "Edit Action" : "Add Action"}</DialogTitle>
539 <DialogDescription>
540 Actions are project-scoped commands you can run from the top bar or keybindings.
541 </DialogDescription>
542 </DialogHeader>
543 <DialogPanel>
544 <form id={addScriptFormId} className="space-y-4" onSubmit={submitAddScript}>
545 <div className="space-y-1.5">
546 <Label htmlFor="script-name">Name</Label>
547 <div className="flex items-center gap-2">
548 <Popover onOpenChange={setIconPickerOpen} open={iconPickerOpen}>
549 <PopoverTrigger
550 render={
551 <Button
552 type="button"
553 variant="outline"
554 className="size-9 shrink-0 hover:bg-popover active:bg-popover data-pressed:bg-popover data-pressed:shadow-xs/5 data-pressed:before:shadow-[0_1px_--theme(--color-black/4%)] dark:border-transparent dark:bg-white/[0.035] dark:data-pressed:before:shadow-none"
555 aria-label="Choose icon"
556 />
557 }
558 >
559 <ScriptIcon icon={icon} className="size-4.5" />
560 </PopoverTrigger>
561 <PopoverPopup align="start">
562 <div className="grid grid-cols-3 gap-2">
563 {SCRIPT_ICONS.map((entry) => {
564 const isSelected = entry.id === icon;
565 return (
566 <button
567 key={entry.id}
568 type="button"
569 className={`relative flex flex-col items-center gap-2 rounded-md border px-2 py-2 text-xs dark:border-transparent ${
570 isSelected
571 ? "border-primary/70 bg-primary/10 dark:ring-1 dark:ring-primary/30"
572 : "border-border/70 hover:bg-accent/60 dark:bg-white/[0.035]"
573 }`}
574 onClick={() => {
575 setIcon(entry.id);
576 setIconPickerOpen(false);
577 }}
578 >
579 <ScriptIcon icon={entry.id} className="size-4" />
580 <span>{entry.label}</span>
581 </button>
582 );
583 })}
584 </div>
585 </PopoverPopup>
586 </Popover>
587 <Input
588 id="script-name"
589 autoFocus
590 placeholder="Test"
591 value={name}
592 onChange={(event) => setName(event.target.value)}
593 />
594 </div>
595 </div>
596 <div className="space-y-1.5">
597 <Label htmlFor="script-keybinding">Keybinding</Label>
598 <Input
599 id="script-keybinding"
600 placeholder="Press shortcut"
601 value={keybinding}
602 readOnly
603 onKeyDown={captureKeybinding}
604 />
605 <p className="text-xs text-muted-foreground">
606 Press a shortcut. Use <code>Backspace</code> to clear.
607 </p>
608 </div>
609 <div className="space-y-1.5">
610 <Label htmlFor="script-command">Command</Label>
611 <Textarea
612 id="script-command"
613 placeholder="bun test"
614 value={command}
615 onChange={(event) => setCommand(event.target.value)}
616 />
617 </div>
618 <div className="space-y-1.5">
619 <Label htmlFor="script-preview-url">Preview URL (optional)</Label>
620 <Input
621 id="script-preview-url"
622 placeholder="http://localhost:5173"
623 value={previewUrl}
624 onChange={(event) => setPreviewUrl(event.target.value)}
625 />
626 <p className="text-xs text-muted-foreground">
627 Open this URL in the in-app preview when this action runs.
628 </p>
629 </div>
630 <label className="flex items-center justify-between gap-3 rounded-md border border-border/70 px-3 py-2 text-sm dark:border-transparent dark:bg-white/[0.035]">
631 <span>Run automatically on worktree creation</span>
632 <Switch
633 checked={runOnWorktreeCreate}
634 onCheckedChange={(checked) => setRunOnWorktreeCreate(Boolean(checked))}
635 />
636 </label>
637 <label
638 className={`flex items-center justify-between gap-3 rounded-md border border-border/70 px-3 py-2 text-sm dark:border-transparent dark:bg-white/[0.035] ${
639 previewUrl.trim().length === 0 ? "opacity-60" : ""
640 }`}
641 >
642 <span>Open preview automatically when this action runs</span>
643 <Switch
644 checked={autoOpenPreview}
645 disabled={previewUrl.trim().length === 0}
646 onCheckedChange={(checked) => setAutoOpenPreview(Boolean(checked))}
647 />
648 </label>
649 {validationError && <p className="text-sm text-destructive">{validationError}</p>}
650 </form>
651 </DialogPanel>
652 <DialogFooter className="dark:border-transparent dark:bg-transparent">
653 {isEditing && (
654 <Button
655 type="button"
656 variant="destructive-outline"
657 className="mr-auto"
658 onClick={() => setDeleteConfirmOpen(true)}
659 >
660 Delete
661 </Button>
662 )}
663 <Button
664 type="button"
665 variant="outline"
666 onClick={() => {
667 setDialogOpen(false);
668 }}
669 >
670 Cancel
671 </Button>
672 <Button form={addScriptFormId} type="submit">
673 {isEditing ? "Save changes" : "Save action"}
674 </Button>
675 </DialogFooter>
676 </DialogPopup>
677 </Dialog>
678
679 <AlertDialog open={deleteConfirmOpen} onOpenChange={setDeleteConfirmOpen}>
680 <AlertDialogPopup>
681 <AlertDialogHeader>
682 <AlertDialogTitle>Delete action "{name}"?</AlertDialogTitle>
683 <AlertDialogDescription>This action cannot be undone.</AlertDialogDescription>
684 </AlertDialogHeader>
685 <AlertDialogFooter>
686 <AlertDialogClose render={<Button variant="outline" />}>Cancel</AlertDialogClose>
687 <Button variant="destructive" onClick={confirmDeleteScript}>
688 Delete action
689 </Button>
690 </AlertDialogFooter>
691 </AlertDialogPopup>
692 </AlertDialog>
693 </>
694 );
695}