feat :update module

This commit is contained in:
lukman
2024-07-25 10:06:55 +08:00
parent 189617274c
commit c2a050a03d
5 changed files with 156 additions and 28 deletions

View File

@@ -12,24 +12,68 @@ import {
Title,
} from "@mantine/core";
import { useRouter } from "next/navigation";
import React from "react";
import React, { useState } from "react";
import toast from "react-hot-toast";
import ViewVerification from "../../varification/view/view_verification";
import { useFocusTrap } from "@mantine/hooks";
function ViewLogin() {
const focusTrapRef = useFocusTrap()
const router = useRouter()
const textInfo =
"Kami akan mengirim kode verifikasi melalui WhatsApp, guna mengonfirmasikan nomor Anda.";
function onMasuk() {
// router.push("/verification")
window.location.href = "/verification"
const [isPhone, setPhone] = useState("")
const [isOTP, setOTP] = useState<any>(null)
const [isValPhone, setValPhone] = useState<any>(null)
const [isUser, setUser] = useState<any>(null)
const [isVerif, setVerif] = useState(false)
const [isLoading, setLoading] = useState(false)
async function onLogin() {
if (isPhone == "")
return toast.error('Please fill in completely')
const cek = await fetch('/api/auth/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ phone: isPhone })
})
const json = await cek.json()
console.log(json)
const code = Math.floor(Math.random() * 1000) + 1000
setLoading(true)
const res = await fetch(`https://wa.wibudev.com/code?nom=${json.phone}&text=${code}`).then(
async (res) => {
if (res.status == 200) {
setValPhone(json.phone)
setOTP(code)
setUser(json.id)
setVerif(true)
setLoading(false)
toast.success('OTP sent successfully')
} else {
toast.error('OTP not sent')
setLoading(false)
}
console.log("code", code)
}
)
}
if (isVerif) return <ViewVerification otp={isOTP} phone={isValPhone} user={isUser} />
return (
<>
<Box p={10}>
<LayoutLogin>
<Stack pt={30}>
<Box p={10}>
<Box p={10} ref={focusTrapRef}>
<TextInput
styles={{
input: {
@@ -43,6 +87,7 @@ function ViewLogin() {
radius={30}
leftSection={<Text>+62</Text>}
placeholder="XXX XXX XXX"
onChange={(val) => { setPhone(val.target.value) }}
/>
<Text fz={10} mt={10} c={WARNA.biruTua}>
{textInfo}
@@ -62,7 +107,10 @@ function ViewLogin() {
size="md"
radius={30}
fullWidth
onClick={onMasuk}
loading={isLoading}
onClick={() => {
onLogin()
}}
>
MASUK
</Button>