feat(whole project): huge changes, huge updates
This commit is contained in:
196 files changed
+9146
-4316
No files matched your search
@@ -1,17 +1,83 @@
|
||||
import { View, Text, TextInput, TouchableOpacity } from 'react-native'
|
||||
import { View, Text, TextInput, TouchableOpacity, Alert } from 'react-native'
|
||||
import React, { useState } from 'react'
|
||||
import TabBar from '../themes/TabBar'
|
||||
import { CheckIcon, ChevronLeftIcon } from 'react-native-heroicons/outline'
|
||||
import { widthPercentageToDP as wp, heightPercentageToDP as hp } from 'react-native-responsive-screen';
|
||||
import Checkbox from 'expo-checkbox';
|
||||
import { useNavigation } from '@react-navigation/native';
|
||||
import { ChevronLeftIcon } from 'react-native-heroicons/outline'
|
||||
import { useNavigation, useRoute } from '@react-navigation/native'
|
||||
import { widthPercentageToDP as wp, heightPercentageToDP as hp } from 'react-native-responsive-screen'
|
||||
|
||||
export default function AddCardScreen() {
|
||||
const navigation = useNavigation()
|
||||
const navigation = useNavigation();
|
||||
const route = useRoute();
|
||||
const { method } = route.params;
|
||||
|
||||
const [cardNumber, setCardNumber] = useState('');
|
||||
const [expiryDate, setExpiryDate] = useState('');
|
||||
const [cvv, setCvv] = useState('');
|
||||
const [cardholderName, setCardholderName] = useState('');
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const formatCardNumber = (text) => {
|
||||
// Remove all non-digit characters
|
||||
const cleaned = text.replace(/\D/g, '');
|
||||
// Add space after every 4 digits
|
||||
const formatted = cleaned.replace(/(\d{4})/g, '$1 ').trim();
|
||||
setCardNumber(formatted);
|
||||
};
|
||||
|
||||
const formatExpiryDate = (text) => {
|
||||
// Remove all non-digit characters
|
||||
const cleaned = text.replace(/\D/g, '');
|
||||
// Add slash after 2 digits
|
||||
if (cleaned.length >= 2) {
|
||||
const formatted = cleaned.slice(0, 2) + '/' + cleaned.slice(2, 4);
|
||||
setExpiryDate(formatted);
|
||||
} else {
|
||||
setExpiryDate(cleaned);
|
||||
}
|
||||
};
|
||||
|
||||
const handleAddCard = async () => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
|
||||
// Basic validation
|
||||
if (!cardNumber || !expiryDate || !cvv || !cardholderName) {
|
||||
Alert.alert('Error', 'Please fill in all card details');
|
||||
return;
|
||||
}
|
||||
|
||||
if (cardNumber.replace(/\s/g, '').length !== 16) {
|
||||
Alert.alert('Error', 'Please enter a valid 16-digit card number');
|
||||
return;
|
||||
}
|
||||
|
||||
if (cvv.length < 3) {
|
||||
Alert.alert('Error', 'Please enter a valid CVV');
|
||||
return;
|
||||
}
|
||||
|
||||
// Here you would typically make an API call to save the card
|
||||
// For now, we'll just show a success message
|
||||
Alert.alert(
|
||||
'Success',
|
||||
'Card added successfully!',
|
||||
[
|
||||
{
|
||||
text: 'OK',
|
||||
onPress: () => navigation.goBack()
|
||||
}
|
||||
]
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Error adding card:', error);
|
||||
Alert.alert('Error', 'Failed to add card. Please try again.');
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const [isChecked, setCheck] = useState(false)
|
||||
return (
|
||||
<View className={`bg-white flex-col`} style={{ height: hp("98%") }}>
|
||||
<View className="bg-white flex-1">
|
||||
<TabBar
|
||||
prefix={""}
|
||||
title={"Add Card"}
|
||||
@@ -32,53 +98,79 @@ export default function AddCardScreen() {
|
||||
containerStyle=""
|
||||
suffixAction={() => navigation.goBack()}
|
||||
/>
|
||||
<View className={`flex-1`}>
|
||||
<View className="bg-green-600 mx-4 mb-7 rounded-xl mt-5" style={{ height: hp('25%') }}></View>
|
||||
<View className={`mx-4 mb-5`}>
|
||||
<Text className={`text-xl font-semibold`}>Card Holder Name</Text>
|
||||
<View className={`px-4 border border-gray-300 rounded-xl mt-2`}>
|
||||
<TextInput placeholder='Name'></TextInput>
|
||||
</View>
|
||||
</View>
|
||||
<View className={`mx-4 mb-5`}>
|
||||
<Text className={`text-xl font-semibold`}>Card Number</Text>
|
||||
<View className={`px-4 border border-gray-300 rounded-xl mt-2`}>
|
||||
<TextInput placeholder='Card number'></TextInput>
|
||||
</View>
|
||||
</View>
|
||||
<View className={`flex-row justify-between items-center mx-4`}>
|
||||
<View className={`flex-1 justify-between items-center`}>
|
||||
|
||||
</View>
|
||||
<View className="flex-1 p-4">
|
||||
<View className="mb-6">
|
||||
<Text className="text-lg font-semibold mb-2">Card Details</Text>
|
||||
<Text className="text-gray-500">Enter your card information securely</Text>
|
||||
</View>
|
||||
<View className={`mx-4 mb-3 flex-row gap-4 justify-between items-center`}>
|
||||
<View className={` mt-2 flex-1`}>
|
||||
<Text className={` text-xl font-semibold `}>Expiry Date</Text>
|
||||
<TextInput className={`border border-gray-300 rounded-xl`} placeholder='272'></TextInput>
|
||||
</View>
|
||||
<View className={`mt-2 flex-1`}>
|
||||
<Text className={`text-xl font-semibold`}>CVV</Text>
|
||||
<TextInput className={`border border-gray-300 rounded-xl`} placeholder='30488'></TextInput>
|
||||
</View>
|
||||
</View>
|
||||
<View className={`mx-4 mt-5 flex-row gap-3 items-center`}>
|
||||
<View className={`bg-primary rounded-lg`}>
|
||||
|
||||
<View className="space-y-4">
|
||||
<View>
|
||||
<Text className="text-sm font-medium mb-1">Cardholder Name</Text>
|
||||
<TextInput
|
||||
className="border border-gray-300 rounded-lg p-3"
|
||||
placeholder="John Doe"
|
||||
value={cardholderName}
|
||||
onChangeText={setCardholderName}
|
||||
/>
|
||||
</View>
|
||||
|
||||
<View className={`flex-row items-center gap-3`}>
|
||||
<Checkbox className={`rou`} value={isChecked} onValueChange={setCheck} color={'#704f38'} />
|
||||
<Text className={`text-xl `}>Save Card</Text>
|
||||
<View>
|
||||
<Text className="text-sm font-medium mb-1">Card Number</Text>
|
||||
<TextInput
|
||||
className="border border-gray-300 rounded-lg p-3"
|
||||
placeholder="1234 5678 9012 3456"
|
||||
value={cardNumber}
|
||||
onChangeText={formatCardNumber}
|
||||
keyboardType="numeric"
|
||||
maxLength={19}
|
||||
/>
|
||||
</View>
|
||||
|
||||
<View className="flex-row space-x-4">
|
||||
<View className="flex-1">
|
||||
<Text className="text-sm font-medium mb-1">Expiry Date</Text>
|
||||
<TextInput
|
||||
className="border border-gray-300 rounded-lg p-3"
|
||||
placeholder="MM/YY"
|
||||
value={expiryDate}
|
||||
onChangeText={formatExpiryDate}
|
||||
keyboardType="numeric"
|
||||
maxLength={5}
|
||||
/>
|
||||
</View>
|
||||
<View className="flex-1">
|
||||
<Text className="text-sm font-medium mb-1">CVV</Text>
|
||||
<TextInput
|
||||
className="border border-gray-300 rounded-lg p-3"
|
||||
placeholder="123"
|
||||
value={cvv}
|
||||
onChangeText={setCvv}
|
||||
keyboardType="numeric"
|
||||
maxLength={4}
|
||||
secureTextEntry
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<TouchableOpacity
|
||||
className="bg-primary mt-8 p-4 rounded-lg"
|
||||
onPress={handleAddCard}
|
||||
disabled={isLoading}
|
||||
>
|
||||
<Text className="text-white text-center font-semibold">
|
||||
{isLoading ? 'Adding Card...' : 'Add Card'}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
|
||||
<View className="mt-4">
|
||||
<Text className="text-xs text-gray-500 text-center">
|
||||
Your card details are encrypted and secure. We never store your full card number.
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View className={` bg-white py-3 rounded-tl-2xl border rounded-tr-2xl gap-3 px-4 h-[90px] border-gray-300`}>
|
||||
<TouchableOpacity className={`border rounded-full bg-primary flex-row justify-center items-center `} style={{ height: hp('5%') }}>
|
||||
<Text className={`text-white text-lg font-semibold`}>Add Card</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
|
||||
</View>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user