Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 06808454

Přidáno uživatelem Schwobik před téměř 2 roky(ů)

Logout and Login fixed
re #10715

Zobrazit rozdíly:

src/pages/LoginPage.tsx
11 11
    Text,
12 12
    KeyboardAvoidingView
13 13
} from "native-base"
14
import { useState } from "react"
14
import { useCallback, useEffect, useState } from "react"
15 15
import { useDispatch, useSelector } from "react-redux"
16
import { login } from "../stores/actions/userThunks"
16
import { checkAuth, login } from "../stores/actions/userThunks"
17 17
import { AppDispatch, RootState } from "../stores/store"
18 18
import { Platform } from "react-native"
19
import { log } from "../logging/logger"
20
import * as SplashScreen from "expo-splash-screen"
21
import { ApplicationHeading } from "../components/reusables/ApplicationHeading"
19 22

  
20 23

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

  
26 29
    const dispatch = useDispatch<AppDispatch>()
27 30

  
28 31
    const loginUser = () => {
32
        log.debug("LoginPage", "loginUser", "dispatching login")
29 33
        dispatch(login({username, password}))
30 34
        //TODO - add error handling
31 35
    }
32 36

  
37

  
38
    useEffect(() => {
39
        dispatch(checkAuth())
40
    }, [])
41

  
33 42
    return (
34 43
        <KeyboardAvoidingView
44
            behavior={ Platform.OS === "ios" ? "padding" : "height" }
45
            flex={ 1 }
46
            justifyContent={ "center" }
35 47
            h={ {
36 48
                base: "400px",
37 49
                lg: "auto"
38 50
            } }
39
            behavior={ Platform.OS === "ios" ? "padding" : "height" }
40 51
        >
41 52
            <Center w="100%">
42
                <Box
43
                    safeArea
53
                <VStack
44 54
                    p="2"
45
                    py="8"
46
                    w="90%"
47
                    maxW="290"
55
                    w="80%"
56
                    justifyContent={ "center" }
48 57
                >
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>
58
                    <ApplicationHeading />
59 59
                    <Heading
60 60
                        mt="10"
61 61
                        textAlign="center"
......
74 74
                    >
75 75
                        Please log in to continue
76 76
                    </Text>
77
                    { lastError && (
78
                        <Text
79
                            mt="1"
80
                            textAlign="center"
81
                            color="error.500"
82
                        >
83
                            { lastError }
84
                        </Text>
85
                    ) }
77 86

  
78
                    <VStack space={ 3 } mt="1">
87
                    <VStack space={ 3 } >
79 88
                        <FormControl>
80 89
                            <FormControl.Label>Username</FormControl.Label>
81 90
                            <Input
......
106 115
                            </Button>
107 116
                        </FormControl>
108 117
                    </VStack>
109
                </Box>
118
                </VStack>
110 119
            </Center>
111 120
        </KeyboardAvoidingView>
112 121
    )

Také k dispozici: Unified diff