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

PendingApprovalCard.tsx

68 lines2.5 KB

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