diff --git a/src/components/DrawerSettings/CustomDrawerContent.tsx b/src/components/DrawerSettings/CustomDrawerContent.tsx index c479bc7..1c912e8 100644 --- a/src/components/DrawerSettings/CustomDrawerContent.tsx +++ b/src/components/DrawerSettings/CustomDrawerContent.tsx @@ -14,14 +14,12 @@ import DrawerButton from "../Button/DrawerButton"; import { useDispatch, useSelector } from "react-redux"; import { RootState } from "../../features/redux/Store/Store"; import LogoutIcon from "../../icons/LogoutIcon/LogoutIcon"; -import { logout } from "../../features/redux/slices/AuthSlice/AuthSlice"; +import { logout } from "../../features/redux/slices/StatusSlice/StatusSlice"; import AsyncStorage from "@react-native-async-storage/async-storage"; export default function CustomDrawerContent(props: {}) { const navigation = useNavigation(); - const logged_in = useSelector( - (state: RootState) => state.auth.creds.logged_in - ); + const logged_in = useSelector((state: RootState) => state.status.logged_in); const dispatch = useDispatch(); if (logged_in) { return ( diff --git a/src/features/redux/Store/Store.tsx b/src/features/redux/Store/Store.tsx index 21d3f6d..9fd7cd1 100644 --- a/src/features/redux/Store/Store.tsx +++ b/src/features/redux/Store/Store.tsx @@ -1,10 +1,10 @@ import { configureStore } from "@reduxjs/toolkit"; -import AuthReducer from "../slices/AuthSlice/AuthSlice"; +import StatusReducer from "../slices/StatusSlice/StatusSlice"; import UserReducer from "../slices/UserSlice/UserSlice"; const store = configureStore({ reducer: { - auth: AuthReducer, + status: StatusReducer, user: UserReducer, }, }); diff --git a/src/features/redux/slices/AuthSlice/AuthSlice.tsx b/src/features/redux/slices/AuthSlice/AuthSlice.tsx deleted file mode 100644 index a4a54f6..0000000 --- a/src/features/redux/slices/AuthSlice/AuthSlice.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import { createSlice } from "@reduxjs/toolkit"; - -export const AuthSlice = createSlice({ - name: "Auth", - initialState: { - creds: { - logged_in: false, - }, - }, - reducers: { - login: (state) => { - state.creds.logged_in = true; - }, - logout: (state) => { - state.creds.logged_in = false; - }, - }, -}); - -// Action creators are generated for each case reducer function -export const { login, logout } = AuthSlice.actions; - -export default AuthSlice.reducer; diff --git a/src/features/redux/slices/StatusSlice/StatusSlice.tsx b/src/features/redux/slices/StatusSlice/StatusSlice.tsx new file mode 100644 index 0000000..c46479d --- /dev/null +++ b/src/features/redux/slices/StatusSlice/StatusSlice.tsx @@ -0,0 +1,28 @@ +import { createSlice } from "@reduxjs/toolkit"; + +export const StatusSlice = createSlice({ + name: "Status", + initialState: { + logged_in: false, + onboarding: false, + }, + reducers: { + login: (state) => { + state.logged_in = true; + }, + logout: (state) => { + state.logged_in = false; + }, + onboard: (state) => { + state.onboarding = true; + }, + not_onboard: (state) => { + state.onboarding = false; + }, + }, +}); + +// Action creators are generated for each case reducer function +export const { login, logout, onboard, not_onboard } = StatusSlice.actions; + +export default StatusSlice.reducer; diff --git a/src/routes/Login/Login.tsx b/src/routes/Login/Login.tsx index 7b8cc4c..a87505d 100644 --- a/src/routes/Login/Login.tsx +++ b/src/routes/Login/Login.tsx @@ -18,7 +18,7 @@ import { UserInfo, UserLogin } from "../../components/Api/Api"; import { ParseLoginError } from "../../components/ParseError/ParseError"; import AnimatedContainer from "../../components/AnimatedContainer/AnimatedContainer"; import { setUser } from "../../features/redux/slices/UserSlice/UserSlice"; -import { login } from "../../features/redux/slices/AuthSlice/AuthSlice"; +import { login } from "../../features/redux/slices/StatusSlice/StatusSlice"; export default function Login() { const navigation = useNavigation(); @@ -55,7 +55,7 @@ export default function Login() { onChange={( e: NativeSyntheticEvent ): void => { - setUser({ ...creds, username: e.nativeEvent.text }); + setCreds({ ...creds, username: e.nativeEvent.text }); }} /> @@ -68,7 +68,7 @@ export default function Login() { onChange={( e: NativeSyntheticEvent ): void => { - setUser({ ...creds, password: e.nativeEvent.text }); + setCreds({ ...creds, password: e.nativeEvent.text }); }} /> @@ -84,7 +84,7 @@ export default function Login() { setUser({ ...creds, username: "", password: "", error: "" }); let user_info = await UserInfo(); dispatch(login()); - console.log(dispatch(setUser(user_info[1]))); + dispatch(setUser(user_info[1])); // Redirect to onboarding if no year level, course, or semester specified if ( user_info[1].year_level == null || diff --git a/src/routes/Revalidation/Revalidation.tsx b/src/routes/Revalidation/Revalidation.tsx index eefc659..ddb1ce5 100644 --- a/src/routes/Revalidation/Revalidation.tsx +++ b/src/routes/Revalidation/Revalidation.tsx @@ -7,7 +7,7 @@ import { colors } from "../../styles"; import { useEffect, useState } from "react"; import { useNavigation } from "@react-navigation/native"; import { RootDrawerParamList } from "../../interfaces/Interfaces"; -import { login } from "../../features/redux/slices/AuthSlice/AuthSlice"; +import { login } from "../../features/redux/slices/StatusSlice/StatusSlice"; import AnimatedContainer from "../../components/AnimatedContainer/AnimatedContainer"; import { setUser } from "../../features/redux/slices/UserSlice/UserSlice"; @@ -21,7 +21,7 @@ export default function Revalidation() { let user_info = await UserInfo(); if (response && user_info[0]) { dispatch(login()); - console.log(dispatch(setUser(user_info[1]))); + dispatch(setUser(user_info[1])); if ( !( user_info[1].year_level ||