PhoneCheck_Cert.js 5.59 KB
import React, { Component } from 'react';
import { View, Text, StyleSheet,TouchableOpacity } from 'react-native';
import CheckBox from '@react-native-community/checkbox'
import { TextInput } from 'react-native-gesture-handler';

export default class AddTab extends Component {
    
    static navigationOptions = {
        
        headerShown: false
        
    }
    state= {
        all:false,
        expired:false,
        time:180,
        intervalId:null,
        data:null,
        input:"",
        phone_num:""
    }
    constructor(props) {
        super(props)

    }
    componentDidMount() {

        const phone_num = this.props.navigation.state.params.phone_num
        if(this.props.navigation.state.params.data) {
            this.setState({
                data:this.props.navigation.state.params.data,
                phone_num:phone_num
            },() => console.log(this.state.data))
        }
        this.setState({
            intervalId:setInterval(() => {
                this.setState({
                    time:this.state.time-1
                })
                if(this.state.time ===0) {
                    this.setState({
                        expired:true
                    })
                }
              }, 1000)
        })

    }
    componentWillUnmount() {
        clearInterval(this.state.intervalId) 
    }
    onHandlecheckBox= (type) => {
        if(type == "SNS") {
            if(this.state.SNS == true) {
                this.setState({
                    SNS:false,
                    all:false,
                })
            }
            else {
                this.setState({
                    SNS:true
                })
            }
        }
        else if(type == "private_info") {
            if(this.state.private_info == true) {
                this.setState({
                    private_info:false,
                    all:false,
                })
            }
            else {
                this.setState({
                    private_info:true
                })
            }
        }
        else if(type == "profile_info") {
            if(this.state.profile_info == true) {
                this.setState({
                    profile_info:false,
                    all:false,
                })
            }
            else {
                this.setState({
                    profile_info:true
                })
            }
        }
    }

    HandlePhoneNum = (e) => {
        this.setState({
            phone_num:e
        })
    }
    
    HandleNavigate = () => {
        if(this.state.expired === true) return alert("인증 시간이 만료되었습니다.")
        if(this.state.data === parseInt(this.state.input)) {
            this.props.navigation.replace("Signup",{phone:this.state.phone_num})
        }
        else {
            alert("인증번호를 확인해주세요.")
        }

    }
    GoFirst = () => {
        this.props.navigation.goBack(null)
    }
    RequestAuthKey = () => {
        
        post(`http://${SERVER}/auth/phone`,{phone_number:this.state.phone_num}).then(res => {
            if(res.data.success) {
                
                this.setState({
                    time:180,
                    expired:false,
                    data:res.data.data,
                })
            }
        })
    }
    render() {
        return (
            <View style={{width:"100%",height:"100%",paddingLeft:"10%",paddingRight:"10%",paddingTop:"10%"}}>
                <View>
                    <Text style={{color:"#615F5F",fontSize:15,textAlign:"center"}}>
                        {this.state.phone_num} 전송받은 4자리
                    </Text>
                    <Text style={{color:"#615F5F",fontSize:15,textAlign:"center"}}>
                        인증번호를 입력해주세요.
                    </Text>
                </View>
                <View style={{flexDirection:"row",paddingTop:9,paddingBottom:9,marginTop:16,marginBottom:14}}>
                    <TextInput value={this.state.input} onChangeText={(e) => this.setState({input:e})} keyboardType="number-pad" placeholder={`${Math.floor(this.state.time/60)}:${this.state.time%60<10? "0"+this.state.time%60 :this.state.time%60}`} 
                    style={{paddingTop:7,paddingBottom:11,width:"80%",paddingRight:16,textAlign:"right",fontSize:15,borderColor:"#FFD63A",borderWidth:1}}/>
                    <TouchableOpacity onPress={() => this.HandleNavigate()} style={{width:"20%",backgroundColor:"#FFD63A"}}>
                        <View style={{flex:1,justifyContent:"center"}}>
                            <Text style={{alignSelf:"center",fontSize:14,textAlign:"center"}}>
                                다음
                            </Text>
                        </View>
                    </TouchableOpacity>
                </View>
                <TouchableOpacity onPress={() => this.RequestAuthKey()} style={{alignSelf:"center"}}>
                    <Text style={{color:"#615F5F",paddingBottom:3,marginBottom:29,borderBottomColor:"#FFD63A",borderBottomWidth:1}}>
                        인증번호 다시 받기
                    </Text>
                </TouchableOpacity>
                
                <TouchableOpacity onPress={() => this.GoFirst()} style={{alignSelf:"center"}}>
                    <Text style={{color:"#615F5F",paddingBottom:3,marginBottom:29,borderColor:"#615F5F",borderWidth:2,paddingBottom:6,paddingTop:7,paddingLeft:17,paddingRight:17}}>
                        처음으로 돌아가기
                    </Text>
                </TouchableOpacity>
            </View>
        );
    }
}
 
const style = StyleSheet.create({
    container: {
    }
});