aboutsummaryrefslogtreecommitdiffstats
path: root/components/Login.jsx
blob: 1a6ef922f5949cc2773d99650ab113bf29a15d41 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { StyleSheet, Text, TextInput, Pressable, View } from 'react-native'
import { useState } from 'react'
import { handleLogin } from '../utils/helpers'
import Loader from './Loader'

const Login = ({ setSession, showError }) => {
  const [email, setEmail] = useState('');
  const [password, setPassword] = useState('');
  const disabled = (e, p) => !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e) || p.length < 6;
  const [loading, setLoading ] = useState(false)

  return (
    <View style={styles.container}>
      {loading
        ? <Loader style={{ width: 100 }} text="Signing in..." />
        : (
          <>
          <Text style={styles.title}>Login to Notes</Text>
          <Text style={styles.text}>Account can be created through apps.pruss.it website</Text>
          <TextInput
            style={styles.input}
            autoComplete="email"
            placeholder="Email"
            placeholderTextColor="#BBB"
            keyboardType="email-address"
            returnKeyType="next"
            autoComplete="email"
            textContentType="emailAddress"
            value={email}
            onChange={e => setEmail(e.nativeEvent.text.toLowerCase())}
          />
          <TextInput
            style={styles.input}
            autoComplete="password"
            placeholder="Password"
            placeholderTextColor="#BBB"
            returnKeyType="next"
            autoComplete="password-new"
            secureTextEntry={true}
            textContentType="newPassword"
            value={password}
            onChange={e => setPassword(e.nativeEvent.text)}
          />
          <Pressable
            onPress={() => handleLogin({ email, password, setSession, setLoading, showError })}
            style={{...styles.button, opacity: disabled(email, password) ? .3 : 1}}
            disabled={disabled(email, password)}
          >
            <Text style={styles.buttonText}>Login</Text>
          </Pressable>
        </>
      )}
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    height: '100%'
  },
  title: {
    color: 'white',
    fontSize: 26,
    marginBottom: 40,
  },
  text: {
    color: 'white',
    marginBottom: 50,
  },
  input: {
    height: 50,
    width: 280,
    padding: 10,
    marginBottom: 20,
    color: 'white',
    backgroundColor: '#444',
    borderColor: '#aaa',
    borderWidth: 1,
    borderStyle: 'solid',
    borderRadius: 10,
  },
  button: {
    width: 100,
    height: 40,
    backgroundColor: '#666',
    borderRadius: 5,
    marginTop: 40,
    alignItems: 'center',
    justifyContent: 'center',
  },
  buttonText: {
    color: 'white',
  }
});

export default Login;