Skip to content

Commit 2e4424a

Browse files
committed
fix(web): mark destructive confirmations
1 parent 903c246 commit 2e4424a

15 files changed

Lines changed: 68 additions & 17 deletions

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4745,6 +4745,7 @@ function ChatViewContent(props: ChatViewProps) {
47454745
"This will discard newer messages and turn diffs in this thread.",
47464746
"This action cannot be undone.",
47474747
].join("\n"),
4748+
{ variant: "destructive" },
47484749
);
47494750
if (!confirmed) {
47504751
return;

‎apps/web/src/components/ConfirmDialogHost.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export function ConfirmDialogHost() {
6161
useEffect(() => registerConfirmDialogHost(), []);
6262

6363
const copy = resolveConfirmDialogCopy(state.status === "idle" ? "" : state.message);
64+
const confirmVariant = state.status === "idle" ? "default" : state.variant;
6465
const onCancel = () => respondToConfirmDialog(false);
6566
const onConfirm = () => respondToConfirmDialog(true);
6667

@@ -85,7 +86,9 @@ export function ConfirmDialogHost() {
8586
</AlertDialogHeader>
8687
<AlertDialogFooter>
8788
<AlertDialogClose render={<Button variant="outline" />}>Cancel</AlertDialogClose>
88-
<Button onClick={onConfirm}>Confirm</Button>
89+
<Button variant={confirmVariant} onClick={onConfirm}>
90+
Confirm
91+
</Button>
8992
</AlertDialogFooter>
9093
</AlertDialogPopup>
9194
</AlertDialog>

‎apps/web/src/components/LegacySidebar.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,7 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
14991499
: []),
15001500
"This removes only this project entry.",
15011501
].join("\n"),
1502+
{ variant: "destructive" },
15021503
);
15031504
if (!confirmed) {
15041505
return;
@@ -1547,7 +1548,7 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
15471548
...(member.environmentLabel ? [`Environment: ${member.environmentLabel}`] : []),
15481549
"This removes only this project entry.",
15491550
].join("\n");
1550-
const confirmed = await api.dialogs.confirm(message);
1551+
const confirmed = await api.dialogs.confirm(message, { variant: "destructive" });
15511552
if (!confirmed) {
15521553
return;
15531554
}
@@ -1830,6 +1831,7 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
18301831
`Delete ${count} thread${count === 1 ? "" : "s"}?`,
18311832
"This permanently clears conversation history for these threads.",
18321833
].join("\n"),
1834+
{ variant: "destructive" },
18331835
);
18341836
if (!confirmed) return;
18351837
}
@@ -2180,6 +2182,7 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
21802182
`Delete thread "${thread.title}"?`,
21812183
"This permanently clears conversation history for this thread.",
21822184
].join("\n"),
2185+
{ variant: "destructive" },
21832186
);
21842187
if (!confirmed) {
21852188
return;

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2808,6 +2808,7 @@ export default function Sidebar() {
28082808
`Delete ${count} thread${count === 1 ? "" : "s"}?`,
28092809
"This permanently clears conversation history for these threads.",
28102810
].join("\n"),
2811+
{ variant: "destructive" },
28112812
),
28122813
);
28132814
if (confirmed._tag === "Failure" || !confirmed.value) return;
@@ -3010,6 +3011,7 @@ export default function Sidebar() {
30103011
`Delete thread "${thread.title}"?`,
30113012
"This permanently clears conversation history for this thread.",
30123013
].join("\n"),
3014+
{ variant: "destructive" },
30133015
),
30143016
);
30153017
if (confirmed._tag === "Failure" || !confirmed.value) return;

‎apps/web/src/components/settings/DiagnosticsSettings.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,7 @@ export function DiagnosticsSettingsPanel() {
914914
try {
915915
confirmed = await ensureLocalApi().dialogs.confirm(
916916
`Send SIGKILL to process ${pid}? This cannot be handled by the process.`,
917+
{ variant: "destructive" },
917918
);
918919
} catch (error) {
919920
clearSignaling();

‎apps/web/src/components/settings/ProjectSettingsPanel.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ function ProjectDetail({
657657
: "Other entries in this grouped project are unaffected.",
658658
"This action cannot be undone.",
659659
].join("\n"),
660+
{ variant: "destructive" },
660661
),
661662
);
662663
if (confirmed._tag === "Failure" || !confirmed.value) return;

‎apps/web/src/components/settings/ResourceTelemetryDiagnostics.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,7 @@ export function ResourceTelemetryDiagnostics() {
873873
try {
874874
confirmed = await ensureLocalApi().dialogs.confirm(
875875
`Send SIGKILL to process ${process.identity.pid}? This cannot be handled by the process.`,
876+
{ variant: "destructive" },
876877
);
877878
} catch (error) {
878879
clearSignaling();

‎apps/web/src/components/settings/SettingsPanels.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ export function useSettingsRestore(onRestored?: () => void) {
571571
["Restore default settings?", `This will reset: ${changedSettingLabels.join(", ")}.`].join(
572572
"\n",
573573
),
574+
{ variant: "destructive" },
574575
);
575576
if (!confirmed) return;
576577

‎apps/web/src/confirmDialog.test.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,22 @@ describe("confirm dialog coordinator", () => {
2828

2929
it("resolves a displayed confirmation and waits for its close transition", async () => {
3030
const unregister = registerConfirmDialogHost();
31-
const confirmation = requireConfirmation(requestConfirmDialog("Delete this thread?"));
31+
const confirmation = requireConfirmation(
32+
requestConfirmDialog("Delete this thread?", { variant: "destructive" }),
33+
);
3234

3335
expect(readConfirmDialogState()).toEqual({
3436
status: "confirming",
3537
message: "Delete this thread?",
38+
variant: "destructive",
3639
});
3740

3841
respondToConfirmDialog(true);
3942
await expect(confirmation).resolves.toBe(true);
4043
expect(readConfirmDialogState()).toEqual({
4144
status: "closing",
4245
message: "Delete this thread?",
46+
variant: "destructive",
4347
});
4448

4549
completeConfirmDialogClose();
@@ -57,12 +61,14 @@ describe("confirm dialog coordinator", () => {
5761
expect(readConfirmDialogState()).toEqual({
5862
status: "closing",
5963
message: "Delete the project?",
64+
variant: "default",
6065
});
6166

6267
completeConfirmDialogClose();
6368
expect(readConfirmDialogState()).toEqual({
6469
status: "confirming",
6570
message: "Delete the worktree too?",
71+
variant: "default",
6672
});
6773

6874
respondToConfirmDialog(true);

‎apps/web/src/confirmDialog.ts‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1+
import type { ConfirmDialogOptions, ConfirmDialogVariant } from "@t3tools/contracts";
2+
13
export type ConfirmDialogState =
24
| { readonly status: "idle" }
3-
| { readonly status: "confirming"; readonly message: string }
4-
| { readonly status: "closing"; readonly message: string };
5+
| {
6+
readonly status: "confirming";
7+
readonly message: string;
8+
readonly variant: ConfirmDialogVariant;
9+
}
10+
| {
11+
readonly status: "closing";
12+
readonly message: string;
13+
readonly variant: ConfirmDialogVariant;
14+
};
515

616
type PendingConfirmation = {
717
readonly message: string;
18+
readonly variant: ConfirmDialogVariant;
819
readonly resolve: (confirmed: boolean) => void;
920
};
1021

@@ -66,18 +77,25 @@ export function registerConfirmDialogHost(): () => void {
6677
* Requests a themed confirmation when a host is mounted. An undefined result
6778
* means no themed host is currently available.
6879
*/
69-
export function requestConfirmDialog(message: string): Promise<boolean> | undefined {
80+
export function requestConfirmDialog(
81+
message: string,
82+
options?: ConfirmDialogOptions,
83+
): Promise<boolean> | undefined {
7084
if (registeredHostCount === 0) return undefined;
7185

7286
const confirmation = new Promise<boolean>((resolve) => {
73-
const pending = { message, resolve } satisfies PendingConfirmation;
87+
const pending = {
88+
message,
89+
variant: options?.variant ?? "default",
90+
resolve,
91+
} satisfies PendingConfirmation;
7492
if (activeConfirmation || state.status === "closing") {
7593
queuedConfirmations.push(pending);
7694
return;
7795
}
7896

7997
activeConfirmation = pending;
80-
publish({ status: "confirming", message });
98+
publish({ status: "confirming", message, variant: pending.variant });
8199
});
82100

83101
return confirmation;
@@ -89,7 +107,7 @@ export function respondToConfirmDialog(confirmed: boolean): void {
89107
const confirmation = activeConfirmation;
90108
activeConfirmation = null;
91109
confirmation.resolve(confirmed);
92-
publish({ status: "closing", message: state.message });
110+
publish({ status: "closing", message: state.message, variant: state.variant });
93111
}
94112

95113
export function completeConfirmDialogClose(): void {
@@ -102,7 +120,7 @@ export function completeConfirmDialogClose(): void {
102120
}
103121

104122
activeConfirmation = next;
105-
publish({ status: "confirming", message: next.message });
123+
publish({ status: "confirming", message: next.message, variant: next.variant });
106124
}
107125

108126
export function resetConfirmDialogForTests(): void {

0 commit comments

Comments
 (0)