Signup.js 3.69 KB
import React, { Component } from 'react';
import { View, Text, StyleSheet,TextInput, TouchableOpacity } from 'react-native';
import {SERVER} from '../../common/servername'
import {post} from 'axios'
import AsyncStorage from '@react-native-community/async-storage';
export default class AddTab extends Component {
    static navigationOptions = {
        
        headerShown: false
        
    }
    state = {
        nickname:"",
        email:"",
        password:"",
        provider:'local',
        res:"",
        phone:""
    }
    constructor(props) {
        super(props)

    }
    componentDidMount() {
        if(this.props.navigation.state.params && this.props.navigation.state.params.phone) {
            this.setState({
                phone:this.props.navigation.state.params.phone
            })
        }
    }
    HandleNavigate= () => {
        const {nickname,email,password,provider} = this.state
        post(`http://${SERVER}/auth/join`,{nickname,email,password,provider,phone:this.state.phone}).then(e => {
            if(e.data.success) {
                alert("회원가입이 완료되었습니다.")
                AsyncStorage.setItem('user', JSON.stringify(e.data.data));
                this.props.navigation.navigate("LoginTab")
            }
            else {
                alert(e.data.message)
            }
        })
    }
    render() {
        return (
            <View style={{paddingTop:"10%",flex:1,justifyContent:"center",backgroundColor:"white"}}>
                <View>
                    <Text style={{paddingLeft:"10%",color:"#615F5F",fontSize:15}}>
                        닉네임
                    </Text>
                </View>
                <TextInput value={this.state.nickname} onChangeText={e => {
                    this.setState({
                        nickname:e
                    })
                }} placeholder="상가톡" style={{marginLeft:"10%",marginRight:"10%",paddingLeft:16,fontSize:15,borderColor:"#FFD63A",borderWidth:1,paddingTop:9,paddingBottom:9,marginTop:16,marginBottom:16}}/>
                <View>
                    <Text style={{paddingLeft:"10%",color:"#615F5F",fontSize:15}}>
                        이메일 아이디
                    </Text>
                </View>
                <TextInput value={this.state.email} onChangeText={e => this.setState({email:e})}  keyboardType="email-address" placeholder="talk@sangga.io" style={{marginLeft:"10%",marginRight:"10%",paddingLeft:16,fontSize:15,borderColor:"#FFD63A",borderWidth:1,paddingTop:9,paddingBottom:9,marginTop:16,marginBottom:16}}/>
                <View>
                    <Text style={{paddingLeft:"10%",color:"#615F5F",fontSize:15}}>
                        비밀번호
                    </Text>
                </View>
                <TextInput secureTextEntry={true}  value={this.state.password} onChangeText={e => this.setState({password:e})}  placeholder="*************" style={{marginLeft:"10%",marginRight:"10%",paddingLeft:16,fontSize:15,borderColor:"#FFD63A",borderWidth:1,paddingTop:9,paddingBottom:9,marginTop:16,marginBottom:16}}/>
                
                
                
            <View style={{display:"flex",flexDirection:"row",position:"absolute",bottom:0,width:"100%"}}>
                <TouchableOpacity onPress={() => this.HandleNavigate()} style={{flex:1,backgroundColor:"#f4cd37",padding:10}}>
                    <Text style={{textAlign:"center",fontSize:18,color:"white"}}>
                        확인
                    </Text>
                </TouchableOpacity>
            </View>
            </View>
        );
    }
}
 
const style = StyleSheet.create({
    container: {
        flex: 1,
        alignItems: 'center',
        justifyContent: 'center',
    }
});