Add:
- lib/api.ts

### No Issue
This commit is contained in:
2025-08-15 17:39:32 +08:00
parent 4f4d9b2f05
commit 6f5d04e73f
5 changed files with 86 additions and 15 deletions

View File

@@ -2,16 +2,28 @@ import ButtonCustom from "@/components/Button/ButtonCustom";
import Spacing from "@/components/_ShareComponent/Spacing";
import ViewWrapper from "@/components/_ShareComponent/ViewWrapper";
import { MainColor } from "@/constants/color-palet";
import { apiLogin, apiVersion } from "@/lib/api";
import { GStyles } from "@/styles/global-styles";
import { router } from "expo-router";
import { useState } from "react";
import { useEffect, useState } from "react";
import { Text, View } from "react-native";
import PhoneInput, { ICountry } from "react-native-international-phone-number";
import Toast from "react-native-toast-message";
export default function LoginView() {
const [version, setVersion] = useState<string>("");
const [selectedCountry, setSelectedCountry] = useState<null | ICountry>(null);
const [inputValue, setInputValue] = useState<string>("");
useEffect(() => {
onLoadVersion();
}, []);
async function onLoadVersion() {
const res = await apiVersion();
setVersion(res.data);
}
function handleInputValue(phoneNumber: string) {
setInputValue(phoneNumber);
}
@@ -20,17 +32,35 @@ export default function LoginView() {
setSelectedCountry(country);
}
function handleLogin() {
const callingCode = selectedCountry?.callingCode.replace(/^\+/, "") || "";
const fixNumber = callingCode + inputValue;
// console.log("fixNumber", fixNumber);
async function handleLogin() {
const callingCode =
selectedCountry?.callingCode.replace(/^\+/, "").trim() || "";
const fixNumber = inputValue.replace(/\s+/g, "");
const realNumber = callingCode + fixNumber;
const randomAlfabet = Math.random().toString(36).substring(2, 8);
const randomNumber = Math.floor(Math.random() * 1000000);
const id = randomAlfabet + randomNumber + fixNumber;
console.log("login user id :", id);
const response = await apiLogin({ nomor: realNumber });
router.navigate("/verification");
if (response.success) {
Toast.show({
type: "success",
text1: "Success",
text2: "Login berhasil",
});
router.navigate(`/verification?kodeId=${response.kodeId}`);
} else {
Toast.show({
type: "error",
text1: "Error",
text2: response.message,
});
}
// const randomAlfabet = Math.random().toString(36).substring(2, 8);
// const randomNumber = Math.floor(Math.random() * 1000000);
// const id = randomAlfabet + randomNumber + fixNumber;
// console.log("login user id :", id);
// router.navigate("/verification");
// router.replace("/(application)/coba");
// router.navigate("/admin/dashboard")
}
@@ -49,15 +79,15 @@ export default function LoginView() {
<Text
style={{
position: "absolute",
bottom: 30,
right: 20,
bottom: 35,
right: 50,
fontSize: 10,
fontWeight: "thin",
fontStyle: "italic",
color: MainColor.white_gray,
}}
>
powered by muku.id
{version} | powered by muku.id
</Text>
</View>
@@ -73,7 +103,6 @@ export default function LoginView() {
<Spacing />
<ButtonCustom onPress={handleLogin}>Login</ButtonCustom>
<Spacing />
{/* <ButtonCustom onPress={() => router.navigate("/admin/investment")}>