Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.54 KB | None | 0 0
  1. 'use strict'
  2. import React, { Component } from 'react'
  3. import {
  4. View, StyleSheet, Text, Alert, ScrollView
  5. } from 'react-native'
  6.  
  7. import RadioButton from 'react-native-simple-radio-button'
  8. import RadioGroup from 'react-native-simple-radio-button'
  9. import Container from './../resources/components/Container'
  10. import NavBar from './../resources/components/NavBar'
  11. import Input from './../resources/components/form/Input'
  12. import Button from './../resources/components/form/Button'
  13. import colors from './../resources/styles/colors'
  14. import { TouchableOpacity } from 'react-native-gesture-handler';
  15. import RadioForm from 'react-native-simple-radio-button';
  16.  
  17. var radio_props = [
  18. {label: 'instansi', kategori: 0 },
  19. {label: 'media', kategori: 1 },
  20. {label: 'pelajar', kategori: 2 }
  21. ];
  22.  
  23.  
  24. class SignUp extends Component {
  25. constructor(props) {
  26. super(props)
  27. this.state = {
  28. email: '',
  29. password: '',
  30. konfirmasikatasandi: '',
  31. nama_awal: '',
  32. nama_akhir: '',
  33. kategori: '',
  34. nomorhp: '',
  35. }
  36.  
  37. }
  38.  
  39.  
  40. render() {
  41. return (
  42. <Container>
  43. <NavBar hideBackButton={true} navigator={ this.props.navigator } title={ 'Daftar' } />
  44. <ScrollView style={styles.scrollView}>
  45. <View style={ styles.body }>
  46. <View style={ styles.group }>
  47. <Text style={ styles.label }>{ 'Email' }</Text>
  48. <Input autoCapitalize='none' placeholder='Masukkan Email Anda' onChangeText={email => this.setState({email})} />
  49. </View>
  50. <View style={ styles.group }>
  51. <Text style={ styles.label }>{ 'Kata Sandi' }</Text>
  52. <Input secureTextEntry={true} placeholder='Kata Sandi' onChangeText={password => this.setState({ password })} />
  53. </View>
  54. <View style={ styles.group }>
  55. <Text style={ styles.label }>{ 'Ketik Ulang Kata Sandi' }</Text>
  56. <Input secureTextEntry={true} placeholder='Ketik Ulang Kata Sandi' onChangeText={konfirmasikatasandi => this.setState({konfirmasikatasandi})} />
  57. </View>
  58. <View style={ styles.group }>
  59. <Text style={ styles.label }>{ 'Masukkan Nama Awal' }</Text>
  60. <Input placeholder='Masukkan Nama Awal' onChangeText={nama_awal => this.setState({nama_awal})} />
  61. </View>
  62. <View style={ styles.group }>
  63. <Text style={ styles.label }>{ 'Masukkan Nama Akhir' }</Text>
  64. <Input placeholder='Masukkan Nama Akhir' onChangeText={nama_akhir => this.setState({nama_akhir})} />
  65. </View>
  66. <View>
  67. <RadioForm
  68. radio_props={radio_props}
  69. initial={0}
  70. onPress={(kategori) => {this.setState({kategori:kategori})}} />
  71. </View>
  72. <View style={ styles.group }>
  73. <Text style={ styles.label }>{ 'Nomor Handphone' }</Text>
  74. <Input autoCapitalize='none' placeholder='Nomor Handphone' onChangeText={nomorhp => this.setState({ nomorhp })} />
  75. </View>
  76. <Text style={ styles.agreement }>{ 'Agreement' }</Text>
  77. <Button title='Daftar' onPress={() => this.registrasi() } />
  78. </View>
  79. </ScrollView>
  80. </Container>
  81.  
  82. )
  83. }
  84.  
  85. registrasi = () => {
  86. const { email } = this.state ;
  87. const { password } = this.state ;
  88. const { konfirmasikatasandi } = this.state ;
  89. const { nama_awal } = this.state ;
  90. const { nama_akhir } = this.state ;
  91. const { kategori } = this.state ;
  92. const { nomorhp } = this.state ;
  93.  
  94.  
  95. if (password !== konfirmasikatasandi) {
  96. alert("Kata sandi tidak sama"); }
  97. else {
  98. fetch('http://192.168.88.171/antara/register.php', {
  99. method: 'POST',
  100. headers: {
  101. 'Accept': 'application/json',
  102. 'Content-Type': 'application/json',
  103. },
  104. body: JSON.stringify({
  105. email: email,
  106. password: password,
  107. nama_awal: nama_awal,
  108. nama_akhir: nama_akhir,
  109. kategori: kategori,
  110. nomorhp: nomorhp
  111. })
  112.  
  113. }).then((response) => response.json())
  114. .then((responseJson) => {
  115.  
  116. // Showing response message coming from server after inserting records.
  117. Alert.alert(responseJson);
  118.  
  119. }).catch((error) => {
  120. console.error(error);
  121. });
  122. }
  123. }
  124.  
  125. _pressSignUp() {
  126. this.props.navigator.push({
  127. ident: this.props.redirectIdent,
  128. demoAuth: true
  129. })
  130. }
  131. }
  132.  
  133. const styles = StyleSheet.create({
  134. body: {
  135. padding: 20
  136. },
  137. label: {
  138. color: colors.txt_description
  139. },
  140. group: {
  141. marginBottom: 15
  142. },
  143. agreement: {
  144. color: colors.txt_dark,
  145. marginBottom: 15,
  146. textAlign: 'center'
  147. },
  148. scrollView: {
  149. backgroundColor: '#f0f0f0',
  150. marginHorizontal: 20,
  151. },
  152. })
  153.  
  154. module.exports = SignUp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement