import React, { useState } from 'react'; import { View, Text, FlatList, TextInput, TouchableOpacity, } from 'react-native'; import { getStyles } from './cartScreen.styles'; import { Header, QuantitySelector, PrimaryButton } from '@components'; import { useAppTheme } from '@theme'; import { useAppDispatch, useAppSelector } from '../../../hooks/useAppDispatch'; import { removeItem, applyCoupon, removeCoupon, selectCartTotal } from '../../../store/cartSlice'; export const CartScreen: React.FC = () => { const { colors } = useAppTheme(); const styles = getStyles(colors); const dispatch = useAppDispatch(); const { items, couponCode } = useAppSelector((state) => state.cart); const totals = useAppSelector(selectCartTotal); const [couponInput, setCouponInput] = useState(''); return (
{}} /> item.id} renderItem={({ item }) => ( {item.item.title} ₹{item.item.price} {}} onDecrement={() => dispatch(removeItem(item.item.id))} /> )} ListFooterComponent={ { if (couponCode) { dispatch(removeCoupon()); setCouponInput(''); } else if (couponInput) { dispatch(applyCoupon(couponInput)); } }} activeOpacity={0.7} > {couponCode ? 'Remove' : 'Apply'} Subtotal ₹{totals.subtotal} Delivery Fee ₹{totals.deliveryFee} Platform Fee ₹{totals.platformFee} {totals.discount > 0 && ( Discount -₹{totals.discount} )} Total ₹{totals.total} } contentContainerStyle={styles.list} /> Total: ₹{totals.total} {}} style={{ flex: 1, marginLeft: 12 }} /> ); };