/* eslint-disable react-hooks/exhaustive-deps */ import { LoaderCustom } from "@/components"; import ViewWrapper from "@/components/_ShareComponent/ViewWrapper"; import LeftButtonCustom from "@/components/Button/BackButton"; import DrawerCustom from "@/components/Drawer/DrawerCustom"; import { MainColor } from "@/constants/color-palet"; import { useAuth } from "@/hooks/use-auth"; import { drawerItemsProfile } from "@/screens/Profile/ListPage"; import Profile_MenuDrawerSection from "@/screens/Profile/menuDrawerSection"; import Profile_PortofolioSection from "@/screens/Profile/PortofolioSection"; import ProfileSection from "@/screens/Profile/ProfileSection"; import { apiGetPortofolio } from "@/service/api-client/api-portofolio"; import { apiProfile } from "@/service/api-client/api-profile"; import { apiUser } from "@/service/api-client/api-user"; import { GStyles } from "@/styles/global-styles"; import { IProfile } from "@/types/Type-Profile"; import { Ionicons } from "@expo/vector-icons"; import { Stack, useFocusEffect, useLocalSearchParams } from "expo-router"; import React, { useCallback, useState } from "react"; import { TouchableOpacity } from "react-native"; export default function Profile() { const { id } = useLocalSearchParams(); const [isDrawerOpen, setIsDrawerOpen] = useState(false); const [data, setData] = useState(); const [dataToken, setDataToken] = useState(); const [listPortofolio, setListPortofolio] = useState(); const { token, logout, isAdmin, user, userData } = useAuth(); const openDrawer = () => { setIsDrawerOpen(true); }; const closeDrawer = () => { setIsDrawerOpen(false); }; useFocusEffect( useCallback(() => { onLoadData(id as string); onLoadPortofolio(id as string); onLoadUserByToken(); isUserCheck(); userData(token as string); }, [id, token]) ); const isUserCheck = () => { const userId = id; const userLoginId = dataToken?.id; return userId === userLoginId; }; const onLoadData = async (id: string) => { const response = await apiProfile({ id: id }); setData(response.data); }; const onLoadUserByToken = async () => { const response = await apiUser(user?.id as string); setDataToken(response?.data?.Profile); }; const onLoadPortofolio = async (id: string) => { try { const response = await apiGetPortofolio({ id: id }); const lastTwoByDate = response.data .sort( (a: any, b: any) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime() ) // urut desc .slice(0, 2); setListPortofolio(lastTwoByDate); } catch (error) { console.log("[ERROR]", error); } }; return ( <> , headerRight: () => ( ), headerStyle: GStyles.headerStyle, headerTitleStyle: GStyles.headerTitleStyle, }} /> {/* Main View */} {!data || !dataToken ? ( ) : ( <> )} {/* Drawer Komponen Eksternal */} ); } const ButtonnDot = ({ id, openDrawer, isUserCheck, logout, }: { id: string; openDrawer: () => void; isUserCheck: boolean; logout: () => Promise; }) => { const isId = id === undefined || id === null; if (isId) { return ( <> ); } return ( <> {isUserCheck && ( )} ); };