import React, { useEffect, useState } from 'react';
import { View, StyleSheet, ScrollView, Dimensions, TouchableOpacity, Platform } from 'react-native';
import { Placeholder, PlaceholderLine, Fade } from 'rn-placeholder';
import { useTheme } from 'styled-components/native';
import { SearchBar } from '../SearchBar';
import {
ToastType,
useToast,
useLanguage,
StoreProductList
} from 'ordering-components/native';
import { NotFoundSource } from '../NotFoundSource';
import { OText, OIcon } from '../shared';
import { IterateCategories } from './IterateCategories';
import { ProductList } from './ProductList'
const BusinessProductListUI = (props: any) => {
const {
navigation,
businessState,
productsList,
updateStoreCategory,
updateStoreProduct,
productSearch,
categorySearch,
handleChangeCategory,
handleChangeProductSearch,
handleChangeCategorySearch,
getCategoryProducts,
categories
} = props;
const { loading, error, business } = businessState;
const [, t] = useLanguage();
const [, { showToast }] = useToast();
const theme = useTheme();
const [showModal, setShowModal] = useState(false)
const handleOpenProducts = (category: any) => {
handleChangeCategory(category)
setShowModal(true)
}
useEffect(() => {
if (error) {
showToast(
ToastType.Error,
error || error[0] || t('NETWORK_ERROR', 'Network Error'),
);
}
}, [loading]);
const styles = StyleSheet.create({
container: {
paddingBottom: 20,
marginBottom: 0,
flex: 1,
},
header: {
flexDirection: 'row',
justifyContent: 'space-between',
marginBottom: 10,
},
sectionTitle: {
fontStyle: 'normal',
fontWeight: '600',
fontSize: 20,
color: theme.colors.textGray,
},
borderStyle: {
borderColor: theme.colors.red,
borderWidth: 0,
borderRadius: 10,
},
btnBackArrow: {
borderWidth: 0,
width: 32,
height: 32,
tintColor: theme.colors.textGray,
backgroundColor: theme.colors.clear,
borderColor: theme.colors.clear,
shadowColor: theme.colors.clear,
paddingLeft: 0,
paddingRight: 0
},
});
return (
<>
navigation?.canGoBack() && navigation.goBack()}
style={styles.btnBackArrow}
>
{t('CATEGORIES', 'Categories')}
handleChangeCategorySearch('')}
placeholder={t('SEARCH', 'Search')}
containerStyle={{ width: 180 }}
/>
{!loading && categories?.length === 0 && (
)}
{!error && !loading && categories?.length > 0 && (
)}
{loading && (
{[...Array(6)].map((item, i) => (
))}
)}
{showModal && (
setShowModal(false)}
/>
)}
>
);
};
export const BusinessProductList = (props: any) => {
const businessProductListProps = {
...props,
UIComponent: BusinessProductListUI,
isIos: Platform.OS === 'ios'
};
return ;
};