import React, { useEffect } from 'react' import { useLanguage, useUtils, useToast, ToastType, useConfig, MultiOrdersDetails as MultiOrdersDetailsController } from 'ordering-components-external/native' import { View, StyleSheet, BackHandler, TouchableOpacity } from 'react-native' import { useTheme } from 'styled-components/native' import { OText, OButton } from '../shared' import { Placeholder, PlaceholderLine, Fade } from 'rn-placeholder' import { SingleOrderCard } from './SingleOrderCard' import AntDesignIcon from 'react-native-vector-icons/AntDesign' import { getOrderStatus } from '../../utils' import { OrdersDetailsContainer, Header, Divider, Section, Customer, InfoBlock, Row, OrdersSummary, BorderLine, StaturBar } from './styles' import { NotFoundSource } from '../NotFoundSource' import LinearGradient from 'react-native-linear-gradient' export const MultiOrdersDetailsUI = (props: any) => { const { navigation, customer, paymentEvents, ordersSummary, isFromMultiCheckout } = props const theme = useTheme() const styles = StyleSheet.create({ btnBackArrow: { borderWidth: 0, backgroundColor: theme.colors.clear, shadowColor: theme.colors.clear, padding: 0, marginLeft: -20 }, statusBar: { height: 12, } }) const { loading, orders, error } = props.ordersList const [, t] = useLanguage() const [{ parsePrice, parseNumber, parseDate }] = useUtils(); const [, { showToast }] = useToast(); const [{ configs }] = useConfig() const isTaxIncludedOnPrice = orders.every((_order: any) => _order.taxes?.length ? _order.taxes?.every((_tax: any) => _tax.type === 1) : true) const deliveryType = orders.find((order: any) => order.delivery_type)?.delivery_type const progressBarStyle = configs.multi_business_checkout_progress_bar_style?.value const showBarInOrder = ['group', 'both'] const showBarInIndividual = ['individual', 'both'] const walletName: any = { cash: { name: t('PAY_WITH_CASH_WALLET', 'Pay with Cash Wallet') }, credit_point: { name: t('PAY_WITH_CREDITS_POINTS_WALLET', 'Pay with Credit Points Wallet') } } const handleArrowBack: any = () => { if (!isFromMultiCheckout) { navigation?.canGoBack() && navigation.goBack(); return; } navigation.navigate('BottomTab'); return true } const handleGoToOrderDetails = (uuid: any) => { navigation.navigate('OrderDetails', { orderId: uuid }) } useEffect(() => { if (error) { showToast(ToastType.Error, error) } }, [error]) useEffect(() => { BackHandler.addEventListener('hardwareBackPress', handleArrowBack) return () => { BackHandler.removeEventListener('hardwareBackPress', handleArrowBack) } }, []) return ( handleArrowBack()} icon={AntDesignIcon} useArrow iconProps={{ name: 'arrowleft', size: 26 }} />
{loading ? ( ) : ( <> {t('HEY', 'Hey')} {customer?.name} {customer?.lastname} {t('ORDER_MESSAGE_HEADER_TEXT', 'Once business accepts your order, we will send you an email, thank you!')} )}
{t('CUSTOMER_DETAILS', 'Customer Details')} {loading ? ( ) : ( {customer?.name} {customer?.lastname} {customer?.address} {customer?.cellphone} )}
{t('PAYMETHOD', 'Payment method')} {paymentEvents.map((event: any) => ( {event?.wallet_event ? walletName[event?.wallet_event?.wallet?.type]?.name : t(event?.paymethod?.name.toUpperCase()?.replace(/ /g, '_'), event?.paymethod?.name)} ))}
{deliveryType === 1 && ( <>
{t('DELIVERYA_V21', 'Delivery address')} {loading ? ( ) : ( {customer?.address} )}
)} {loading ? ( ) : ( {t('ORDER_SUMMARY', 'Order summary')} {(showBarInOrder.includes(progressBarStyle)) && ( )} {getOrderStatus(orders[0]?.status, t)?.value} {orders.map((order: any) => ( {t('ORDER', 'Order')} #{order.id} {parsePrice(order?.summary?.total ?? order?.total)} ))} {!isTaxIncludedOnPrice && ( <> {t('TOTAL_BEFORE_TAX', 'Total before tax')}: {parsePrice(ordersSummary?.subtotal)} {t('ESTIMATED_TAX_TO_BE_COLLECTED', 'Estimated tax to be collected')}: {parsePrice(ordersSummary?.tax)} )} {t('PAYMENT_TOTAL', 'Payment total')}: {parsePrice(ordersSummary?.total)} )} {loading ? ( [...Array(3).keys()].map(i => ( )) ) : ( <> {orders.map((order: any) => ( ))} )} {!loading && (error || orders?.length === 0) && ( error?.includes('ERROR_ACCESS_EXPIRED') ? ( ) : ( ) )}
) } export const MultiOrdersDetails = (props: any) => { const MultiOrdersDetails = { ...props, UIComponent: MultiOrdersDetailsUI } return }