import React, { useEffect, useRef, useState } from 'react' import { useLanguage, useUtils, useConfig } from 'ordering-components/native' import { useTheme } from 'styled-components/native'; import { OButton, OIcon, OText } from '../shared' import { ActiveOrdersContainer, Card, Map, Information, Logo, OrderInformation, BusinessInformation, Price } from './styles' import { View, StyleSheet, TouchableWithoutFeedback } from 'react-native' import { getGoogleMapImage } from '../../utils' import { ActiveOrdersParams } from '../../types' import { ScrollView as GestureHandlerScrollView } from 'react-native-gesture-handler' export const ActiveOrders = (props: ActiveOrdersParams) => { const { onNavigationRedirect, orders, pagination, loadMoreOrders, getOrderStatus, isPreorders, preordersLength } = props const theme = useTheme() const [{configs}] = useConfig() const [, t] = useLanguage() const [{ parseDate, parsePrice, optimizeImage }] = useUtils() const containerRef = useRef() const handleClickCard = (uuid: string) => { onNavigationRedirect && onNavigationRedirect('OrderDetails', { orderId: uuid }) } const scrollToBegin = () => { containerRef?.current?.scrollTo({x: 0, y: 0, animated: true}) } const scrollToEnd = () => { containerRef?.current?.scrollTo({x: 330 * (orders?.length - preordersLength - pagination.pageSize + 1 || 0), y: 0, animated: true}) } useEffect(() => { scrollToBegin() }, [isPreorders]) useEffect(() => { if(orders.length > 10){ scrollToEnd() } }, [orders.length]) const Order = ({ order }: { order: any }) => ( handleClickCard(order?.uuid)} > {!!(configs?.google_maps_api_key?.value) && ( )} {!!order.business?.logo && ( )} {order.business?.name} {t('ORDER_NUMBER', 'Order No.')} {order.id} {order?.delivery_datetime_utc ? parseDate(order?.delivery_datetime_utc) : parseDate(order?.delivery_datetime, { utc: false })} {parsePrice(order?.summary?.total || order?.total)} {order?.status !== 0 && ( {getOrderStatus(order.status)?.value} )} ) return ( {orders.length > 0 && ( orders.map((order: any) => ( )) )} {!isPreorders && pagination?.totalPages && pagination?.currentPage < pagination?.totalPages && ( )} ) } const styles = StyleSheet.create({ logo: { borderRadius: 10, width: 75, height: '100%' }, orderNumber: { flexDirection: 'row' }, loadOrders: { justifyContent: 'center', alignItems: 'center', minWidth: 230 } })