import React, { Component } from 'react'
import {
StyleSheet, View, PixelRatio, Text, RefreshControl,
FlatList, ProgressBarAndroid, ProgressViewIOS, Alert, StatusBar
} from 'react-native'
import BaseScreen from './../BaseScreen'
import { responsiveHeight, responsiveWidth } from 'react-native-responsive-dimensions'
import { listAllMembers } from './../../webservice/MemberGeolocatedApi'
import { listFreeCodesSuperViseur } from './../../webservice/NetworkApi'
import { readUser, listDemandAdhesion, acceptDemandAdhesion, deleteUser } from "../../webservice/AuthApi";
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import Icons from 'react-native-vector-icons/Ionicons'
import Swipeout from 'react-native-swipeout'
import { theme } from "../BaseScreen";
require("./../../utils/Translations");
import I18n from 'react-native-i18n'
const route = require('./../../route.json')
import LottieView from 'lottie-react-native'; // if you have "esModuleInterop": true
import { IndicatorViewPager, PagerTabIndicator } from 'react-native-best-viewpager';
import Tag from '../../components/Tag';
import { Card, CardTitle, CardContent, CardAction, CardButton, CardImage } from 'react-native-material-cards'
let moment = require('moment-timezone');
import 'moment/locale/fr'
import 'moment/locale/es-us'
import 'moment/locale/en-au'
import 'moment/locale/en-ca'
import 'moment/locale/en-ie'
import 'moment/locale/en-il'
import 'moment/locale/en-nz'
import { Header } from "react-native-elements";
import { IlinkEmitter } from "../../utils/events";
import DeviceInfo from 'react-native-device-info'
import { Color } from '../../config/Color'
import { Typography, FontWeight } from '../../config/typography'
import { thousandsSeparators } from '../../utils/UtilsFunction'
const thousands = require('thousands');
var users = null;
var chart = null;
export default class SuperViseurGroupeHome extends BaseScreen {
static tabsStyle: {
tabBarButtonColor: '#ff0000'
}
static navigatorStyle = {
tabBarHidden: false,
topTabTextColor: '#ffffff',
topTabsHeight: 70,
topTabTextFontFamily: 'BioRhyme-Bold',
selectedTopTabTextColor: '#ff505c',
statusBarColor: theme.primaryDark,
navBarBackgroundColor: theme.primary,
navBarTextColor: 'white',
navBarButtonColor: 'white',
// Icons
topTabIconColor: '#ffffff',
selectedTopTabIconColor: '#ff505c',
// Tab indicator
selectedTopTabIndicatorHeight: PixelRatio.get() * 2,
selectedTopTabIndicatorColor: '#ff505c',
};
static options(passProps) {
return {
topBar: {
rightButtons: []
}
}
}
static navigationOptions = ({ navigation }) => {
return {
title: I18n.t("GROUP_MANAGE"),
drawerLabel: navigation.getParam("name", I18n.t('GROUP_MANAGE')),
drawerIcon: ({ tintColor }) => (
),
}
};
constructor(props) {
super(props, true);
this.state = SuperViseurGroupeHome.initState();
readUser().then((user) => {
this.setState({ user: user })
listFreeCodesSuperViseur(user.code_membre).then((codes) => {
console.log("codes", codes)
if (codes.success != undefined) {
this.setState({ freeCodes: codes.networks })
}
})
});
listAllMembers().then((data) => {
console.log(data);
if (data !== null) {
this.setState({ listmembers: data, isLoading: false, isRefreshing: false })
}
});
this._populateIcons().then((values) => {
this.setState({ usersicon: values[0], charticon: values[1] })
});
listDemandAdhesion().then((items) => {
console.log(items)
let filtereds = [];
items.forEach((item) => {
let b = false;
filtereds.forEach((f) => {
if (f.code_membre === item.code_membre) {
b = true;
}
})
if (!b) filtereds.push(item)
})
console.log('filtered', filtereds)
if (items !== undefined) {
this.setState({ demands: filtereds, isLoadingDemand: false })
}
})
IlinkEmitter.on("langueChange", this.updateLangue.bind(this))
this.currentLocale = DeviceInfo.getDeviceLocale().includes("fr") ? "fr" : "en-gb";
moment.locale(this.currentLocale);
}
updateLangue() {
this.props.navigation.setParams({ name: I18n.t('GROUP_MANAGE') })
this.forceUpdate()
}
static initState() {
return ({
enabledListMembers: true,
listmembers: [],
usersicon: null,
isLoadingDemand: true,
charticon: null,
isRefreshing: false,
user: {},
freeCodes: [],
isLoading: true,
})
}
render() {
return (
{this.state.isLoading ? this._renderLoadingItems() : this._renderListMembers()}
{this.state.isLoadingDemand ? this._renderLoadingItems() : this.state.user.category === 'hyper' ?
this._renderListDemandAdhesion() : this._renderListCodeUnused()}
);
}
_populateIcons = function () {
return new Promise(function (resolve, reject) {
Promise.all(
[
Icon.getImageSource('users', 30),
Icon.getImageSource('chart-pie', 30),
]
).then((values) => {
users = values[0];
chart = values[0];
resolve(values);
}).catch((error) => {
console.log(error);
reject(error);
}).done();
});
};
_renderTabIndicatorAdmin() {
let tabs = [{
text: I18n.t('MEMBER_LIST'),
iconSource: this.state.usersicon
}, {
text: I18n.t('MEMBERSHIP_REQUEST'),
iconSource: this.state.charticon
}]
return ;
}
_renderTabIndicator() {
let tabs = [{
text: I18n.t('MEMBER_LIST'),
iconSource: this.state.usersicon
}
]
return ;
}
_renderListMembers() {
return (
{
return (
{I18n.t('NO_MEMBERS')}
)
}
}
refreshControl={
{
this.setState({ isRefreshing: true })
listAllMembers().then((data) => {
console.log("from refresh", data)
if (data !== null && data.datas) {
this.setState({ listmembers: data, isLoading: false, isRefreshing: false })
}
});
}}
/>
}
renderItem={({ item }) =>
this.renderMembers(item)
}
/>
)
}
_renderLoadingItems() {
return (
)
}
renderMembers(item) {
var re = moment.tz(item.created_at, 'Etc/GMT+0').format();
re = moment(re).fromNow();
if (true) {
return (
{item.phone}
{I18n.t('PRINCIPAL_ACCOUNT_TITLE')}
{item.balance_princ === null ? 0 : thousands(item.balance_princ, ' ')}
{I18n.t('COMMISSION_ACCOUNT_TITLE')}
{item.balance_com === null ? 0 : thousands(item.balance_com, ' ')}
{/*
{item.phone}
*/}
{
Alert.alert(
I18n.t("TITLE_SUPPRESS_CONFIRM"),
I18n.t("TEXT_SUPPRESS_CONFIRM"),
[
{ text: I18n.t('NO'), onPress: () => { } },
{
text: I18n.t('YES'), onPress: () => {
deleteUser(item).then(() => {
this.setState({ isLoading: true })
listAllMembers().then((data) => {
console.log(data)
if (data !== null) {
this.setState({ listmembers: data, isLoading: false, isRefreshing: false })
}
});
})
},
style: 'cancel'
},
],
)
}}
title={I18n.t('DELETE_GEOLOCATED_USER')}
color="crimson"
/>
)
} else
return (
{ } },
{
text: 'Oui', onPress: () => {
deleteUser(item).then(() => {
this.setState({ isLoading: true })
listAllMembers().then((data) => {
if (data !== null) {
this.setState({ listmembers: data, isLoading: false })
}
});
})
},
style: 'cancel'
},
],
)
}
}
]}
buttonWidth={responsiveWidth(40)}
>
{item.firstname}
{item.lastname}
{item.phone}
{item.balance}
)
}
/*
{re}
*/
_renderListDemandAdhesion() {
if (this.state.user.category === 'hyper') {
if (this.state.demands.length > 0) {
return (
this._renderAddhesionItem(item)}
refreshControl={
{
this.setState({ isRefreshing: true })
listAllMembers().then((data) => {
console.log("from refresh", data)
if (data !== null && data.datas) {
this.setState({ listmembers: data, isLoading: false, isRefreshing: false })
}
});
}}
/>
}
ListEmptyComponent={() => {
return (
{I18n.t('NO_MEMBERS')}
)
}}
/>
)
} else {
return (
{I18n.t('NO_DEMAND_ADHESION')}
)
}
}
}
_renderLoadingDemandItems() {
if (this.state.freeCodes.length > 0) {
return (
this._renderAddhesionItem(item)}
/>
)
} else {
return (
{I18n.t('NO_GEO_POINT_CODE')}
)
}
}
_renderAddhesionItem(item) {
return (
{I18n.t('NAME')} : {item.lastname}
{I18n.t('PHONE_NUMBER')} : {item.phone}
{I18n.t('EMAIL')} : {item.email}
{I18n.t('NETWORK')} : {item.network}
{
acceptDemandAdhesion(item).then((data) => {
Alert.alert(I18n.t('ACTIVATE_ACCOUNT'), I18n.t('THE_ACCOUNT') + ' ' + item.lastname + " " + I18n.t('ACTIVATED'), [{
text: "Ok"
}])
let datas = this.state.demands
datas.splice(datas.indexOf(item), 1);
this.setState({ demands: datas })
})
}}
color={"green"}
/>
{ }}
/>
)
}
_renderListCodeUnused() {
if (this.state.freeCodes.length > 0) {
return (
this._renderFreeCodeItem(item)}
/>
)
} else {
return (
{I18n.t('NO_GEO_POINT_CODE')}
)
}
}
_renderFreeCodeItem(item) {
console.log(item)
return (
Contact : {item.phone}
code Membre : {item.code_membre}
code Validation : {item.validation_code}
)
}
}
const styles = StyleSheet.create({
circlePoint: {
width: 50,
height: 50,
marginRight: 5,
alignItems: 'center',
justifyContent: 'center',
},
container: {
flex: 1,
backgroundColor: 'white'
},
fromNow: {
color: theme.accentLight
},
callIcon: {
marginRight: 5,
},
phone: {
textAlign: 'center',
color: "white"
},
balanceMember: {
marginLeft: 7,
fontSize: 18,
fontWeight: "bold",
color: theme.primary,
},
balanceIcon: {
},
name: {
color: 'black',
fontSize: 20,
margin: 20,
fontWeight: 'bold'
},
surname: {
fontSize: 17,
marginLeft: 20,
},
text: {
fontSize: 17,
fontWeight: 'bold',
},
lottie: {
width: 248,
height: 248
},
})