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

PendingApprovalCard.tsx

73 lines2.8 KB

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>;
19​
20const DEFAULT_APPROVAL_OPTIONS = [
21 { decision: "accept", label: "Allow once" },
22 { decision: "acceptForSession", label: "Allow session" },
23 { decision: "decline", label: "Decline" },
24] satisfies ReadonlyArray<ProviderApprovalOption>;
25​
26export function PendingApprovalCard(props: PendingApprovalCardProps) {
27 const options = props.approval.options ?? DEFAULT_APPROVAL_OPTIONS;
28 // Opaque for the same reason as PendingUserInputCard: nothing blurs the feed
29 // behind this card, so a translucent surface bleeds messages through it.
30 return (
31 <View className="gap-2.5 rounded-[20px] border border-neutral-200 bg-neutral-100 p-4 dark:border-white/6 dark:bg-neutral-900">
32 <Text className="font-t3-bold text-2xs uppercase tracking-[1.1px] text-sky-700 dark:text-sky-300">
33 Approval needed
34 </Text>
35 <Text className="font-t3-bold text-lg text-neutral-950 dark:text-neutral-50">
36 {props.approval.appName ?? props.approval.requestKind}
37 </Text>
38 {props.approval.detail ? (
39 <Text className="font-sans text-sm leading-normal text-neutral-600 dark:text-neutral-400">
40 {props.approval.detail}
41 </Text>
42 ) : null}
43 <View className="flex-row flex-wrap gap-2.5">
44 {options.map((option) => (
45 <Pressable
46 key={option.decision}
47 className={`items-center justify-center rounded-[14px] px-3.5 py-3 ${
48 option.decision === "accept"
49 ? "bg-blue-500"
50 : option.decision === "decline"
51 ? "bg-rose-100 dark:bg-rose-500/18"
52 : "bg-neutral-200 dark:bg-neutral-800"
53 }`}
54 disabled={props.respondingApprovalId === props.approval.requestId}
55 onPress={() => void props.onRespond(props.approval.requestId, option.decision)}
56 >
57 <Text
58 className={`text-sm ${
59 option.decision === "accept"
60 ? "font-t3-extrabold text-white"
61 : option.decision === "decline"
62 ? "font-t3-bold text-rose-700 dark:text-rose-300"
63 : "font-t3-bold text-neutral-950 dark:text-neutral-50"
64 }`}
65 >
66 {option.label}
67 </Text>
68 </Pressable>
69 ))}
70 </View>
71 </View>
72 );