loan order working
This commit is contained in:
135
src/screens/Loan/LoanOrderDetailsScreen.js
Normal file
135
src/screens/Loan/LoanOrderDetailsScreen.js
Normal file
@@ -0,0 +1,135 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { View, Text, StyleSheet, ActivityIndicator, TouchableOpacity, Alert, ScrollView, SafeAreaView } from 'react-native';
|
||||
import { Ionicons } from '@expo/vector-icons';
|
||||
import { useNavigation, useRoute } from '@react-navigation/native';
|
||||
import apiService from '../../services/apiService';
|
||||
import { COLORS } from '../../constants/colors';
|
||||
import { StatusBar } from 'expo-status-bar';
|
||||
|
||||
const formatDate = (dstr) => {
|
||||
if (!dstr) return '-';
|
||||
const d = new Date(dstr);
|
||||
return isNaN(d) ? dstr : d.toLocaleDateString('tk-TM');
|
||||
};
|
||||
|
||||
const DetailRow = ({ label, value, last }) => (
|
||||
<View style={[styles.detailRow, !last && styles.detailRowBorder]}>
|
||||
<Text style={styles.detailKey}>{label}</Text>
|
||||
<Text style={styles.detailValue}>{String(value)}</Text>
|
||||
</View>
|
||||
);
|
||||
|
||||
const LoanOrderDetailsScreen = () => {
|
||||
const navigation = useNavigation();
|
||||
const route = useRoute();
|
||||
const { orderId } = route.params || {};
|
||||
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [order, setOrder] = useState(null);
|
||||
|
||||
const fetchDetails = async () => {
|
||||
setLoading(true);
|
||||
const res = await apiService.getLoanOrder(orderId);
|
||||
if (res.success) {
|
||||
setOrder(res.data);
|
||||
} else {
|
||||
Alert.alert('Error', res.error || 'Could not fetch details');
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchDetails();
|
||||
}, []);
|
||||
|
||||
const handleDelete = () => {
|
||||
Alert.alert('Confirm', 'Delete this order?', [
|
||||
{ text: 'Cancel', style: 'cancel' },
|
||||
{ text: 'Delete', style: 'destructive', onPress: deleteOrder },
|
||||
]);
|
||||
};
|
||||
|
||||
const deleteOrder = async () => {
|
||||
const res = await apiService.deleteLoanOrder(orderId);
|
||||
if (res.success) {
|
||||
Alert.alert('Deleted', res.message || 'Order deleted', [
|
||||
{ text: 'OK', onPress: () => navigation.goBack() },
|
||||
]);
|
||||
} else {
|
||||
Alert.alert('Error', res.error || 'Could not delete');
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<View style={styles.centered}>
|
||||
<ActivityIndicator size="large" color={COLORS.primary} />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (!order) {
|
||||
return (
|
||||
<View style={styles.centered}>
|
||||
<Text>No data</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<SafeAreaView style={styles.container}>
|
||||
<StatusBar style="dark" />
|
||||
<TouchableOpacity style={styles.backBtn} onPress={() => navigation.goBack()}>
|
||||
<Ionicons name="close" size={28} color={COLORS.textPrimary} />
|
||||
</TouchableOpacity>
|
||||
|
||||
<ScrollView contentContainerStyle={{ paddingBottom: 40, paddingHorizontal: 24 }}>
|
||||
<Text style={styles.title}>Karz sargyt maglumatlary</Text>
|
||||
|
||||
<View style={styles.detailCard}>
|
||||
<DetailRow label="ID" value={order.id} />
|
||||
<DetailRow label="Karz mukdary" value={order.loan_amount} />
|
||||
<DetailRow label="Loan type" value={order.loan_type} />
|
||||
<DetailRow label="Status" value={order.status ?? '-'} />
|
||||
<DetailRow label="Bellik" value={order.notes ?? '-'} last />
|
||||
</View>
|
||||
|
||||
<Text style={styles.sectionTitle}>Müşderi</Text>
|
||||
<View style={styles.detailCard}>
|
||||
<DetailRow label="FIO" value={`${order.customer_name} ${order.customer_surname} ${order.customer_patronic_name ?? ''}`.trim()} />
|
||||
<DetailRow label="Doglan senesi" value={formatDate(order.born_at)} />
|
||||
<DetailRow label="Telefon" value={order.phone} />
|
||||
<DetailRow label="Passport" value={`${order.passport_serie} ${order.passport_id}`} last />
|
||||
</View>
|
||||
|
||||
{/* Address */}
|
||||
<Text style={styles.sectionTitle}>Salgylary</Text>
|
||||
<View style={styles.detailCard}>
|
||||
<DetailRow label="Passport salgysy" value={order.passport_address} />
|
||||
<DetailRow label="Real salgysy" value={order.real_address} last />
|
||||
</View>
|
||||
|
||||
<TouchableOpacity style={styles.deleteBtn} onPress={handleDelete}>
|
||||
<Text style={styles.deleteText}>Poz</Text>
|
||||
</TouchableOpacity>
|
||||
</ScrollView>
|
||||
</SafeAreaView>
|
||||
);
|
||||
};
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: { flex: 1, backgroundColor: COLORS.backgroundSecondary },
|
||||
centered: { flex: 1, alignItems: 'center', justifyContent: 'center' },
|
||||
backBtn: { alignSelf: 'flex-end', marginBottom: 16, marginRight: 24 },
|
||||
title: { fontSize: 24, fontWeight: 'bold', color: COLORS.textPrimary, marginBottom: 24 },
|
||||
sectionTitle: { fontSize: 18, fontWeight: '700', color: COLORS.textPrimary, marginBottom: 12 },
|
||||
detailCard: { backgroundColor: COLORS.white, borderRadius: 12, padding: 20, marginBottom: 32 },
|
||||
detailRow: { flexDirection: 'row', justifyContent: 'space-between', paddingVertical: 12 },
|
||||
detailRowBorder: { borderBottomWidth: 1, borderBottomColor: COLORS.border },
|
||||
detailKey: { fontWeight: '600', color: COLORS.textSecondary },
|
||||
detailValue: { color: COLORS.textPrimary, maxWidth: '60%', textAlign: 'right' },
|
||||
deleteBtn: { backgroundColor: COLORS.error, paddingVertical: 14, borderRadius: 8, alignItems: 'center' },
|
||||
deleteText: { color: COLORS.white, fontSize: 16, fontWeight: '600' },
|
||||
});
|
||||
|
||||
export default LoanOrderDetailsScreen;
|
||||
Reference in New Issue
Block a user