The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { T } from "gt-react"; |
| 2 | import { useState } from "react"; |
| 3 | |
| 4 | import { |
| 5 | AlertDialog, |
| 6 | AlertDialogClose, |
| 7 | AlertDialogDescription, |
| 8 | AlertDialogFooter, |
| 9 | AlertDialogHeader, |
| 10 | AlertDialogPopup, |
| 11 | AlertDialogTitle, |
| 12 | } from "../ui/alert-dialog"; |
| 13 | import { Button } from "../ui/button"; |
| 14 | import { Checkbox } from "../ui/checkbox"; |
| 15 | import { Spinner } from "../ui/spinner"; |
| 16 | |
| 17 | export interface ConnectDeviceRevokeRequest { |
| 18 | readonly title: string; |
| 19 | /** Revokes the device; resolves once the attempt finished, failed or not. */ |
| 20 | readonly revoke: () => Promise<void>; |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * With approval off, a revoked T3 Connect device signs straight back in, so revoking offers to |
| 25 | * turn approval on first. |
| 26 | */ |
| 27 | export function RevokeConnectDeviceDialog({ |
| 28 | request, |
| 29 | onClose, |
| 30 | requireApproval, |
| 31 | }: { |
| 32 | readonly request: ConnectDeviceRevokeRequest | null; |
| 33 | readonly onClose: () => void; |
| 34 | /** Saves the setting; resolves false when the save failed. */ |
| 35 | readonly requireApproval: () => Promise<boolean>; |
| 36 | }) { |
| 37 | return ( |
| 38 | <AlertDialog |
| 39 | open={request !== null} |
| 40 | onOpenChange={(open) => { |
| 41 | if (!open) onClose(); |
| 42 | }} |
| 43 | > |
| 44 | {request ? ( |
| 45 | <RevokeConnectDeviceDialogPopup |
| 46 | key={request.title} |
| 47 | request={request} |
| 48 | onClose={onClose} |
| 49 | requireApproval={requireApproval} |
| 50 | /> |
| 51 | ) : null} |
| 52 | </AlertDialog> |
| 53 | ); |
| 54 | } |
| 55 | |
| 56 | function RevokeConnectDeviceDialogPopup({ |
| 57 | request, |
| 58 | onClose, |
| 59 | requireApproval, |
| 60 | }: { |
| 61 | readonly request: ConnectDeviceRevokeRequest; |
| 62 | readonly onClose: () => void; |
| 63 | readonly requireApproval: () => Promise<boolean>; |
| 64 | }) { |
| 65 | const [turnOnApproval, setTurnOnApproval] = useState(true); |
| 66 | const [busy, setBusy] = useState(false); |
| 67 | |
| 68 | const confirm = async () => { |
| 69 | setBusy(true); |
| 70 | if (turnOnApproval && !(await requireApproval())) { |
| 71 | setBusy(false); |
| 72 | return; |
| 73 | } |
| 74 | await request.revoke(); |
| 75 | setBusy(false); |
| 76 | onClose(); |
| 77 | }; |
| 78 | |
| 79 | return ( |
| 80 | <AlertDialogPopup> |
| 81 | <AlertDialogHeader> |
| 82 | <AlertDialogTitle>{request.title}</AlertDialogTitle> |
| 83 | <AlertDialogDescription> |
| 84 | <T> |
| 85 | Approval for new devices is off, so a revoked device signed in to your T3 Connect |
| 86 | account can connect again on its own. |
| 87 | </T> |
| 88 | </AlertDialogDescription> |
| 89 | <label className="mt-2 flex cursor-pointer items-start gap-3"> |
| 90 | <Checkbox |
| 91 | className="mt-0.5" |
| 92 | checked={turnOnApproval} |
| 93 | disabled={busy} |
| 94 | onCheckedChange={(checked) => setTurnOnApproval(checked === true)} |
| 95 | /> |
| 96 | <span className="min-w-0"> |
| 97 | <span className="block text-sm font-medium text-foreground"> |
| 98 | <T>Require approval for new devices</T> |
| 99 | </span> |
| 100 | <span className="block text-xs text-muted-foreground"> |
| 101 | <T>The device has to be approved here before it can connect again.</T> |
| 102 | </span> |
| 103 | </span> |
| 104 | </label> |
| 105 | </AlertDialogHeader> |
| 106 | <AlertDialogFooter> |
| 107 | <AlertDialogClose disabled={busy} render={<Button variant="outline" disabled={busy} />}> |
| 108 | <T>Cancel</T> |
| 109 | </AlertDialogClose> |
| 110 | <Button variant="destructive" disabled={busy} onClick={() => void confirm()}> |
| 111 | {busy && <Spinner size="sm" />} |
| 112 | <T>Revoke</T> |
| 113 | </Button> |
| 114 | </AlertDialogFooter> |
| 115 | </AlertDialogPopup> |
| 116 | ); |
| 117 | } |