diff --git a/App.tsx b/App.tsx
index b766208..eb068e7 100644
--- a/App.tsx
+++ b/App.tsx
@@ -75,9 +75,9 @@ export default function App() {
drawerContent={CustomDrawerContent}
screenOptions={DrawerScreenSettings}
>
-
+
diff --git a/src/components/Api/Api.tsx b/src/components/Api/Api.tsx
index b6362d7..9537cd1 100644
--- a/src/components/Api/Api.tsx
+++ b/src/components/Api/Api.tsx
@@ -254,6 +254,7 @@ export async function PatchStudentStatus(info: StudentStatusPatchType) {
})
.catch((error) => {
let error_message = ParseError(error);
+ console.log("DEBUG", error.response.data);
return [false, error_message];
});
}
diff --git a/src/components/DrawerSettings/CustomDrawerContent.tsx b/src/components/DrawerSettings/CustomDrawerContent.tsx
index b74d053..40901f0 100644
--- a/src/components/DrawerSettings/CustomDrawerContent.tsx
+++ b/src/components/DrawerSettings/CustomDrawerContent.tsx
@@ -5,7 +5,10 @@ import { Text, View } from "react-native";
import { colors } from "../../styles";
import styles from "../../styles";
-import { RootDrawerParamList } from "../../interfaces/Interfaces";
+import {
+ RootDrawerParamList,
+ StudentStatusPatchType,
+} from "../../interfaces/Interfaces";
import AppIcon from "../../icons/AppIcon/AppIcon";
import HomeIcon from "../../icons/HomeIcon/HomeIcon";
import LoginIcon from "../../icons/LoginIcon/LoginIcon";
@@ -18,13 +21,48 @@ import { logout } from "../../features/redux/slices/StatusSlice/StatusSlice";
import AsyncStorage from "@react-native-async-storage/async-storage";
import UserIcon from "../../icons/UserIcon/UserIcon";
import SubjectIcon from "../../icons/SubjectIcon/SubjectIcon";
-import { useQueryClient } from "@tanstack/react-query";
+import { useMutation, useQueryClient } from "@tanstack/react-query";
+import toast from "react-native-toast-notifications/lib/typescript/toast";
+import { PatchStudentStatus } from "../Api/Api";
+import { useToast } from "react-native-toast-notifications";
export default function CustomDrawerContent(props: {}) {
const navigation = useNavigation();
const status = useSelector((state: RootState) => state.status);
const dispatch = useDispatch();
const queryClient = useQueryClient();
+ const debug = false;
+ const toast = useToast();
+ const stop_studying_logout = useMutation({
+ mutationFn: async (info: StudentStatusPatchType) => {
+ const data = await PatchStudentStatus(info);
+ if (data[0] != true) {
+ return Promise.reject(new Error());
+ }
+ console.log("DEBUG", data);
+ return data;
+ },
+ onSuccess: async () => {
+ toast.show("Logged out. Stopped studying", {
+ type: "warning",
+ placement: "top",
+ duration: 2000,
+ animationType: "slide-in",
+ });
+ queryClient.clear();
+ dispatch(logout());
+ await AsyncStorage.clear();
+ navigation.navigate("Login");
+ },
+ onError: (error: Error) => {
+ toast.show(String(error), {
+ type: "warning",
+ placement: "top",
+ duration: 2000,
+ animationType: "slide-in",
+ });
+ },
+ });
if (status.logged_in && status.onboarding) {
return (
@@ -39,11 +77,10 @@ export default function CustomDrawerContent(props: {}) {
{
- dispatch(logout());
- await AsyncStorage.clear();
- queryClient.clear();
- navigation.navigate("Login");
+ onPress={() => {
+ stop_studying_logout.mutate({
+ active: false,
+ });
}}
>
@@ -88,10 +125,10 @@ export default function CustomDrawerContent(props: {}) {
Subjects
{
- dispatch(logout());
- await AsyncStorage.clear();
- navigation.navigate("Login");
+ onPress={() => {
+ stop_studying_logout.mutate({
+ active: false,
+ });
}}
>
diff --git a/src/interfaces/Interfaces.tsx b/src/interfaces/Interfaces.tsx
index 8dd10b1..ae61d63 100644
--- a/src/interfaces/Interfaces.tsx
+++ b/src/interfaces/Interfaces.tsx
@@ -13,6 +13,7 @@ export interface ResponsiveIconProps {
export interface RootDrawerParamList {
navigate: any;
+ replace: any;
}
// Redux Interfaces