Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | 2x 5x 2x 5x 5x 5x 2x 2x 12x 12x 5x 1x 2x 2x 2x 17x | import React from "react";
import { Text, View } from "react-native";
import { StopIcon, TickCircleIcon } from "@repo/ui/icons";
import { useTheme } from "@repo/ui/themes";
import { makeStyles } from "@repo/ui/themes/makeStyles";
import { textStyles } from "@repo/ui/themes/typography";
import { Block } from "@/types/chat";
import { TableUserRow } from "./TableUserRow";
// The title is already the past-tense label for what happened ("Removed",
// "Added"), so the footer reads as one sentence with the card heading.
const formatActionedAt = (at: Date, verb: string) =>
`${verb} at ${at.toLocaleTimeString("en-US", {
hour: "2-digit",
minute: "2-digit",
})} • ${at.toLocaleDateString("en-US", {
month: "short",
day: "numeric",
year: "numeric",
})}`;
const SuccessStatus = ({ block }: { block: Block }) => {
const styles = useStyles();
const theme = useTheme();
return (
<View style={styles.successBlockContainer}>
<View style={styles.successCard}>
{!!block.title && <Text style={styles.successCardTitle}>{block.title.toUpperCase()}</Text>}
{block.data?.information && (
<View style={styles.successCardBody}>
{block.data.information.map((row, i) => (
<View key={i} style={styles.tableRow}>
<TableUserRow row={row} />
</View>
))}
</View>
)}
<View style={styles.successCardFooter}>
<Text style={styles.successCardFooterDate}>
{formatActionedAt(new Date(), block.title || "Updated")}
</Text>
</View>
</View>
<View style={styles.successMessageRow}>
<TickCircleIcon width={20} height={20} color={theme.theme.colors.green80} />
<Text style={styles.successMessageText}>
{block.description || "Action completed successfully"}
</Text>
</View>
</View>
);
};
export const StatusBlock = ({ block }: { block: Block }) => {
const styles = useStyles();
switch (block.status) {
case "success":
return <SuccessStatus block={block} />;
case "cancelled":
return (
<View style={styles.blockStatus}>
<Text style={styles.cancelledText}>
Looks like someone changed their mind. Operation was cancelled by the user
</Text>
</View>
);
case "cancel_stream":
return (
<View style={styles.blockStatus}>
<StopIcon width={24} height={24} />
<Text style={styles.cancelledText}>{block.title || "You stopped this response"}</Text>
</View>
);
case "error":
return (
<View style={styles.blockStatus}>
<Text style={styles.cancelledText}>
{block.description ||
"Sorry, something went wrong while processing your request. Please try again."}
</Text>
</View>
);
default:
return (
<View style={styles.blockStatus}>
<Text style={styles.statusText}>{block.title || "Status"}</Text>
</View>
);
}
};
const useStyles = makeStyles((theme) => ({
successBlockContainer: {
marginVertical: 0,
},
successCard: {
backgroundColor: theme.colors.background.card,
borderRadius: 12,
borderWidth: 1,
borderColor: theme.colors.border.divider,
padding: 16,
marginBottom: 8,
},
successCardTitle: {
...textStyles.content.semiBold,
fontSize: 14,
color: theme.colors.text.heading,
textTransform: "uppercase",
},
successCardBody: {
marginBottom: 4,
},
successCardFooter: {
borderTopColor: theme.colors.border.divider,
},
successCardFooterDate: {
...textStyles.content.regular,
fontSize: 13,
color: theme.colors.text.placeholder,
},
successMessageRow: {
flexDirection: "row",
alignItems: "flex-start",
gap: 8,
paddingHorizontal: 4,
},
successMessageText: {
...textStyles.content.medium,
fontSize: 14,
color: theme.colors.green80,
flex: 1,
},
tableRow: {
flexDirection: "column",
borderBottomWidth: 0,
paddingVertical: 14,
},
blockStatus: {
padding: 10,
flexDirection: "row",
alignItems: "center",
gap: 4,
borderRadius: 16,
},
cancelledText: {
...textStyles.content.regular,
fontSize: 13,
color: theme.colors.text.muted,
},
statusText: {
...textStyles.content.medium,
},
}));
|