diff --git a/app/(application)/home.tsx b/app/(application)/home.tsx index b45163c..7da9162 100644 --- a/app/(application)/home.tsx +++ b/app/(application)/home.tsx @@ -16,7 +16,7 @@ import { useQuery, useQueryClient } from "@tanstack/react-query"; import { LinearGradient } from "expo-linear-gradient"; import { Stack } from "expo-router"; import { useEffect, useState } from "react"; -import { Dimensions, Platform, RefreshControl, SafeAreaView, ScrollView, View } from "react-native"; +import { Alert, Dimensions, Platform, RefreshControl, SafeAreaView, ScrollView, View } from "react-native"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import { useDispatch, useSelector } from "react-redux"; @@ -55,6 +55,26 @@ export default function Home() { } }, [isError, signOut]) + useEffect(() => { + if (profile && profile.isActive === false) { + Alert.alert( + 'Akun Dinonaktifkan', + 'Akun kamu telah dinonaktifkan. Silahkan hubungi admin untuk informasi lebih lanjut.', + [{ text: 'OK', onPress: signOut }] + ) + } + }, [profile, signOut]) + + useEffect(() => { + if (profile && profile.villageIsActive === false) { + Alert.alert( + 'Desa Dinonaktifkan', + 'Desa kamu saat ini telah dinonaktifkan. Silahkan hubungi pengelola sistem untuk informasi lebih lanjut.', + [{ text: 'OK', onPress: signOut }] + ) + } + }, [profile, signOut]) + const handleRefresh = async () => { setRefreshing(true) // Invalidate all queries related to the home screen diff --git a/providers/AuthProvider.tsx b/providers/AuthProvider.tsx index 1087f55..a1793cd 100644 --- a/providers/AuthProvider.tsx +++ b/providers/AuthProvider.tsx @@ -2,6 +2,7 @@ import { ConstEnv } from '@/constants/ConstEnv'; import { apiRegisteredToken, apiUnregisteredToken } from '@/lib/api'; import { getToken } from '@/lib/useNotification'; import AsyncStorage from '@react-native-async-storage/async-storage'; +import { useQueryClient } from '@tanstack/react-query'; import CryptoES from "crypto-es"; import { router } from "expo-router"; import { createContext, MutableRefObject, ReactNode, useCallback, useContext, useEffect, useRef, useState } from 'react'; @@ -30,6 +31,7 @@ export function useAuthSession() { export default function AuthProvider({ children }: { children: ReactNode }): ReactNode { const tokenRef = useRef(null); const [isLoading, setIsLoading] = useState(true); + const queryClient = useQueryClient(); useEffect(() => { (async (): Promise => { @@ -87,6 +89,7 @@ export default function AuthProvider({ children }: { children: ReactNode }): Rea } finally { await AsyncStorage.setItem('@token', ''); tokenRef.current = null; + queryClient.clear(); router.replace('/'); } }, []);