bug fixes
This commit is contained in:
BIN
src/screens/Auth/.VerificationScreen.js.swp
Normal file
BIN
src/screens/Auth/.VerificationScreen.js.swp
Normal file
Binary file not shown.
@@ -49,8 +49,8 @@ const VerificationScreen = ({ navigation }) => {
|
||||
};
|
||||
|
||||
if (Platform.OS === 'android') {
|
||||
BackHandler.addEventListener('hardwareBackPress', onBackPress);
|
||||
return () => BackHandler.removeEventListener('hardwareBackPress', onBackPress);
|
||||
const sub = BackHandler.addEventListener('hardwareBackPress', onBackPress);
|
||||
return () => sub.remove();
|
||||
}
|
||||
}, [handleGoBack])
|
||||
);
|
||||
|
||||
@@ -20,6 +20,12 @@ const yearOptions = Array.from({ length: 60 }).map((_, i) => {
|
||||
|
||||
const PASSPORT_SERIES = ['I-AS','I-MR','II-MR','I-AH','II-AH','I-LB','II-LB','I-BN','II-BN','I-DZ','II-DZ'];
|
||||
|
||||
// Helper to format card number with spaces
|
||||
const formatCardNumber = (value) => {
|
||||
const digits = String(value).replace(/[^0-9]/g, '').slice(0, 16);
|
||||
return (digits.match(/.{1,4}/g) || []).join(' ');
|
||||
};
|
||||
|
||||
const CreateCardBalanceOrderScreen = () => {
|
||||
const navigation = useNavigation();
|
||||
const [cardNumber, setCardNumber] = useState('');
|
||||
@@ -42,7 +48,11 @@ const CreateCardBalanceOrderScreen = () => {
|
||||
useEffect(() => {
|
||||
if (user) {
|
||||
if (user.passport_serie) setPassportSerie(user.passport_serie);
|
||||
if (user.passport_id) setPassportId(String(user.passport_id));
|
||||
if (user.passport_id) setPassportId(String(user.passport_id));e
|
||||
|
||||
if (user.card_number) setCardNumber(formatCardNumber(user.card_number));
|
||||
if (user.card_month) setCardMonth(String(user.card_month).padStart(2, '0'));
|
||||
if (user.card_year) setCardYear(String(user.card_year));
|
||||
}
|
||||
}, [user]);
|
||||
|
||||
|
||||
@@ -21,6 +21,12 @@ const yearOptions = Array.from({ length: 60 }).map((_, i) => {
|
||||
|
||||
const PASSPORT_SERIES = ['I-AS','I-MR','II-MR','I-AH','II-AH','I-LB','II-LB','I-BN','II-BN','I-DZ','II-DZ'];
|
||||
|
||||
// Helper to format card number 9999 9999 9999 9999
|
||||
const formatCardNumber = (value) => {
|
||||
const digits = value.replace(/[^0-9]/g, '').slice(0, 16);
|
||||
return (digits.match(/.{1,4}/g) || []).join(' ');
|
||||
};
|
||||
|
||||
const CreateCardTransactionOrderScreen = () => {
|
||||
const navigation = useNavigation();
|
||||
const [cardNumber, setCardNumber] = useState('');
|
||||
@@ -35,16 +41,25 @@ const CreateCardTransactionOrderScreen = () => {
|
||||
if (user) {
|
||||
if (user.passport_serie) setPassportSerie(user.passport_serie);
|
||||
if (user.passport_id) setPassportId(String(user.passport_id));
|
||||
|
||||
if (user.card_number) setCardNumber(formatCardNumber(String(user.card_number)));
|
||||
if (user.card_month) setCardMonth(String(user.card_month).padStart(2,'0'));
|
||||
if (user.card_year) setCardYear(String(user.card_year));
|
||||
}
|
||||
}, [user]);
|
||||
|
||||
const handleCardNumberChange = (val) => {
|
||||
setCardNumber(formatCardNumber(val));
|
||||
};
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!cardNumber.trim() || !cardMonth || !cardYear || !passportSerie || !passportId.trim()) {
|
||||
Alert.alert('Error', 'All fields are required');
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
const res = await apiService.createCardTransactionOrder(cardNumber.trim(), cardMonth, cardYear, passportSerie, passportId.trim());
|
||||
const rawCard = cardNumber.replace(/\s+/g, '').trim();
|
||||
const res = await apiService.createCardTransactionOrder(rawCard, cardMonth, cardYear, passportSerie, passportId.trim());
|
||||
setLoading(false);
|
||||
if (res.success) {
|
||||
Alert.alert('Success', res.message || 'Order created successfully', [
|
||||
@@ -85,10 +100,11 @@ const CreateCardTransactionOrderScreen = () => {
|
||||
label="*Kart belgisi"
|
||||
placeholder="9934..."
|
||||
value={cardNumber}
|
||||
onChangeText={setCardNumber}
|
||||
onChangeText={handleCardNumberChange}
|
||||
keyboardType="numeric"
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
maxLength={19}
|
||||
/>
|
||||
|
||||
<SelectInput
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useState } from 'react';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { View, Text, StyleSheet, TouchableOpacity, ActivityIndicator, Alert, SafeAreaView } from 'react-native';
|
||||
import { Ionicons } from '@expo/vector-icons';
|
||||
import { useNavigation } from '@react-navigation/native';
|
||||
@@ -6,19 +6,33 @@ import apiService from '../../services/apiService';
|
||||
import { COLORS } from '../../constants/colors';
|
||||
import Input from '../../components/Input';
|
||||
import { StatusBar } from 'expo-status-bar';
|
||||
import SelectInput from '../../components/SelectInput';
|
||||
import { useAuth } from '../../contexts/AuthContext';
|
||||
|
||||
const CreateLoanRemainingOrderScreen = () => {
|
||||
const navigation = useNavigation();
|
||||
const [accountNumber, setAccountNumber] = useState('');
|
||||
const [passportSerie, setPassportSerie] = useState('');
|
||||
const [passportId, setPassportId] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const { user } = useAuth();
|
||||
|
||||
useEffect(() => {
|
||||
if (user) {
|
||||
if (user.passport_serie) setPassportSerie(user.passport_serie);
|
||||
if (user.passport_id) setPassportId(String(user.passport_id));
|
||||
}
|
||||
}, [user]);
|
||||
|
||||
const PASSPORT_SERIES = ['I-AS','I-MR','II-MR','I-AH','II-AH','I-LB','II-LB','I-BN','II-BN','I-DZ','II-DZ'];
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (accountNumber.trim().length === 0) {
|
||||
Alert.alert('Error', 'Account number is required');
|
||||
if (accountNumber.trim().length === 0 || !passportSerie || passportId.trim().length === 0) {
|
||||
Alert.alert('Error', 'All fields are required');
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
const res = await apiService.createLoanRemainingOrder(accountNumber.trim());
|
||||
const res = await apiService.createLoanRemainingOrder(accountNumber.trim(), passportSerie, passportId.trim());
|
||||
setLoading(false);
|
||||
if (res.success) {
|
||||
Alert.alert('Success', res.message || 'Order created successfully', [
|
||||
@@ -40,6 +54,22 @@ const CreateLoanRemainingOrderScreen = () => {
|
||||
|
||||
<Text style={styles.title}>Täze sargyt</Text>
|
||||
|
||||
<SelectInput
|
||||
label="*Passport seriýasy"
|
||||
value={passportSerie}
|
||||
onValueChange={setPassportSerie}
|
||||
options={PASSPORT_SERIES.map((v) => ({ label: v, value: v }))}
|
||||
placeholder="Saýla"
|
||||
/>
|
||||
|
||||
<Input
|
||||
label="*Passport belgisi"
|
||||
placeholder="123456"
|
||||
value={passportId}
|
||||
onChangeText={setPassportId}
|
||||
keyboardType="numeric"
|
||||
/>
|
||||
|
||||
<Input
|
||||
label="Karz hasaby"
|
||||
placeholder="1420..."
|
||||
|
||||
@@ -106,9 +106,9 @@ class ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
async createLoanRemainingOrder(accountNumber) {
|
||||
async createLoanRemainingOrder(accountNumber, passportSerie = null, passportId = null) {
|
||||
try {
|
||||
const response = await authService.createLoanRemainingOrder(accountNumber);
|
||||
const response = await authService.createLoanRemainingOrder(accountNumber, passportSerie, passportId);
|
||||
return { success: true, message: response.message };
|
||||
} catch (error) {
|
||||
return { success: false, error: error.message };
|
||||
@@ -124,9 +124,9 @@ class ApiService {
|
||||
}
|
||||
}
|
||||
|
||||
async updateLoanRemainingOrder(orderId, accountNumber) {
|
||||
async updateLoanRemainingOrder(orderId, accountNumber, passportSerie = null, passportId = null) {
|
||||
try {
|
||||
const response = await authService.updateLoanRemainingOrder(orderId, accountNumber);
|
||||
const response = await authService.updateLoanRemainingOrder(orderId, accountNumber, passportSerie, passportId);
|
||||
return { success: true, message: response.message };
|
||||
} catch (error) {
|
||||
return { success: false, error: error.message };
|
||||
|
||||
@@ -184,15 +184,21 @@ class AuthService {
|
||||
return this.makeRequest('/loan-remaining-order', null, true, 'GET');
|
||||
}
|
||||
|
||||
// CREATE order (requires only account number – passport details are fetched from user profile)
|
||||
async createLoanRemainingOrder(accountNumber) {
|
||||
const user = await this.getStoredUser();
|
||||
if (!user?.passport_serie || !user?.passport_id) {
|
||||
throw new Error('Passport details are missing from profile');
|
||||
// CREATE order (passport can be supplied or fetched from profile)
|
||||
async createLoanRemainingOrder(accountNumber, passportSerie = null, passportId = null) {
|
||||
let serie = passportSerie;
|
||||
let pid = passportId;
|
||||
if (!serie || !pid) {
|
||||
const user = await this.getStoredUser();
|
||||
serie = serie || user?.passport_serie;
|
||||
pid = pid || user?.passport_id;
|
||||
}
|
||||
if (!serie || !pid) {
|
||||
throw new Error('Passport details are missing');
|
||||
}
|
||||
const payload = {
|
||||
passport_serie: user.passport_serie,
|
||||
passport_id: user.passport_id,
|
||||
passport_serie: serie,
|
||||
passport_id: pid,
|
||||
account_number: accountNumber,
|
||||
};
|
||||
return this.makeRequest('/loan-remaining-order', payload, true, 'POST');
|
||||
@@ -204,14 +210,20 @@ class AuthService {
|
||||
}
|
||||
|
||||
// UPDATE order (only account number can change; passport details stay the same)
|
||||
async updateLoanRemainingOrder(orderId, accountNumber) {
|
||||
const user = await this.getStoredUser();
|
||||
if (!user?.passport_serie || !user?.passport_id) {
|
||||
throw new Error('Passport details are missing from profile');
|
||||
async updateLoanRemainingOrder(orderId, accountNumber, passportSerie = null, passportId = null) {
|
||||
let serie = passportSerie;
|
||||
let pid = passportId;
|
||||
if (!serie || !pid) {
|
||||
const user = await this.getStoredUser();
|
||||
serie = serie || user?.passport_serie;
|
||||
pid = pid || user?.passport_id;
|
||||
}
|
||||
if (!serie || !pid) {
|
||||
throw new Error('Passport details are missing');
|
||||
}
|
||||
const payload = {
|
||||
passport_serie: user.passport_serie,
|
||||
passport_id: user.passport_id,
|
||||
passport_serie: serie,
|
||||
passport_id: pid,
|
||||
account_number: accountNumber,
|
||||
};
|
||||
return this.makeRequest(`/loan-remaining-order/${orderId}`, payload, true, 'POST');
|
||||
|
||||
Reference in New Issue
Block a user