From a179edeee5909e05477f48ba7dd5cc1ad84decd9 Mon Sep 17 00:00:00 2001 From: Juthatip McDevitt Date: Fri, 26 Jul 2024 22:35:00 -0500 Subject: [PATCH] created recepit page --- donutshop/app/components/OrderReceiptCard.tsx | 60 +++++++++++++++++++ donutshop/app/components/OrderReceiptItem.tsx | 53 ++++++++++++++++ donutshop/app/screen/OrderReceipt.tsx | 46 ++++++++++++-- donutshop/app/screen/Payment.tsx | 27 ++++++++- 4 files changed, 180 insertions(+), 6 deletions(-) create mode 100644 donutshop/app/components/OrderReceiptCard.tsx create mode 100644 donutshop/app/components/OrderReceiptItem.tsx diff --git a/donutshop/app/components/OrderReceiptCard.tsx b/donutshop/app/components/OrderReceiptCard.tsx new file mode 100644 index 0000000..b75354f --- /dev/null +++ b/donutshop/app/components/OrderReceiptCard.tsx @@ -0,0 +1,60 @@ +import { Pressable, StyleSheet, Text, View } from 'react-native'; +import React from 'react'; +import OrderReceiptItem from '../components/OrderReceiptItem'; + + +interface OrderHistoryCardProps { + navigationHandler: any; + CartList: any; + CartListPrice: string; + OrderDate: string; +} + +const OrderReceiptCard: React.FC = ({ + navigationHandler, + CartList, + CartListPrice, + OrderDate, +}) => { + + return ( + + + + Order Time + {OrderDate} + + + Total Amount + $ {CartListPrice} + + + + + + {CartList.map((data: any, index: any) => ( + { + navigationHandler({ + index: data.index, + id: data.id, + type: data.type, + }); + }}> + + + ))} + + + ) +} + +export default OrderReceiptCard + +const styles = StyleSheet.create({}) \ No newline at end of file diff --git a/donutshop/app/components/OrderReceiptItem.tsx b/donutshop/app/components/OrderReceiptItem.tsx new file mode 100644 index 0000000..78553b1 --- /dev/null +++ b/donutshop/app/components/OrderReceiptItem.tsx @@ -0,0 +1,53 @@ +import { Image, ImageProps, StyleSheet, Text, View } from 'react-native' +import React from 'react' + + +interface OrderReceiptItemProps{ + type: string; + name: string; + donutname: string; + image_item: ImageProps; + prices: any; + ItemPrice: string; + } + + +const OrderReceiptItem: React.FC = ({ + type, + name, + donutname, + image_item, + prices, + ItemPrice, +}) => { + return ( + + + + + {prices.map((item: any, index: any) => ( + + {name || donutname} {item.size} + + ))} + + + ${ItemPrice} + + + {prices.map((data: any, index: any) => ( + + + ${data.price} + X {data.quantity} + + ${(data.quantity * data.price).toFixed(2).toString()} + + ))} + + ) +} + +export default OrderReceiptItem + +const styles = StyleSheet.create({}) \ No newline at end of file diff --git a/donutshop/app/screen/OrderReceipt.tsx b/donutshop/app/screen/OrderReceipt.tsx index 81dc8e5..00e6049 100644 --- a/donutshop/app/screen/OrderReceipt.tsx +++ b/donutshop/app/screen/OrderReceipt.tsx @@ -1,10 +1,46 @@ -import { View, Text } from 'react-native' -import React from 'react' +import { View, Text, ScrollView, Image } from 'react-native'; +import React from 'react'; +import { useStore } from '../store/store'; +import OrderReceiptCard from '../components/OrderReceiptCard'; + + + + +const OrderReceipt = ({navigation}: any) => { + const ReceiptList = useStore((state: any) => state.ReceiptList); + const navigationHandler = ({index, id, type}: any) => { + navigation.push('detail', { + index, + id, + type, + }); + }; + -const OrderReceipt = () => { return ( - - OrderHistory + + + + Receipt + {ReceiptList.length == 0 ? ( + + + + ):( + + {ReceiptList.map((data: any, index: any) => ( + + ))} + + )} + + ) } diff --git a/donutshop/app/screen/Payment.tsx b/donutshop/app/screen/Payment.tsx index 5a8a9f0..039cb11 100644 --- a/donutshop/app/screen/Payment.tsx +++ b/donutshop/app/screen/Payment.tsx @@ -4,6 +4,7 @@ import { Ionicons } from '@expo/vector-icons'; import PaymentOption from "../components/PaymentOption"; import PaymentFooter from "../components/PaymentFooter"; import { LinearGradient } from 'expo-linear-gradient'; +import { useStore } from '../store/store'; const PaymentOptionList = [ @@ -29,10 +30,34 @@ const PaymentOptionList = [ const Payment = ({navigation, route}: any) => { + const calculateCartPrice = useStore((state: any) => state.calculateCartPrice); + const addToReceiptList = useStore(((state: any) => state.addToReceiptList)); + const [paymentMethod, setPaymentMenthod] = useState('Credit card'); + const [showApprove, setShowApprove] = useState(false); + + + const buttonPressHandler = () => { + setShowApprove(true); + addToReceiptList(); + calculateCartPrice(); + setTimeout(() => { + setShowApprove(false); + navigation.navigate('receipt') + }, 3000) + }; return ( + {showApprove ? ( + + + Approved! + Thank you for your order! + + ) : ( + <> + )} {navigation.pop()}}> @@ -71,7 +96,7 @@ const Payment = ({navigation, route}: any) => { {}} + buttonPressHandler={buttonPressHandler} /> )