import React, { useState, useEffect } from 'react';
import {
StyleSheet,
TouchableOpacity,
ScrollView,
View,
Dimensions,
} from 'react-native';
import MaterialIcon from 'react-native-vector-icons/MaterialIcons';
import { Placeholder, PlaceholderLine, Fade } from 'rn-placeholder';
import { useTheme } from 'styled-components/native';
import {
Contacts as ContactsController,
useLanguage,
useUtils,
} from 'ordering-components/native';
import { Card, Logo, Information, Header, Badge, Stars } from './styles';
import { NotFoundSource } from '../NotFoundSource';
import { OIcon, OText, OButton } from '../shared';
import { ContactParams } from '../../types';
const ContactsUI = (props: ContactParams) => {
const {
contacts: { data, loading, error },
activeTag,
pagination,
getBusinesses,
getCustomers,
getDrivers,
loadMore,
onNavigationRedirect,
} = props;
const [, t] = useLanguage();
const theme = useTheme();
const [{ parseDate, optimizeImage }] = useUtils();
const [orientation, setOrientation] = useState(
Dimensions.get('window').width < Dimensions.get('window').height
? 'Portrait'
: 'Landscape',
);
const handlePressOrder = (order: any) => {
const uuid = order?.id;
onNavigationRedirect &&
onNavigationRedirect('OrderMessage', { orderId: uuid });
};
useEffect(() => {
if (!loading) {
switch (activeTag) {
case 2:
getBusinesses && getBusinesses();
break;
case 3:
getCustomers && getCustomers();
break;
case 4:
getDrivers && getDrivers();
break;
}
}
}, [activeTag]);
Dimensions.addEventListener('change', ({ window: { width, height } }) => {
if (width < height) {
setOrientation('Portrait');
} else {
setOrientation('Landscape');
}
});
const styles = StyleSheet.create({
btnCard: {
flex: 1,
minHeight: 64,
marginBottom: 30,
},
icon: {
borderRadius: 7.6,
width: 73,
height: 73,
},
name: {
fontFamily: 'Poppins',
fontStyle: 'normal',
fontWeight: '600',
fontSize: 18,
color: theme.colors.textGray,
},
badge: {
fontFamily: 'Poppins',
fontStyle: 'normal',
fontWeight: 'normal',
fontSize: 14,
color: theme.colors.primary,
},
star: {
fontFamily: 'Poppins',
fontStyle: 'normal',
fontWeight: 'normal',
fontSize: 15,
color: theme.colors.unselectText,
},
order: {
fontFamily: 'Poppins',
fontStyle: 'normal',
fontWeight: 'normal',
color: theme.colors.orderTypeColor,
},
btn: {
borderRadius: 7.6,
height: 44,
marginBottom: 40,
marginTop: 5,
},
btnText: {
color: theme.colors.white,
fontFamily: 'Poppins',
fontStyle: 'normal',
fontWeight: 'normal',
fontSize: 18,
},
});
return (
<>
{data?.length > 0 &&
data?.map((contact: any) => (
handlePressOrder(contact)}
onPress={() => {}}
style={styles.btnCard}
activeOpacity={1}>
{contact?.name + ' ' + (contact?.lastname ?? '')}
{contact?.unread_count > 0 && (
{contact?.unread_count}
)}
{[
...Array(
Number.isInteger(contact?.qualification)
? contact?.qualification ?? 3
: Math.floor(contact?.qualification) || 3,
),
].map((item, index) => (
))}
{[
...Array(
(Number.isInteger(contact?.qualification)
? contact?.qualification ?? 3
: Math.ceil(contact?.qualification) || 3) -
(Number.isInteger(contact?.qualification)
? contact?.qualification ?? 3
: Math.floor(contact?.qualification) || 3),
),
].map((item, index) => (
))}
{[
...Array(
5 -
(Number.isInteger(contact?.qualification)
? contact?.qualification ?? 3
: Math.ceil(contact?.qualification) || 3),
),
].map((item, index) => (
))}
{contact?.level === 4
? contact?.assigned_orders_count
: contact?.level === 3
? contact?.assigned_orders_count || ''
: ''}{' '}
{t('ORDERS', 'Orders')}
))}
{!loading && data?.length === 0 && (
)}
{loading && (
<>
{[...Array(5)].map((item, i) => (
))}
>
)}
{!loading && pagination?.currentPage < pagination?.totalPages && (
loadMore && loadMore(activeTag)}
text={t('LOAD_MORE', 'Load more')}
imgRightSrc={null}
textStyle={styles.btnText}
style={styles.btn}
bgColor={theme.colors.primary}
borderColor={theme.colors.primary}
/>
)}
>
);
};
export const Contacts = (props: ContactParams) => {
const contactProps = {
...props,
firstFetch: 'businesses',
paginationSettings: {
page: 1,
pageSize: 6,
controlType: 'infinity',
},
orderBy: 'name',
orderDirection: 'asc',
UIComponent: ContactsUI,
};
return ;
};