The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { Button } from "../../components/ui/Button"; |
| 2 | import type { |
| 3 | ProviderApprovalDecision, |
| 4 | ProviderApprovalOption, |
| 5 | RuntimeRequestId, |
| 6 | } from "@t3tools/contracts"; |
| 7 | import { |
| 8 | FULL_ACCESS_OVERRIDE_QUESTION, |
| 9 | fullAccessOverrideExplanation, |
| 10 | } from "@t3tools/client-runtime/state/thread-requests"; |
| 11 | import { T, useGT, useMessages } from "gt-react-native"; |
| 12 | import { useState } from "react"; |
| 13 | import { Pressable, View } from "react-native"; |
| 14 | |
| 15 | import { AppText as Text } from "../../components/ui/AppText"; |
| 16 | import type { PendingApproval } from "../../lib/threadActivity"; |
| 17 | |
| 18 | export interface PendingApprovalCardProps { |
| 19 | readonly canOperateThread: boolean; |
| 20 | readonly approval: PendingApproval; |
| 21 | readonly respondingApprovalId: RuntimeRequestId | null; |
| 22 | readonly onRespond: ( |
| 23 | requestId: RuntimeRequestId, |
| 24 | decision: ProviderApprovalDecision, |
| 25 | ) => Promise<unknown>; |
| 26 | } |
| 27 | |
| 28 | export function PendingApprovalCard(props: PendingApprovalCardProps) { |
| 29 | const gt = useGT(); |
| 30 | const m = useMessages(); |
| 31 | const options: ReadonlyArray<ProviderApprovalOption> = props.approval.options ?? [ |
| 32 | { decision: "accept", label: gt("Allow once") }, |
| 33 | { decision: "acceptForSession", label: gt("Allow session") }, |
| 34 | { |
| 35 | decision: "decline", |
| 36 | label: gt("Decline", { $context: "verb, rejects the approval request" }), |
| 37 | }, |
| 38 | ]; |
| 39 | const warning = options.find((option) => option.warning)?.warning; |
| 40 | const canRespond = props.approval.responseCapability === "live"; |
| 41 | const disabled = !canRespond || props.respondingApprovalId === props.approval.requestId; |
| 42 | const [explanationOpen, setExplanationOpen] = useState(false); |
| 43 | return ( |
| 44 | <View className="gap-2.5 rounded-[20px] border border-border bg-card-alt p-4"> |
| 45 | <Text className="font-t3-bold text-2xs uppercase tracking-[1.1px] text-foreground-secondary"> |
| 46 | <T>Approval needed</T> |
| 47 | </Text> |
| 48 | <Text className="font-t3-bold text-lg text-foreground"> |
| 49 | {props.approval.appName ?? props.approval.requestKind} |
| 50 | </Text> |
| 51 | {props.approval.detail ? ( |
| 52 | <Text className="font-sans text-sm leading-normal text-foreground-secondary"> |
| 53 | {props.approval.detail} |
| 54 | </Text> |
| 55 | ) : null} |
| 56 | {props.approval.reason ? ( |
| 57 | <Text className="font-sans text-xs leading-normal text-warning-foreground"> |
| 58 | {props.approval.reason} |
| 59 | </Text> |
| 60 | ) : null} |
| 61 | {props.approval.fullAccessOverride ? ( |
| 62 | <Pressable |
| 63 | accessibilityRole="button" |
| 64 | accessibilityState={{ expanded: explanationOpen }} |
| 65 | onPress={() => setExplanationOpen((open) => !open)} |
| 66 | > |
| 67 | <Text className="font-t3-bold text-xs text-foreground-secondary underline"> |
| 68 | {m(FULL_ACCESS_OVERRIDE_QUESTION)} |
| 69 | </Text> |
| 70 | {explanationOpen ? ( |
| 71 | <Text className="mt-1 font-sans text-xs leading-normal text-foreground-muted"> |
| 72 | {fullAccessOverrideExplanation(props.approval.fullAccessOverride, m)} |
| 73 | </Text> |
| 74 | ) : null} |
| 75 | </Pressable> |
| 76 | ) : null} |
| 77 | {!canRespond ? ( |
| 78 | <Text className="font-sans text-sm leading-5 text-foreground-muted"> |
| 79 | <T> |
| 80 | The provider process for this request is no longer available. Interrupt or restart the |
| 81 | run to continue. |
| 82 | </T> |
| 83 | </Text> |
| 84 | ) : null} |
| 85 | {warning ? ( |
| 86 | <Text className="font-sans text-xs leading-normal text-warning-foreground">{warning}</Text> |
| 87 | ) : null} |
| 88 | <View className="gap-2"> |
| 89 | {options.map((option) => ( |
| 90 | <Button |
| 91 | key={option.decision} |
| 92 | label={option.label} |
| 93 | tone={ |
| 94 | option.decision === "accept" |
| 95 | ? "primary" |
| 96 | : option.decision === "decline" |
| 97 | ? "danger" |
| 98 | : "secondary" |
| 99 | } |
| 100 | disabled={disabled || !props.canOperateThread} |
| 101 | onPress={() => void props.onRespond(props.approval.requestId, option.decision)} |
| 102 | fullWidth |
| 103 | /> |
| 104 | ))} |
| 105 | </View> |
| 106 | {!props.canOperateThread ? ( |
| 107 | <Text className="font-sans text-xs text-foreground-muted"> |
| 108 | <T>This connection cannot respond to approvals.</T> |
| 109 | </Text> |
| 110 | ) : null} |
| 111 | </View> |
| 112 | ); |
| 113 | } |