import React, { useState, useEffect } from 'react' import { useLanguage, useToast, ToastType, ReviewProduct as ReviewProductController } from 'ordering-components-external/native' import { OText, OButton } from '../shared' import NavBar from '../NavBar' import { ReviewProductParams } from '../../types' import { FloatingBottomContainer } from '../../layouts/FloatingBottomContainer' import { useTheme } from 'styled-components/native' import { SingleProductReview } from '../SingleProductReview' import { ReviewProductsContainer, ActionContainer, SkipButton } from './styles' const ReviewProductsUI = (props: ReviewProductParams) => { const { navigation, order, onNavigationRedirect, formState, handleChangeFormState, handleSendProductReview } = props const [, t] = useLanguage() const theme = useTheme() const [, { showToast }] = useToast() const [isProductReviewed, setIsProductReviewed] = useState(false) const [alertState, setAlertState] = useState<{ open: boolean, content: Array, success?: boolean }>({ open: false, content: [], success: false }) const handleContinueClick = () => { setAlertState({ ...alertState, success: true }) handleSendProductReview() } useEffect(() => { if (alertState.open) { alertState.content && showToast( ToastType.Error, alertState.content ) } }, [alertState.content]) useEffect(() => { if (!formState.loading && formState.result?.error) { setAlertState({ open: true, success: false, content: formState.result?.result || [t('ERROR', 'Error')] }) } if (!formState.loading && !formState.result?.error && alertState.success) { setIsProductReviewed && setIsProductReviewed(true) if (order?.driver && !order?.user_review) { onNavigationRedirect('ReviewDriver', { order: order }) } else { onNavigationRedirect('BottomTab', { screen: 'MyOrders' }) } } }, [formState]) return ( <> onNavigationRedirect('BottomTab', { screen: 'MyOrders' })} showCall={false} btnStyle={{ paddingLeft: 0 }} style={{ flexDirection: 'column', alignItems: 'flex-start' }} titleWrapStyle={{ paddingHorizontal: 0 }} titleStyle={{ marginRight: 0, marginLeft: 0 }} /> {order?.products && order.products.length > 0 && order?.products.map(productsOrder => ( productsOrder?.length ? productsOrder?.map((product: any, i: any) => !product?.deleted ? : null ) : (!productsOrder?.deleted ? ( ) : null ) ))} (order?.driver && !order?.user_review) ? onNavigationRedirect('ReviewDriver', { order: order }) : onNavigationRedirect('BottomTab', { screen: 'MyOrders' }) } > {t('FRONT_VISUALS_SKIP', 'Skip')} handleContinueClick()} /> ) } export const ReviewProducts = (props: any) => { const reviewProductProps = { ...props, UIComponent: ReviewProductsUI, isToast: true } return }