import * as React from 'react'; import { View, Text, Platform, Linking, Alert, TouchableOpacity } from 'react-native'; import { connect } from "react-redux"; import { openComposer } from 'react-native-email-link' import NetInfo from "../../components/netstatus"; import CustomHeader from '../../components/header.js'; import Elements from '../../components/elements.js'; import Icon from '../../components/icons.js'; import REQUEST from '../../components/api/'; import DB from '../../components/storage/index'; import CustomSafeArea from '../../components/safeArea.component'; class Contact extends React.Component { constructor(props) { super(props) } state = { data: {}, connected: false, cn: '', } componentDidMount() { this.initContact() } componentWillUnmount() { } initContact = () => { NetInfo.netstatus(isConnected => { if(isConnected) { this.init() } else { Elements.nointernet2() } }) } init = async () => { let user_profile = await DB.profile() console.log(user_profile.data.card_number) this.setState({ connected: true, cn: user_profile.data.card_number }) await REQUEST("contact_us", "get", {}, {}, {}, async (res) => { if(res.status == 1 && res.data){ this.setState({ data: res.data }) }else{ console.log(res.message, res.data) } }, function(error){ console.log(error) }) } getData = (type) => { return type == "email" ? this.state.data.contact_email_address_mobile : this.state.data.contact_number_mobile } render() { console.log(this.state) if(!this.state.connected){ return ( this.init()} /> ) } return ( Our Unioil Customer Service team is ready to assist you if you have any questions or problems using the app. The team is available during office hours only, Mon-Fri, 8:00 AM - 5:00 PM. For immediate response, you may contact us through the following: { openComposer({ to: this.getData("email") || "loyalty@unioil.com", subject: `Mobile App Feedback:\nCN${this.state.cn}`, body: '' }) }} style={{flex: 1, flexDirection: 'row',margin: 15, height: 120, padding: 5}}> {this.getData("email") || "loyalty@unioil.com"} { let url = Platform.OS == 'ios' ? 'telprompt:' : 'tel:' Linking.canOpenURL(url).then(supported => { if (!supported) { console.log('Cant handle url') alert("Call Not Supported") } else { Alert.alert("Call Customer Service", "You will be redirected to the dialer to call Unioil Customer Service", [{ text: 'Cancel', style: 'cancel', }, { text: 'OK', onPress: () => Linking.openURL(`${url}${this.state.data.contact_number_mobile || "0286878877"}`) }, ], {cancelable: true}) return true } }).catch(err => { console.error('An error occurred', err) }) }} style={{flex: 1, flexDirection: 'row',margin: 15, padding: 5}}> {this.getData("mobile") || "0286878877"} ); } } const mapStateToProps = (state) => { return { app_theme: state.appThemeReducer.theme } } export default connect(mapStateToProps, null)(Contact);