Skip to content
Source
Sign inSign up
Open History to see the last commit

RemoveT3ConnectEnvironmentDialog.tsx

96 lines3.0 KB

1import { Discovery } from "@t3tools/client-runtime/relay";
2import type { EnvironmentId } from "@t3tools/contracts";
3import { useState } from "react";
4​
5import { useRelayEnvironmentDiscovery } from "../../state/environments";
6import {
7 AlertDialog,
8 AlertDialogClose,
9 AlertDialogDescription,
10 AlertDialogFooter,
11 AlertDialogHeader,
12 AlertDialogPopup,
13 AlertDialogTitle,
14} from "../ui/alert-dialog";
15import { Button, InlineButton } from "../ui/button";
16import { useT3ConnectAccountPage } from "./T3ConnectAccountPages";
17​
18export function RemoveT3ConnectEnvironmentDialog({
19 environmentLabel,
20 environmentId,
21 onCancel,
22 onConfirm,
23}: {
24 readonly environmentLabel: string | null;
25 readonly environmentId: EnvironmentId | null;
26 readonly onCancel: () => void;
27 readonly onConfirm: () => void;
28}) {
29 const accountPage = useT3ConnectAccountPage();
30 const discovery = useRelayEnvironmentDiscovery();
31 const registration = environmentId
32 ? Discovery.relayEnvironmentRegistration(discovery, environmentId)
33 : "unknown";
34 const [shown, setShown] = useState({ label: environmentLabel, registration });
35 if (
36 environmentLabel !== null &&
37 (environmentLabel !== shown.label || registration !== shown.registration)
38 ) {
39 setShown({ label: environmentLabel, registration });
40 }
41 const openAccountPage = accountPage.open;
42 const accountPageLink = openAccountPage ? (
43 <InlineButton
44 onClick={() => {
45 onCancel();
46 openAccountPage();
47 }}
48 >
49 T3 Connect settings
50 </InlineButton>
51 ) : (
52 "T3 Connect settings"
53 );
54​
55 return (
56 <>
57 <AlertDialog
58 open={environmentLabel !== null}
59 onOpenChange={(open) => {
60 if (!open) onCancel();
61 }}
62 >
63 <AlertDialogPopup>
64 <AlertDialogHeader>
65 <AlertDialogTitle>Remove {shown.label} from this device?</AlertDialogTitle>
66 <AlertDialogDescription>
67 This forgets its pairing, credentials, and cached threads here.
68 </AlertDialogDescription>
69 <AlertDialogDescription>
70 {shown.registration === "registered" ? (
71 <>
72 It stays on your T3 Connect account and keeps its host space. Deregister it in{" "}
73 {accountPageLink} to free it.
74 </>
75 ) : shown.registration === "unregistered" ? (
76 "It's no longer on your T3 Connect account."
77 ) : (
78 <>
79 This doesn't change your T3 Connect account. To deregister it there, use{" "}
80 {accountPageLink}.
81 </>
82 )}
83 </AlertDialogDescription>
84 </AlertDialogHeader>
85 <AlertDialogFooter>
86 <AlertDialogClose render={<Button variant="secondary" />}>Cancel</AlertDialogClose>
87 <Button variant="destructive" onClick={onConfirm}>
88 Remove from this device
89 </Button>
90 </AlertDialogFooter>
91 </AlertDialogPopup>
92 </AlertDialog>
93 {accountPage.portals}
94 </>
95 );