Projekt

Obecné

Profil

Stáhnout (3.74 KB) Statistiky
| Větev: | Tag: | Revize:
1
import {
2
    Center,
3
    Box,
4
    Heading,
5
    VStack,
6
    FormControl,
7
    Link,
8
    Input,
9
    Button,
10
    HStack,
11
    Text,
12
    KeyboardAvoidingView
13
} from "native-base"
14
import { useState } from "react"
15
import { useDispatch, useSelector } from "react-redux"
16
import { login } from "../stores/actions/userThunks"
17
import { AppDispatch, RootState } from "../stores/store"
18
import { Platform } from "react-native"
19

    
20

    
21
const LoginPage = () => {
22
    const [username, setUsername] = useState("")
23
    const [password, setPassword] = useState("")
24
    const status = useSelector((state: RootState) => state.user.loggedIn)
25

    
26
    const dispatch = useDispatch<AppDispatch>()
27

    
28
    const loginUser = () => {
29
        dispatch(login({username, password}))
30
        //TODO - add error handling
31
    }
32

    
33
    return (
34
        <KeyboardAvoidingView
35
            h={ {
36
                base: "400px",
37
                lg: "auto"
38
            } }
39
            behavior={ Platform.OS === "ios" ? "padding" : "height" }
40
        >
41
            <Center w="100%">
42
                <Box
43
                    safeArea
44
                    p="2"
45
                    py="8"
46
                    w="90%"
47
                    maxW="290"
48
                >
49
                    <Heading
50
                        size="2xl"
51
                        color="primary.500"
52
                        textAlign="center"
53
                        _dark={ {
54
                            color: "primary.100"
55
                        } }
56
                    >
57
                        Inventaria Rudolphina
58
                    </Heading>
59
                    <Heading
60
                        mt="10"
61
                        textAlign="center"
62
                        _dark={ {
63
                            color: "primary.500"
64
                        } }
65

    
66
                        fontWeight="bold"
67
                        size="xl"
68
                    >
69
                        Log in
70
                    </Heading>
71
                    <Text
72
                        mt="1"
73
                        textAlign="center"
74
                    >
75
                        Please log in to continue
76
                    </Text>
77

    
78
                    <VStack space={ 3 } mt="1">
79
                        <FormControl>
80
                            <FormControl.Label>Username</FormControl.Label>
81
                            <Input
82
                                // value={username}
83
                                textContentType={"username"}
84
                                rounded={ "xl" }
85
                                autoComplete={"username"}
86
                                onSubmitEditing={ () => { loginUser() } }
87
                                onChangeText={ (username) => setUsername(username) }
88
                            />
89
                            <FormControl.Label>Password</FormControl.Label>
90
                            <Input
91
                                type="password"
92
                                autoComplete={ "password" }
93
                                id={ "password" }
94
                                returnKeyType={ "go" }
95
                                rounded={ "xl" }
96
                                onSubmitEditing={ () => loginUser() }
97
                                onChangeText={ (password) => setPassword(password) }
98
                            />
99
                            <Button
100
                                mt="2"
101
                                bg={ "primary.500" }
102
                                onPress={ loginUser }
103
                                rounded={ "xl"}
104
                            >
105
                                Sign in
106
                            </Button>
107
                        </FormControl>
108
                    </VStack>
109
                </Box>
110
            </Center>
111
        </KeyboardAvoidingView>
112
    )
113
}
114

    
115
export default LoginPage
(3-3/5)