profile update works

This commit is contained in:
2025-07-03 23:47:22 +05:00
parent 77e3ca0f18
commit e2b696655d
5 changed files with 542 additions and 5 deletions

View File

@@ -14,6 +14,7 @@ import { StatusBar } from 'expo-status-bar';
import { Ionicons } from '@expo/vector-icons';
import { useAuth } from '../../contexts/AuthContext';
import apiService from '../../services/apiService';
import EditProfileModal from '../../components/EditProfileModal';
import { COLORS } from '../../constants/colors';
const ProfileScreen = () => {
@@ -21,6 +22,8 @@ const ProfileScreen = () => {
const [isLoading, setIsLoading] = useState(false);
const [isRefreshing, setIsRefreshing] = useState(false);
const [profileData, setProfileData] = useState(null);
const [isEditModalVisible, setIsEditModalVisible] = useState(false);
const [isUpdatingProfile, setIsUpdatingProfile] = useState(false);
useEffect(() => {
loadProfileData();
@@ -108,8 +111,35 @@ const ProfileScreen = () => {
};
const handleEditPersonalInfo = () => {
// Navigate to edit personal info screen
Alert.alert('Şahsy maglumatlar', 'Şahsy maglumatlar sahypasy açylýar...');
setIsEditModalVisible(true);
};
const handleSaveProfile = async (updatedData) => {
try {
setIsUpdatingProfile(true);
const result = await apiService.updateProfile(updatedData);
if (result.success) {
// Update local profile data optimistically
setProfileData(prev => ({
...prev,
...updatedData,
}));
// Optionally refresh profile from server
await loadProfileData();
Alert.alert('Success', result.message);
setIsEditModalVisible(false);
} else {
Alert.alert('Error', result.error || 'Could not update profile');
}
} catch (error) {
console.error('Error updating profile:', error);
Alert.alert('Error', error.message || 'Could not update profile');
} finally {
setIsUpdatingProfile(false);
}
};
const handleEditContactInfo = () => {
@@ -295,6 +325,15 @@ const ProfileScreen = () => {
<View style={styles.bottomSpacing} />
</ScrollView>
{/* Edit Profile Modal */}
<EditProfileModal
visible={isEditModalVisible}
onClose={() => setIsEditModalVisible(false)}
onSave={handleSaveProfile}
initialData={profileData || user}
isLoading={isUpdatingProfile}
/>
</SafeAreaView>
);
};