import React, { useState } from 'react' import { AwesomeModal } from '../../organisms/AwesomeModal' import { Button, Column, Icon, Row, Text } from '../../atoms' import { EmptyData, type Methods, Pagination, SearchBar, Skeleton, Stepper } from '../../molecules' import type { Data, ProductFood } from './types' import { MiniCardProduct } from '../../organisms/MiniCardProduct' import { getGlobalStyle } from '../../../helpers' import { AsideSales } from './AsideSales' import { CategoriesProducts, VirtualizedList } from '../../organisms' import type { MiniCardProductProps } from '../../organisms/MiniCardProduct/type' import type { Root } from '../../organisms/CategorieProducts/types' import { HeaderInfo } from './HeaderInfo' import styles from './styles.module.css' import { SwipeableCard } from '../../molecules/SwipeableCard' import { ProductsSales } from './components/products-sales' import InputHooks from '../../molecules/Inputs/InputHooks/InputHooks' import Sorter, { SortOption } from '../../molecules/Sorter' import { MODAL_SIZES } from '../../molecules/Modal/helpers' import { Query, Sort } from './components/querys' interface IpropsSliderCategory { data: Root[] handleChangeCheck: (id: string) => void breakpoints: Record< string, { slidesPerView: number | string spaceBetween: number | string } > } interface Client { clientName: string ccClient: string ClientAddress: string clientNumber: string } interface GenerateSalesProps { productsFood?: ProductFood[] pagination: { currentPage: number totalPages: number } storeTables: any[] show: boolean loadingProduct: boolean client: Client propsSliderCategory?: IpropsSliderCategory openAside: boolean loadingClients: boolean totalProductPrice: string isLoading: boolean data?: Data values?: { cliId: string change: string ValueDelivery: string tableId: string } errors?: { change: boolean ValueDelivery: boolean } paymentMethods?: Methods[] dataClientes?: any[] handleClickAction?: () => void handleAddProduct?: (product: ProductFood) => void handleChange?: (e: React.ChangeEvent) => void dispatch?: React.Dispatch fetchMoreProducts?: () => void handlePageChange?: (pageNumber: number | string) => void handleDecrement?: (product: ProductFood) => void handleFreeProducts?: (product: ProductFood) => void handleSave?: () => void handleChangeFilter: (value: string, event?: React.ChangeEvent) => void handleOpenAside?: () => void handleComment?: (product: ProductFood) => void onClick?: () => void numberFormat?: (number: string | number) => number setShow?: React.Dispatch> } export const GenerateSales: React.FC = ({ productsFood = [], dataClientes = [], storeTables = [], paymentMethods = [], propsSliderCategory = { data: [] }, data = { PRODUCT: [], counter: 0, getOneTags: { nameTag: '' }, payId: '' }, values = { cliId: '', change: '', ValueDelivery: '', tableId: '' }, totalProductPrice = 0, errors = { change: false, ValueDelivery: false }, pagination = { currentPage: 1, totalPages: 0 }, show = false, openAside = false, isLoading = false, loadingClients = false, dataFilter, client = { clientName: '', ccClient: '', ClientAddress: '', clientNumber: '' }, dispatch = () => { }, setActiveFilter = () => { }, activeFilter = () => { }, handleFreeProducts = () => { }, onClick = (product: MiniCardProductProps) => { return product }, handlePageChange = () => { }, handleChange = () => { }, setShow = () => { }, handleDecrement = () => { }, handleSave = () => { }, handleComment = () => { }, handleOpenAside = () => { }, handleChangeFilter = () => { }, numberFormat = (number) => { return number }, handleAddProduct = (product: ProductFood) => { return product } }) => { const findChecked = propsSliderCategory.data?.some((item) => Boolean(item?.checked) ) const fields = [ { key: 'name', label: 'Nombre', defaultDirection: 'asc' }, { key: 'created_at', label: 'Fecha de creación', defaultDirection: 'desc' }, { key: 'price', label: 'Precio', defaultDirection: 'asc' } ] as SortOption[] const [sort, setSort] = useState({ field: 'name', direction: 'asc' }) const [showFilter, setShowFilter] = useState(false) return ( { setShow(false) }} zIndex={getGlobalStyle('--z-index-high')} > { setShowFilter(false) }} zIndex={getGlobalStyle('--z-index-high')} >
{ return handleChangeFilter(value, event as any) }} padding='0px 20px' placeholder='Buscar producto por nombre o código' />
setShowFilter(true)} onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault() setShowFilter(true) } }} data-test-id='filter-advanced' style={{ backgroundColor: '#fcebea', border: showFilter ? '1px solid #fcebea' : '1px solid transparent', }} > Filtros
Limpiar
} render={(product) => { const tag = { tag: product?.getOneTags?.nameTag }; const isExistInSale = Boolean(product?.existsInSale); const manageStock = Boolean(product?.manageStock) const ProPrice = product.ProPrice return ( { dispatch({ type: 'ADD_TO_CART', payload: product }) }} handleDecrement={() => { handleDecrement(product) }} handleIncrement={() => { handleAddProduct(product) }} pName={product.pName} tag={product?.getOneTags?.nameTag !== null && tag} withStock={true} /> ) }} /> { return handlePageChange(pagination.currentPage + 1) }} handleOnClick={(pageNumber) => { return handlePageChange(pageNumber) }} handlePrevPage={() => { return handlePageChange(pagination.currentPage - 1) }} isVisableButtonLeft={pagination.currentPage > 1} isVisableButtonRight={pagination.currentPage < pagination.totalPages} isVisableButtons={Boolean(pagination?.totalPages ?? 0 > 1)} items={Array.from({ length: pagination.totalPages ?? 0 }, (_, index) => { return index + 1 })} />
0 ? 'grid' : 'block' }} >
{data?.counter > 99 ? '+99' : data?.counter ?? 0}
{totalProductPrice}
) }