"use client" import { LayoutLogin, WARNA } from "@/module/_global"; import { Box, Button, Stack, Text, TextInput } from "@mantine/core"; import { useFocusTrap } from "@mantine/hooks"; import { useState } from "react"; import toast from "react-hot-toast"; import ViewVerification from "../../varification/view/view_verification"; function ViewLogin() { const focusTrapRef = useFocusTrap() const textInfo = "Kami akan mengirimkan kode verifikasi melalui WhatsApp untuk mengonfirmasi nomor Anda."; const [isPhone, setPhone] = useState("") const [isOTP, setOTP] = useState(null) const [isValPhone, setValPhone] = useState(null) const [isUser, setUser] = useState(null) const [isVerif, setVerif] = useState(false) const [isLoading, setLoading] = useState(false) async function onLogin() { if (isPhone == "") return toast.error('Silakan diisi dengan lengkap') if (isPhone.toString().length <= 8) return toast.error('Nomor telepon tidak valid') try { setLoading(true) const cek = await fetch('/api/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ phone: isPhone }) }) const cekLogin = await cek.json() if (cekLogin.success) { const code = Math.floor(Math.random() * 1000) + 1000 try { const res = await fetch(`https://wa.wibudev.com/code?nom=${cekLogin.phone}&text=*DARMASABA*%0A%0A JANGAN BERIKAN KODE RAHASIA ini kepada siapa pun TERMASUK PIHAK DARMASABA. Masukkan otentikasi: *${encodeURIComponent(code)}*`).then( async (res) => { if (res.status == 200) { setValPhone(cekLogin.phone) setOTP(code) setUser(cekLogin.id) setVerif(true) toast.success('Kode verifikasi telah dikirim') } else { console.error(res.status) toast.error('Internal Server Error') } } ) } catch (error) { console.error(error) toast.error('Internal Server Error') } } else { return toast.error(cekLogin.message) } } catch (error) { console.error(error) toast.error('Internal Server Error') } finally { setLoading(false) } } if (isVerif) return return ( <> +62} placeholder="XXX XXX XXX" onChange={(val) => { setPhone('62' + val.target.value) }} /> {textInfo} {/* Ingat saya } /> */} ); } export default ViewLogin;