upd: proses login

nb: blm selesai
This commit is contained in:
amel
2025-04-11 17:54:42 +08:00
parent 1447144e2e
commit b6b23742d2
5 changed files with 207 additions and 33 deletions

View File

@@ -1,17 +1,17 @@
import { ButtonForm } from "@/components/buttonForm";
import { InputForm } from "@/components/inputForm";
import ModalLoading from "@/components/modalLoading";
import Styles from "@/constants/Styles";
import { apiCheckPhoneLogin } from "@/lib/api";
import ViewLogin from "@/components/auth/viewLogin";
import ViewVerification from "@/components/auth/viewVerification";
import { useAuthSession } from "@/providers/AuthProvider";
import { Redirect, router } from "expo-router";
import { Redirect } from "expo-router";
import { useState } from "react";
import { Image, Text, ToastAndroid, View } from "react-native";
import { Text } from "react-native";
export default function Index() {
const [loadingLogin, setLoadingLogin] = useState(false)
// const [loadingLogin, setLoadingLogin] = useState(false)
// const [disableLogin, setDisableLogin] = useState(true)
const [isValid, setValid] = useState(false)
const [phone, setPhone] = useState('')
const [otp, setOtp] = useState(0)
const { token, isLoading } = useAuthSession()
if (isLoading) {
@@ -22,27 +22,29 @@ export default function Index() {
return <Redirect href="/home" />;
}
const handleCheckPhone = async () => {
try {
setLoadingLogin(true)
const response = await apiCheckPhoneLogin({ phone: `62${phone}` });
if (response.success) {
const otp = Math.floor(1000 + Math.random() * 9000);
console.log(otp);
// return router.push('/verification')
}
return ToastAndroid.show(response.message, ToastAndroid.SHORT)
} catch (error) {
console.error('Error fetching data:', error);
return ToastAndroid.show('Terjadi kesalahan', ToastAndroid.SHORT)
} finally {
setLoadingLogin(false)
}
};
// const handleCheckPhone = async () => {
// try {
// setLoadingLogin(true)
// const response = await apiCheckPhoneLogin({ phone: `62${phone}` });
// if (response.success) {
// const otp = Math.floor(1000 + Math.random() * 9000);
// console.log(otp);
// // return router.push('/verification')
// }
// return ToastAndroid.show(response.message, ToastAndroid.SHORT)
// } catch (error) {
// console.error('Error fetching data:', error);
// return ToastAndroid.show('Terjadi kesalahan', ToastAndroid.SHORT)
// } finally {
// setLoadingLogin(false)
// }
// };
if (isValid) { return <ViewVerification phone={phone} otp={otp} /> }
return (
<>
<View style={Styles.wrapLogin} >
{/* <View style={Styles.wrapLogin} >
<View style={{ alignItems: "center", marginVertical: 50 }}>
<Image
source={require("../assets/images/splash-icon.png")}
@@ -51,7 +53,10 @@ export default function Index() {
<Text style={[Styles.textSubtitle]}>PERBEKEL DARMASABA</Text>
</View>
<InputForm
onChange={setPhone}
onChange={(val) => {
val == "" ? setDisableLogin(true) : setDisableLogin(false)
setPhone(val)
}}
type="numeric"
placeholder="XXX-XXX-XXXX"
round
@@ -59,14 +64,20 @@ export default function Index() {
info="Kami akan mengirim kode verifikasi melalui WhatsApp, guna mengonfirmasikan nomor Anda." />
<ButtonForm
text="MASUK"
onPress={() => {
handleCheckPhone()
}}
onPress={() => { handleCheckPhone() }}
disabled={disableLogin}
/>
</View>
{
loadingLogin && <ModalLoading isVisible={true} setVisible={setLoadingLogin} />
}
} */}
<ViewLogin
onValidate={(val) => {
setPhone(val.phone)
setOtp(val.otp)
setValid(true)
}}
/>
</>
);
}