import * as React from 'react';
import { View, Text, TouchableOpacity, ScrollView, SafeAreaView, TextInput, Alert } from 'react-native';
import { connect } from "react-redux";
import moment from 'moment';
import Elements from '../../components/elements.js';
import NetInfo from "../../components/netstatus";
import REQUEST from '../../components/api/';
import Icon from './../../components/icons.js';
import Theme from '../../components/theme.style.js';
import DB from '../../components/storage/';
import CustomSafeArea from '../../components/safeArea.component.js';
const CustomInput = (props) => {
const titlecolor = props.current == props.index && props.focus ? Theme.colors.darkGray : Theme.colors.darkGray
const bordercolor = props.error ? Theme.colors.primary : (props.focus && props.current == props.index ? Theme.colors.darkGray : 'gray')
const borderwidth = props.error ? 1.6 : (props.focus && props.current == props.index ? 1.5 : 1)
const style = {
container: {flexDirection: 'row', width: '80%', marginTop: props.top || 30, alignItems: 'center'},
title: {fontSize: 12, color: titlecolor, marginTop: -25, marginBottom: 15},
input: {width: '100%', fontSize: 16, padding: 0, borderBottomColor: bordercolor, borderBottomWidth: borderwidth, color: props?.isDarkMode ? props?.textColor : Theme.colors.black },
error: {fontSize: 12, color: Theme.colors.primary, marginTop: 5, marginBottom: 15}
}
return (
{props.current >= props.index ?
{props.title}
: null}
{props.error ? {props.errorMessage} : null }
)
}
class SecurityQuestion extends React.Component {
constructor(props) {
super(props)
}
state = {
loading: false,
email: null,
birthdate: null,
openDatepicker: false,
error: null,
valid: true,
}
componentDidMount() {
this.setState({ data: this.props.route.params })
console.log(this.props.route)
}
componentWillUnmount() {
}
checkValidAccountInfo = () => {
return (this.state.email && this.state.birthdate)
}
submitAccountInfo = () => {
NetInfo.netstatus(async isConnected => {
if(isConnected) {
this.setState({ loading: true })
this.requestUpdateAccountInfo(success => {
this.setState({ loading: false })
if(success.status == 1) {
this.props.navigation.navigate("Setnewmpin", { sessiondata: this.state.data })
} else {
Platform.OS == 'ios' ? setTimeout(() => {
Alert.alert("Account Information.", success.message)
}, 300) : Alert.alert("Account Information.", success.message)
}
}, error => {
this.setState({ loading: false })
Platform.OS == 'ios' ? setTimeout(() => {
Alert.alert("Account Information.", "Failed to submit account information")
}, 300) : Alert.alert("Account Information.", "Failed to submit account information")
})
} else {
this.setState({ loading: false })
Elements.nointernet2(this.props)
}
})
}
requestUpdateAccountInfo = async (successCallback, errorCallback) => {
const SESSION = await DB.session()
const params = {
card_number: this.props.route.params.card_number,
birthdate: moment(this.state.birthdate).format("YYYY-MM-DD"),
email_address: this.state.email
}
await REQUEST("security_question", "post", {
Authorization: SESSION.token,
}, {}, params, function(data){
console.log(data)
successCallback(data)
}, function(error){
console.log(error)
errorCallback(error)
})
}
render() {
return(
{
this.props.navigation.reset({
index: 0,
routes: [{name: 'Mpin'}],
});
}}>
Account Information
{}}>
What email address did you use to register to Unioil?
{
this.setState({ email: val, valid: true })
}}/>
When is your Birthday?
{
this.setState({ openDatepicker: true })
if(this.state.errors && this.state.errors.birthdate) delete this.state.errors.birthdate
}} style={{}}>
{/* Birthday */}
{this.state.birthdate || "Enter your Birthday"}
{this.state.errors && this.state.errors.birthdate ?
{this.state.errors?.birthdate[0]}
: null}
{
this.setState({ birthdate: selectedDate ? moment(selectedDate).format("DD MMM YYYY") : this.state.birthdate != null ? this.state.birthdate : null, openDatepicker: false })
}}
onCancel={() => this.setState({ openDatepicker: false })}/>
{/* this.submitAccountInfo()}>
Submit
*/}
this.submitAccountInfo()} style={{width: '92%', padding: 15, borderRadius: 10, backgroundColor: this.state.valid && this.checkValidAccountInfo() ? Theme.colors.primary : this.props.app_theme?.theme.dark ? this.props.app_theme?.theme.colors.border : Theme.colors.primary + "15"}}>
Submit
)
}
}
const mapStateToProps = (state) => {
return {
app_theme: state.appThemeReducer.theme
}
}
export default connect(mapStateToProps, null)(SecurityQuestion)