profile update works
This commit is contained in:
@@ -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>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user