yosadade

register.js

Jul 19th, 2020
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. import React, {useState} from 'react';
  2. import {
  3. StyleSheet,
  4. View,
  5. ScrollView,
  6. Text,
  7. ImageBackground,
  8. } from 'react-native';
  9. import {Header, Input, Gap, Button, StatusBar, Loading} from '../../components';
  10. import {colors, fonts, useForm, storeData, showError} from '../../utils';
  11. import {ILRegister} from '../../assets';
  12. import {Fire} from '../../config';
  13. import {showMessage} from 'react-native-flash-message';
  14.  
  15. const Register = ({navigation}) => {
  16. const [form, setForm] = useForm({
  17. displayName: '',
  18. email: '',
  19. phoneNumber: '',
  20. password: '',
  21. });
  22.  
  23. const [loading, setLoading] = useState(false);
  24.  
  25. const onContinue = () => {
  26. setLoading(true);
  27. console.log(form);
  28. Fire.auth()
  29. .createUserWithEmailAndPassword(form.email, form.password)
  30. .then(success => {
  31. console.log('success', success);
  32. setLoading(false);
  33. setForm('reset');
  34. const data = {
  35. displayName: form.displayName,
  36. email: form.email,
  37. phoneNumber: form.phoneNumber,
  38. };
  39. Fire.database()
  40. .ref('users/' + success.user.uid + '/')
  41. .set(data);
  42. storeData('user', data);
  43. navigation.replace('MainApp', data);
  44. })
  45. .catch(error => {
  46. const errorMessage = error.message;
  47. setLoading(false);
  48. showMessage({
  49. message: errorMessage,
  50. type: 'default',
  51. backgroundColor: colors.background.tertiary,
  52. color: colors.text.secondary,
  53. });
  54. });
  55. };
  56.  
  57. return (
  58. <>
  59. <ImageBackground source={ILRegister} style={styles.page}>
  60. <RenderStatusBar />
  61. <RenderHeader navigation={navigation} />
  62. <ScrollView showsVerticalScrollIndicator={false}>
  63. <View style={styles.content}>
  64. <Input
  65. label="Name"
  66. onChangeText={value => setForm('displayName', value)}
  67. value={form.displayName}
  68. />
  69. <Input
  70. label="Email"
  71. onChangeText={value => setForm('email', value)}
  72. value={form.email}
  73. />
  74. <Input
  75. label="No Whatsapp"
  76. onChangeText={value => setForm('phoneNumber', value)}
  77. value={form.phoneNumber}
  78. />
  79. <Input
  80. label="Password"
  81. secureTextEntry
  82. onChangeText={value => setForm('password', value)}
  83. value={form.password}
  84. />
  85. <Gap height={40} />
  86. <Button title="DAFTAR" type="secondary" onPress={onContinue} />
  87. </View>
  88. </ScrollView>
  89. </ImageBackground>
  90. {loading && <Loading />}
  91. </>
  92. );
  93. };
  94.  
  95. const RenderStatusBar = () => {
  96. return (
  97. <StatusBar type="secondary" background={colors.background.secondary} />
  98. );
  99. };
  100.  
  101. const RenderHeader = ({navigation}) => {
  102. return (
  103. <>
  104. <Header
  105. icon="back-light"
  106. onPress={() => navigation.navigate('GetStarted')}
  107. title="Daftar Sekarang"
  108. />
  109. <View style={styles.wrapperTitle}>
  110. <Text style={styles.title}>Akun Baru</Text>
  111. </View>
  112. <Gap height={120} />
  113. </>
  114. );
  115. };
  116.  
  117. export default Register;
  118.  
  119. const styles = StyleSheet.create({
  120. page: {
  121. flex: 1,
  122. },
  123. content: {
  124. justifyContent: 'center',
  125. paddingHorizontal: 40,
  126. paddingBottom: 40,
  127. },
  128. wrapperTitle: {
  129. paddingHorizontal: 40,
  130. width: 200,
  131. },
  132. title: {
  133. fontSize: 30,
  134. fontFamily: fonts.primary[900],
  135. color: colors.primary,
  136. },
  137. });
Add Comment
Please, Sign In to add comment