loan orders delete functionalatiy
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import React, { useState, useCallback } from 'react';
|
import React, { useState, useCallback } from 'react';
|
||||||
import { View, Text, StyleSheet, FlatList, ActivityIndicator, TouchableOpacity, RefreshControl, SafeAreaView } from 'react-native';
|
import { View, Text, StyleSheet, FlatList, ActivityIndicator, TouchableOpacity, RefreshControl, SafeAreaView, Alert } from 'react-native';
|
||||||
import { Ionicons } from '@expo/vector-icons';
|
import { Ionicons } from '@expo/vector-icons';
|
||||||
import { useNavigation, useFocusEffect } from '@react-navigation/native';
|
import { useNavigation, useFocusEffect } from '@react-navigation/native';
|
||||||
import apiService from '../../services/apiService';
|
import apiService from '../../services/apiService';
|
||||||
@@ -47,6 +47,32 @@ const LoanOrdersScreen = () => {
|
|||||||
const amount = (item.loan_amount + ' TMT') || '-';
|
const amount = (item.loan_amount + ' TMT') || '-';
|
||||||
const created = item.created_at ? new Date(item.created_at).toLocaleDateString() : '';
|
const created = item.created_at ? new Date(item.created_at).toLocaleDateString() : '';
|
||||||
|
|
||||||
|
const handleDelete = async (orderId) => {
|
||||||
|
Alert.alert(
|
||||||
|
"Sargyty pozmak",
|
||||||
|
"Siz hakykatdanam bu sargyty pozmak isleýärsiňizmi?",
|
||||||
|
[
|
||||||
|
{ text: "Ýok", style: "cancel" },
|
||||||
|
{
|
||||||
|
text: "Hawa",
|
||||||
|
onPress: async () => {
|
||||||
|
try {
|
||||||
|
const res = await apiService.deleteLoanOrder(orderId);
|
||||||
|
if (res.success) {
|
||||||
|
setOrders(prevOrders => prevOrders.filter(order => order.id !== orderId));
|
||||||
|
} else {
|
||||||
|
console.warn('Failed to delete order:', res.error);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error deleting order:', e.message);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
{ cancelable: true }
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TouchableOpacity style={styles.card} onPress={() => navigation.navigate('LoanOrderDetails', { orderId: item.id })}>
|
<TouchableOpacity style={styles.card} onPress={() => navigation.navigate('LoanOrderDetails', { orderId: item.id })}>
|
||||||
<View style={styles.circle}>
|
<View style={styles.circle}>
|
||||||
@@ -58,8 +84,11 @@ const LoanOrdersScreen = () => {
|
|||||||
<Text style={{ color: COLORS.textPrimary }}>{amount}</Text>
|
<Text style={{ color: COLORS.textPrimary }}>{amount}</Text>
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
<Text style={styles.dateText}>{created}</Text>
|
<Text style={styles.dateText}>Döredilen senesi: {created}</Text>
|
||||||
</View>
|
</View>
|
||||||
|
<TouchableOpacity onPress={() => handleDelete(item.id)} style={styles.deleteButton}>
|
||||||
|
<Ionicons name="trash" size={24} color={COLORS.error} />
|
||||||
|
</TouchableOpacity>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -112,6 +141,7 @@ const styles = StyleSheet.create({
|
|||||||
borderRadius: 12,
|
borderRadius: 12,
|
||||||
padding: 16,
|
padding: 16,
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
|
justifyContent: 'space-between',
|
||||||
},
|
},
|
||||||
circle: {
|
circle: {
|
||||||
width: 40,
|
width: 40,
|
||||||
@@ -127,7 +157,7 @@ const styles = StyleSheet.create({
|
|||||||
passportText: { fontWeight: '700', color: COLORS.textPrimary, marginBottom: 4 },
|
passportText: { fontWeight: '700', color: COLORS.textPrimary, marginBottom: 4 },
|
||||||
accountLabel: { color: COLORS.textSecondary, fontSize: 14 },
|
accountLabel: { color: COLORS.textSecondary, fontSize: 14 },
|
||||||
accountValue: { color: COLORS.textPrimary, marginBottom: 4 },
|
accountValue: { color: COLORS.textPrimary, marginBottom: 4 },
|
||||||
dateText: { color: COLORS.textSecondary, fontSize: 12, textAlign: 'right' },
|
dateText: { color: COLORS.textSecondary, fontSize: 12, textAlign: 'left' },
|
||||||
emptyContainer: { flex: 1, justifyContent: 'center', alignItems: 'center' },
|
emptyContainer: { flex: 1, justifyContent: 'center', alignItems: 'center' },
|
||||||
emptyText: { fontSize: 16, color: COLORS.textSecondary },
|
emptyText: { fontSize: 16, color: COLORS.textSecondary },
|
||||||
fab: {
|
fab: {
|
||||||
@@ -142,6 +172,9 @@ const styles = StyleSheet.create({
|
|||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
elevation: 4,
|
elevation: 4,
|
||||||
},
|
},
|
||||||
|
deleteButton: {
|
||||||
|
padding: 8,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default LoanOrdersScreen;
|
export default LoanOrdersScreen;
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useState, useCallback } from 'react';
|
import React, { useState, useCallback } from 'react';
|
||||||
import { View, Text, StyleSheet, FlatList, ActivityIndicator, TouchableOpacity, RefreshControl, SafeAreaView } from 'react-native';
|
import { View, Text, StyleSheet, FlatList, ActivityIndicator, TouchableOpacity, RefreshControl, SafeAreaView, Alert } from 'react-native';
|
||||||
import { Ionicons } from '@expo/vector-icons';
|
import { Ionicons } from '@expo/vector-icons';
|
||||||
import { useNavigation, useFocusEffect } from '@react-navigation/native';
|
import { useNavigation, useFocusEffect } from '@react-navigation/native';
|
||||||
import apiService from '../../services/apiService';
|
import apiService from '../../services/apiService';
|
||||||
@@ -47,6 +47,32 @@ const LoanPaidOffLetterOrdersScreen = () => {
|
|||||||
const accountLine = `Karz hasaby:`;
|
const accountLine = `Karz hasaby:`;
|
||||||
const created = item.created_at ? new Date(item.created_at).toLocaleDateString() : '';
|
const created = item.created_at ? new Date(item.created_at).toLocaleDateString() : '';
|
||||||
|
|
||||||
|
const handleDelete = async (orderId) => {
|
||||||
|
Alert.alert(
|
||||||
|
"Sargyty pozmak",
|
||||||
|
"Siz hakykatdanam bu sargyty pozmak isleýärsiňizmi?",
|
||||||
|
[
|
||||||
|
{ text: "Ýok", style: "cancel" },
|
||||||
|
{
|
||||||
|
text: "Hawa",
|
||||||
|
onPress: async () => {
|
||||||
|
try {
|
||||||
|
const res = await apiService.deleteLoanPaidOffLetterOrder(orderId);
|
||||||
|
if (res.success) {
|
||||||
|
setOrders(prevOrders => prevOrders.filter(order => order.id !== orderId));
|
||||||
|
} else {
|
||||||
|
console.warn('Failed to delete order:', res.error);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error deleting order:', e.message);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
{ cancelable: true }
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TouchableOpacity style={styles.card} onPress={() => navigation.navigate('LoanPaidOffLetterOrderDetails', { orderId: item.id })}>
|
<TouchableOpacity style={styles.card} onPress={() => navigation.navigate('LoanPaidOffLetterOrderDetails', { orderId: item.id })}>
|
||||||
<View style={styles.circle}>
|
<View style={styles.circle}>
|
||||||
@@ -58,6 +84,9 @@ const LoanPaidOffLetterOrdersScreen = () => {
|
|||||||
<Text style={styles.accountValue}>{item.loan_contract_number || '-'}</Text>
|
<Text style={styles.accountValue}>{item.loan_contract_number || '-'}</Text>
|
||||||
<Text style={styles.dateText}>{created}</Text>
|
<Text style={styles.dateText}>{created}</Text>
|
||||||
</View>
|
</View>
|
||||||
|
<TouchableOpacity onPress={() => handleDelete(item.id)} style={styles.deleteButton}>
|
||||||
|
<Ionicons name="trash" size={24} color={COLORS.error} />
|
||||||
|
</TouchableOpacity>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -110,6 +139,7 @@ const styles = StyleSheet.create({
|
|||||||
borderRadius: 12,
|
borderRadius: 12,
|
||||||
padding: 16,
|
padding: 16,
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
|
justifyContent: 'space-between',
|
||||||
},
|
},
|
||||||
circle: {
|
circle: {
|
||||||
width: 40,
|
width: 40,
|
||||||
@@ -140,6 +170,9 @@ const styles = StyleSheet.create({
|
|||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
elevation: 4,
|
elevation: 4,
|
||||||
},
|
},
|
||||||
|
deleteButton: {
|
||||||
|
padding: 8,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default LoanPaidOffLetterOrdersScreen;
|
export default LoanPaidOffLetterOrdersScreen;
|
||||||
@@ -65,6 +65,32 @@ const LoanRemainingOrdersScreen = () => {
|
|||||||
const accountLabel = 'Karz hasaby:';
|
const accountLabel = 'Karz hasaby:';
|
||||||
const created = item.created_at ? new Date(item.created_at).toLocaleDateString() : '';
|
const created = item.created_at ? new Date(item.created_at).toLocaleDateString() : '';
|
||||||
|
|
||||||
|
const handleDelete = async (orderId) => {
|
||||||
|
Alert.alert(
|
||||||
|
"Sargyty pozmak",
|
||||||
|
"Siz hakykatdanam bu sargyty pozmak isleýärsiňizmi?",
|
||||||
|
[
|
||||||
|
{ text: "Ýok", style: "cancel" },
|
||||||
|
{
|
||||||
|
text: "Hawa",
|
||||||
|
onPress: async () => {
|
||||||
|
try {
|
||||||
|
const res = await apiService.deleteLoanRemainingOrder(orderId);
|
||||||
|
if (res.success) {
|
||||||
|
setOrders(prevOrders => prevOrders.filter(order => order.id !== orderId));
|
||||||
|
} else {
|
||||||
|
console.warn('Failed to delete order:', res.error);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error deleting order:', e.message);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
{ cancelable: true }
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TouchableOpacity style={styles.card} onPress={() => handleItemPress(item)}>
|
<TouchableOpacity style={styles.card} onPress={() => handleItemPress(item)}>
|
||||||
<View style={styles.circle}>
|
<View style={styles.circle}>
|
||||||
@@ -74,8 +100,11 @@ const LoanRemainingOrdersScreen = () => {
|
|||||||
<Text style={styles.passportText}>{passportLine}</Text>
|
<Text style={styles.passportText}>{passportLine}</Text>
|
||||||
<Text style={styles.accountLabel}>{accountLabel}</Text>
|
<Text style={styles.accountLabel}>{accountLabel}</Text>
|
||||||
<Text style={styles.accountValue}>{item.account_number}</Text>
|
<Text style={styles.accountValue}>{item.account_number}</Text>
|
||||||
<Text style={styles.dateText}>{created}</Text>
|
<Text style={styles.dateText}>Döredilen senesi: {created}</Text>
|
||||||
</View>
|
</View>
|
||||||
|
<TouchableOpacity onPress={() => handleDelete(item.id)} style={styles.deleteButton}>
|
||||||
|
<Ionicons name="trash" size={24} color={COLORS.error} />
|
||||||
|
</TouchableOpacity>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -204,6 +233,7 @@ const styles = StyleSheet.create({
|
|||||||
borderRadius: 12,
|
borderRadius: 12,
|
||||||
padding: 16,
|
padding: 16,
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
|
justifyContent: 'space-between', // Added to push delete button to the right
|
||||||
},
|
},
|
||||||
circle: {
|
circle: {
|
||||||
width: 40,
|
width: 40,
|
||||||
@@ -318,6 +348,9 @@ const styles = StyleSheet.create({
|
|||||||
fontWeight: '600',
|
fontWeight: '600',
|
||||||
color: COLORS.textPrimary,
|
color: COLORS.textPrimary,
|
||||||
},
|
},
|
||||||
|
deleteButton: {
|
||||||
|
padding: 8,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export default LoanRemainingOrdersScreen;
|
export default LoanRemainingOrdersScreen;
|
||||||
Reference in New Issue
Block a user