| 1 | import { TouchableOpacity, StyleSheet, Text, SectionList, View, Alert } from 'react-native';
|
| 2 | import { SafeAreaView, SafeAreaProvider } from 'react-native-safe-area-context';
|
| 3 | import { useState } from 'react';
|
| 4 | import ParallaxScrollView from '@/components/misc/parallax-scroll-view';
|
| 5 | import { Link } from 'expo-router'
|
| 6 | import { StatusBar } from 'expo-status-bar';
|
| 7 |
|
| 8 | import { ThemedText } from '@/components/misc/themed-text';
|
| 9 | import { ThemedView } from '@/components/misc/themed-view';
|
| 10 | import { IconSymbol } from '@/components/ui/icon-symbol';
|
| 11 | import { Fonts } from '@/constants/theme';
|
| 12 | import { useThemeColor } from '@/hooks/use-theme-color';
|
| 13 | import { useAuth } from '@/context/AuthContext';
|
| 14 |
|
| 15 | const SECTIONS = [
|
| 16 | {
|
| 17 | title: 'Geral',
|
| 18 | data: [{
|
| 19 | title: 'Perfil & Senha',
|
| 20 | path: '/profile'
|
| 21 | }]
|
| 22 | },
|
| 23 | {
|
| 24 | title: 'Sobre',
|
| 25 | data: [
|
| 26 | {
|
| 27 | title: 'Sobre o aplicativo',
|
| 28 | path: '/about'
|
| 29 | },
|
| 30 | {
|
| 31 | title: 'O que acontece com seus dados?',
|
| 32 | path: '/data'
|
| 33 | },
|
| 34 | {
|
| 35 | title: 'Sair',
|
| 36 | path: '/logout',
|
| 37 | logout: true
|
| 38 | }
|
| 39 | ]
|
| 40 | }
|
| 41 | ]
|
| 42 |
|
| 43 | export default function Settings() {
|
| 44 | const { user, logout } = useAuth();
|
| 45 | const [options] = useState([
|
| 46 | { id: 'profile', name: 'Perfil', path: '/profile'}
|
| 47 | ])
|
| 48 |
|
| 49 | const textColor = useThemeColor({}, 'text');
|
| 50 | const tintColor = useThemeColor({}, 'tint');
|
| 51 |
|
| 52 | const handleLogout = async () => {
|
| 53 | Alert.alert(
|
| 54 | 'Sair',
|
| 55 | 'Tem certeza que quer sair?',
|
| 56 | [
|
| 57 | { text: 'Cancelar', style: 'cancel' },
|
| 58 | {
|
| 59 | text: 'Sair',
|
| 60 | style: 'destructive',
|
| 61 | onPress: logout
|
| 62 | },
|
| 63 | ]
|
| 64 | );
|
| 65 | };
|
| 66 |
|
| 67 | const renderItem = ({item}) => {
|
| 68 | const itemStyle = [
|
| 69 | styles.item,
|
| 70 | ]
|
| 71 |
|
| 72 | const itemColor = { color: item.logout ? '#FF2C2C' : textColor }
|
| 73 |
|
| 74 | if (item.logout) {
|
| 75 | return (
|
| 76 | <TouchableOpacity onPress={handleLogout} style={itemStyle}>
|
| 77 | <Text style={itemColor}>
|
| 78 | Sair
|
| 79 | </Text>
|
| 80 | </TouchableOpacity>
|
| 81 | )
|
| 82 | }
|
| 83 |
|
| 84 | return (
|
| 85 | <View>
|
| 86 | <Link key={item.id} href={item.path} asChild style={itemStyle}>
|
| 87 | <TouchableOpacity>
|
| 88 | <Text style={itemColor}>
|
| 89 | {item.title}
|
| 90 | </Text>
|
| 91 | </TouchableOpacity>
|
| 92 | </Link>
|
| 93 | </View>
|
| 94 | )
|
| 95 | }
|
| 96 |
|
| 97 | return (
|
| 98 | <SafeAreaProvider>
|
| 99 | <SafeAreaView style={styles.container} edges={['top']}>
|
| 100 | <StatusBar style="dark" />
|
| 101 | <SectionList
|
| 102 | sections={SECTIONS}
|
| 103 | keyExtractor={(item, index) => item.title + index}
|
| 104 | renderItem={renderItem}
|
| 105 | renderSectionHeader={({section: {title}}) => (
|
| 106 | <ThemedText style={styles.header}>{title}</ThemedText>
|
| 107 | )} />
|
| 108 | </SafeAreaView>
|
| 109 | </SafeAreaProvider>
|
| 110 | )
|
| 111 | }
|
| 112 |
|
| 113 | const styles = StyleSheet.create({
|
| 114 | container: {
|
| 115 | flex: 1,
|
| 116 | marginHorizontal: 16,
|
| 117 | paddingTop: 10
|
| 118 | },
|
| 119 | item: {
|
| 120 | paddingTop: 20,
|
| 121 | paddingBottom: 20,
|
| 122 | },
|
| 123 | header: {
|
| 124 | fontSize: 22,
|
| 125 | fontWeight: 'bold'
|
| 126 | },
|
| 127 | logout: {
|
| 128 | textColor: '#FF2C2C'
|
| 129 | }
|
| 130 | });
|