TermsCheck.js 6.97 KB
import React, { Component } from 'react';
import { View, Text, StyleSheet,TouchableOpacity } from 'react-native';
import RNKakao from 'rn-kakao-login';
import CheckBox from '@react-native-community/checkbox'
import AsyncStorage from '@react-native-community/async-storage'
import {post } from 'axios'
import firebase from '@react-native-firebase/messaging';
import { SERVER } from '../../common/servername';
export default class AddTab extends Component {
    
    static navigationOptions = {
        
        headerShown: false
        
    }
    state= {
        all:false,
        SNS:false,
        private_info:false,
        profile_info:false,
        fcmToken:""
    }
    constructor(props) {
        super(props)

    }
    componentDidMount() {

    }
    kakaoLogin = async () => {
        try {
            
            await firebase().requestPermission();
            const fcmToken = await firebase().getToken()
          const result = await RNKakao.login();
          
          console.log(result.accessToken)
          post(`http://${SERVER}/auth/kakao/join`,{kakao_access_token:result.accessToken}).then(async res => {
              if(res.data.success) {
                AsyncStorage.setItem("user",JSON.stringify(result))
                AsyncStorage.setItem("token",JSON.stringify(res.data.data.token.token))
                AsyncStorage.setItem("refreshtoken",JSON.stringify(res.data.data.refresh_token))
                post(`http://${SERVER}/auth/kakao/login`,{kakao_access_token:result.accessToken,fcm_token:fcmToken}).then(res => { 
                      this.props.navigation.goBack(null)
                })
                this.props.navigation.navigate("Main_")
              }
              else {
                  const a = await RNKakao.logout()
                  alert("서버 오류입니다.")
              }
                console.log(res.data)
                
          })

        } catch (e) {
            console.log(e)
            alert("서버 내부 오류입니다. 다시 시도해주세요.")
        }
      }    
    onHandlecheckBox= (type) => {
        if(type == "all") {
            if(this.state.all == true) {
                this.setState({
                    SNS:false,
                    all:false,
                    private_info:false,
                    profile_info:false
                })
            }
            else {
                this.setState({
                    SNS:true,
                    all:true,
                    private_info:true,
                    profile_info:true
                })
            }
        }
        else 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
                })
            }
        }
    }
    HandleNavigate = () => {
        if(this.state.SNS === false || this.state.private_info === false) return alert("필수 약관에 모두 동의해주세요.")
        this.kakaoLogin()
    }
    render() {
        return (
            <View style={{width:"100%",height:"100%"}}>
                <View style={{top:"60%"}}>
                    <View style={{display:"flex",flexDirection:"row",borderBottomColor:"#615F5F",borderBottomWidth:2,marginLeft:16.4,marginRight:16.4,paddingBottom:16}}>
                        <CheckBox value={this.state.all} onChange={() => this.onHandlecheckBox("all")} tintColors={{true:'#f4cd37'}}  style={{marginTop:-5}}/>
                        <TouchableOpacity onPress={() =>this.onHandlecheckBox("all")}>
                        <Text style={{color:"black",fontWeight:"bold",fontSize:14,marginLeft:10}}>
                            모두 동의
                        </Text>
                        </TouchableOpacity>
                    </View>
                    
                    <View style={{display:"flex",flexDirection:"row",marginLeft:16.4,marginRight:16.4,marginTop:16}}>
                        <CheckBox onChange={() => this.onHandlecheckBox("SNS")} value={this.state.SNS} tintColors={{true:'#f4cd37'}}  style={{marginTop:-5}}/>
                        <TouchableOpacity onPress={() => this.onHandlecheckBox("SNS")} >
                        <Text style={{color:"black",fontWeight:"200",fontSize:14,marginLeft:10}}>
                            [필수] 카카오계정 약관
                        </Text>
                        </TouchableOpacity>
                    </View>
                    
                    <View style={{display:"flex",flexDirection:"row",marginLeft:16.4,marginRight:16.4,marginTop:16}}>
                        <CheckBox onChange={() => this.onHandlecheckBox("private_info")}  value={this.state.private_info} tintColors={{true:'#f4cd37'}}  style={{marginTop:-5}}/>
                        <TouchableOpacity onPress={() => this.onHandlecheckBox("private_info")}>
                        <Text style={{color:"black",fontWeight:"200",fontSize:14,marginLeft:10}}>
                            [필수] 개인정보 수집  이용 동의
                        </Text>
                        </TouchableOpacity>
                    </View>
                    
                    <View style={{display:"flex",flexDirection:"row",marginLeft:16.4,marginRight:16.4,marginTop:16}}>
                        <CheckBox onChange={() => this.onHandlecheckBox("profile_info")}  value={this.state.profile_info} tintColors={{true:'#f4cd37'}}  style={{marginTop:-5}}/>
                        <TouchableOpacity onPress={() => this.onHandlecheckBox("profile_info")}>
                        <Text style={{color:"black",fontWeight:"200",fontSize:14,marginLeft:10}}>
                            [선택] 프로필 정보 추가 수집 동의
                        </Text>
                        </TouchableOpacity>
                    </View>
                </View>
                <TouchableOpacity onPress={() => this.HandleNavigate()} style={{position:"absolute",bottom:0,width:"100%",backgroundColor:"#FFD63A",paddingTop:21,paddingBottom:19}}>
                    <Text style={{textAlign:"center"}}>
                        확인
                    </Text>
                </TouchableOpacity>
            </View>
        );
    }
}
 
const style = StyleSheet.create({
    container: {
    }
});