1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
import React, { useContext } from 'react';
import { View, Text, Button, StyleSheet, ScrollView } from 'react-native';
import { CartContext } from '../../context/CartContext';
import emailService from '../../services/emailService';
const CheckoutScreen = ({ navigation }) => {
const { cart } = useContext(CartContext);
const handlePayment = async () => {
// Simulate payment processing
alert('Payment successful!');
await emailService.sendInvoice(cart);
navigation.navigate('Invoice');
};
const totalAmount = cart.reduce((total, item) => total + item.price * item.quantity, 0);
return (
<ScrollView contentContainerStyle={styles.container}>
<Text style={styles.title}>Checkout</Text>
{cart.map((item, index) => (
<View key={index} style={styles.itemContainer}>
<Text style={styles.itemText}>{item.name}</Text>
<Text style={styles.priceText}>${(item.price * item.quantity).toFixed(2)}</Text>
</View>
))}
<View style={styles.totalContainer}>
<Text style={styles.totalText}>Total: ${totalAmount.toFixed(2)}</Text>
</View>
<View style={styles.buttonContainer}>
<Button title="Confirm and Pay" onPress={handlePayment} />
</View>
</ScrollView>
);
};
const styles = StyleSheet.create({
container: {
padding: 16,
backgroundColor: '#f8f9fa',
},
title: {
fontSize: 24,
fontWeight: 'bold',
marginBottom: 20,
textAlign: 'center',
},
itemContainer: {
backgroundColor: '#ffffff',
padding: 16,
borderRadius: 8,
marginBottom: 12,
elevation: 2,
shadowColor: '#000',
shadowOpacity: 0.2,
shadowRadius: 3,
shadowOffset: { width: 1, height: 2 },
},
itemText: {
fontSize: 18,
color: '#333',
},
priceText: {
fontSize: 16,
color: '#888',
},
totalContainer: {
marginTop: 20,
padding: 16,
backgroundColor: '#ffffff',
borderRadius: 8,
elevation: 2,
shadowColor: '#000',
shadowOpacity: 0.2,
shadowRadius: 3,
shadowOffset: { width: 1, height: 2 },
},
totalText: {
fontSize: 20,
fontWeight: 'bold',
textAlign: 'center',
color: '#333',
},
buttonContainer: {
marginTop: 20,
borderRadius: 8,
},
});
export default CheckoutScreen;
|