Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import React from "react";
  2. import { useState } from "react";
  3. import { View, TextInput, Text, StyleSheet } from "react-native";
  4. import Button from "../components/Buttons/Button";
  5. import { login } from "../thunks/user.thunk";
  6. import { useDispatch } from "react-redux";
  7. export const LogIn = () => {
  8. const [username, setUsername] = useState()
  9. const [password, setPassword] = useState()
  10. const [error, setError] = useState()
  11. const dispatch = useDispatch();
  12. const loginHandler = () => {
  13. dispatch(
  14. login(username, password, function (result) {
  15. console.log(result.data)
  16. if (!result.OK) {
  17. setUsername("");
  18. setPassword("");
  19. setError(result.data.Message ? result.data.Message : "Error occurred during Login,please try again!");
  20. }
  21. })
  22. )
  23. }
  24. return (
  25. <View style={{flex: 1, justifyContent: 'center'}}>
  26. <Text style={styles.errorMessage}>{error && error}</Text>
  27. <TextInput focus={true}
  28. style={styles.input}
  29. placeholder='Username'
  30. placeholderTextColor='#000'
  31. value={username}
  32. onChangeText={setUsername}
  33. />
  34. <TextInput focus={true}
  35. style={styles.input}
  36. placeholder='Password'
  37. placeholderTextColor='#000'
  38. value={password}
  39. onChangeText={setPassword}
  40. secureTextEntry />
  41. <Button
  42. onPress={loginHandler}
  43. title='Log In'
  44. style={{ margin: 12, backgroundColor: '#3E5076' }}
  45. />
  46. </View>
  47. )
  48. }
  49. const styles = StyleSheet.create({
  50. input: {
  51. height: 40,
  52. margin: 12,
  53. borderWidth: 1,
  54. padding: 10,
  55. borderRadius: 5
  56. },
  57. errorMessage: {
  58. color: 'red',
  59. margin: 12
  60. }
  61. });