import Spacing from "@/components/_ShareComponent/Spacing"; import ViewWrapper from "@/components/_ShareComponent/ViewWrapper"; import ButtonCustom from "@/components/Button/ButtonCustom"; import { MainColor } from "@/constants/color-palet"; import { useAuth } from "@/hooks/use-auth"; import { apiCheckCodeOtp } from "@/service/api-config"; import { GStyles } from "@/styles/global-styles"; import { registerForPushNotificationsAsync } from "@/utils/notifications"; import AsyncStorage from "@react-native-async-storage/async-storage"; import { router, useLocalSearchParams } from "expo-router"; import { useEffect, useState } from "react"; import { Text, View } from "react-native"; import { OtpInput } from "react-native-otp-entry"; import { ActivityIndicator } from "react-native-paper"; import Toast from "react-native-toast-message"; export default function VerificationView() { const { nomor } = useLocalSearchParams<{ nomor: string }>(); console.log("[NOMOR]", nomor); const [inputOtp, setInputOtp] = useState(""); const [userNumber, setUserNumber] = useState(""); const [loading, setLoading] = useState(false); const [recodeOtp, setRecodeOtp] = useState(false); // 🔑 DETEKSI MODE REVIEW (HANYA UNTUK NOMOR DEMO & PRODUCTION) const isReviewMode = typeof window !== "undefined" && // pastikan di browser/production process.env.NODE_ENV === "production" && nomor === "6282340374412"; // --- Context --- const { validateOtp, isLoading, loginWithNomor } = useAuth(); useEffect(() => { setUserNumber(nomor?.replace(/^\+/, "") || ""); if (!isReviewMode) { // Hanya jalankan logika OTP normal jika BUKAN review mode onLoadCheckCodeOtp(); } console.log("[NODE_ENV]:", process.env.NODE_ENV); console.log("[isReviewMode]:", isReviewMode); console.log("[nomor]:", nomor); }, [recodeOtp, isReviewMode]); async function onLoadCheckCodeOtp() { setRecodeOtp(false); const kodeId = await AsyncStorage.getItem("kode_otp"); if (!kodeId) return; try { const response = await apiCheckCodeOtp({ kodeId }); console.log( "[OTP] >>", JSON.stringify(response.otp, null, 2) ); // Kita tidak perlu simpan codeOtp di state karena verifikasi dilakukan di backend // Cukup simpan nomor } catch (error) { console.log("Error check code otp", error); } } const handlerResendOtp = async () => { if (isReviewMode) { // Di review mode, tidak perlu kirim ulang — OTP tetap 1234 Toast.show({ type: "info", text1: "OTP demo: 1234" }); return; } try { setLoading(true); await loginWithNomor(nomor as string); setRecodeOtp(true); // ❌ Kamu tidak punya nomor di sini, jadi pastikan `nomor` tersedia // Sebaiknya simpan nomor saat login, atau gunakan dari `useLocalSearchParams` router.setParams({ nomor }); // opsional } catch (error) { console.log("Error resend OTP", error); } finally { setLoading(false); } }; const handleVerification = async () => { if (isReviewMode) { // ✅ VERIFIKASI OTOMATIS UNTUK APPLE REVIEW if (inputOtp === "1234") { try { await validateOtp(nomor as string); return; } catch (error) { console.log("Error verification", error); Toast.show({ type: "error", text1: "Gagal verifikasi" }); } } else { Toast.show({ type: "error", text1: "Kode OTP tidak sesuai" }); } return; } // 🔁 VERIFIKASI NORMAL (untuk pengguna sungguhan) try { await validateOtp(nomor as string); return } catch (error) { console.log("Error verification", error); Toast.show({ type: "error", text1: "Gagal verifikasi" }); } }; return ( <> Verifikasi Kode OTP Masukan 4 digit kode otp Yang dikirim ke +{userNumber} setInputOtp(otp)} /> Tidak menerima kode? {loading ? ( ) : ( {" Kirim Ulang"} )} Verifikasi ); }