Projekt

Obecné

Profil

Stáhnout (3.74 KB) Statistiky
| Větev: | Tag: | Revize:
1 ddc84a2f Schwobik
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 5ed9692c Schwobik
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 ddc84a2f Schwobik
import { Platform } from "react-native"
19 7e4b4e6a mschwob
20 5c86e446 mschwob
21 7e4b4e6a mschwob
const LoginPage = () => {
22 5ed9692c Schwobik
    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 ddc84a2f Schwobik
        dispatch(login({username, password}))
30 5ed9692c Schwobik
        //TODO - add error handling
31
    }
32
33 7e4b4e6a mschwob
    return (
34 ddc84a2f Schwobik
        <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 1980ed09 Schwobik
                        color="primary.500"
52 ddc84a2f Schwobik
                        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 1980ed09 Schwobik
                            color: "primary.500"
64 ddc84a2f Schwobik
                        } }
65 1980ed09 Schwobik
66 ddc84a2f Schwobik
                        fontWeight="bold"
67
                        size="xl"
68 5ed9692c Schwobik
                    >
69 ddc84a2f Schwobik
                        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 ca53e9f1 Schwobik
                                textContentType={"username"}
84 1980ed09 Schwobik
                                rounded={ "xl" }
85 ca53e9f1 Schwobik
                                autoComplete={"username"}
86
                                onSubmitEditing={ () => { loginUser() } }
87 ddc84a2f Schwobik
                                onChangeText={ (username) => setUsername(username) }
88
                            />
89
                            <FormControl.Label>Password</FormControl.Label>
90 ca53e9f1 Schwobik
                            <Input
91
                                type="password"
92
                                autoComplete={ "password" }
93
                                id={ "password" }
94 1980ed09 Schwobik
                                returnKeyType={ "go" }
95
                                rounded={ "xl" }
96 ca53e9f1 Schwobik
                                onSubmitEditing={ () => loginUser() }
97
                                onChangeText={ (password) => setPassword(password) }
98 ddc84a2f Schwobik
                            />
99 1980ed09 Schwobik
                            <Button
100
                                mt="2"
101
                                bg={ "primary.500" }
102
                                onPress={ loginUser }
103
                                rounded={ "xl"}
104
                            >
105
                                Sign in
106
                            </Button>
107 ddc84a2f Schwobik
                        </FormControl>
108
                    </VStack>
109
                </Box>
110
            </Center>
111
        </KeyboardAvoidingView>
112 5c86e446 mschwob
    )
113 7e4b4e6a mschwob
}
114
115
export default LoginPage