Open History to see the last commit
1import { type GitStatusResult, type GitStackedAction, type NativeApi } from "@t3tools/contracts";
2import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
3import { useCallback, useEffect, useMemo, useState } from "react";
4import { ChevronDownIcon, CloudUploadIcon, GitCommitIcon, InfoIcon } from "lucide-react";
5import { GitHubIcon } from "./Icons";
6import {
7 buildGitActionProgressStages,
8 buildMenuItems,
9 type GitActionIconName,
10 type GitActionMenuItem,
11 type GitDialogAction,
12 type GitQuickAction,
13 requiresDefaultBranchConfirmation,
14 resolveQuickAction,
15 summarizeGitResult,
16} from "./GitActionsControl.logic";
17import { Button } from "~/components/ui/button";
18import {
19 Dialog,
20 DialogDescription,
21 DialogFooter,
22 DialogHeader,
23 DialogPanel,
24 DialogPopup,
25 DialogTitle,
26} from "~/components/ui/dialog";
27import { Group, GroupSeparator } from "~/components/ui/group";
28import { Menu, MenuItem, MenuPopup, MenuTrigger } from "~/components/ui/menu";
29import { Popover, PopoverPopup, PopoverTrigger } from "~/components/ui/popover";
30import { ScrollArea } from "~/components/ui/scroll-area";
31import { Textarea } from "~/components/ui/textarea";
32import { toastManager } from "~/components/ui/toast";
33import {
34 gitBranchesQueryOptions,
35 gitInitMutationOptions,
36 gitPullMutationOptions,
37 gitRunStackedActionMutationOptions,
38 gitStatusQueryOptions,
39 invalidateGitQueries,
40} from "~/lib/gitReactQuery";
41import { useStore } from "~/store";
42import { preferredTerminalEditor, resolvePathLinkTarget } from "~/terminal-links";
43
44interface GitActionsControlProps {
45 api: NativeApi | undefined;
46 gitCwd: string | null;
47}
48
49function getMenuActionDisabledReason(
50 item: GitActionMenuItem,
51 gitStatus: GitStatusResult | null,
52 isBusy: boolean,
53): string | null {
54 if (!item.disabled) return null;
55 if (isBusy) return "Git action in progress.";
56 if (!gitStatus) return "Git status is unavailable.";
57
58 const hasBranch = gitStatus.branch !== null;
59 const hasChanges = gitStatus.hasWorkingTreeChanges;
60 const hasOpenPr = gitStatus.openPr !== null;
61 const isAhead = gitStatus.aheadCount > 0;
62 const isBehind = gitStatus.behindCount > 0;
63
64 if (item.id === "commit") {
65 if (!hasChanges) {
66 return "Worktree is clean. Make changes before committing.";
67 }
68 return "Commit is currently unavailable.";
69 }
70
71 if (item.id === "push") {
72 if (!hasBranch) {
73 return "Detached HEAD: checkout a branch before pushing.";
74 }
75 if (hasChanges) {
76 return "Commit or stash local changes before pushing.";
77 }
78 if (isBehind) {
79 return "Branch is behind upstream. Pull/rebase before pushing.";
80 }
81 if (!isAhead) {
82 return "No local commits to push.";
83 }
84 return "Push is currently unavailable.";
85 }
86
87 if (hasOpenPr) {
88 return "Open PR is currently unavailable.";
89 }
90 if (!hasBranch) {
91 return "Detached HEAD: checkout a branch before creating a PR.";
92 }
93 if (hasChanges) {
94 return "Commit local changes before creating a PR.";
95 }
96 if (!isAhead) {
97 return "No local commits to include in a PR.";
98 }
99 if (!gitStatus.hasUpstream) {
100 return "Set an upstream branch before creating a PR.";
101 }
102 if (isBehind) {
103 return "Branch is behind upstream. Pull/rebase before creating a PR.";
104 }
105 return "Create PR is currently unavailable.";
106}
107
108const DIALOG_TITLE_BY_ACTION = {
109 commit: "Commit changes",
110 push: "Push branch",
111 create_pr: "Create pull request",
112};
113
114const DIALOG_DESCRIPTION_BY_ACTION = {
115 commit: "Review and confirm your commit. Leave the message blank to auto-generate one.",
116 push: "Push this branch now.",
117 create_pr: "Create a pull request using generated title/body content.",
118};
119
120function GitActionItemIcon({ icon }: { icon: GitActionIconName }) {
121 if (icon === "commit") return <GitCommitIcon />;
122 if (icon === "push") return <CloudUploadIcon />;
123 return <GitHubIcon />;
124}
125
126function GitQuickActionIcon({ quickAction }: { quickAction: GitQuickAction }) {
127 const iconClassName = "size-3.5";
128 if (quickAction.kind === "open_pr") return <GitHubIcon className={iconClassName} />;
129 if (quickAction.kind === "run_pull") return <InfoIcon className={iconClassName} />;
130 if (quickAction.kind === "run_action") {
131 if (quickAction.action === "commit") return <GitCommitIcon className={iconClassName} />;
132 if (quickAction.action === "commit_push") return <CloudUploadIcon className={iconClassName} />;
133 return <GitHubIcon className={iconClassName} />;
134 }
135 if (quickAction.label === "Commit") return <GitCommitIcon className={iconClassName} />;
136 return <InfoIcon className={iconClassName} />;
137}
138
139export default function GitActionsControl({ api, gitCwd }: GitActionsControlProps) {
140 const { state } = useStore();
141 const activeThreadId = state.activeThreadId;
142 const threadToastData = useMemo(
143 () => (activeThreadId ? { threadId: activeThreadId } : undefined),
144 [activeThreadId],
145 );
146 const queryClient = useQueryClient();
147 const [activeDialogAction, setActiveDialogAction] = useState<GitDialogAction | null>(null);
148 const [dialogCommitMessage, setDialogCommitMessage] = useState("");
149
150 const { data: gitStatus = null, error: gitStatusError } = useQuery(
151 gitStatusQueryOptions(api, gitCwd),
152 );
153
154 const { data: branchList = null } = useQuery(gitBranchesQueryOptions(api, gitCwd));
155 // Default to true while loading so we don't flash init controls.
156 const isRepo = branchList?.isRepo ?? true;
157 const currentBranch = branchList?.branches.find((branch) => branch.current)?.name ?? null;
158 const isGitStatusOutOfSync =
159 !!gitStatus?.branch && !!currentBranch && gitStatus.branch !== currentBranch;
160
161 useEffect(() => {
162 if (!isGitStatusOutOfSync) return;
163 void invalidateGitQueries(queryClient);
164 }, [isGitStatusOutOfSync, queryClient]);
165
166 const gitStatusForActions = isGitStatusOutOfSync ? null : gitStatus;
167
168 const initMutation = useMutation(gitInitMutationOptions({ api, cwd: gitCwd, queryClient }));
169
170 const runImmediateGitActionMutation = useMutation(
171 gitRunStackedActionMutationOptions({ api, cwd: gitCwd, queryClient }),
172 );
173 const pullMutation = useMutation(gitPullMutationOptions({ api, cwd: gitCwd, queryClient }));
174
175 const isGitActionRunning = runImmediateGitActionMutation.isPending || pullMutation.isPending;
176 const isDefaultBranch = useMemo(() => {
177 const branchName = gitStatusForActions?.branch;
178 if (!branchName) return false;
179 const current = branchList?.branches.find((branch) => branch.name === branchName);
180 return current?.isDefault ?? (branchName === "main" || branchName === "master");
181 }, [branchList?.branches, gitStatusForActions?.branch]);
182
183 const gitActionMenuItems = useMemo(
184 () => buildMenuItems(gitStatusForActions, isGitActionRunning),
185 [gitStatusForActions, isGitActionRunning],
186 );
187 const quickAction = useMemo(
188 () => resolveQuickAction(gitStatusForActions, isGitActionRunning, isDefaultBranch),
189 [gitStatusForActions, isDefaultBranch, isGitActionRunning],
190 );
191 const quickActionDisabledReason = quickAction.disabled
192 ? (quickAction.hint ?? "This action is currently unavailable.")
193 : null;
194
195 const maybeConfirmPushToDefaultBranch = useCallback(
196 async (action: GitStackedAction): Promise<boolean> => {
197 if (!api) return false;
198 if (
199 !requiresDefaultBranchConfirmation(action, isDefaultBranch) ||
200 !gitStatusForActions?.branch
201 ) {
202 return true;
203 }
204 return api.dialogs.confirm(
205 `You're about to push to the default branch "${gitStatusForActions.branch}". Continue?`,
206 );
207 },
208 [api, gitStatusForActions?.branch, isDefaultBranch],
209 );
210
211 const openExistingPr = useCallback(async () => {
212 if (!api) {
213 toastManager.add({
214 type: "error",
215 title: "Link opening is unavailable.",
216 data: threadToastData,
217 });
218 return;
219 }
220 const prUrl = gitStatusForActions?.openPr?.url ?? null;
221 if (!prUrl) {
222 toastManager.add({
223 type: "error",
224 title: "No open PR found.",
225 data: threadToastData,
226 });
227 return;
228 }
229 const promise = api.shell.openExternal(prUrl);
230 toastManager.promise(promise, {
231 loading: { title: "Opening PR...", data: threadToastData },
232 success: { title: "PR opened", data: threadToastData },
233 error: (err) => ({
234 title: "Unable to open PR link",
235 description: err instanceof Error ? err.message : "An error occurred.",
236 data: threadToastData,
237 }),
238 });
239 void promise.catch(() => undefined);
240 }, [api, gitStatusForActions?.openPr?.url, threadToastData]);
241
242 const runGitActionWithToast = useCallback(
243 async ({
244 action,
245 commitMessage,
246 forcePushOnlyProgress = false,
247 onConfirmed,
248 }: {
249 action: GitStackedAction;
250 commitMessage?: string;
251 forcePushOnlyProgress?: boolean;
252 onConfirmed?: () => void;
253 }) => {
254 const confirmed = await maybeConfirmPushToDefaultBranch(action);
255 if (!confirmed) return;
256 onConfirmed?.();
257
258 const pushTarget = gitStatusForActions?.branch
259 ? `origin/${gitStatusForActions.branch}`
260 : undefined;
261 const progressStages = buildGitActionProgressStages({
262 action,
263 hasCustomCommitMessage: !!commitMessage?.trim(),
264 hasWorkingTreeChanges: !!gitStatusForActions?.hasWorkingTreeChanges,
265 forcePushOnly: forcePushOnlyProgress,
266 ...(pushTarget ? { pushTarget } : {}),
267 });
268 const progressToastId = toastManager.add({
269 type: "loading",
270 title: progressStages[0] ?? "Running git action...",
271 timeout: 0,
272 data: threadToastData,
273 });
274
275 let stageIndex = 0;
276 const stageInterval = setInterval(() => {
277 stageIndex = Math.min(stageIndex + 1, progressStages.length - 1);
278 toastManager.update(progressToastId, {
279 title: progressStages[stageIndex] ?? "Running git action...",
280 type: "loading",
281 timeout: 0,
282 data: threadToastData,
283 });
284 }, 1100);
285
286 const stopProgressUpdates = () => {
287 clearInterval(stageInterval);
288 };
289
290 const promise = runImmediateGitActionMutation.mutateAsync({
291 action,
292 ...(commitMessage ? { commitMessage } : {}),
293 });
294
295 try {
296 const result = await promise;
297 stopProgressUpdates();
298 const resultToast = summarizeGitResult(result);
299
300 const prUrl = result.pr.url ?? gitStatusForActions?.openPr?.url;
301 const shouldOfferPushCta = action === "commit" && result.commit.status === "created";
302 const shouldOfferOpenPrCta =
303 (action === "commit_push" || action === "commit_push_pr") && !!prUrl && !isDefaultBranch;
304 const shouldOfferCreatePrCta =
305 action === "commit_push" && !prUrl && result.push.status === "pushed" && !isDefaultBranch;
306 const closeResultToast = () => {
307 toastManager.close(progressToastId);
308 };
309
310 toastManager.update(progressToastId, {
311 type: "success",
312 title: resultToast.title,
313 description: resultToast.description,
314 timeout: 0,
315 data: {
316 ...threadToastData,
317 dismissAfterVisibleMs: 10_000,
318 },
319 ...(shouldOfferPushCta
320 ? {
321 actionProps: {
322 children: "Push",
323 onClick: () => {
324 void runGitActionWithToast({
325 action: "commit_push",
326 forcePushOnlyProgress: true,
327 onConfirmed: closeResultToast,
328 });
329 },
330 },
331 }
332 : shouldOfferOpenPrCta
333 ? {
334 actionProps: {
335 children: "Open PR",
336 onClick: () => {
337 closeResultToast();
338 void api?.shell.openExternal(prUrl);
339 },
340 },
341 }
342 : shouldOfferCreatePrCta
343 ? {
344 actionProps: {
345 children: "Create PR",
346 onClick: () => {
347 closeResultToast();
348 setActiveDialogAction("create_pr");
349 },
350 },
351 }
352 : {}),
353 });
354 } catch (err) {
355 stopProgressUpdates();
356 toastManager.update(progressToastId, {
357 type: "error",
358 title: "Action failed",
359 description: err instanceof Error ? err.message : "An error occurred.",
360 data: threadToastData,
361 });
362 }
363 },
364 [
365 api,
366 gitStatusForActions?.branch,
367 gitStatusForActions?.hasWorkingTreeChanges,
368 gitStatusForActions?.openPr?.url,
369 isDefaultBranch,
370 maybeConfirmPushToDefaultBranch,
371 runImmediateGitActionMutation,
372 setActiveDialogAction,
373 threadToastData,
374 ],
375 );
376
377 const runQuickAction = useCallback(() => {
378 if (quickAction.kind === "open_pr") {
379 void openExistingPr();
380 return;
381 }
382 if (quickAction.kind === "run_pull") {
383 const promise = pullMutation.mutateAsync();
384 toastManager.promise(promise, {
385 loading: { title: "Pulling...", data: threadToastData },
386 success: (result) => ({
387 title: result.status === "pulled" ? "Pulled" : "Already up to date",
388 description:
389 result.status === "pulled"
390 ? `Updated ${result.branch} from ${result.upstreamBranch ?? "upstream"}`
391 : `${result.branch} is already synchronized.`,
392 data: threadToastData,
393 }),
394 error: (err) => ({
395 title: "Pull failed",
396 description: err instanceof Error ? err.message : "An error occurred.",
397 data: threadToastData,
398 }),
399 });
400 void promise.catch(() => undefined);
401 return;
402 }
403 if (quickAction.kind === "show_hint") {
404 toastManager.add({
405 type: "info",
406 title: quickAction.label,
407 description: quickAction.hint,
408 data: threadToastData,
409 });
410 return;
411 }
412 if (quickAction.action) {
413 void runGitActionWithToast({ action: quickAction.action });
414 }
415 }, [openExistingPr, pullMutation, quickAction, runGitActionWithToast, threadToastData]);
416
417 const openDialogForMenuItem = useCallback(
418 (item: GitActionMenuItem) => {
419 if (item.disabled) return;
420 if (item.kind === "open_pr") {
421 void openExistingPr();
422 return;
423 }
424 if (item.dialogAction === "push") {
425 void runGitActionWithToast({ action: "commit_push", forcePushOnlyProgress: true });
426 return;
427 }
428 if (item.dialogAction) {
429 setActiveDialogAction(item.dialogAction);
430 }
431 },
432 [openExistingPr, runGitActionWithToast],
433 );
434
435 const runDialogAction = useCallback(() => {
436 if (!activeDialogAction) return;
437 const action: GitStackedAction =
438 activeDialogAction === "commit"
439 ? "commit"
440 : activeDialogAction === "push"
441 ? "commit_push"
442 : "commit_push_pr";
443 const commitMessage = activeDialogAction === "commit" ? dialogCommitMessage.trim() : "";
444 const forcePushOnlyProgress = activeDialogAction === "push";
445 setActiveDialogAction(null);
446 void runGitActionWithToast({
447 action,
448 ...(commitMessage ? { commitMessage } : {}),
449 ...(forcePushOnlyProgress ? { forcePushOnlyProgress } : {}),
450 });
451 }, [activeDialogAction, dialogCommitMessage, runGitActionWithToast]);
452
453 const openChangedFileInEditor = useCallback(
454 (filePath: string) => {
455 if (!api || !gitCwd) {
456 toastManager.add({
457 type: "error",
458 title: "Editor opening is unavailable.",
459 data: threadToastData,
460 });
461 return;
462 }
463 const target = resolvePathLinkTarget(filePath, gitCwd);
464 void api.shell.openInEditor(target, preferredTerminalEditor()).catch((error) => {
465 toastManager.add({
466 type: "error",
467 title: "Unable to open file",
468 description: error instanceof Error ? error.message : "An error occurred.",
469 data: threadToastData,
470 });
471 });
472 },
473 [api, gitCwd, threadToastData],
474 );
475
476 if (!gitCwd) return null;
477
478 return (
479 <>
480 {!isRepo ? (
481 <Button
482 variant="outline"
483 size="xs"
484 disabled={initMutation.isPending}
485 onClick={() => initMutation.mutate()}
486 >
487 {initMutation.isPending ? "Initializing..." : "Initialize Git"}
488 </Button>
489 ) : (
490 <Group aria-label="Git actions">
491 {quickActionDisabledReason ? (
492 <Popover>
493 <PopoverTrigger
494 openOnHover
495 render={
496 <Button
497 aria-disabled="true"
498 className="cursor-not-allowed rounded-e-none border-e-0 opacity-64 before:rounded-e-none"
499 size="xs"
500 variant="outline"
501 />
502 }
503 >
504 <GitQuickActionIcon quickAction={quickAction} />
505 <span className="ml-0.5">{quickAction.label}</span>
506 </PopoverTrigger>
507 <PopoverPopup tooltipStyle side="bottom" align="start">
508 {quickActionDisabledReason}
509 </PopoverPopup>
510 </Popover>
511 ) : (
512 <Button
513 variant="outline"
514 size="xs"
515 disabled={isGitActionRunning || quickAction.disabled}
516 onClick={runQuickAction}
517 >
518 <GitQuickActionIcon quickAction={quickAction} />
519 <span className="ml-0.5">{quickAction.label}</span>
520 </Button>
521 )}
522 <GroupSeparator />
523 <Menu
524 onOpenChange={(open) => {
525 if (open) void invalidateGitQueries(queryClient);
526 }}
527 >
528 <MenuTrigger
529 render={<Button aria-label="Git action options" size="icon-xs" variant="outline" />}
530 disabled={isGitActionRunning}
531 >
532 <ChevronDownIcon aria-hidden="true" className="size-4" />
533 </MenuTrigger>
534 <MenuPopup align="end" className="w-full">
535 {gitActionMenuItems.map((item) => {
536 const disabledReason = getMenuActionDisabledReason(
537 item,
538 gitStatusForActions,
539 isGitActionRunning,
540 );
541 if (item.disabled && disabledReason) {
542 return (
543 <Popover key={`${item.id}-${item.label}`}>
544 <PopoverTrigger
545 openOnHover
546 nativeButton={false}
547 render={<span className="block w-max cursor-not-allowed" />}
548 >
549 <MenuItem className="w-full" disabled>
550 <GitActionItemIcon icon={item.icon} />
551 {item.label}
552 </MenuItem>
553 </PopoverTrigger>
554 <PopoverPopup tooltipStyle side="left" align="center">
555 {disabledReason}
556 </PopoverPopup>
557 </Popover>
558 );
559 }
560
561 return (
562 <MenuItem
563 key={`${item.id}-${item.label}`}
564 disabled={item.disabled}
565 onClick={() => {
566 openDialogForMenuItem(item);
567 }}
568 >
569 <GitActionItemIcon icon={item.icon} />
570 {item.label}
571 </MenuItem>
572 );
573 })}
574 {gitStatusForActions?.branch === null && (
575 <p className="px-2 py-1.5 text-xs text-warning">
576 Detached HEAD: create and checkout a branch to enable push and PR actions.
577 </p>
578 )}
579 {gitStatusForActions &&
580 gitStatusForActions.branch !== null &&
581 !gitStatusForActions.hasWorkingTreeChanges &&
582 gitStatusForActions.behindCount > 0 &&
583 gitStatusForActions.aheadCount === 0 && (
584 <p className="px-2 py-1.5 text-xs text-warning">
585 Behind upstream. Pull/rebase first.
586 </p>
587 )}
588 {isGitStatusOutOfSync && (
589 <p className="px-2 py-1.5 text-xs text-muted-foreground">
590 Refreshing git status...
591 </p>
592 )}
593 {gitStatusError && (
594 <p className="px-2 py-1.5 text-xs text-destructive">{gitStatusError.message}</p>
595 )}
596 </MenuPopup>
597 </Menu>
598 </Group>
599 )}
600
601 <Dialog
602 open={activeDialogAction !== null}
603 onOpenChange={(open) => {
604 if (!open) {
605 setActiveDialogAction(null);
606 setDialogCommitMessage("");
607 }
608 }}
609 >
610 <DialogPopup>
611 <DialogHeader>
612 <DialogTitle>{DIALOG_TITLE_BY_ACTION[activeDialogAction ?? "commit"]}</DialogTitle>
613 <DialogDescription>
614 {DIALOG_DESCRIPTION_BY_ACTION[activeDialogAction ?? "commit"]}
615 </DialogDescription>
616 </DialogHeader>
617 <DialogPanel className="space-y-4">
618 <div className="space-y-3 rounded-lg border border-input bg-muted/40 p-3 text-xs">
619 <div className="grid grid-cols-[auto_1fr] items-center gap-x-2 gap-y-1">
620 <span className="text-muted-foreground">Branch</span>
621 <span className="font-medium">
622 {gitStatusForActions?.branch ?? "(detached HEAD)"}
623 </span>
624 {activeDialogAction !== "commit" && (
625 <>
626 <span className="text-muted-foreground">Upstream</span>
627 <span className="font-medium">
628 {!gitStatusForActions || !gitStatusForActions.hasUpstream
629 ? "No upstream configured"
630 : gitStatusForActions.aheadCount === 0 &&
631 gitStatusForActions.behindCount === 0
632 ? "Up to date"
633 : gitStatusForActions.aheadCount > 0 && gitStatusForActions.behindCount > 0
634 ? `Diverged (+${gitStatusForActions.aheadCount} / -${gitStatusForActions.behindCount})`
635 : gitStatusForActions.aheadCount > 0
636 ? `Ahead by ${gitStatusForActions.aheadCount}`
637 : `Behind by ${gitStatusForActions.behindCount}`}
638 </span>
639 <span className="text-muted-foreground">Working tree</span>
640 <span className="font-medium">
641 {!gitStatusForActions || !gitStatusForActions.hasWorkingTreeChanges
642 ? "Clean"
643 : `${gitStatusForActions.workingTree.files.length} file(s)`}
644 </span>
645 <span className="text-muted-foreground">Diff</span>
646 <span className="font-mono">
647 {!gitStatusForActions || !gitStatusForActions.hasWorkingTreeChanges ? (
648 "none"
649 ) : (
650 <>
651 <span className="text-success">
652 +{gitStatusForActions.workingTree.insertions}
653 </span>
654 <span className="text-muted-foreground"> / </span>
655 <span className="text-destructive">
656 -{gitStatusForActions.workingTree.deletions}
657 </span>
658 </>
659 )}
660 </span>
661 </>
662 )}
663 </div>
664 <div className="space-y-1">
665 <p className="text-muted-foreground">Files</p>
666 {!gitStatusForActions || gitStatusForActions.workingTree.files.length === 0 ? (
667 <p className="font-medium">none</p>
668 ) : (
669 <div className="space-y-2">
670 <ScrollArea className="h-44 rounded-md border border-input bg-background">
671 <div className="space-y-1 p-1">
672 {gitStatusForActions.workingTree.files.map((file) => (
673 <button
674 type="button"
675 key={file.path}
676 className="flex w-full items-center justify-between gap-3 rounded-md px-2 py-1 font-mono text-left transition-colors hover:bg-accent/50"
677 onClick={() => openChangedFileInEditor(file.path)}
678 >
679 <span className="truncate">{file.path}</span>
680 <span className="shrink-0">
681 <span className="text-success">+{file.insertions}</span>
682 <span className="text-muted-foreground"> / </span>
683 <span className="text-destructive">-{file.deletions}</span>
684 </span>
685 </button>
686 ))}
687 </div>
688 </ScrollArea>
689 <div className="flex justify-end font-mono">
690 <span className="text-success">
691 +{gitStatusForActions.workingTree.insertions}
692 </span>
693 <span className="text-muted-foreground"> / </span>
694 <span className="text-destructive">
695 -{gitStatusForActions.workingTree.deletions}
696 </span>
697 </div>
698 </div>
699 )}
700 </div>
701 </div>
702 {activeDialogAction === "commit" && (
703 <div className="space-y-1">
704 <p className="text-xs font-medium">Commit message (optional)</p>
705 <Textarea
706 value={dialogCommitMessage}
707 onChange={(event) => setDialogCommitMessage(event.target.value)}
708 placeholder="Leave empty to auto-generate"
709 size="sm"
710 />
711 </div>
712 )}
713 </DialogPanel>
714 <DialogFooter>
715 <Button
716 variant="outline"
717 size="sm"
718 onClick={() => {
719 setActiveDialogAction(null);
720 setDialogCommitMessage("");
721 }}
722 >
723 Cancel
724 </Button>
725 <Button size="sm" onClick={runDialogAction}>
726 {activeDialogAction === "commit"
727 ? "Commit"
728 : activeDialogAction === "push"
729 ? "Push"
730 : "Create PR"}
731 </Button>
732 </DialogFooter>
733 </DialogPopup>
734 </Dialog>
735 </>
736 );
737}