"use client"; import { AccentColor, MainColor, } from "@/app_modules/_global/color/color_pallet"; import ComponentGlobal_ErrorInput from "@/app_modules/_global/component/error_input"; import { ComponentGlobal_NotifikasiBerhasil, ComponentGlobal_NotifikasiGagal, ComponentGlobal_NotifikasiPeringatan, } from "@/app_modules/_global/notif_global"; import { UIGlobal_LayoutDefault } from "@/app_modules/_global/ui"; import { clientLogger } from "@/util/clientLogger"; import { Box, Button, Center, Group, Stack, Text, Title } from "@mantine/core"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { PhoneInput } from "react-international-phone"; import "react-international-phone/style.css"; import { apiFetchLogin } from "../_lib/api_fetch_auth"; export default function Login({ version }: { version: string }) { const router = useRouter(); const [loading, setLoading] = useState(false); const [isError, setError] = useState(false); const [phone, setPhone] = useState(""); const [countryCode, setCountryCode] = useState("62"); // default ke Indonesia async function onLogin() { const nomor = phone; if (nomor.length <= 4) return setError(true); const fixPhone = `${countryCode}${nomor}`; try { setLoading(true); const respone = await apiFetchLogin({ nomor: fixPhone }); if (respone && respone.success) { localStorage.setItem("hipmi_auth_code_id", respone.kodeId); ComponentGlobal_NotifikasiBerhasil(respone.message, 2000); router.push("/validasi", { scroll: false }); } else { setLoading(false); ComponentGlobal_NotifikasiPeringatan(respone?.message); } } catch (error) { setLoading(false); clientLogger.error("Error login:", error); ComponentGlobal_NotifikasiGagal("Terjadi Kesalahan"); } } return ( <> WELCOME TO HIPMI BADUNG APPS powered by muku.id
Nomor telepon
{ const dialCode = meta.country.dialCode; // string, misal: "62" let localNumber = fullPhone; // Hapus kode negara dari awal string if (fullPhone.startsWith(`+${dialCode}`)) { localNumber = fullPhone.slice(`+${dialCode}`.length); } // Bersihkan semua non-digit localNumber = localNumber.replace(/\D/g, ""); // ✅ Filter khusus: untuk Indonesia (+62), hapus leading zero if (dialCode === "62" && localNumber.startsWith("0")) { localNumber = localNumber.replace(/^0+/, ""); // hapus semua 0 di awal } // Simpan hasil akhir setCountryCode(dialCode); setPhone(localNumber); }} /> {isError ? ( ) : ( "" )}
v {version}
); }