import React, { useState, useEffect } from 'react' import { useLanguage, useToast, ToastType, ReviewProduct as ReviewProductController } from 'ordering-components/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('MyOrders') } } }, [formState]) useEffect(() => { const _changes = order?.products.map(product => { return { product_id: product?.product_id, comment: '', qualification: 5 } }) handleChangeFormState(_changes) }, []) return ( <> onNavigationRedirect('MyOrders')} showCall={false} btnStyle={{ paddingLeft: 0 }} paddingTop={0} /> {order?.products.map((product: any) => ( ))} (order?.driver && !order?.user_review) ? onNavigationRedirect('ReviewDriver', { order: order }) : onNavigationRedirect('MyOrders')} > {t('FRONT_VISUALS_SKIP', 'Skip')} handleContinueClick()} /> ) } export const ReviewProducts = (props: any) => { const reviewProductProps = { ...props, UIComponent: ReviewProductsUI, isToast: true } return }