diff --git a/mobile/src/screens/ProfileScreen.tsx b/mobile/src/screens/ProfileScreen.tsx index d8b478e..b608c5f 100644 --- a/mobile/src/screens/ProfileScreen.tsx +++ b/mobile/src/screens/ProfileScreen.tsx @@ -1,18 +1,266 @@ -import React from 'react'; -import { View, Text, useColorScheme } from 'react-native'; +import React, { useState } from 'react'; +import { View, Text, TouchableOpacity, useColorScheme, ScrollView, Alert, Image, ActivityIndicator, Modal } from 'react-native'; +import { Ionicons } from '@expo/vector-icons'; +import { useNavigation } from '@react-navigation/native'; +import { NativeStackNavigationProp } from '@react-navigation/native-stack'; +import { RootStackParamList } from '../navigation/AppNavigator'; import { getThemeStyles, commonStyles } from '../theme/styles'; +import { useAuthStore } from '../store/useAuthStore'; +import { authService } from '../services/api'; +import { COLORS } from '../theme/colors'; +import appConfig from '../../app.json'; export default function ProfileScreen() { + const navigation = useNavigation>(); + const { user, logout } = useAuthStore(); + const [isResending, setIsResending] = useState(false); + const [isModalVisible, setIsModalVisible] = useState(false); const colorScheme = useColorScheme(); const isDark = colorScheme === 'dark'; const themeStyles = getThemeStyles(isDark); + const themeColors = isDark ? COLORS.DARK : COLORS.LIGHT; + + if (!user) return null; + + const displayName = + (user.user?.first_name && user.user?.last_name) ? `${user.user.first_name} ${user.user.last_name}` : + user.user?.username ? user.user.username : + user.user?.email ? user.user.email.split('@')[0] : + 'User Name'; + + const handleResendVerification = async () => { + setIsResending(true); + const result = await authService.resendVerificationEmail(); + setIsResending(false); + + if (result.ok) { + Alert.alert('Email Sent', 'Please check your email (or server logs) for the verification link.'); + } else { + Alert.alert('Error', result.message || 'Failed to resend verification email'); + } + }; + + const handleDeleteAccount = () => { + Alert.alert( + 'Delete Account', + 'Are you sure you want to permanently delete your account? This action cannot be undone.', + [ + { text: 'Cancel', style: 'cancel' }, + { + text: 'Delete', + style: 'destructive', + onPress: async () => { + const result = await authService.deleteAccount(); + if (result.ok) { + logout(); + Alert.alert('Success', 'Your account has been deleted.'); + } else { + Alert.alert('Error', 'Failed to delete account.'); + } + } + }, + ] + ); + }; + + const MenuItem = ({ icon, label, onPress, isDestructive = false }: { icon: string, label: string, onPress: () => void, isDestructive?: boolean }) => ( + + + + + + {label} + + + + ); return ( - - - Profile Screen - User profile details will go here. + + {!user.user?.email_verified_at && ( + + + + + Your email is not verified. Tap to resend link. + + + {isResending ? ( + + ) : ( + + )} + + )} + + {/* Header Profile Section */} + + + {user.user?.avatar ? ( + setIsModalVisible(true)} style={{ width: '100%', height: '100%' }}> + + + ) : ( + + {displayName.charAt(0).toUpperCase()} + + )} + + + {displayName} + + + {user.user?.email} + - + + {/* Settings Section */} + + navigation.navigate('EditProfile')} /> + {}} /> + Alert.alert('Your Token', user.token)} /> + {}} /> + + + {/* Danger Zone */} + + + + + + + Version {appConfig.expo.version} + + + setIsModalVisible(false)} + > + setIsModalVisible(false)} + > + {user.user?.avatar && ( + + + + )} + setIsModalVisible(false)} + > + + + + + ); }