Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Card payment #18

Merged
merged 4 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions app/AddCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { SafeAreaView, StyleSheet, View } from "react-native";
import React, { useState } from "react";
import { SB_COLOR_SCHEME } from "@/constants";
import { router } from "expo-router";
import { Button } from "@swift-byte/switftbytecomponents";
import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";
import AddCardDetails from "@/components/AddCardDetails";

export default function AddCard() {
return (
<SafeAreaView style={styles.container}>
<KeyboardAwareScrollView style={styles.scrollView}>
<View style={styles.container}>
<View style={{ paddingBottom: 24 }}>
<AddCardDetails />
</View>

<Button
text={"Add"}
type={"primary"}
onPress={() => router.navigate("/PaymentMethod")}
></Button>
</View>
</KeyboardAwareScrollView>
</SafeAreaView>
);
}

const styles = StyleSheet.create({
container: {
padding: 32,
flex: 1,
},
scrollView: {
backgroundColor: "white",
},
title: {
fontSize: 20,
fontWeight: "bold",
color: SB_COLOR_SCHEME.SB_PRIMARY,
},
dFlex: {
display: "flex",
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
},
subtitle: {
fontSize: 15,
fontWeight: "bold",
color: SB_COLOR_SCHEME.SB_PRIMARY,
},
});
24 changes: 17 additions & 7 deletions app/PaymentMethod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import {
View,
TouchableOpacity,
} from "react-native";
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import { SB_COLOR_SCHEME } from "@/constants";
import { Card, myCards } from "@/mock_data";
import RadioOutline from "../assets/icons/icon-radio-outline.svg";
import RadioFilled from "../assets/icons/icon-radio-filled.svg";
import AddCard from "../assets/icons/logo-add-card.svg";
import { Link } from "expo-router";
import { Link, router } from "expo-router";
import { Button } from "@swift-byte/switftbytecomponents";
import {
NavigationProp,
Expand All @@ -30,15 +30,20 @@ interface PaymentProps {
}

export default function PaymentMethod({ route, navigation }: PaymentProps) {
const [cards, setCards] = useState<Card[]>(myCards);
const [selectedCard, setSelectedCard] = useState<Card>(myCards[0]);

useEffect(() => {
setCards(myCards)
}, [])

return (
<SafeAreaView style={styles.container}>
<ScrollView style={styles.scrollView}>
<View style={styles.container}>
<View style={{ paddingBottom: 24 }}>
<View>
{myCards.map((card) => {
{cards.map((card: Card) => {
return (
<View
key={card.id}
Expand All @@ -56,7 +61,9 @@ export default function PaymentMethod({ route, navigation }: PaymentProps) {
<PaypalLogo />
)}
</View>
<Text>**** {card.last3Digits}</Text>
<Text>
{card.cardNumber.toString().replace(/.(?=.{3})/g, "*")}
</Text>
</View>
<TouchableOpacity onPress={() => setSelectedCard(card)}>
<RadioOutline
Expand All @@ -77,18 +84,21 @@ export default function PaymentMethod({ route, navigation }: PaymentProps) {
);
})}
</View>
<View style={[styles.dFlex, { justifyContent: "flex-start" }]}>
<TouchableOpacity
style={[styles.dFlex, { justifyContent: "flex-start" }]}
onPress={() => router.navigate("/AddCard")}
>
<AddCard style={{ marginRight: 16 }} />
<Text>New payment method</Text>
</View>
</TouchableOpacity>
</View>

<Link href="/success" asChild>
<Button
text={"Pay Now"}
type={"primary"}
onPress={function (): void {
console.log("pressed");
// router.navigate({ pathname: '/success', params: { type: ''}})
}}
></Button>
</Link>
Expand Down
29 changes: 19 additions & 10 deletions app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,11 @@ function RootLayoutNav() {

return (
<ThemeProvider value={colorScheme === "dark" ? DarkTheme : DefaultTheme}>
<Stack>
<Stack initialRouteName="welcome">
<Stack.Screen name="Reviews"/>
<Stack.Screen name="welcome" options={{ headerShown: false }} />
<Stack.Screen
name="signIn"
options={{ headerShown: false }}
/>
<Stack.Screen
name="signUp"
options={{ headerShown: false }}
/>
<Stack.Screen name="signIn" options={{ headerShown: false }} />
<Stack.Screen name="signUp" options={{ headerShown: false }} />
<Stack.Screen name="onboarding" options={{ headerShown: false }} />
<Stack.Screen name="(tabs)" options={{ headerShown: false }} />
<Stack.Screen
Expand All @@ -89,6 +83,7 @@ function RootLayoutNav() {
},
}}
/>

<Stack.Screen
name="delivery"
options={{
Expand All @@ -112,7 +107,21 @@ function RootLayoutNav() {
},
}}
/>
<Stack.Screen name="notifications" options={{ presentation: "modal", headerTitle: 'Notifications' }} />
<Stack.Screen
name="AddCard"
options={{
title: "Add Card",
headerTintColor: SB_COLOR_SCHEME.SB_PRIMARY,
headerBackTitle: "Back",
contentStyle: {
backgroundColor: "white",
},
}}
/>
<Stack.Screen
name="notifications"
options={{ presentation: "modal", headerTitle: "Notifications" }}
/>
<Stack.Screen
name="success"
options={{ presentation: "modal", headerShown: false }}
Expand Down
72 changes: 72 additions & 0 deletions components/AddCardDetails.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { SB_COLOR_SCHEME } from "@/constants";
import React from "react";
import { View, Text, TextInput, StyleSheet } from "react-native";

const AddCardDetails = () => {
return (
<View style={styles.card}>
<Text style={styles.label}>Name</Text>
<TextInput
style={styles.input}
placeholder="e.g. John Smith"
// value={name}
// onChangeText={setName}
/>
<Text style={styles.label}>Card Number</Text>
<TextInput
style={styles.input}
placeholder="XXXX XXXX XXXX XXXX"
// value={cardNumber.toString()}
keyboardType="numeric"
maxLength={16}
// onChangeText={(input) => setCardNumber(parseInt(input))}
/>
<View style={styles.row}>
<View style={{ flex: 1 }}>
<Text style={styles.label}>CVV</Text>
<TextInput style={styles.smallInput} placeholder="XXX" />
</View>
<View style={{ flex: 1 }}>
<Text style={styles.label}>Expiry Date</Text>
<TextInput style={styles.smallInput} placeholder="dd/mm/yyyy" />
</View>
</View>
</View>
);
};

const styles = StyleSheet.create({
card: {
backgroundColor: "#fff",
borderRadius: 10,
flex: 1,
},
label: {
fontSize: 15,
fontWeight: "bold",
color: SB_COLOR_SCHEME.SB_PRIMARY,
marginBottom: 10,
},
input: {
fontSize: 16,
padding: 15,
borderRadius: 10,
marginBottom: 20,
borderColor: "#BBC5C1",
borderWidth: 1,
},
row: {
flexDirection: "row",
gap: 10,
flex: 1,
},
smallInput: {
fontSize: 16,
padding: 15,
borderRadius: 10,
borderColor: "#BBC5C1",
borderWidth: 1,
},
});

export default AddCardDetails;
52 changes: 38 additions & 14 deletions mock_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ export interface Customer {
phone: string;
}

export interface User {
id: string;
firstName: string;
lastName: string;
email: string;
phone: string;
address: string;
password: string;
isMember: string;
cards: Card[];
}

export interface Payment {
id: string;
amount: number;
Expand All @@ -64,9 +76,11 @@ export interface Cart {

export interface Card {
id: number,
type: string,
last3Digits: number,
title: string
name: string;
cardNumber: number;
cvv: number;
expiryDate: string; // dd/mm/yyyy
type: 'visa' | 'master' | 'paypal' // visa, master, or paypal
}

export interface Order {
Expand Down Expand Up @@ -286,23 +300,29 @@ export const promoCode = [
export const myCards: Card[] = [
{
id: 1,
type: 'visa',
last3Digits: 4567,
title: ''
name: "John Doe",
cardNumber: 1234567890123456,
cvv: 123,
expiryDate: "12/25/2024",
type: "visa"
},
{
id: 2,
type: 'master',
last3Digits: 7890,
title: 'Credit Card'
name: "Alice Smith",
cardNumber: 9876543210987654,
cvv: 456,
expiryDate: "06/27/2023",
type: "master"
},
{
id: 3,
type: 'paypal',
last3Digits: 2345,
title: 'Paypal'
name: "Bob Johnson",
cardNumber: 4567890123456789,
cvv: 789,
expiryDate: "09/30/2025",
type: "paypal"
}
]
];

export const customers: Customer[] = [
{
Expand Down Expand Up @@ -402,4 +422,8 @@ export const notifications = [
isNew: true,
},

]
]

// export currentUser: User = {

// }
Loading