Skip to content

Commit e8d7430

Browse files
committed
signup fields now working and display in profile tab
1 parent 6694a45 commit e8d7430

11 files changed

Lines changed: 719 additions & 224 deletions

File tree

KonditionExpo/app/(tabs)/profile.tsx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
import React, { useState } from 'react';
22
import { SafeAreaView, View, Text, StyleSheet, ScrollView, TouchableOpacity, Image, Switch } from 'react-native';
3-
import { useUser } from '@/contexts/UserContext';
43
import { useAuth } from '@/contexts/AuthContext';
54
import { router } from 'expo-router';
65
import { DevTools } from '@/components/DevTools';
76
import { Dialog } from '@/components/ui/Dialog';
87
import { Button } from '@/components/ui/Button';
98

109
const ProfileScreen = () => {
11-
const { name, height, weight, age } = useUser();
1210
const { user, logout, isLoading } = useAuth();
1311
const [notificationsEnabled, setNotificationsEnabled] = useState(false);
1412
const [showDevTools, setShowDevTools] = useState(false);
1513
const [showLogoutDialog, setShowLogoutDialog] = useState(false);
1614

1715
const toggleNotifications = () => setNotificationsEnabled(prev => !prev);
1816

17+
// Calculate age from date of birth
18+
const calculateAge = (dateOfBirth: string | undefined): number => {
19+
if (!dateOfBirth) return 0;
20+
const today = new Date();
21+
const birthDate = new Date(dateOfBirth);
22+
let age = today.getFullYear() - birthDate.getFullYear();
23+
const monthDiff = today.getMonth() - birthDate.getMonth();
24+
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
25+
age--;
26+
}
27+
return age;
28+
};
29+
30+
const age = calculateAge(user?.date_of_birth);
31+
1932
const handleLogout = () => {
2033
setShowLogoutDialog(true);
2134
};
@@ -49,7 +62,7 @@ const ProfileScreen = () => {
4962
<ScrollView contentContainerStyle={styles.content}>
5063
{/* Profile Box */}
5164
<View style={styles.profileBox}>
52-
<Text style={styles.profileName}>{user?.full_name || name || 'User'}</Text>
65+
<Text style={styles.profileName}>{user?.full_name || user?.email || 'User'}</Text>
5366
<Text style={styles.profileEmail}>{user?.email || 'No email'}</Text>
5467
<TouchableOpacity style={styles.editBtn}>
5568
<Text style={styles.editText}>Edit</Text>
@@ -58,11 +71,11 @@ const ProfileScreen = () => {
5871
<View style={styles.statsRow}>
5972
<View style={styles.statBox}>
6073
<Text style={styles.statLabel}>Height</Text>
61-
<Text style={styles.statValue}>{height ? `${height} cm` : '-'}</Text>
74+
<Text style={styles.statValue}>{user?.height ? `${user.height} cm` : '-'}</Text>
6275
</View>
6376
<View style={styles.statBox}>
6477
<Text style={styles.statLabel}>Weight</Text>
65-
<Text style={styles.statValue}>{weight ? `${weight} kg` : '-'}</Text>
78+
<Text style={styles.statValue}>{user?.weight ? `${user.weight} kg` : '-'}</Text>
6679
</View>
6780
<View style={styles.statBox}>
6881
<Text style={styles.statLabel}>Age</Text>

KonditionExpo/app/index.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,38 @@
11
import React, { useEffect } from 'react';
22
import { View, ActivityIndicator, StyleSheet } from 'react-native';
3-
import { router } from 'expo-router';
3+
import { router, useSegments } from 'expo-router';
44
import { useAuth } from '@/contexts/AuthContext';
55
import { useThemeColor } from '@/hooks/useThemeColor';
66
import { ThemedText } from '@/components/ThemedText';
77

88
export default function IndexScreen() {
9-
const { isAuthenticated, isLoading } = useAuth();
9+
const { isAuthenticated, isLoading, isInSignupFlow } = useAuth();
10+
const segments = useSegments();
1011
const backgroundColor = useThemeColor({}, 'background');
1112
const textColor = useThemeColor({}, 'text');
1213

1314
useEffect(() => {
1415
if (!isLoading) {
16+
// Don't redirect if we're already on a specific route (like signup2)
17+
const currentRoute = segments[0];
18+
if (currentRoute) {
19+
console.log('IndexScreen: Already on route:', currentRoute, '- not redirecting');
20+
return;
21+
}
22+
23+
// Don't redirect if user is in signup flow - let them complete it
24+
if (isInSignupFlow) {
25+
console.log('IndexScreen: User in signup flow - not redirecting');
26+
return;
27+
}
28+
1529
if (isAuthenticated) {
1630
router.replace('/(tabs)');
1731
} else {
1832
router.replace('/login');
1933
}
2034
}
21-
}, [isAuthenticated, isLoading]);
35+
}, [isAuthenticated, isLoading, isInSignupFlow, segments]);
2236

2337
return (
2438
<View style={[styles.container, { backgroundColor }]}>

KonditionExpo/app/profile.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
import React, { useState } from 'react';
22
import { SafeAreaView, View, Text, StyleSheet, ScrollView, TouchableOpacity, Image, Switch } from 'react-native';
3-
import { useUser } from '@/contexts/UserContext';
3+
import { useAuth } from '@/contexts/AuthContext';
44
import { router } from 'expo-router';
55

66
const ProfileScreen = () => {
7-
const { name, height, weight, age } = useUser();
7+
const { user } = useAuth();
88
const [notificationsEnabled, setNotificationsEnabled] = useState(false);
99

1010
const toggleNotifications = () => setNotificationsEnabled(prev => !prev);
1111

12+
// Calculate age from date of birth
13+
const calculateAge = (dateOfBirth: string | undefined): number => {
14+
if (!dateOfBirth) return 0;
15+
const today = new Date();
16+
const birthDate = new Date(dateOfBirth);
17+
let age = today.getFullYear() - birthDate.getFullYear();
18+
const monthDiff = today.getMonth() - birthDate.getMonth();
19+
if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birthDate.getDate())) {
20+
age--;
21+
}
22+
return age;
23+
};
24+
25+
const age = calculateAge(user?.date_of_birth);
26+
1227
return (
1328
<SafeAreaView style={styles.container}>
1429
<ScrollView contentContainerStyle={styles.content}>
@@ -19,19 +34,19 @@ const ProfileScreen = () => {
1934

2035
{/* Profile Box */}
2136
<View style={styles.profileBox}>
22-
<Text style={styles.profileName}>{name || 'User'}</Text>
37+
<Text style={styles.profileName}>{user?.full_name || user?.email || 'User'}</Text>
2338
<TouchableOpacity style={styles.editBtn}>
2439
<Text style={styles.editText}>Edit</Text>
2540
</TouchableOpacity>
2641

2742
<View style={styles.statsRow}>
2843
<View style={styles.statBox}>
2944
<Text style={styles.statLabel}>Height</Text>
30-
<Text style={styles.statValue}>{height ? `${height} cm` : '-'}</Text>
45+
<Text style={styles.statValue}>{user?.height ? `${user.height} cm` : '-'}</Text>
3146
</View>
3247
<View style={styles.statBox}>
3348
<Text style={styles.statLabel}>Weight</Text>
34-
<Text style={styles.statValue}>{weight ? `${weight} kg` : '-'}</Text>
49+
<Text style={styles.statValue}>{user?.weight ? `${user.weight} kg` : '-'}</Text>
3550
</View>
3651
<View style={styles.statBox}>
3752
<Text style={styles.statLabel}>Age</Text>

KonditionExpo/app/signup.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,8 @@ export default function SignUpScreen() {
2525
const textColor = useThemeColor({}, 'text');
2626
const tintColor = useThemeColor({}, 'tint');
2727

28-
// Redirect if already authenticated
29-
useEffect(() => {
30-
if (isAuthenticated) {
31-
router.replace('/(tabs)');
32-
}
33-
}, [isAuthenticated]);
28+
// Note: We don't redirect authenticated users here anymore since we want them
29+
// to complete the profile setup flow after signup
3430

3531
const validateForm = () => {
3632
const newErrors: typeof errors = {};
@@ -75,12 +71,17 @@ export default function SignUpScreen() {
7571
}
7672

7773
try {
74+
console.log('Starting signup process...');
7875
await signup({
7976
email: email.trim(),
8077
password,
8178
full_name: fullName.trim(),
8279
});
83-
// Navigation will happen automatically via useEffect when isAuthenticated becomes true
80+
81+
console.log('Signup successful, user is now logged in. Navigating to profile completion...');
82+
// User is now logged in automatically, redirect to profile completion
83+
router.replace('/signup2');
84+
console.log('Navigation to profile completion initiated');
8485
} catch (error) {
8586
console.error('Signup error:', error);
8687
Alert.alert(

0 commit comments

Comments
 (0)