aboutsummaryrefslogblamecommitdiffstats
path: root/src/screens/Checkout/CheckoutScreen.js
blob: 4cd89383e5c4f62e6a5db170e9c8b5029469de2f (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
                                          
                                                                          












                                                        

                                                                                          
          

                                                         
                                  



                                                                                          
         






                                                                              


    




















































                                          
                              
 
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;