The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import type { RelayClientDeviceRecord } from "@t3tools/contracts/relay"; |
| 2 | import { T, useGT, useMessages } from "gt-react"; |
| 3 | import { SmartphoneIcon } from "lucide-react"; |
| 4 | |
| 5 | import { useManagedRelayDevices } from "../../cloud/managedRelayState"; |
| 6 | import { Badge } from "../ui/badge"; |
| 7 | import { Button } from "../ui/button"; |
| 8 | import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from "../ui/empty"; |
| 9 | import { Skeleton } from "../ui/skeleton"; |
| 10 | import { |
| 11 | mobileClientNotificationDetail, |
| 12 | mobileClientPlatformLabel, |
| 13 | mobileClientUpdatedAtLabel, |
| 14 | } from "./MobileClientsUserProfilePage.logic"; |
| 15 | import { |
| 16 | ClerkUserProfilePage, |
| 17 | ClerkUserProfileRefreshButton, |
| 18 | ClerkUserProfileRow, |
| 19 | } from "./ClerkUserProfilePage"; |
| 20 | |
| 21 | const MOBILE_CLIENT_SKELETON_ROWS = ["primary", "secondary"] as const; |
| 22 | |
| 23 | function MobileClientStatusBadge({ |
| 24 | enabled, |
| 25 | label, |
| 26 | }: { |
| 27 | readonly enabled: boolean; |
| 28 | readonly label: string; |
| 29 | }) { |
| 30 | const gt = useGT(); |
| 31 | return ( |
| 32 | <Badge variant={enabled ? "success" : "outline"}> |
| 33 | {enabled |
| 34 | ? gt("{label}: On", { label, $context: "a setting is on" }) |
| 35 | : gt("{label}: Off", { label, $context: "a setting is off" })} |
| 36 | </Badge> |
| 37 | ); |
| 38 | } |
| 39 | |
| 40 | function MobileClientRow({ device }: { readonly device: RelayClientDeviceRecord }) { |
| 41 | const gt = useGT(); |
| 42 | const m = useMessages(); |
| 43 | return ( |
| 44 | <ClerkUserProfileRow icon={<SmartphoneIcon className="size-4" />}> |
| 45 | <div className="flex flex-col gap-0.5 sm:flex-row sm:items-start sm:justify-between sm:gap-3"> |
| 46 | <div className="min-w-0"> |
| 47 | <h3 className="truncate text-sm leading-4.5 font-medium text-foreground"> |
| 48 | {device.label} |
| 49 | </h3> |
| 50 | <p className="text-xs leading-4.5 text-muted-foreground"> |
| 51 | {mobileClientPlatformLabel(device)} |
| 52 | </p> |
| 53 | </div> |
| 54 | <p className="shrink-0 text-2xs leading-4 text-muted-foreground/75"> |
| 55 | {mobileClientUpdatedAtLabel(device.updatedAt, m)} |
| 56 | </p> |
| 57 | </div> |
| 58 | <div className="mt-2 flex flex-wrap gap-1.5"> |
| 59 | <MobileClientStatusBadge |
| 60 | enabled={device.notifications.enabled} |
| 61 | label={gt("Push notifications")} |
| 62 | /> |
| 63 | <MobileClientStatusBadge |
| 64 | enabled={device.liveActivities.enabled} |
| 65 | label={gt("Live Activities")} |
| 66 | /> |
| 67 | </div> |
| 68 | <p className="mt-1.5 text-xs leading-4.5 text-muted-foreground/80"> |
| 69 | {mobileClientNotificationDetail(device, m)} |
| 70 | </p> |
| 71 | </ClerkUserProfileRow> |
| 72 | ); |
| 73 | } |
| 74 | |
| 75 | function MobileClientsSkeleton() { |
| 76 | const gt = useGT(); |
| 77 | return ( |
| 78 | <div aria-label={gt("Loading mobile clients")} className="divide-y border-t" role="status"> |
| 79 | {MOBILE_CLIENT_SKELETON_ROWS.map((row) => ( |
| 80 | <div key={row} className="py-4"> |
| 81 | <div className="flex gap-3"> |
| 82 | <Skeleton shape="card" className="size-8 shrink-0" /> |
| 83 | <div className="flex-1 space-y-2"> |
| 84 | <Skeleton className="h-3.5 w-36" /> |
| 85 | <Skeleton className="h-3 w-28" /> |
| 86 | <div className="flex gap-2"> |
| 87 | <Skeleton className="h-4.5 w-28" /> |
| 88 | <Skeleton className="h-4.5 w-24" /> |
| 89 | </div> |
| 90 | </div> |
| 91 | </div> |
| 92 | </div> |
| 93 | ))} |
| 94 | </div> |
| 95 | ); |
| 96 | } |
| 97 | |
| 98 | function EmptyMobileClients() { |
| 99 | return ( |
| 100 | <Empty size="compact"> |
| 101 | <EmptyMedia variant="icon"> |
| 102 | <SmartphoneIcon /> |
| 103 | </EmptyMedia> |
| 104 | <EmptyHeader> |
| 105 | <EmptyTitle> |
| 106 | <T>No mobile clients</T> |
| 107 | </EmptyTitle> |
| 108 | <EmptyDescription> |
| 109 | <T> |
| 110 | Install T3 Code on your phone and sign in to T3 Connect to get push notifications and |
| 111 | Live Activities. |
| 112 | </T> |
| 113 | </EmptyDescription> |
| 114 | </EmptyHeader> |
| 115 | </Empty> |
| 116 | ); |
| 117 | } |
| 118 | |
| 119 | export function MobileClientsUserProfilePage() { |
| 120 | const devicesState = useManagedRelayDevices(); |
| 121 | const gt = useGT(); |
| 122 | const devices = devicesState.data ?? []; |
| 123 | const isInitialLoad = |
| 124 | !devicesState.accountId || (devicesState.data === null && !devicesState.error); |
| 125 | const hasErrorWithoutData = devicesState.error !== null && devicesState.data === null; |
| 126 | |
| 127 | return ( |
| 128 | <ClerkUserProfilePage |
| 129 | title={gt("Mobile clients")} |
| 130 | description={gt("Mobile devices that get notifications from your environments.")} |
| 131 | action={ |
| 132 | <ClerkUserProfileRefreshButton |
| 133 | isPending={devicesState.isPending} |
| 134 | onClick={devicesState.refresh} |
| 135 | /> |
| 136 | } |
| 137 | > |
| 138 | <div> |
| 139 | {devicesState.error ? ( |
| 140 | <div |
| 141 | className="mb-4 flex flex-col gap-3 border-t border-destructive/35 py-3 text-xs sm:flex-row sm:items-center sm:justify-between" |
| 142 | role="alert" |
| 143 | > |
| 144 | <div> |
| 145 | <p className="font-medium text-destructive-foreground"> |
| 146 | <T>Could not load mobile clients</T> |
| 147 | </p> |
| 148 | <p className="mt-0.5 text-xs text-muted-foreground">{devicesState.error}</p> |
| 149 | </div> |
| 150 | <Button size="xs" variant="outline" onClick={devicesState.refresh}> |
| 151 | <T>Try again</T> |
| 152 | </Button> |
| 153 | </div> |
| 154 | ) : null} |
| 155 | |
| 156 | {isInitialLoad ? ( |
| 157 | <MobileClientsSkeleton /> |
| 158 | ) : hasErrorWithoutData ? null : devices.length > 0 ? ( |
| 159 | <ul className="border-t"> |
| 160 | {devices.map((device) => ( |
| 161 | <MobileClientRow key={device.deviceId} device={device} /> |
| 162 | ))} |
| 163 | </ul> |
| 164 | ) : ( |
| 165 | <div className="border-t"> |
| 166 | <EmptyMobileClients /> |
| 167 | </div> |
| 168 | )} |
| 169 | </div> |
| 170 | </ClerkUserProfilePage> |
| 171 | ); |
| 172 | } |