From 877da5123ae52a8e1cfdd3c21d7d942a07d979ac Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Tue, 4 Jul 2023 19:37:55 +0800 Subject: [PATCH] Improved drawer logout and activation page --- .../DrawerSettings/CustomDrawerContent.tsx | 5 ++- src/routes/Activation/Activation.tsx | 41 ++++++++++++------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/components/DrawerSettings/CustomDrawerContent.tsx b/src/components/DrawerSettings/CustomDrawerContent.tsx index 39be406..21332e3 100644 --- a/src/components/DrawerSettings/CustomDrawerContent.tsx +++ b/src/components/DrawerSettings/CustomDrawerContent.tsx @@ -48,7 +48,8 @@ export default function CustomDrawerContent(props: {}) { color={colors.blue_2} onPress={async () => { dispatch(await clear()); - AsyncStorage.clear(); + await AsyncStorage.clear(); + navigation.navigate("Home"); }} > @@ -90,7 +91,7 @@ export default function CustomDrawerContent(props: {}) { color={colors.blue_2} onPress={() => { dispatch(clear()); - navigation.navigate("Login"); + navigation.navigate("Register"); }} > diff --git a/src/routes/Activation/Activation.tsx b/src/routes/Activation/Activation.tsx index d9d7b9d..dce7f24 100644 --- a/src/routes/Activation/Activation.tsx +++ b/src/routes/Activation/Activation.tsx @@ -2,9 +2,10 @@ import * as React from "react"; import styles, { colors } from "../../styles"; import { View, Text, ActivityIndicator } from "react-native"; import AnimatedContainer from "../../components/AnimatedContainer/AnimatedContainer"; -import { useRoute } from "@react-navigation/native"; +import { useNavigation, useRoute } from "@react-navigation/native"; import { useEffect, useState } from "react"; import { UserActivate } from "../../components/Api/Api"; +import { RootDrawerParamList } from "../../interfaces/Interfaces"; interface ActivationRouteParams { uid?: string; @@ -14,26 +15,35 @@ interface ActivationRouteParams { export default function Activation() { const route = useRoute(); const { uid, token } = (route.params as ActivationRouteParams) || ""; - + const navigation = useNavigation(); const [state, setState] = useState( "Activating with UID " + uid + " and Token " + token ); const [loading, setLoading] = useState(true); - async function activate() { - if (await UserActivate({ uid: String(uid), token: String(token) })) { - setTimeout(() => { - setState("Activation successful!"); - }, 1000); - } else { - setTimeout(() => { - setState("Activation unsuccessful\nPlease contact support"); - }, 1000); - } - setLoading(false); - } + useEffect(() => { + async function activate() { + let result = await UserActivate({ + uid: String(uid), + token: String(token), + }); + if (result) { + setTimeout(() => { + setState("Activation successful!"); + }, 1000); + setTimeout(() => { + navigation.navigate("Login"); + }, 2000); + } else { + setTimeout(() => { + setState("Activation unsuccessful\nPlease contact support"); + }, 1000); + } + setLoading(false); + } activate(); - }, []); + }, [uid, token]); + return ( @@ -54,6 +64,7 @@ export default function Activation() { color={colors.blue_1} /> {state} + {uid + "\n" + token} );