diff --git a/app/(application)/admin/user-access/[id]/index.tsx b/app/(application)/admin/user-access/[id]/index.tsx index 17c8468..827b3d4 100644 --- a/app/(application)/admin/user-access/[id]/index.tsx +++ b/app/(application)/admin/user-access/[id]/index.tsx @@ -10,14 +10,10 @@ import { import AdminBackButtonAntTitle from "@/components/_ShareComponent/Admin/BackButtonAntTitle"; import GridTwoView from "@/components/_ShareComponent/GridTwoView"; import { useAuth } from "@/hooks/use-auth"; -import { routeUser } from "@/lib/routeApp"; import { apiAdminUserAccessGetById, apiAdminUserAccessUpdateStatus, } from "@/service/api-admin/api-admin-user-access"; -import { - apiNotificationsSendById -} from "@/service/api-notifications"; import { router, useFocusEffect, useLocalSearchParams } from "expo-router"; import { useCallback, useState } from "react"; import Toast from "react-native-toast-message"; @@ -70,20 +66,6 @@ export default function AdminUserAccessDetail() { text1: "Update aktifasi berhasil ", }); - if (data.active === false) { - await apiNotificationsSendById({ - data: { - title: "Akun anda telah diaktifkan", - body: "Selamat menjelajahi HIConnect", - userLoginId: user?.id || "", - kategoriApp: "OTHER", - type: "announcement", - deepLink: routeUser.home, - }, - id: id as string, - }); - } - router.back(); } catch (error) { console.log("[ERROR UPDATE STATUS]", error); diff --git a/components/Image/AvatarComp.tsx b/components/Image/AvatarComp.tsx index 59b9542..1c88c23 100644 --- a/components/Image/AvatarComp.tsx +++ b/components/Image/AvatarComp.tsx @@ -30,7 +30,6 @@ export default function AvatarComp({ href = `/(application)/(image)/preview-image/${fileId}`, }: AvatarCompProps) { const dimension = sizeMap[size]; - const avatarImage = () => { return ( router.navigate(href as any) : onPress } + disabled={!fileId} > {avatarImage()} diff --git a/context/AuthContext.tsx b/context/AuthContext.tsx index 39b67af..8dd2818 100644 --- a/context/AuthContext.tsx +++ b/context/AuthContext.tsx @@ -30,7 +30,10 @@ type AuthContextType = { termsOfServiceAccepted: boolean; }) => Promise; userData: (token: string) => Promise; - acceptedTerms: (nomor: string, onSetModalVisible: (visible: boolean) => void) => Promise; + acceptedTerms: ( + nomor: string, + onSetModalVisible: (visible: boolean) => void, + ) => Promise; }; // --- Create Context --- @@ -80,34 +83,12 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => { console.log("[RESPONSE AUTH]", JSON.stringify(response, null, 2)); if (response.success && response.isAcceptTerms) { - await AsyncStorage.setItem("kode_otp", response.kodeId); router.push(`/verification?nomor=${nomor}`); return true; } else { - // router.push(`/eula?nomor=${nomor}`); return false; } - - // if (response.success) { - // if (response.isAcceptTerms) { - // Toast.show({ - // type: "success", - // text1: "Sukses", - // text2: "Kode OTP berhasil dikirim", - // }); - - // await AsyncStorage.setItem("kode_otp", response.kodeId); - // router.push(`/verification?nomor=${nomor}`); - // return false - // } else { - // // router.push(`/eula?nomor=${nomor}`); - // return true - // } - // } else { - // router.push(`/eula?nomor=${nomor}`); - // return true; - // } } catch (error: any) { throw new Error(error.response?.data?.message || "Gagal kirim OTP"); } finally { @@ -266,29 +247,24 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => { }; // --- 6. Accept Terms --- - const acceptedTerms = async (nomor: string, onSetModalVisible: (visible: boolean) => void) => { + const acceptedTerms = async ( + nomor: string, + onSetModalVisible: (visible: boolean) => void, + ) => { try { setIsLoading(true); const response = await apiUpdatedTermCondition({ nomor: nomor }); if (response.success) { - router.replace(`/verification?nomor=${nomor}`); + return `/verification?nomor=${nomor}`; } else { - if (response.status === 404) { - router.replace(`/register?nomor=${nomor}`); - } else { - Toast.show({ - type: "error", - text1: "Error", - text2: response.message, - }); - } + return `/register?nomor=${nomor}`; } } catch (error) { console.log("Error accept terms", error); } finally { setIsLoading(false); - // onSetModalVisible(false); + onSetModalVisible(false); } }; diff --git a/screens/Authentication/EULASection.tsx b/screens/Authentication/EULASection.tsx index ad4a662..d73e6e4 100644 --- a/screens/Authentication/EULASection.tsx +++ b/screens/Authentication/EULASection.tsx @@ -7,13 +7,21 @@ import { StyleSheet, } from "react-native"; import { useState, useRef } from "react"; -import { useLocalSearchParams, useRouter } from "expo-router"; +import { router, useLocalSearchParams, useRouter } from "expo-router"; import { SafeAreaView } from "react-native-safe-area-context"; import { AccentColor, MainColor } from "@/constants/color-palet"; import { useAuth } from "@/hooks/use-auth"; +import Toast from "react-native-toast-message"; - -export default function EULASection({ nomor, onSetModalVisible }: { nomor: string, onSetModalVisible: (visible: boolean) => void }) { +export default function EULASection({ + nomor, + onSetModalVisible, + setLoadingTerm, +}: { + nomor: string; + onSetModalVisible: (visible: boolean) => void; + setLoadingTerm: (loading: boolean) => void; +}) { const { acceptedTerms } = useAuth(); const [isLoading, setIsLoading] = useState(false); const [isAtBottom, setIsAtBottom] = useState(false); @@ -35,12 +43,26 @@ export default function EULASection({ nomor, onSetModalVisible }: { nomor: strin if (!isAtBottom) return; setIsLoading(true); - await acceptedTerms(nomor as string, onSetModalVisible); + const responseAccept = await acceptedTerms( + nomor as string, + onSetModalVisible, + ); + + console.log("Accept terms", responseAccept); + setLoadingTerm(true); + + setTimeout(() => { + router.replace(responseAccept); + }, 500); } catch (error) { console.log("Error accept terms", error); + Toast.show({ + type: "error", + text1: "Error", + text2: "Terjadi kesalahan saat menerima syarat dan ketentuan", + }); } finally { setIsLoading(false); - } }; diff --git a/screens/Authentication/LoginView.tsx b/screens/Authentication/LoginView.tsx index 1ea8558..f52db47 100644 --- a/screens/Authentication/LoginView.tsx +++ b/screens/Authentication/LoginView.tsx @@ -1,18 +1,16 @@ -import { NewWrapper, TextCustom } from "@/components"; +import { NewWrapper } from "@/components"; import ButtonCustom from "@/components/Button/ButtonCustom"; import ModalReactNative from "@/components/Modal/ModalReactNative"; import Spacing from "@/components/_ShareComponent/Spacing"; -import ViewWrapper from "@/components/_ShareComponent/ViewWrapper"; import { MainColor } from "@/constants/color-palet"; import { useAuth } from "@/hooks/use-auth"; import { apiVersion, BASE_URL } from "@/service/api-config"; import { GStyles } from "@/styles/global-styles"; import { openBrowser } from "@/utils/openBrower"; import versionBadge from "@/utils/viersionBadge"; -import VersionBadge from "@/utils/viersionBadge"; import { Redirect } from "expo-router"; import { useEffect, useState } from "react"; -import { Modal, RefreshControl, Text, View } from "react-native"; +import { RefreshControl, Text, View } from "react-native"; import PhoneInput, { ICountry } from "react-native-international-phone-number"; import Toast from "react-native-toast-message"; import EULASection from "./EULASection"; @@ -26,6 +24,7 @@ export default function LoginView() { const [refreshing, setRefreshing] = useState(false); const [modalVisible, setModalVisible] = useState(false); const [numberToEULA, setNumberToEULA] = useState(""); + const [loadingTerm, setLoadingTerm] = useState(false); const { loginWithNomor, token, isAdmin, isUserActive } = useAuth(); @@ -90,7 +89,6 @@ export default function LoginView() { let fixNumber = inputValue.replace(/\s+/g, "").replace(/^0+/, ""); const realNumber = callingCode + fixNumber; - try { setLoading(true); @@ -129,6 +127,8 @@ export default function LoginView() { return ; } + console.log("load term", loadingTerm); + return ( - WELCOME TO @@ -172,21 +171,15 @@ export default function LoginView() { - + Login - {/* { - setModalVisible(true); - console.log("Show modal", modalVisible); - }} - > - Show Modal - */} - {/* setTerm(!term)} /> */} - @@ -208,7 +201,11 @@ export default function LoginView() { - + ); diff --git a/screens/Forum/ViewBeranda3.tsx b/screens/Forum/ViewBeranda3.tsx index 997e3fd..f119d65 100644 --- a/screens/Forum/ViewBeranda3.tsx +++ b/screens/Forum/ViewBeranda3.tsx @@ -2,21 +2,20 @@ import { AvatarComp, BackButton, FloatingButton, - SearchInput, - TextCustom, + SearchInput } from "@/components"; import NewWrapper from "@/components/_ShareComponent/NewWrapper"; -import { useAuth } from "@/hooks/use-auth"; +import { MainColor } from "@/constants/color-palet"; import { createPaginationComponents } from "@/helpers/paginationHelpers"; +import { useAuth } from "@/hooks/use-auth"; +import { usePagination } from "@/hooks/use-pagination"; import Forum_BoxDetailSection from "@/screens/Forum/DiscussionBoxSection"; import { apiForumGetAll } from "@/service/api-client/api-forum"; import { apiUser } from "@/service/api-client/api-user"; import { router, Stack } from "expo-router"; import _ from "lodash"; import { useEffect, useState } from "react"; -import { RefreshControl, View } from "react-native"; -import { MainColor } from "@/constants/color-palet"; -import { usePagination } from "@/hooks/use-pagination"; +import { RefreshControl, TouchableOpacity, View } from "react-native"; const PAGE_SIZE = 5; @@ -36,7 +35,7 @@ export default function Forum_ViewBeranda3() { const pagination = usePagination({ fetchFunction: async (page, searchQuery) => { if (!user?.id) return { data: [] }; - + return await apiForumGetAll({ category: "beranda", search: searchQuery || "", @@ -51,16 +50,17 @@ export default function Forum_ViewBeranda3() { }); // Generate komponen (menggantikan 40+ lines code!) - const { ListEmptyComponent, ListFooterComponent } = createPaginationComponents({ - loading: pagination.loading, - refreshing: pagination.refreshing, - listData: pagination.listData, - searchQuery: search, - emptyMessage: "Tidak ada diskusi", - emptySearchMessage: "Tidak ada hasil pencarian", - skeletonCount: 5, - skeletonHeight: 150, - }); + const { ListEmptyComponent, ListFooterComponent } = + createPaginationComponents({ + loading: pagination.loading, + refreshing: pagination.refreshing, + listData: pagination.listData, + searchQuery: search, + emptyMessage: "Tidak ada diskusi", + emptySearchMessage: "Tidak ada hasil pencarian", + skeletonCount: 5, + skeletonHeight: 150, + }); // Render item forum const renderForumItem = ({ item }: { item: any }) => ( @@ -74,11 +74,11 @@ export default function Forum_ViewBeranda3() { /> ); -// const ListHeaderComponent = ( -// -// Diskusi Terbaru -// -// ); + // const ListHeaderComponent = ( + // + // Diskusi Terbaru + // + // ); return ( <> @@ -87,11 +87,15 @@ export default function Forum_ViewBeranda3() { title: "Forum", headerLeft: () => , headerRight: () => ( - + router.navigate(`/forum/${user?.id}/forumku`)} + > + + ), }} /> @@ -129,4 +133,4 @@ export default function Forum_ViewBeranda3() { /> ); -} \ No newline at end of file +} diff --git a/screens/Profile/AvatarAndBackground.tsx b/screens/Profile/AvatarAndBackground.tsx index 4d490c1..3090b91 100644 --- a/screens/Profile/AvatarAndBackground.tsx +++ b/screens/Profile/AvatarAndBackground.tsx @@ -21,6 +21,7 @@ const AvatarAndBackground = ({ `/(application)/(image)/preview-image/${backgroundId}` ); }} + disabled={!backgroundId} >