Fakultas Ilmu Komputer UI

Commit c94127c7 authored by Ahmad Izzudin Alifyandra's avatar Ahmad Izzudin Alifyandra
Browse files

Feat: Add initial User Redux state

parent 41d18560
import { StatusBar } from "expo-status-bar"; import { StatusBar } from "expo-status-bar";
import React from "react"; import React from "react";
import { SafeAreaProvider } from "react-native-safe-area-context"; import { SafeAreaProvider } from "react-native-safe-area-context";
import { Provider as StoreProvider } from "react-redux";
import useCachedResources from "./src/hooks/useCachedResources"; import useCachedResources from "./src/hooks/useCachedResources";
import useColorScheme from "./src/hooks/useColorScheme"; import useColorScheme from "./src/hooks/useColorScheme";
import Navigation from "./src/navigation"; import Navigation from "./src/navigation";
import store from "./src/redux/store";
export default function App() { export default function App() {
const isLoadingComplete = useCachedResources(); const isLoadingComplete = useCachedResources();
...@@ -12,10 +14,12 @@ export default function App() { ...@@ -12,10 +14,12 @@ export default function App() {
return null; return null;
} else { } else {
return ( return (
<SafeAreaProvider> <StoreProvider store={store}>
<Navigation /> <SafeAreaProvider>
<StatusBar /> <Navigation />
</SafeAreaProvider> <StatusBar />
</SafeAreaProvider>
</StoreProvider>
); );
} }
} }
import { combineReducers, createStore } from "redux";
import userReducer from "./user/reducer";
const rootReducer = combineReducers({
user: userReducer,
});
const store = createStore(rootReducer);
export type RootState = ReturnType<typeof rootReducer>;
export default store;
import firebase from "firebase/app";
import { Dispatch } from "react-redux/node_modules/@types/react";
const db = firebase.firestore();
export const getUser = (uid) => {
return async (dispatch: Dispatch<any>) => {
try {
const user = await db.collection("users").doc(uid).get();
dispatch({ type: "LOGIN", payload: { ...user.data(), id: user.id } });
} catch (e) {
console.log(e);
}
};
};
//TODO add loginUser
//TODO add logoutUser
//TODO change password
import { AnyAction } from "redux";
import { IUser } from "../../types/firebase/User";
const initialState: IUser = {
id: "",
firstName: "",
lastName: "",
phone: "",
email: "",
pic: "",
};
const userReducer = (state = initialState, action: AnyAction): IUser => {
switch (action.type) {
case "LOGIN":
return action.payload as IUser;
case "LOGOUT":
return initialState;
default:
return state;
}
};
export default userReducer;
export type IUser = {
id?: string;
firstName: string;
lastName: string;
email: string;
phone: string;
pic: string;
};
...@@ -1111,7 +1111,7 @@ ...@@ -1111,7 +1111,7 @@
pirates "^4.0.0" pirates "^4.0.0"
source-map-support "^0.5.16" source-map-support "^0.5.16"
"@babel/runtime@^7.0.0", "@babel/runtime@^7.1.2", "@babel/runtime@^7.7.2", "@babel/runtime@^7.8.4": "@babel/runtime@^7.0.0", "@babel/runtime@^7.1.2", "@babel/runtime@^7.12.1", "@babel/runtime@^7.7.2", "@babel/runtime@^7.8.4", "@babel/runtime@^7.9.2":
version "7.15.4" version "7.15.4"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.15.4.tgz" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.15.4.tgz"
integrity sha512-99catp6bHCaxr4sJ/DbTGgHS4+Rs2RVd2g7iOap6SLGPDknRK9ztKNsE/Fg6QhSeh1FGE5f6gHGQmvvn3I3xhw== integrity sha512-99catp6bHCaxr4sJ/DbTGgHS4+Rs2RVd2g7iOap6SLGPDknRK9ztKNsE/Fg6QhSeh1FGE5f6gHGQmvvn3I3xhw==
...@@ -2772,6 +2772,14 @@ ...@@ -2772,6 +2772,14 @@
resolved "https://registry.yarnpkg.com/@types/hammerjs/-/hammerjs-2.0.40.tgz" resolved "https://registry.yarnpkg.com/@types/hammerjs/-/hammerjs-2.0.40.tgz"
integrity sha512-VbjwR1fhsn2h2KXAY4oy1fm7dCxaKy0D+deTb8Ilc3Eo3rc5+5eA4rfYmZaHgNJKxVyI0f6WIXzO2zLkVmQPHA== integrity sha512-VbjwR1fhsn2h2KXAY4oy1fm7dCxaKy0D+deTb8Ilc3Eo3rc5+5eA4rfYmZaHgNJKxVyI0f6WIXzO2zLkVmQPHA==
"@types/hoist-non-react-statics@^3.3.0":
version "3.3.1"
resolved "https://registry.yarnpkg.com/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz#1124aafe5118cb591977aeb1ceaaed1070eb039f"
integrity sha512-iMIqiko6ooLrTh1joXodJK5X9xeEALT1kM5G3ZLhD3hszxBdIEd5C75U834D9mLcINgD4OyZf5uQXjkuYydWvA==
dependencies:
"@types/react" "*"
hoist-non-react-statics "^3.3.0"
"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0", "@types/istanbul-lib-coverage@^2.0.1": "@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0", "@types/istanbul-lib-coverage@^2.0.1":
version "2.0.3" version "2.0.3"
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.3.tgz" resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.3.tgz"
...@@ -2874,6 +2882,16 @@ ...@@ -2874,6 +2882,16 @@
dependencies: dependencies:
"@types/react" "*" "@types/react" "*"
"@types/react-redux@^7.1.16":
version "7.1.18"
resolved "https://registry.yarnpkg.com/@types/react-redux/-/react-redux-7.1.18.tgz#2bf8fd56ebaae679a90ebffe48ff73717c438e04"
integrity sha512-9iwAsPyJ9DLTRH+OFeIrm9cAbIj1i2ANL3sKQFATqnPWRbg+jEFXyZOKHiQK/N86pNRXbb4HRxAxo0SIX1XwzQ==
dependencies:
"@types/hoist-non-react-statics" "^3.3.0"
"@types/react" "*"
hoist-non-react-statics "^3.3.0"
redux "^4.0.0"
"@types/react@*": "@types/react@*":
version "17.0.20" version "17.0.20"
resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.20.tgz" resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.20.tgz"
...@@ -9075,7 +9093,7 @@ react-dom@16.13.1: ...@@ -9075,7 +9093,7 @@ react-dom@16.13.1:
prop-types "^15.6.2" prop-types "^15.6.2"
scheduler "^0.19.1" scheduler "^0.19.1"
react-is@^16.12.0, react-is@^16.13.0, react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.4, react-is@^16.8.6: react-is@^16.12.0, react-is@^16.13.0, react-is@^16.13.1, react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.4, react-is@^16.8.6:
version "16.13.1" version "16.13.1"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz" resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz"
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ== integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
...@@ -9210,6 +9228,18 @@ react-native-web@~0.13.12: ...@@ -9210,6 +9228,18 @@ react-native-web@~0.13.12:
use-subscription "^1.0.0" use-subscription "^1.0.0"
whatwg-fetch "^3.0.0" whatwg-fetch "^3.0.0"
react-redux@^7.2.5:
version "7.2.5"
resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-7.2.5.tgz#213c1b05aa1187d9c940ddfc0b29450957f6a3b8"
integrity sha512-Dt29bNyBsbQaysp6s/dN0gUodcq+dVKKER8Qv82UrpeygwYeX1raTtil7O/fftw/rFqzaf6gJhDZRkkZnn6bjg==
dependencies:
"@babel/runtime" "^7.12.1"
"@types/react-redux" "^7.1.16"
hoist-non-react-statics "^3.3.2"
loose-envify "^1.4.0"
prop-types "^15.7.2"
react-is "^16.13.1"
react-refresh@^0.4.0: react-refresh@^0.4.0:
version "0.4.3" version "0.4.3"
resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.4.3.tgz" resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.4.3.tgz"
...@@ -9294,6 +9324,13 @@ realpath-native@^2.0.0: ...@@ -9294,6 +9324,13 @@ realpath-native@^2.0.0:
resolved "https://registry.yarnpkg.com/realpath-native/-/realpath-native-2.0.0.tgz" resolved "https://registry.yarnpkg.com/realpath-native/-/realpath-native-2.0.0.tgz"
integrity sha512-v1SEYUOXXdbBZK8ZuNgO4TBjamPsiSgcFr0aP+tEKpQZK8vooEUqV6nm6Cv502mX4NF2EfsnVqtNAHG+/6Ur1Q== integrity sha512-v1SEYUOXXdbBZK8ZuNgO4TBjamPsiSgcFr0aP+tEKpQZK8vooEUqV6nm6Cv502mX4NF2EfsnVqtNAHG+/6Ur1Q==
redux@^4.0.0, redux@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/redux/-/redux-4.1.1.tgz#76f1c439bb42043f985fbd9bf21990e60bd67f47"
integrity sha512-hZQZdDEM25UY2P493kPYuKqviVwZ58lEmGQNeQ+gXa+U0gYPUBf7NKYazbe3m+bs/DzM/ahN12DbF+NG8i0CWw==
dependencies:
"@babel/runtime" "^7.9.2"
regenerate-unicode-properties@^8.2.0: regenerate-unicode-properties@^8.2.0:
version "8.2.0" version "8.2.0"
resolved "https://registry.yarnpkg.com/regenerate-unicode-properties/-/regenerate-unicode-properties-8.2.0.tgz" resolved "https://registry.yarnpkg.com/regenerate-unicode-properties/-/regenerate-unicode-properties-8.2.0.tgz"
......
Supports Markdown
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