import React, { Component } from 'react' import { View } from 'react-native' import Switch_notification from './Switch_notification' import { BackgroundImage } from '../../components/BackgroundImage' import Text from '../../components/Text'; import LinearGradient from 'react-native-linear-gradient'; import { Badge, } from 'native-base' import { bindActionCreators } from 'redux' import { appCleanToken, appCleanUser } from '../../redux/app/action' import { connect } from 'react-redux' import { getSubscription, postSubscription } from "../../api/UserApi"; import { t } from '../../utils/i18n'; class SettingsNotificationScreen extends Component { constructor(props) { super(props) console.log('user => ',this.props) this.state = { auth: false, isSwitchNews: false, isSwitchPromotion: false, isSwitchDelivery: false, isSwitchPaymnt: false } this.toggleSwitch = this.toggleSwitch.bind(this) } componentDidMount() { if (this.props.token != null && this.props.user != null) { this.getSubscriptionUser() this.setState({ auth: true }) } else { this.setState({ auth: false }) } } componentWillReceiveProps() { if (this.props.token != null && this.props.user != null) { this.setState({ auth: true, }) } else { this.setState({ auth: false }) } } getSubscriptionUser(){ getSubscription(this.props.user.id, this.props.type) .then(res => { this.setState({ isSwitchNews: res.data.is_receive_news, isSwitchPromotion: res.data.is_receive_promotion, isSwitchDelivery: res.data.is_receive_delivery, isSwitchPaymnt: res.data.is_receive_payment }) }) } toggleSwitch(customerId,switchType){ console.log('select toggle type ------------> ',switchType) postSubscription(customerId,switchType) switch(switchType){ case 'news': this.setState({ isSwitchNews: !this.state.isSwitchNews }) break; case 'promotion': this.setState({ isSwitchPromotion: !this.state.isSwitchPromotion }) break; case 'delivery': this.setState({ isSwitchDelivery: !this.state.isSwitchDelivery }) break; case 'payment': this.setState({ isSwitchPaymnt: !this.state.isSwitchPaymnt }) break; } } render() { return ( {t('news2')} {t('promotion')} {this.state.auth == true ? {t('parcel_list')} : null} {this.state.auth == true ? {t('payment_due')} : null} ) } } const styles = { box_setting_style: { flexDirection: 'row', height: 25, display: 'flex', alignItems: 'center', margin: 10 } } const mapDisPatchToProps = state => { return state.app } const redux_connect = dispatch => bindActionCreators({ }, dispatch) export default connect(mapDisPatchToProps, redux_connect)(SettingsNotificationScreen)