Open History to see the last commit
1import type {
2 ApprovalRequestId,
3 ProviderApprovalDecision,
4 ProviderApprovalOption,
5} from "@t3tools/contracts";
6import { Pressable, View } from "react-native";
7
8import { AppText as Text } from "../../components/AppText";
9import type { PendingApproval } from "../../lib/threadActivity";
10
11export interface PendingApprovalCardProps {
12 readonly approval: PendingApproval;
13 readonly respondingApprovalId: ApprovalRequestId | null;
14 readonly onRespond: (
15 requestId: ApprovalRequestId,
16 decision: ProviderApprovalDecision,
17 ) => Promise<unknown>;
18}
19
20const DEFAULT_APPROVAL_OPTIONS: ReadonlyArray<ProviderApprovalOption> = [
21 { decision: "accept", label: "Allow once" },
22 { decision: "acceptForSession", label: "Allow session" },
23 { decision: "decline", label: "Decline" },
24];
25
26export function PendingApprovalCard(props: PendingApprovalCardProps) {
27 const options: ReadonlyArray<ProviderApprovalOption> =
28 props.approval.options ?? DEFAULT_APPROVAL_OPTIONS;
29 const warning = options.find((option) => option.warning)?.warning;
30 // Opaque for the same reason as PendingUserInputCard: nothing blurs the feed
31 // behind this card, so a translucent surface bleeds messages through it.
32 return (
33 <View className="gap-2.5 rounded-[20px] border border-border bg-card-alt p-4">
34 <Text className="font-t3-bold text-2xs uppercase tracking-[1.1px] text-foreground-secondary">
35 Approval needed
36 </Text>
37 <Text className="font-t3-bold text-lg text-foreground">
38 {props.approval.appName ?? props.approval.requestKind}
39 </Text>
40 {props.approval.detail ? (
41 <Text className="font-sans text-sm leading-normal text-foreground-secondary">
42 {props.approval.detail}
43 </Text>
44 ) : null}
45 {warning ? (
46 <Text className="font-sans text-xs leading-normal text-warning-foreground">{warning}</Text>
47 ) : null}
48 <View className="flex-row flex-wrap gap-2.5">
49 {options.map((option) => (
50 <Pressable
51 key={option.decision}
52 className={`items-center justify-center rounded-[14px] px-3.5 py-3 ${
53 option.decision === "accept"
54 ? "bg-primary"
55 : option.decision === "decline"
56 ? "bg-danger"
57 : "bg-subtle-strong"
58 }`}
59 disabled={props.respondingApprovalId === props.approval.requestId}
60 onPress={() => void props.onRespond(props.approval.requestId, option.decision)}
61 >
62 <Text
63 className={`text-sm ${
64 option.decision === "accept"
65 ? "font-t3-extrabold text-primary-foreground"
66 : option.decision === "decline"
67 ? "font-t3-bold text-danger-foreground"
68 : "font-t3-bold text-foreground"
69 }`}
70 >
71 {option.label}
72 </Text>
73 </Pressable>
74 ))}
75 </View>
76 </View>
77 );
78}