add delete account button && homescrolling

This commit is contained in:
2025-07-10 23:10:49 +05:00
parent 89200eacd5
commit f16e8c19b6
3 changed files with 99 additions and 3 deletions

View File

@@ -7,6 +7,7 @@ import {
ScrollView,
TouchableOpacity,
ActivityIndicator,
RefreshControl,
} from 'react-native';
import { StatusBar } from 'expo-status-bar';
import { Ionicons } from '@expo/vector-icons';
@@ -23,6 +24,7 @@ const HomeScreen = () => {
const [loadingCardBalance, setLoadingCardBalance] = useState(true);
const [cardBalanceError, setCardBalanceError] = useState(null);
const [isBalanceVisible, setIsBalanceVisible] = useState(true);
const [refreshing, setRefreshing] = useState(false);
const showBalanceCard = !loadingCardBalance && cardBalanceError === null && cardBalance !== null;
@@ -79,11 +81,64 @@ const HomeScreen = () => {
fetchCardBalance();
}, [user]);
const handleRefresh = async () => {
setRefreshing(true);
await Promise.all([
(async () => {
try {
const response = await apiService.getMetrics();
if (response.success) {
setMetrics(response.data);
} else {
console.warn('Failed to fetch metrics during refresh:', response.error);
}
} catch (error) {
console.warn('Error fetching metrics during refresh:', error);
}
})(),
(async () => {
if (!user?.passport_serie || !user?.passport_id || !user?.card_number || !user?.card_month || !user?.card_year) {
setCardBalance(null); // Clear previous balance if conditions are not met
setCardBalanceError(null);
return;
}
try {
const res = await apiService.getCardBalanceQuickCheck();
if (res.success) {
const raw = res.data;
let balanceValue = null;
if (raw && typeof raw === 'object') {
balanceValue = raw.balance ?? raw.card_balance ?? raw.amount ?? null;
}
setCardBalance(balanceValue);
setCardBalanceError(null);
} else {
console.warn('Failed to fetch card balance during refresh:', res.error);
setCardBalanceError(res.error || 'Error');
}
} catch (e) {
console.warn('Error fetching card balance during refresh:', e);
}
})(),
]);
setRefreshing(false);
};
return (
<SafeAreaView style={styles.container}>
<StatusBar style="dark" />
<ScrollView style={styles.scrollView} showsVerticalScrollIndicator={false}>
<ScrollView
style={styles.scrollView}
showsVerticalScrollIndicator={false}
refreshControl={
<RefreshControl
refreshing={refreshing}
onRefresh={handleRefresh}
tintColor={COLORS.primary}
/>
}
>
{/* Header */}
<View style={styles.header}>
<View>

View File

@@ -81,6 +81,7 @@ const ProfileScreen = () => {
// { id: 11, title: 'Ulanmak düzgünleri', icon: 'document-text', hasArrow: true },
// { id: 12, title: 'Gizlinlik syýasaty', icon: 'lock-open', hasArrow: true },
{ id: 13, title: 'Programma barada', icon: 'information-circle', value: 'v1.0.0', hasArrow: true },
{ id: 14, title: 'Hasaby poz', icon: 'trash', hasArrow: false, color: COLORS.red },
],
},
];
@@ -102,6 +103,12 @@ const ProfileScreen = () => {
case 5: // Security
handleSecuritySettings();
break;
case 13: // About App
Alert.alert('Üns beriň', 'Programma barada maglumatlar açylýar...');
break;
case 14: // Delete Account
handleDeleteAccount();
break;
default:
// Alert.alert('Üns beriň', 'Bu funksiýa entek işlenok');
}
@@ -201,6 +208,40 @@ const ProfileScreen = () => {
}
};
const handleDeleteAccount = () => {
Alert.alert(
'Hasaby pozmak',
'Hasabyňyzy pozmak isleýändigiňize ynamlymy? Bu amal yzyna gaýtarylmaz.',
[
{
text: 'Ýok',
style: 'cancel',
},
{
text: 'Hawa',
style: 'destructive',
onPress: async () => {
try {
setIsLoading(true);
const result = await apiService.deleteAccount();
if (result.message == 'user deleted successfully') {
Alert.alert('Üstünlik', 'Hasabyňyz üstünlikli pozuldy.');
logout(); // Log out the user after successful deletion
} else {
Alert.alert('Ýalňyşlyk', result.error || 'Hasaby pozmak amala aşmady.');
}
} catch (error) {
Alert.alert('Ýalňyşlyk', error.message || 'Hasaby pozmakda näsazlyk ýüze çykdy.');
} finally {
setIsLoading(false);
}
},
},
]
);
};
const handleNotificationSettings = () => {
Alert.alert('Bildirişler', 'Bildiriş sazlamalary sahypasy açylýar...');
};
@@ -294,7 +335,7 @@ const ProfileScreen = () => {
>
<View style={styles.profileItemLeft}>
<View style={styles.profileItemIcon}>
<Ionicons name={item.icon} size={20} color={COLORS.primary} />
<Ionicons name={item.icon} size={20} color={item.color || COLORS.primary} />
</View>
<Text style={styles.profileItemTitle}>{item.title}</Text>
</View>

View File

@@ -170,7 +170,7 @@ class AuthService {
}
async deleteAccount() {
return this.makeRequest('/user/delete-account', null, true, 'DELETE');
return this.makeRequest(API_CONFIG.ENDPOINTS.AUTH.DELETE_USER, null, true, 'POST');
}
// ================================