fitness profileand personal details

fix
This commit is contained in:
echo 2025-11-26 02:59:53 +01:00
parent b014734f33
commit c038a54f2e
4 changed files with 690 additions and 202 deletions

Binary file not shown.

View File

@ -1,5 +1,6 @@
import { View, Text, StyleSheet, TouchableOpacity, Image, Alert } from "react-native"; import { View, Text, StyleSheet, TouchableOpacity, Image, Alert } from "react-native";
import { useUser, useClerk } from "@clerk/clerk-expo"; import { useUser, useClerk } from "@clerk/clerk-expo";
import { useRouter } from "expo-router";
import { Ionicons } from "@expo/vector-icons"; import { Ionicons } from "@expo/vector-icons";
import { LinearGradient } from "expo-linear-gradient"; import { LinearGradient } from "expo-linear-gradient";
import { theme } from "../../styles/theme"; import { theme } from "../../styles/theme";
@ -9,6 +10,7 @@ import { GradientBackground } from "../../components/GradientBackground";
export default function ProfileScreen() { export default function ProfileScreen() {
const { user } = useUser(); const { user } = useUser();
const { signOut } = useClerk(); const { signOut } = useClerk();
const router = useRouter();
const handleSignOut = async () => { const handleSignOut = async () => {
try { try {
@ -57,7 +59,7 @@ export default function ProfileScreen() {
<View style={styles.section}> <View style={styles.section}>
<Text style={styles.sectionTitle}>Account</Text> <Text style={styles.sectionTitle}>Account</Text>
<View style={[styles.infoCard, theme.shadows.subtle]}> <View style={[styles.infoCard, theme.shadows.subtle]}>
<TouchableOpacity style={styles.infoRow}> <TouchableOpacity style={styles.infoRow} onPress={() => router.push('/personal-details')}>
<LinearGradient <LinearGradient
colors={['rgba(59, 130, 246, 0.1)', 'rgba(59, 130, 246, 0.05)']} colors={['rgba(59, 130, 246, 0.1)', 'rgba(59, 130, 246, 0.05)']}
style={styles.iconContainer} style={styles.iconContainer}
@ -68,7 +70,7 @@ export default function ProfileScreen() {
<Ionicons name="chevron-forward" size={20} color={theme.colors.gray400} /> <Ionicons name="chevron-forward" size={20} color={theme.colors.gray400} />
</TouchableOpacity> </TouchableOpacity>
<View style={styles.divider} /> <View style={styles.divider} />
<TouchableOpacity style={styles.infoRow}> <TouchableOpacity style={styles.infoRow} onPress={() => router.push('/fitness-profile')}>
<LinearGradient <LinearGradient
colors={['rgba(16, 185, 129, 0.1)', 'rgba(16, 185, 129, 0.05)']} colors={['rgba(16, 185, 129, 0.1)', 'rgba(16, 185, 129, 0.05)']}
style={styles.iconContainer} style={styles.iconContainer}

View File

@ -1,4 +1,4 @@
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from 'react';
import { import {
View, View,
Text, Text,
@ -7,13 +7,15 @@ import {
TouchableOpacity, TouchableOpacity,
ActivityIndicator, ActivityIndicator,
Alert, Alert,
} from "react-native"; TextInput,
import { useRouter } from "expo-router"; Platform,
import { useAuth } from "@clerk/clerk-expo"; } from 'react-native';
import { Ionicons } from "@expo/vector-icons"; import { useRouter } from 'expo-router';
import { Input } from "../components/Input"; import { useAuth } from '@clerk/clerk-expo';
import { Picker } from "../components/Picker"; import { Ionicons } from '@expo/vector-icons';
import { API_BASE_URL } from "../config/api"; import { LinearGradient } from 'expo-linear-gradient';
import { theme } from '../styles/theme';
import { API_BASE_URL } from '../config/api';
interface FitnessProfileData { interface FitnessProfileData {
height?: number; height?: number;
@ -27,6 +29,28 @@ interface FitnessProfileData {
injuries?: string; injuries?: string;
} }
const GENDER_OPTIONS = [
{ label: 'Male', value: 'male', icon: 'male' },
{ label: 'Female', value: 'female', icon: 'female' },
{ label: 'Other', value: 'other', icon: 'transgender' },
];
const FITNESS_GOAL_OPTIONS = [
{ label: 'Weight Loss', value: 'weight_loss', icon: 'trending-down', color: theme.colors.danger },
{ label: 'Muscle Gain', value: 'muscle_gain', icon: 'barbell', color: theme.colors.primary },
{ label: 'Endurance', value: 'endurance', icon: 'bicycle', color: theme.colors.success },
{ label: 'Flexibility', value: 'flexibility', icon: 'body', color: theme.colors.purple },
{ label: 'General Fitness', value: 'general_fitness', icon: 'fitness', color: theme.colors.warning },
];
const ACTIVITY_LEVEL_OPTIONS = [
{ label: 'Sedentary', value: 'sedentary', description: 'Little to no exercise' },
{ label: 'Light', value: 'light', description: '1-3 days/week' },
{ label: 'Moderate', value: 'moderate', description: '3-5 days/week' },
{ label: 'Active', value: 'active', description: '6-7 days/week' },
{ label: 'Very Active', value: 'very_active', description: 'Intense daily training' },
];
export default function FitnessProfileScreen() { export default function FitnessProfileScreen() {
const router = useRouter(); const router = useRouter();
const { userId, getToken } = useAuth(); const { userId, getToken } = useAuth();
@ -34,29 +58,6 @@ export default function FitnessProfileScreen() {
const [fetchingProfile, setFetchingProfile] = useState(true); const [fetchingProfile, setFetchingProfile] = useState(true);
const [profileData, setProfileData] = useState<FitnessProfileData>({}); const [profileData, setProfileData] = useState<FitnessProfileData>({});
const genderOptions = [
{ label: "Male", value: "male" },
{ label: "Female", value: "female" },
{ label: "Other", value: "other" },
{ label: "Prefer not to say", value: "prefer_not_to_say" },
];
const fitnessGoalOptions = [
{ label: "Weight Loss", value: "weight_loss" },
{ label: "Muscle Gain", value: "muscle_gain" },
{ label: "Endurance", value: "endurance" },
{ label: "Flexibility", value: "flexibility" },
{ label: "General Fitness", value: "general_fitness" },
];
const activityLevelOptions = [
{ label: "Sedentary", value: "sedentary" },
{ label: "Lightly Active", value: "lightly_active" },
{ label: "Moderately Active", value: "moderately_active" },
{ label: "Very Active", value: "very_active" },
{ label: "Extremely Active", value: "extremely_active" },
];
useEffect(() => { useEffect(() => {
fetchProfile(); fetchProfile();
}, []); }, []);
@ -65,8 +66,7 @@ export default function FitnessProfileScreen() {
try { try {
setFetchingProfile(true); setFetchingProfile(true);
const token = await getToken(); const token = await getToken();
const apiUrl = `${API_BASE_URL}` || "http://localhost:3000"; const response = await fetch(`${API_BASE_URL}/api/profile/fitness?userId=${userId}`, {
const response = await fetch(`${apiUrl}/api/fitness-profile`, {
headers: { headers: {
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
}, },
@ -79,17 +79,21 @@ export default function FitnessProfileScreen() {
height: data.profile.height, height: data.profile.height,
weight: data.profile.weight, weight: data.profile.weight,
age: data.profile.age, age: data.profile.age,
gender: data.profile.gender || "", gender: data.profile.gender || '',
fitnessGoal: data.profile.fitnessGoal || "", fitnessGoal: Array.isArray(data.profile.fitnessGoals)
activityLevel: data.profile.activityLevel || "", ? data.profile.fitnessGoals[0]
medicalConditions: data.profile.medicalConditions || "", : (typeof data.profile.fitnessGoals === 'string'
allergies: data.profile.allergies || "", ? JSON.parse(data.profile.fitnessGoals)[0]
injuries: data.profile.injuries || "", : ''),
activityLevel: data.profile.activityLevel || '',
medicalConditions: data.profile.medicalConditions || '',
allergies: data.profile.allergies || '',
injuries: data.profile.injuries || '',
}); });
} }
} }
} catch (error) { } catch (error) {
console.error("Error fetching profile:", error); console.error('Error fetching profile:', error);
} finally { } finally {
setFetchingProfile(false); setFetchingProfile(false);
} }
@ -99,28 +103,41 @@ export default function FitnessProfileScreen() {
try { try {
setLoading(true); setLoading(true);
const token = await getToken(); const token = await getToken();
const apiUrl = `${API_BASE_URL}/api/fitness-profile` || "http://localhost:3000";
const response = await fetch(`${apiUrl}`, { // Prepare data with userId and convert fitnessGoal to fitnessGoals array
method: "POST", const dataToSave = {
userId: userId,
height: profileData.height,
weight: profileData.weight,
age: profileData.age,
gender: profileData.gender,
fitnessGoals: profileData.fitnessGoal ? [profileData.fitnessGoal] : [],
activityLevel: profileData.activityLevel,
medicalConditions: profileData.medicalConditions,
allergies: profileData.allergies,
injuries: profileData.injuries,
};
const response = await fetch(`${API_BASE_URL}/api/profile/fitness`, {
method: 'POST',
headers: { headers: {
"Content-Type": "application/json", 'Content-Type': 'application/json',
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
}, },
body: JSON.stringify(profileData), body: JSON.stringify(dataToSave),
}); });
if (response.ok) { if (response.ok) {
Alert.alert("Success", "Fitness profile saved successfully!", [ Alert.alert('Success', 'Fitness profile saved successfully!', [
{ text: "OK", onPress: () => router.back() }, { text: 'OK', onPress: () => router.back() },
]); ]);
} else { } else {
const error = await response.json(); const error = await response.json();
Alert.alert("Error", error.message || "Failed to save profile"); Alert.alert('Error', error.error || 'Failed to save profile');
} }
} catch (error) { } catch (error) {
console.error("Error saving profile:", error); console.error('Error saving profile:', error);
Alert.alert("Error", "Failed to save fitness profile"); Alert.alert('Error', 'Failed to save fitness profile');
} finally { } finally {
setLoading(false); setLoading(false);
} }
@ -133,142 +150,233 @@ export default function FitnessProfileScreen() {
if (fetchingProfile) { if (fetchingProfile) {
return ( return (
<View style={styles.loadingContainer}> <View style={styles.loadingContainer}>
<ActivityIndicator size="large" color="#2563eb" /> <ActivityIndicator size="large" color={theme.colors.primary} />
</View> </View>
); );
} }
return ( return (
<View style={styles.container}> <View style={styles.container}>
<View style={styles.header}> {/* Header */}
<TouchableOpacity <LinearGradient colors={theme.gradients.primary} style={styles.header}>
onPress={() => router.back()} <TouchableOpacity style={styles.backButton} onPress={() => router.back()}>
style={styles.backButton} <Ionicons name="arrow-back" size={24} color="#fff" />
>
<Ionicons name="arrow-back" size={24} color="#1f2937" />
</TouchableOpacity> </TouchableOpacity>
<Text style={styles.headerTitle}>Fitness Profile</Text> <Text style={styles.headerTitle}>Fitness Profile</Text>
<View style={styles.headerSpacer} /> <View style={{ width: 40 }} />
</View> </LinearGradient>
<ScrollView <ScrollView
style={styles.scrollView} style={styles.scrollView}
contentContainerStyle={styles.scrollContent}
showsVerticalScrollIndicator={false} showsVerticalScrollIndicator={false}
> >
<View style={styles.content}> {/* Basic Information */}
<View style={styles.section}> <View style={styles.section}>
<Text style={styles.sectionTitle}>Basic Information</Text> <Text style={styles.sectionTitle}>Basic Information</Text>
<View style={styles.card}>
<Input <View style={styles.row}>
label="Height (cm)" <View style={styles.inputGroup}>
value={profileData.height?.toString() || ""} <Text style={styles.label}>Height (cm)</Text>
onChangeText={(text) => <View style={styles.inputContainer}>
updateField("height", text ? parseFloat(text) : undefined) <Ionicons name="resize-outline" size={20} color={theme.colors.gray400} />
} <TextInput
keyboardType="decimal-pad" style={styles.input}
placeholder="e.g., 175" value={profileData.height?.toString() || ''}
/> onChangeText={(text) =>
updateField('height', text ? parseFloat(text) : undefined)
<Input }
label="Weight (kg)" keyboardType="decimal-pad"
value={profileData.weight?.toString() || ""} placeholder="175"
onChangeText={(text) => placeholderTextColor={theme.colors.gray400}
updateField("weight", text ? parseFloat(text) : undefined) />
} </View>
keyboardType="decimal-pad" </View>
placeholder="e.g., 70" <View style={styles.inputGroup}>
/> <Text style={styles.label}>Weight (kg)</Text>
<View style={styles.inputContainer}>
<Input <Ionicons name="scale-outline" size={20} color={theme.colors.gray400} />
label="Age" <TextInput
value={profileData.age?.toString() || ""} style={styles.input}
onChangeText={(text) => value={profileData.weight?.toString() || ''}
updateField("age", text ? parseInt(text, 10) : undefined) onChangeText={(text) =>
} updateField('weight', text ? parseFloat(text) : undefined)
keyboardType="number-pad" }
placeholder="e.g., 25" keyboardType="decimal-pad"
/> placeholder="70"
placeholderTextColor={theme.colors.gray400}
<Picker />
label="Gender" </View>
value={profileData.gender || ""} </View>
onValueChange={(value) => updateField("gender", value)} </View>
items={genderOptions} <View style={styles.inputGroup}>
/> <Text style={styles.label}>Age</Text>
<View style={styles.inputContainer}>
<Ionicons name="calendar-outline" size={20} color={theme.colors.gray400} />
<TextInput
style={styles.input}
value={profileData.age?.toString() || ''}
onChangeText={(text) =>
updateField('age', text ? parseInt(text, 10) : undefined)
}
keyboardType="number-pad"
placeholder="25"
placeholderTextColor={theme.colors.gray400}
/>
</View>
</View>
</View> </View>
</View>
<View style={styles.section}> {/* Gender Selection */}
<Text style={styles.sectionTitle}>Fitness Goals</Text> <View style={styles.section}>
<Text style={styles.sectionTitle}>Gender</Text>
<Picker <View style={styles.optionsRow}>
label="Primary Goal" {GENDER_OPTIONS.map((option) => (
value={profileData.fitnessGoal || ""} <TouchableOpacity
onValueChange={(value) => updateField("fitnessGoal", value)} key={option.value}
items={fitnessGoalOptions} style={[
/> styles.optionCard,
profileData.gender === option.value && styles.optionCardActive,
<Picker ]}
label="Activity Level" onPress={() => updateField('gender', option.value)}
value={profileData.activityLevel || ""} >
onValueChange={(value) => updateField("activityLevel", value)} <Ionicons
items={activityLevelOptions} name={option.icon as any}
/> size={24}
color={
profileData.gender === option.value
? theme.colors.primary
: theme.colors.gray400
}
/>
<Text
style={[
styles.optionLabel,
profileData.gender === option.value && styles.optionLabelActive,
]}
>
{option.label}
</Text>
</TouchableOpacity>
))}
</View> </View>
</View>
<View style={styles.section}> {/* Fitness Goal */}
<Text style={styles.sectionTitle}>Health Information</Text> <View style={styles.section}>
<Text style={styles.sectionTitle}>Primary Fitness Goal</Text>
<Input <View style={styles.card}>
label="Medical Conditions (optional)" {FITNESS_GOAL_OPTIONS.map((option, index) => (
value={profileData.medicalConditions || ""} <React.Fragment key={option.value}>
onChangeText={(text) => updateField("medicalConditions", text)} <TouchableOpacity
placeholder="e.g., Asthma, diabetes..." style={styles.listItem}
multiline onPress={() => updateField('fitnessGoal', option.value)}
numberOfLines={3} >
style={styles.textArea} <View style={[styles.iconCircle, { backgroundColor: `${option.color}20` }]}>
/> <Ionicons name={option.icon as any} size={20} color={option.color} />
</View>
<Input <Text style={styles.listItemText}>{option.label}</Text>
label="Allergies (optional)" {profileData.fitnessGoal === option.value && (
value={profileData.allergies || ""} <Ionicons name="checkmark-circle" size={24} color={theme.colors.primary} />
onChangeText={(text) => updateField("allergies", text)} )}
placeholder="e.g., Peanuts, latex..." </TouchableOpacity>
multiline {index < FITNESS_GOAL_OPTIONS.length - 1 && <View style={styles.divider} />}
numberOfLines={3} </React.Fragment>
style={styles.textArea} ))}
/>
<Input
label="Injuries (optional)"
value={profileData.injuries || ""}
onChangeText={(text) => updateField("injuries", text)}
placeholder="e.g., Previous knee injury..."
multiline
numberOfLines={3}
style={styles.textArea}
/>
</View> </View>
</View>
<TouchableOpacity {/* Activity Level */}
style={[styles.saveButton, loading && styles.saveButtonDisabled]} <View style={styles.section}>
onPress={handleSave} <Text style={styles.sectionTitle}>Activity Level</Text>
disabled={loading} <View style={styles.card}>
> {ACTIVITY_LEVEL_OPTIONS.map((option, index) => (
<React.Fragment key={option.value}>
<TouchableOpacity
style={styles.listItem}
onPress={() => updateField('activityLevel', option.value)}
>
<View style={{ flex: 1 }}>
<Text style={styles.listItemText}>{option.label}</Text>
<Text style={styles.listItemDescription}>{option.description}</Text>
</View>
{profileData.activityLevel === option.value && (
<Ionicons name="checkmark-circle" size={24} color={theme.colors.primary} />
)}
</TouchableOpacity>
{index < ACTIVITY_LEVEL_OPTIONS.length - 1 && <View style={styles.divider} />}
</React.Fragment>
))}
</View>
</View>
{/* Health Information */}
<View style={styles.section}>
<Text style={styles.sectionTitle}>Health Information (Optional)</Text>
<View style={styles.card}>
<View style={styles.inputGroup}>
<Text style={styles.label}>Medical Conditions</Text>
<TextInput
style={[styles.textArea]}
value={profileData.medicalConditions || ''}
onChangeText={(text) => updateField('medicalConditions', text)}
placeholder="e.g., Asthma, diabetes..."
placeholderTextColor={theme.colors.gray400}
multiline
numberOfLines={3}
textAlignVertical="top"
/>
</View>
<View style={styles.inputGroup}>
<Text style={styles.label}>Allergies</Text>
<TextInput
style={[styles.textArea]}
value={profileData.allergies || ''}
onChangeText={(text) => updateField('allergies', text)}
placeholder="e.g., Peanuts, latex..."
placeholderTextColor={theme.colors.gray400}
multiline
numberOfLines={3}
textAlignVertical="top"
/>
</View>
<View style={styles.inputGroup}>
<Text style={styles.label}>Injuries</Text>
<TextInput
style={[styles.textArea]}
value={profileData.injuries || ''}
onChangeText={(text) => updateField('injuries', text)}
placeholder="e.g., Previous knee injury..."
placeholderTextColor={theme.colors.gray400}
multiline
numberOfLines={3}
textAlignVertical="top"
/>
</View>
</View>
</View>
</ScrollView>
{/* Save Button */}
<View style={styles.footer}>
<TouchableOpacity
style={[styles.saveButton, loading && styles.saveButtonDisabled]}
onPress={handleSave}
disabled={loading}
>
<LinearGradient colors={theme.gradients.primary} style={styles.saveButtonGradient}>
{loading ? ( {loading ? (
<ActivityIndicator color="white" /> <ActivityIndicator color="#fff" />
) : ( ) : (
<> <>
<Ionicons <Ionicons name="checkmark-circle" size={20} color="#fff" />
name="checkmark-circle-outline"
size={20}
color="white"
/>
<Text style={styles.saveButtonText}>Save Profile</Text> <Text style={styles.saveButtonText}>Save Profile</Text>
</> </>
)} )}
</TouchableOpacity> </LinearGradient>
</View> </TouchableOpacity>
</ScrollView> </View>
</View> </View>
); );
} }
@ -276,73 +384,185 @@ export default function FitnessProfileScreen() {
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
flex: 1, flex: 1,
backgroundColor: "#f9fafb", backgroundColor: theme.colors.background,
}, },
loadingContainer: { loadingContainer: {
flex: 1, flex: 1,
justifyContent: "center", justifyContent: 'center',
alignItems: "center", alignItems: 'center',
backgroundColor: "#f9fafb", backgroundColor: theme.colors.background,
}, },
header: { header: {
flexDirection: "row", flexDirection: 'row',
alignItems: "center", alignItems: 'center',
justifyContent: "space-between", justifyContent: 'space-between',
paddingHorizontal: 16, paddingTop: Platform.OS === 'ios' ? 60 : 40,
paddingTop: 60, paddingBottom: 20,
paddingBottom: 16, paddingHorizontal: 20,
backgroundColor: "white",
borderBottomWidth: 1,
borderBottomColor: "#e5e7eb",
}, },
backButton: { backButton: {
padding: 4, width: 40,
height: 40,
borderRadius: 20,
backgroundColor: 'rgba(255, 255, 255, 0.2)',
justifyContent: 'center',
alignItems: 'center',
}, },
headerTitle: { headerTitle: {
fontSize: 18, fontSize: theme.typography.fontSize['2xl'],
fontWeight: "600", fontWeight: theme.typography.fontWeight.bold,
color: "#1f2937", color: '#fff',
},
headerSpacer: {
width: 32,
}, },
scrollView: { scrollView: {
flex: 1, flex: 1,
}, },
content: { scrollContent: {
padding: 20, padding: 20,
paddingBottom: 100,
}, },
section: { section: {
marginBottom: 24, marginBottom: 24,
}, },
sectionTitle: { sectionTitle: {
fontSize: 16, fontSize: theme.typography.fontSize.lg,
fontWeight: "600", fontWeight: theme.typography.fontWeight.bold,
color: "#1f2937", color: theme.colors.gray900,
marginBottom: 12,
},
card: {
backgroundColor: '#fff',
borderRadius: theme.borderRadius.xl,
padding: 16,
...theme.shadows.subtle,
borderWidth: 1,
borderColor: theme.colors.gray100,
},
row: {
flexDirection: 'row',
gap: 12,
marginBottom: 16, marginBottom: 16,
}, },
inputGroup: {
flex: 1,
marginBottom: 16,
},
label: {
fontSize: theme.typography.fontSize.sm,
fontWeight: theme.typography.fontWeight.semibold,
color: theme.colors.gray700,
marginBottom: 8,
},
inputContainer: {
flexDirection: 'row',
alignItems: 'center',
backgroundColor: theme.colors.gray50,
borderRadius: theme.borderRadius.lg,
borderWidth: 1,
borderColor: theme.colors.gray200,
paddingHorizontal: 12,
gap: 8,
},
input: {
flex: 1,
paddingVertical: 12,
fontSize: theme.typography.fontSize.base,
color: theme.colors.gray900,
},
textArea: { textArea: {
height: 80, backgroundColor: theme.colors.gray50,
textAlignVertical: "top", borderRadius: theme.borderRadius.lg,
paddingTop: 12, borderWidth: 1,
borderColor: theme.colors.gray200,
padding: 12,
fontSize: theme.typography.fontSize.base,
color: theme.colors.gray900,
minHeight: 80,
},
optionsRow: {
flexDirection: 'row',
gap: 12,
},
optionCard: {
flex: 1,
backgroundColor: '#fff',
borderRadius: theme.borderRadius.lg,
padding: 16,
alignItems: 'center',
gap: 8,
borderWidth: 2,
borderColor: theme.colors.gray200,
...theme.shadows.subtle,
},
optionCardActive: {
borderColor: theme.colors.primary,
backgroundColor: `${theme.colors.primary}10`,
},
optionLabel: {
fontSize: theme.typography.fontSize.sm,
fontWeight: theme.typography.fontWeight.medium,
color: theme.colors.gray600,
},
optionLabelActive: {
color: theme.colors.primary,
fontWeight: theme.typography.fontWeight.bold,
},
listItem: {
flexDirection: 'row',
alignItems: 'center',
paddingVertical: 12,
gap: 12,
},
iconCircle: {
width: 40,
height: 40,
borderRadius: 20,
justifyContent: 'center',
alignItems: 'center',
},
listItemText: {
flex: 1,
fontSize: theme.typography.fontSize.base,
fontWeight: theme.typography.fontWeight.medium,
color: theme.colors.gray900,
},
listItemDescription: {
fontSize: theme.typography.fontSize.xs,
color: theme.colors.gray500,
marginTop: 2,
},
divider: {
height: 1,
backgroundColor: theme.colors.gray100,
},
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: { saveButton: {
backgroundColor: "#2563eb", borderRadius: theme.borderRadius.lg,
borderRadius: 8, overflow: 'hidden',
padding: 16, },
flexDirection: "row", saveButtonGradient: {
alignItems: "center", flexDirection: 'row',
justifyContent: "center", alignItems: 'center',
marginTop: 8, justifyContent: 'center',
marginBottom: 40, paddingVertical: 16,
gap: 8,
}, },
saveButtonDisabled: { saveButtonDisabled: {
opacity: 0.6, opacity: 0.6,
}, },
saveButtonText: { saveButtonText: {
color: "white", fontSize: theme.typography.fontSize.base,
fontSize: 16, fontWeight: theme.typography.fontWeight.bold,
fontWeight: "600", color: '#fff',
marginLeft: 8,
}, },
}); });

View File

@ -0,0 +1,266 @@
import React, { useState } from 'react';
import {
View,
Text,
StyleSheet,
ScrollView,
TouchableOpacity,
TextInput,
Alert,
Platform,
} from 'react-native';
import { useRouter } 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 (
<View style={styles.container}>
{/* Header */}
<LinearGradient
colors={theme.gradients.primary}
style={styles.header}
>
<TouchableOpacity
style={styles.backButton}
onPress={() => router.back()}
>
<Ionicons name="arrow-back" size={24} color="#fff" />
</TouchableOpacity>
<Text style={styles.headerTitle}>Personal Details</Text>
<View style={{ width: 40 }} />
</LinearGradient>
<ScrollView
style={styles.content}
contentContainerStyle={styles.scrollContent}
showsVerticalScrollIndicator={false}
>
{/* First Name */}
<View style={styles.field}>
<Text style={styles.label}>First Name *</Text>
<View style={styles.inputContainer}>
<Ionicons name="person-outline" size={20} color={theme.colors.gray400} style={styles.inputIcon} />
<TextInput
style={styles.input}
value={formData.firstName}
onChangeText={(value) => updateField('firstName', value)}
placeholder="Enter first name"
placeholderTextColor={theme.colors.gray400}
/>
</View>
</View>
{/* Last Name */}
<View style={styles.field}>
<Text style={styles.label}>Last Name *</Text>
<View style={styles.inputContainer}>
<Ionicons name="person-outline" size={20} color={theme.colors.gray400} style={styles.inputIcon} />
<TextInput
style={styles.input}
value={formData.lastName}
onChangeText={(value) => updateField('lastName', value)}
placeholder="Enter last name"
placeholderTextColor={theme.colors.gray400}
/>
</View>
</View>
{/* Email (Read-only) */}
<View style={styles.field}>
<Text style={styles.label}>Email</Text>
<View style={[styles.inputContainer, styles.disabledInput]}>
<Ionicons name="mail-outline" size={20} color={theme.colors.gray400} style={styles.inputIcon} />
<TextInput
style={[styles.input, styles.disabledText]}
value={formData.email}
editable={false}
placeholderTextColor={theme.colors.gray400}
/>
<Ionicons name="lock-closed-outline" size={16} color={theme.colors.gray400} />
</View>
<Text style={styles.helperText}>Email cannot be changed here</Text>
</View>
{/* Phone (Read-only for now) */}
<View style={styles.field}>
<Text style={styles.label}>Phone Number</Text>
<View style={[styles.inputContainer, styles.disabledInput]}>
<Ionicons name="call-outline" size={20} color={theme.colors.gray400} style={styles.inputIcon} />
<TextInput
style={[styles.input, styles.disabledText]}
value={formData.phone || 'Not set'}
editable={false}
placeholderTextColor={theme.colors.gray400}
/>
<Ionicons name="lock-closed-outline" size={16} color={theme.colors.gray400} />
</View>
<Text style={styles.helperText}>Phone number cannot be changed here</Text>
</View>
</ScrollView>
{/* Save Button */}
<View style={styles.footer}>
<TouchableOpacity
style={[styles.saveButton, loading && styles.saveButtonDisabled]}
onPress={handleSave}
disabled={loading}
>
<LinearGradient
colors={theme.gradients.primary}
style={styles.saveButtonGradient}
>
<Ionicons name="checkmark-circle" size={20} color="#fff" />
<Text style={styles.saveButtonText}>
{loading ? 'Saving...' : 'Save Changes'}
</Text>
</LinearGradient>
</TouchableOpacity>
</View>
</View>
);
}
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',
},
});