upd: login

Deskripsi:
- update axios api check phone number
- modal loading
- fungsi random number 4 digit

No Issues
This commit is contained in:
amel
2025-04-10 17:41:35 +08:00
parent 823b892a7c
commit 1447144e2e
7 changed files with 108 additions and 18 deletions

View File

@@ -1,11 +1,18 @@
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 { useAuthSession } from "@/providers/AuthProvider";
import { Redirect, router } from "expo-router";
import { Image, Text, View } from "react-native";
import { useState } from "react";
import { Image, Text, ToastAndroid, View } from "react-native";
export default function Index() {
const [loadingLogin, setLoadingLogin] = useState(false)
const [phone, setPhone] = useState('')
const { token, isLoading } = useAuthSession()
if (isLoading) {
return <Text>Loading...</Text>;
@@ -15,22 +22,51 @@ 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)
}
};
return (
<View style={Styles.wrapLogin} >
<View style={{ alignItems: "center", marginVertical: 50 }}>
<Image
source={require("../assets/images/splash-icon.png")}
style={{ width: 130, height: 130 }}
<>
<View style={Styles.wrapLogin} >
<View style={{ alignItems: "center", marginVertical: 50 }}>
<Image
source={require("../assets/images/splash-icon.png")}
style={{ width: 130, height: 130 }}
/>
<Text style={[Styles.textSubtitle]}>PERBEKEL DARMASABA</Text>
</View>
<InputForm
onChange={setPhone}
type="numeric"
placeholder="XXX-XXX-XXXX"
round
itemLeft={<Text>+62</Text>}
info="Kami akan mengirim kode verifikasi melalui WhatsApp, guna mengonfirmasikan nomor Anda." />
<ButtonForm
text="MASUK"
onPress={() => {
handleCheckPhone()
}}
/>
<Text style={[Styles.textSubtitle]}>PERBEKEL DARMASABA</Text>
</View>
<InputForm
type="numeric"
placeholder="XXX-XXX-XXXX"
round
itemLeft={<Text>+62</Text>}
info="Kami akan mengirim kode verifikasi melalui WhatsApp, guna mengonfirmasikan nomor Anda." />
<ButtonForm text="MASUK" onPress={() => { router.push("/verification") }} />
</View>
{
loadingLogin && <ModalLoading isVisible={true} setVisible={setLoadingLogin} />
}
</>
);
}

View File

@@ -22,7 +22,6 @@ export default function Index() {
// var C = require("crypto-js");
// var Decrypted = C.AES.decrypt(encrypted, "your password");
// var result = Decrypted.toString(C.enc.Utf8);
// console.log(encrypted,result);
signIn(encrypted);
}
return (