Changed auth slice to status slice to better reflect onboarding state tracking

This commit is contained in:
Keannu Bernasol 2023-07-06 21:13:02 +08:00
parent 90f227a2c0
commit b30bbb62df
6 changed files with 38 additions and 35 deletions

View file

@ -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<RootDrawerParamList>();
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 (

View file

@ -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,
},
});

View file

@ -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;

View file

@ -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;

View file

@ -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<RootDrawerParamList>();
@ -55,7 +55,7 @@ export default function Login() {
onChange={(
e: NativeSyntheticEvent<TextInputChangeEventData>
): void => {
setUser({ ...creds, username: e.nativeEvent.text });
setCreds({ ...creds, username: e.nativeEvent.text });
}}
/>
<View style={{ paddingVertical: 4 }} />
@ -68,7 +68,7 @@ export default function Login() {
onChange={(
e: NativeSyntheticEvent<TextInputChangeEventData>
): void => {
setUser({ ...creds, password: e.nativeEvent.text });
setCreds({ ...creds, password: e.nativeEvent.text });
}}
/>
<View style={{ paddingVertical: 2 }} />
@ -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 ||

View file

@ -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 ||