import { NewWrapper } from "@/components"; import ButtonCustom from "@/components/Button/ButtonCustom"; import ModalReactNative from "@/components/Modal/ModalReactNative"; import Spacing from "@/components/_ShareComponent/Spacing"; 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 { Redirect } from "expo-router"; import { useEffect, useState } from "react"; 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"; export default function LoginView() { const url = BASE_URL; const [version, setVersion] = useState(""); const [selectedCountry, setSelectedCountry] = useState(null); const [inputValue, setInputValue] = useState(""); const [loading, setLoading] = useState(false); 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(); useEffect(() => { onLoadVersion(); }, []); async function onLoadVersion() { const res = await apiVersion(); if (res.success) { setVersion(versionBadge()); } } async function handleRefresh() { setRefreshing(true); await onLoadVersion(); setInputValue(""); setLoading(false); setRefreshing(false); } function handleInputValue(phoneNumber: string) { setInputValue(phoneNumber); } function handleSelectedCountry(country: ICountry) { setSelectedCountry(country); } async function validateData() { if (inputValue.length === 0) { return Toast.show({ type: "error", text1: "Masukan nomor anda", }); } if (selectedCountry === null) { return Toast.show({ type: "error", text1: "Pilih negara", }); } if (inputValue.length < 9) { return Toast.show({ type: "error", text1: "Nomor tidak valid", }); } return true; } async function handleLogin() { const isValid = await validateData(); if (!isValid) return; const callingCode = selectedCountry?.callingCode.replace(/^\+/, "") || ""; let fixNumber = inputValue.replace(/\s+/g, "").replace(/^0+/, ""); const realNumber = callingCode + fixNumber; try { setLoading(true); const loginRes = await loginWithNomor(realNumber); if (!loginRes) { setModalVisible(true); } setNumberToEULA(realNumber); } catch (error) { console.log("Error login", error); Toast.show({ type: "error", text1: "Error", text2: error as string, }); } finally { setLoading(false); } } if (token && token !== "" && !isUserActive) { return ; } if (token && token !== "" && !isAdmin) { return ; } if (token && token !== "" && isAdmin) { // Akan di aktifkan jika sudah losos review // return ; // Sementara gunakan ini return ; } return ( } > WELCOME TO HIPMI BADUNG APPS {version} | powered by muku.id Login Dengan menggunakan aplikasi ini, Anda telah menyetujui{" "} { const toUrl = `${url}/terms-of-service.html`; openBrowser(toUrl); }} > Syarat & Ketentuan {" "} dan seluruh kebijakan privasi yang berlaku. ); }