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

PendingApprovalCard.tsx

80 lines3.0 KB

1import { RequestActionButton } from "./RequestActionButton";
2import type {
3 ProviderApprovalDecision,
4 ProviderApprovalOption,
5 RuntimeRequestId,
6} from "@t3tools/contracts";
7import { View } from "react-native";
8​
9import { AppText as Text } from "../../components/ui/AppText";
10import type { PendingApproval } from "../../lib/threadActivity";
11​
12export interface PendingApprovalCardProps {
13 readonly canOperateThread: boolean;
14 readonly approval: PendingApproval;
15 readonly respondingApprovalId: RuntimeRequestId | null;
16 readonly onRespond: (
17 requestId: RuntimeRequestId,
18 decision: ProviderApprovalDecision,
19 ) => Promise<unknown>;
21​
22const DEFAULT_APPROVAL_OPTIONS: ReadonlyArray<ProviderApprovalOption> = [
23 { decision: "accept", label: "Allow once" },
24 { decision: "acceptForSession", label: "Allow session" },
25 { decision: "decline", label: "Decline" },
26];
27​
28export function PendingApprovalCard(props: PendingApprovalCardProps) {
29 const options: ReadonlyArray<ProviderApprovalOption> =
30 props.approval.options ?? DEFAULT_APPROVAL_OPTIONS;
31 const warning = options.find((option) => option.warning)?.warning;
32 const canRespond = props.approval.responseCapability === "live";
33 const disabled = !canRespond || props.respondingApprovalId === props.approval.requestId;
34 return (
35 <View className="gap-2.5 rounded-[20px] border border-border bg-card-alt p-4">
36 <Text className="font-t3-bold text-2xs uppercase tracking-[1.1px] text-foreground-secondary">
37 Approval needed
38 </Text>
39 <Text className="font-t3-bold text-lg text-foreground">
40 {props.approval.appName ?? props.approval.requestKind}
41 </Text>
42 {props.approval.detail ? (
43 <Text className="font-sans text-sm leading-normal text-foreground-secondary">
44 {props.approval.detail}
45 </Text>
46 ) : null}
47 {!canRespond ? (
48 <Text className="font-sans text-sm leading-5 text-foreground-muted">
49 The provider process for this request is no longer available. Interrupt or restart the run
50 to continue.
51 </Text>
52 ) : null}
53 {warning ? (
54 <Text className="font-sans text-xs leading-normal text-warning-foreground">{warning}</Text>
55 ) : null}
56 <View className="flex-row flex-wrap gap-2.5">
57 {options.map((option) => (
58 <RequestActionButton
59 key={option.decision}
60 label={option.label}
61 tone={
62 option.decision === "accept"
63 ? "primary"
64 : option.decision === "decline"
65 ? "danger"
66 : "secondary"
67 }
68 disabled={disabled || !props.canOperateThread}
69 onPress={() => void props.onRespond(props.approval.requestId, option.decision)}
70 />
71 ))}
72 </View>
73 {!props.canOperateThread ? (
74 <Text className="font-sans text-xs text-foreground-muted">
75 This connection cannot respond to approvals.
76 </Text>
77 ) : null}
78 </View>
79 );