mirror of
https://github.com/lemeow125/Reactnative-notesapp.git
synced 2025-06-28 16:35:44 +08:00
Integrate api for login
This commit is contained in:
parent
0318f4eb53
commit
c597e9eaab
11 changed files with 4923 additions and 466 deletions
|
@ -3,8 +3,9 @@ import {View, Text} from 'react-native';
|
|||
import styles from '../../styles';
|
||||
import Background from '../../Components/Background/Background';
|
||||
import AppIcon from '../../Components/Icons/AppIcon/AppIcon';
|
||||
|
||||
import { useDispatch } from "react-redux";
|
||||
export default function Home() {
|
||||
const dispatch = useDispatch();
|
||||
return (
|
||||
<Background>
|
||||
<View
|
||||
|
|
|
@ -1,58 +1,87 @@
|
|||
import * as React from 'react';
|
||||
import {View, Text, TextInput} from 'react-native';
|
||||
import { View, Text, TextInput } from 'react-native';
|
||||
import styles from '../../styles';
|
||||
import Background from '../../Components/Background/Background';
|
||||
import { SafeAreaView} from "react-native";
|
||||
import { SafeAreaView, NativeSyntheticEvent, TextInputChangeEventData } from "react-native";
|
||||
import { StatusBar } from "expo-status-bar";
|
||||
import { useState } from "react";
|
||||
import {TouchableOpacity,} from "react-native";
|
||||
|
||||
|
||||
import { TouchableOpacity, } from "react-native";
|
||||
import { NavigationHelpersContext, useNavigation } from "@react-navigation/native";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { SetUser } from "../../Features/Redux/Slices/LoggedInUserSlice/LoggedInUserSlice";
|
||||
import { SetLoggedIn } from "../../Features/Redux/Slices/LoginSlice/LoginSlice";
|
||||
import { UserInfo, UserLogin } from "../../Components/Api/Api";
|
||||
import { RootDrawerParamList } from "../../Interfaces/Interfaces";
|
||||
|
||||
export default function Login() {
|
||||
const [username, setUsername] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
|
||||
const navigation = useNavigation<RootDrawerParamList>();
|
||||
const dispatch = useDispatch();
|
||||
const [user, setUser] = useState({
|
||||
username: "",
|
||||
password: "",
|
||||
});
|
||||
const [error, setError] = useState("");
|
||||
return (
|
||||
<Background>
|
||||
<Text style={{...styles.text_white, ...{fontSize: 32}}}></Text>
|
||||
<Text style={{ ...styles.text_white, ...{ fontSize: 32 } }}></Text>
|
||||
<SafeAreaView>
|
||||
<View style={styles.container}>
|
||||
<Text style ={styles.loginlabel}>Login to Clip Notes</Text>
|
||||
<StatusBar style="auto" />
|
||||
<View style={styles.inputView}>
|
||||
<TextInput
|
||||
style={styles.TextInput}
|
||||
placeholder="Username"
|
||||
placeholderTextColor="white"
|
||||
onChangeText={setUsername}
|
||||
value={username}
|
||||
/>
|
||||
</View>
|
||||
|
||||
<View style={styles.inputView}>
|
||||
<TextInput
|
||||
style={styles.TextInput}
|
||||
placeholder="Password"
|
||||
placeholderTextColor="white"
|
||||
secureTextEntry={true}
|
||||
onChangeText={setPassword}
|
||||
value={password}
|
||||
/>
|
||||
</View>
|
||||
<View style={styles.container}>
|
||||
<Text style={styles.loginlabel}>Login to Clip Notes</Text>
|
||||
<StatusBar style="auto" />
|
||||
<View style={styles.inputView}>
|
||||
<TextInput
|
||||
style={styles.TextInput}
|
||||
placeholder="Username"
|
||||
placeholderTextColor="white"
|
||||
value={user.username}
|
||||
maxLength={20}
|
||||
onChange={(e: NativeSyntheticEvent<TextInputChangeEventData>): void => {
|
||||
setUser({ ...user, username: e.nativeEvent.text });
|
||||
console.log(user.username)
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
|
||||
<TouchableOpacity>
|
||||
<Text style={styles.forgot_button}>Forgot Password?</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity style={styles.loginBtn}>
|
||||
<Text style={styles.loginText}>LOGIN</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity style={styles.registerbtn}>
|
||||
<Text style={styles.registertext}>REGISTER</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
<View style={styles.inputView}>
|
||||
<TextInput
|
||||
style={styles.TextInput}
|
||||
placeholder="Password"
|
||||
placeholderTextColor="white"
|
||||
secureTextEntry={true}
|
||||
value={user.password}
|
||||
onChange={(e: NativeSyntheticEvent<TextInputChangeEventData>): void => {
|
||||
setUser({ ...user, password: e.nativeEvent.text });
|
||||
console.log(user.password)
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
|
||||
<TouchableOpacity>
|
||||
<Text style={styles.forgot_button}>Forgot Password?</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity onPress={async () => {
|
||||
setUser({
|
||||
username: "",
|
||||
password: "",
|
||||
});
|
||||
if (await UserLogin(user)) {
|
||||
await dispatch(SetLoggedIn());
|
||||
await dispatch(SetUser(await UserInfo()));
|
||||
navigation.navigate("Home");
|
||||
} else {
|
||||
setError("Invalid Login");
|
||||
}
|
||||
}}
|
||||
style={styles.loginBtn}>
|
||||
<Text style={styles.loginText}>LOGIN</Text>
|
||||
</TouchableOpacity>
|
||||
<Text style={styles.text_small_red}>{error}</Text>
|
||||
<TouchableOpacity style={styles.registerbtn}>
|
||||
<Text style={styles.registertext}>REGISTER</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</SafeAreaView>
|
||||
</Background>
|
||||
);
|
||||
</Background>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue