import React, { useState } from 'react';
import {
View,
Text,
StyleSheet,
ScrollView,
TouchableOpacity,
TextInput,
Alert,
Platform,
} from 'react-native';
import { useRouter, Stack } from 'expo-router';
import { useUser } from '@clerk/clerk-expo';
import { Ionicons } from '@expo/vector-icons';
import { LinearGradient } from 'expo-linear-gradient';
import { theme } from '../styles/theme';
export default function PersonalDetailsScreen() {
const router = useRouter();
const { user } = useUser();
const [loading, setLoading] = useState(false);
// Initialize with current user data
const [formData, setFormData] = useState({
firstName: user?.firstName || '',
lastName: user?.lastName || '',
email: user?.primaryEmailAddress?.emailAddress || '',
phone: user?.primaryPhoneNumber?.phoneNumber || '',
});
const handleSave = async () => {
setLoading(true);
try {
// Update user profile via Clerk
await user?.update({
firstName: formData.firstName,
lastName: formData.lastName,
});
Alert.alert('Success', 'Personal details updated successfully', [
{ text: 'OK', onPress: () => router.back() },
]);
} catch (error) {
console.error('Error updating personal details:', error);
Alert.alert('Error', 'Failed to update personal details. Please try again.');
} finally {
setLoading(false);
}
};
const updateField = (field: string, value: string) => {
setFormData(prev => ({ ...prev, [field]: value }));
};
return (
<>
{/* Header */}
router.back()}
>
Personal Details
{/* First Name */}
First Name *
updateField('firstName', value)}
placeholder="Enter first name"
placeholderTextColor={theme.colors.gray400}
/>
{/* Last Name */}
Last Name *
updateField('lastName', value)}
placeholder="Enter last name"
placeholderTextColor={theme.colors.gray400}
/>
{/* Email (Read-only) */}
Email
Email cannot be changed here
{/* Phone (Read-only for now) */}
Phone Number
Phone number cannot be changed here
{/* Save Button */}
{loading ? 'Saving...' : 'Save Changes'}
>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: theme.colors.background,
},
header: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
paddingTop: Platform.OS === 'ios' ? 60 : 40,
paddingBottom: 20,
paddingHorizontal: 20,
},
backButton: {
width: 40,
height: 40,
borderRadius: 20,
backgroundColor: 'rgba(255, 255, 255, 0.2)',
justifyContent: 'center',
alignItems: 'center',
},
headerTitle: {
fontSize: theme.typography.fontSize['2xl'],
fontWeight: theme.typography.fontWeight.bold,
color: '#fff',
},
content: {
flex: 1,
},
scrollContent: {
padding: 20,
paddingBottom: 100,
},
field: {
marginBottom: 24,
},
label: {
fontSize: theme.typography.fontSize.sm,
fontWeight: theme.typography.fontWeight.semibold,
color: theme.colors.gray700,
marginBottom: 8,
},
inputContainer: {
flexDirection: 'row',
alignItems: 'center',
backgroundColor: '#fff',
borderRadius: theme.borderRadius.lg,
borderWidth: 1,
borderColor: theme.colors.gray200,
paddingHorizontal: 16,
...theme.shadows.subtle,
},
inputIcon: {
marginRight: 12,
},
input: {
flex: 1,
paddingVertical: 16,
fontSize: theme.typography.fontSize.base,
color: theme.colors.gray900,
},
disabledInput: {
backgroundColor: theme.colors.gray50,
},
disabledText: {
color: theme.colors.gray500,
},
helperText: {
fontSize: theme.typography.fontSize.xs,
color: theme.colors.gray500,
marginTop: 6,
marginLeft: 4,
},
footer: {
position: 'absolute',
bottom: 0,
left: 0,
right: 0,
padding: 20,
paddingBottom: Platform.OS === 'ios' ? 40 : 20,
backgroundColor: '#fff',
borderTopWidth: 1,
borderTopColor: theme.colors.gray100,
...theme.shadows.medium,
},
saveButton: {
borderRadius: theme.borderRadius.lg,
overflow: 'hidden',
},
saveButtonGradient: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
paddingVertical: 16,
gap: 8,
},
saveButtonDisabled: {
opacity: 0.6,
},
saveButtonText: {
fontSize: theme.typography.fontSize.base,
fontWeight: theme.typography.fontWeight.bold,
color: '#fff',
},
});