Commit c32a69cd authored by Neranga K.T.'s avatar Neranga K.T.

.

parent 89274bdb
......@@ -20,12 +20,14 @@ import {createStore, combineReducers} from 'redux';
import {Provider} from 'react-redux';
import memoryReducer from './src/store/reducers/memory';
import timeReducer from './src/store/reducers/memory'
import userReducer from './src/store/reducers/login';
import AppRouter from "./src/router/router"
const rootReducer = combineReducers({
memory: memoryReducer,
time: timeReducer
time: timeReducer,
users: userReducer
});
const store = createStore(rootReducer);
......
import Users from '../model/Users';
export const USERS = [
new Users(
'1',
'teran@helply.com',
'12345678',
'teran'
),
new Users(
'2',
'rusiru@helply.com',
'12345678',
'rusiru'
),
new Users(
'3',
'madawa@helply.com',
'12345678',
'madawa'
),
new Users(
'4',
'navodh@helply.com',
'12345678',
'navodh'
),
]
\ No newline at end of file
class Users {
constructor(uid,email, password, name){
this.uid = uid,
this.email = email,
this.password = password,
this.name = name
}
}
export default Users;
\ No newline at end of file
......@@ -2,6 +2,8 @@ import { useNavigation } from "@react-navigation/native";
import Orientation from 'react-native-orientation-locker';
import React, { useState } from "react";
import { SafeAreaView, ScrollView, View, StyleSheet, ImageBackground, Text, TextInput, TouchableOpacity, Image } from "react-native";
import {useSelector, useDispatch} from 'react-redux';
import {userLogin} from '../../store/actions/login';
import client from "../client/Client";
......@@ -23,6 +25,10 @@ const isValidEmail = (value) => {
const Login = () => {
const dispatch = useDispatch();
const users = useSelector(state=>state.users.users);
const navigation = useNavigation();
React.useEffect(() => {
......@@ -66,6 +72,20 @@ const Login = () => {
return true;
}
const loginHandler = () => {
const loggedInUser = users.find(user=>user.email === email && user.password === password)
if(loggedInUser){
console.log(loggedInUser);
dispatch(userLogin({
name: loggedInUser.name,
id: loggedInUser.uid
}));
navigation.navigate('Home');
}else{
console.log('Invalid user credentials...');
}
}
const submitForm = () => {
if (isValidForm()){
......
export const USER_LOGIN = 'USER_LOGIN';
export const userLogin = (user) => {
return {type: USER_LOGIN, user: user}
}
\ No newline at end of file
import {USER_LOGIN} from '../actions/login';
import { USERS } from '../../data/dummy-data';
const initialState = {
users : USERS,
loggedInUser: {}
}
const userReducer = (state = initialState, action) => {
switch (action.type) {
case USER_LOGIN:
return{
...state,
loggedInUser: action.user
}
default:
return state;
}
return state;
}
export default userReducer;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment