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
|
import { Ionicons } from "@expo/vector-icons";
import { useEffect, useState } from "react";
import { ActivityIndicator, Text, View } from "react-native";
import { Alert, getAlerts } from "../../api";
import { t } from "../../lib/locales";
import { colors } from "../../lib/theme";
import { Card, Divider, H2, Muted, Pill, Row, Screen } from "../../lib/ui";
export default function AlertsScreen() {
const [alerts, setAlerts] = useState<Alert[]>([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
console.log("AlertsScreen: Fetching alerts...");
setLoading(true);
getAlerts()
.then((data) => {
console.log("AlertsScreen: Received alerts:", data);
setAlerts(data);
})
.catch((error) => {
console.error("AlertsScreen: Error fetching alerts:", error);
})
.finally(() => {
setLoading(false);
});
}, []);
return (
<Screen>
{loading ? (
<View style={{ padding: 20, alignItems: "center" }}>
<ActivityIndicator size="large" color={colors.primary} />
<Text style={{ color: colors.onSurfaceVariant, marginTop: 10 }}>
{t("loadingAlerts")}
</Text>
</View>
) : alerts.length === 0 ? (
<Card>
<View style={{ alignItems: "center", padding: 20 }}>
<Ionicons
name="checkmark-circle"
size={48}
color={colors.onSurfaceVariant}
/>
<H2>{t("allClearTitle")}</H2>
<Muted style={{ textAlign: "center", marginTop: 5 }}>
{t("noAlertsToReview")}
</Muted>
</View>
</Card>
) : (
alerts.map((alert) => (
<Card key={alert.id}>
<Row
left={
<View
style={{
flexDirection: "row",
alignItems: "center",
gap: 10,
}}
>
<Ionicons
name={
alert.severity === "needs_attention"
? "alert-circle"
: "information-circle"
}
size={18}
color={
alert.severity === "needs_attention"
? colors.primary
: colors.onSurfaceVariant
}
/>
<View style={{ flex: 1 }}>
<H2>{alert.title}</H2>
<Muted>{alert.timeLabel}</Muted>
</View>
</View>
}
right={
<Pill
label={
alert.severity === "needs_attention"
? t("reviewPill")
: t("fyiPill")
}
tone={
alert.severity === "needs_attention"
? "attention"
: "neutral"
}
/>
}
/>
<Divider />
<H2>{t("whatHappened")}</H2>
<Muted>{alert.whatHappened}</Muted>
<H2>{t("whyItMatters")}</H2>
<Muted>{alert.whyItMatters}</Muted>
<H2>{t("suggestedNextStep")}</H2>
<Muted>{alert.suggestedAction}</Muted>
</Card>
))
)}
</Screen>
);
}
|