| 1 | import {
|
| 2 | TouchableOpacity,
|
| 3 | StyleSheet,
|
| 4 | Text,
|
| 5 | SectionList,
|
| 6 | View,
|
| 7 | Alert,
|
| 8 | Switch,
|
| 9 | Pressable,
|
| 10 | } from "react-native";
|
| 11 | import { useState } from "react";
|
| 12 | import { router } from "expo-router";
|
| 13 | import { Card } from "@/components/ui/Cards";
|
| 14 | import ScreenLayout from "@/components/ui/ScreenLayout";
|
| 15 | import { BorderRadius, Colors, Fonts, Spacing } from "@/constants/theme";
|
| 16 | import { useThemeColor } from "@/hooks/use-theme-color";
|
| 17 | import { useAuth } from "@/context/AuthContext";
|
| 18 | import { Section, SectionHeader } from "@/components/ui/Sections";
|
| 19 | import { Ionicons, MaterialIcons } from "@expo/vector-icons";
|
| 20 | import { Button } from "@/components/ui/Button";
|
| 21 |
|
| 22 | export default function Settings() {
|
| 23 | const { user, logout } = useAuth();
|
| 24 | const [allowNotifications, setAllowNotifications] = useState(false);
|
| 25 | const [allowWeeklyInsights, setAllowWeeklyInsights] = useState(false);
|
| 26 |
|
| 27 | const textColor = useThemeColor({}, "text");
|
| 28 |
|
| 29 | const handleLogout = async () => {
|
| 30 | Alert.alert("Sair", "Tem certeza que quer sair?", [
|
| 31 | { text: "Cancelar", style: "cancel" },
|
| 32 | {
|
| 33 | text: "Sair",
|
| 34 | style: "destructive",
|
| 35 | onPress: logout,
|
| 36 | },
|
| 37 | ]);
|
| 38 | };
|
| 39 |
|
| 40 | const handleProfilePress = () => {
|
| 41 | router.push("/profile");
|
| 42 | };
|
| 43 |
|
| 44 | const handleInvisibleMode = () => {};
|
| 45 |
|
| 46 | const handleDataExport = () => {
|
| 47 | Alert.alert("Exportar dados", "Deseja exportar seus dados?", [
|
| 48 | { text: "Cancelar", style: "cancel" },
|
| 49 | {
|
| 50 | text: "Exportar",
|
| 51 | style: "destructive",
|
| 52 | onPress: () => {
|
| 53 | Alert.alert(
|
| 54 | "Exportar dados",
|
| 55 | "Você receberá um e-mail com os dados exportados.",
|
| 56 | [{ text: "OK", style: "default" }],
|
| 57 | );
|
| 58 | },
|
| 59 | },
|
| 60 | ]);
|
| 61 | };
|
| 62 |
|
| 63 | return (
|
| 64 | <ScreenLayout
|
| 65 | userName={user.firstName}
|
| 66 | userAvatar={user.avatarURL}
|
| 67 | showNotificationBadge={true}
|
| 68 | >
|
| 69 | <Section>
|
| 70 | <SectionHeader title="Perfil" />
|
| 71 |
|
| 72 | <Card style={{ padding: Spacing.cardGap }} onPress={handleProfilePress}>
|
| 73 | <View
|
| 74 | style={{
|
| 75 | flexDirection: "row",
|
| 76 | alignItems: "center",
|
| 77 | justifyContent: "space-between",
|
| 78 | }}
|
| 79 | >
|
| 80 | <View
|
| 81 | style={{
|
| 82 | flexDirection: "column",
|
| 83 | alignItems: "center",
|
| 84 | justifyContent: "space-between",
|
| 85 | }}
|
| 86 | >
|
| 87 | <Text style={styles.cardTitle}>Dados Pessoais</Text>
|
| 88 | <Text style={styles.cardSubtitle}>Nome, Email e senha</Text>
|
| 89 | </View>
|
| 90 |
|
| 91 | <Ionicons name="chevron-forward" size={24} color={textColor} />
|
| 92 | </View>
|
| 93 | </Card>
|
| 94 | </Section>
|
| 95 |
|
| 96 | <Section>
|
| 97 | <SectionHeader title="Notificações" />
|
| 98 |
|
| 99 | <Card style={{ padding: Spacing.cardGap }}>
|
| 100 | <View
|
| 101 | style={{
|
| 102 | flexDirection: "row",
|
| 103 | alignItems: "center",
|
| 104 | justifyContent: "space-between",
|
| 105 | }}
|
| 106 | >
|
| 107 | <View
|
| 108 | style={[
|
| 109 | styles.cardIcon,
|
| 110 | { backgroundColor: Colors.light.accentBlue },
|
| 111 | ]}
|
| 112 | >
|
| 113 | <Ionicons
|
| 114 | name="notifications-outline"
|
| 115 | size={20}
|
| 116 | color={Colors.light.black}
|
| 117 | />
|
| 118 | </View>
|
| 119 |
|
| 120 | <View
|
| 121 | style={{
|
| 122 | flexDirection: "column",
|
| 123 | alignItems: "flex-start",
|
| 124 | justifyContent: "space-between",
|
| 125 | marginLeft: 12,
|
| 126 | flex: 1,
|
| 127 | }}
|
| 128 | >
|
| 129 | <Text style={styles.cardTitle}>Notificações</Text>
|
| 130 | <Text>Diário as 20:00</Text>
|
| 131 | </View>
|
| 132 |
|
| 133 | <Switch
|
| 134 | onValueChange={setAllowNotifications}
|
| 135 | thumbColor={Colors.light.tint}
|
| 136 | trackColor={{
|
| 137 | false: Colors.light.disabled,
|
| 138 | true: Colors.light.gray,
|
| 139 | }}
|
| 140 | value={allowNotifications}
|
| 141 | />
|
| 142 | </View>
|
| 143 |
|
| 144 | <View style={styles.divider} />
|
| 145 |
|
| 146 | <View
|
| 147 | style={{
|
| 148 | flexDirection: "row",
|
| 149 | alignItems: "center",
|
| 150 | justifyContent: "space-between",
|
| 151 | }}
|
| 152 | >
|
| 153 | <View
|
| 154 | style={[
|
| 155 | styles.cardIcon,
|
| 156 | { backgroundColor: Colors.light.accentPurple },
|
| 157 | ]}
|
| 158 | >
|
| 159 | <Ionicons name="sparkles" size={20} color={Colors.light.black} />
|
| 160 | </View>
|
| 161 |
|
| 162 | <View
|
| 163 | style={{
|
| 164 | flexDirection: "column",
|
| 165 | alignItems: "flex-start",
|
| 166 | justifyContent: "space-between",
|
| 167 | marginLeft: 12,
|
| 168 | flex: 1,
|
| 169 | }}
|
| 170 | >
|
| 171 | <Text style={styles.cardTitle}>Indicadores semanais</Text>
|
| 172 | <Text>Relatórios de progressos</Text>
|
| 173 | </View>
|
| 174 |
|
| 175 | <Switch
|
| 176 | onValueChange={setAllowWeeklyInsights}
|
| 177 | value={allowWeeklyInsights}
|
| 178 | thumbColor={Colors.light.tint}
|
| 179 | trackColor={{
|
| 180 | false: Colors.light.disabled,
|
| 181 | true: Colors.light.gray,
|
| 182 | }}
|
| 183 | />
|
| 184 | </View>
|
| 185 | </Card>
|
| 186 | </Section>
|
| 187 |
|
| 188 | <Section>
|
| 189 | <SectionHeader title="Privacidade" />
|
| 190 |
|
| 191 | <Card style={{ padding: Spacing.cardGap }}>
|
| 192 | <TouchableOpacity
|
| 193 | style={{
|
| 194 | flexDirection: "row",
|
| 195 | alignItems: "center",
|
| 196 | justifyContent: "space-between",
|
| 197 | }}
|
| 198 | onPress={handleInvisibleMode}
|
| 199 | >
|
| 200 | <View style={{ flexDirection: "row", alignItems: "center" }}>
|
| 201 | <MaterialIcons
|
| 202 | name="lock"
|
| 203 | size={24}
|
| 204 | color={Colors.light.textSecondary}
|
| 205 | />
|
| 206 |
|
| 207 | <Text
|
| 208 | style={{
|
| 209 | marginLeft: 8,
|
| 210 | color: Colors.light.text,
|
| 211 | fontSize: 14,
|
| 212 | fontWeight: "500" as const,
|
| 213 | }}
|
| 214 | >
|
| 215 | Privacidade
|
| 216 | </Text>
|
| 217 | </View>
|
| 218 |
|
| 219 | <Ionicons name="chevron-forward" size={24} color={textColor} />
|
| 220 | </TouchableOpacity>
|
| 221 |
|
| 222 | <View style={styles.divider} />
|
| 223 |
|
| 224 | <TouchableOpacity
|
| 225 | style={{
|
| 226 | flexDirection: "row",
|
| 227 | alignItems: "center",
|
| 228 | justifyContent: "space-between",
|
| 229 | }}
|
| 230 | onPress={handleDataExport}
|
| 231 | >
|
| 232 | <View style={{ flexDirection: "row", alignItems: "center" }}>
|
| 233 | <MaterialIcons
|
| 234 | name="storage"
|
| 235 | size={24}
|
| 236 | color={Colors.light.textSecondary}
|
| 237 | />
|
| 238 |
|
| 239 | <Text
|
| 240 | style={{
|
| 241 | marginLeft: 8,
|
| 242 | color: Colors.light.text,
|
| 243 | fontSize: 14,
|
| 244 | fontWeight: "500" as const,
|
| 245 | }}
|
| 246 | >
|
| 247 | Exportar Meus Dados
|
| 248 | </Text>
|
| 249 | </View>
|
| 250 |
|
| 251 | <MaterialIcons
|
| 252 | name="file-download"
|
| 253 | size={24}
|
| 254 | color={Colors.light.textSecondary}
|
| 255 | />
|
| 256 | </TouchableOpacity>
|
| 257 | </Card>
|
| 258 | </Section>
|
| 259 |
|
| 260 | <Button
|
| 261 | title="Sair da Conta"
|
| 262 | onPress={handleLogout}
|
| 263 | variant="outline"
|
| 264 | style={{ borderColor: Colors.light.danger }}
|
| 265 | textStyle={{ color: Colors.light.danger }}
|
| 266 | />
|
| 267 | </ScreenLayout>
|
| 268 | );
|
| 269 | }
|
| 270 |
|
| 271 | const styles = StyleSheet.create({
|
| 272 | container: {
|
| 273 | flex: 1,
|
| 274 | marginHorizontal: 16,
|
| 275 | paddingTop: 10,
|
| 276 | },
|
| 277 | item: {
|
| 278 | paddingTop: 20,
|
| 279 | paddingBottom: 20,
|
| 280 | },
|
| 281 | header: {
|
| 282 | fontSize: 22,
|
| 283 | fontWeight: "bold",
|
| 284 | },
|
| 285 | cardIcon: {
|
| 286 | paddingVertical: 15,
|
| 287 | paddingHorizontal: 14,
|
| 288 | width: 48,
|
| 289 | borderRadius: BorderRadius.md,
|
| 290 | },
|
| 291 | cardTitle: {
|
| 292 | fontSize: 16,
|
| 293 | fontWeight: "bold",
|
| 294 | },
|
| 295 | cardSubtitle: {
|
| 296 | fontSize: 12,
|
| 297 | color: Colors.light.textSecondary,
|
| 298 | },
|
| 299 | logout: {
|
| 300 | color: "#FF2C2C",
|
| 301 | },
|
| 302 | divider: {
|
| 303 | height: StyleSheet.hairlineWidth,
|
| 304 | backgroundColor: "#D1D5DB",
|
| 305 | marginVertical: 16,
|
| 306 | },
|
| 307 | });
|