Add: service api
-  service/
- app.config.js
- app.json.backup

Package:
- react-native-dotenv
- expo-module-scripts

### No Issue
This commit is contained in:
2025-08-19 11:07:42 +08:00
parent 0b6c360500
commit a4825343ba
14 changed files with 5033 additions and 92 deletions

View File

@@ -2,7 +2,7 @@ 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 { apiLogin, apiVersion } from "@/service/api";
import { GStyles } from "@/styles/global-styles";
import { router } from "expo-router";
import { useEffect, useState } from "react";
@@ -14,6 +14,7 @@ export default function LoginView() {
const [version, setVersion] = useState<string>("");
const [selectedCountry, setSelectedCountry] = useState<null | ICountry>(null);
const [inputValue, setInputValue] = useState<string>("");
const [loading, setLoading] = useState<boolean>(false);
useEffect(() => {
onLoadVersion();
@@ -65,15 +66,17 @@ export default function LoginView() {
const fixNumber = inputValue.replace(/\s+/g, "");
const realNumber = callingCode + fixNumber;
setLoading(true);
const response = await apiLogin({ nomor: realNumber });
if (response.success) {
Toast.show({
type: "success",
text1: "Success",
text2: "Login berhasil",
text1: "Sukses",
text2: "Kode OTP berhasil dikirim",
});
router.navigate(`/verification?kodeId=${response.kodeId}`);
setLoading(false);
// router.replace("/(application)/coba");
} else {
Toast.show({
@@ -81,6 +84,7 @@ export default function LoginView() {
text1: "Error",
text2: response.message,
});
setLoading(false);
}
}
@@ -121,7 +125,9 @@ export default function LoginView() {
<Spacing />
<ButtonCustom onPress={handleLogin}>Login</ButtonCustom>
<ButtonCustom onPress={handleLogin} isLoading={loading}>
Login
</ButtonCustom>
<Spacing />
{/* <ButtonCustom onPress={() => router.navigate("/admin/investment")}>

View File

@@ -5,16 +5,71 @@ import TextInputCustom from "@/components/TextInput/TextInputCustom";
import { MainColor } from "@/constants/color-palet";
import { GStyles } from "@/styles/global-styles";
import { MaterialCommunityIcons } from "@expo/vector-icons";
import { router } from "expo-router";
import { router, useLocalSearchParams } from "expo-router";
import { Text, View } from "react-native";
import { useState } from "react";
import { apiRegister } from "@/service/api";
import Toast from "react-native-toast-message";
export default function RegisterView() {
const [username, setUsername] = useState("Bagas Banuna");
const handleRegister = () => {
console.log("Success register", username);
router.push("/(application)/(user)/home");
const { nomor } = useLocalSearchParams();
const [username, setUsername] = useState("");
const [loading, setLoading] = useState(false);
const validasiData = () => {
if (!nomor) {
Toast.show({
type: "error",
text1: "Gagal",
text2: "Nomor tidak ditemukan",
});
return false;
}
if (!username) {
Toast.show({
type: "error",
text1: "Gagal",
text2: "Username tidak boleh kosong",
});
return false;
}
return true;
};
async function handleRegister() {
const isValid = validasiData();
if (!isValid) return;
const data = {
nomor: nomor as string,
username: username,
};
try {
setLoading(true);
const response = await apiRegister({ data });
console.log("Success register", JSON.stringify(response, null, 2));
if (response.success) {
Toast.show({
type: "success",
text1: "Sukses",
text2: "Anda berhasil terdaftar",
});
router.replace("/(application)/(user)/waiting-room");
}
Toast.show({
type: "info",
text1: "Info",
text2: response.message,
});
} catch (error: any) {
console.log("Error register", error);
} finally {
setLoading(false);
}
}
return (
<>
<ViewWrapper withBackground>
@@ -33,7 +88,7 @@ export default function RegisterView() {
<Text style={GStyles.textLabel}>
Anda akan terdaftar dengan nomor
</Text>
<Text style={GStyles.textLabel}>+6282xxxxxxxxx</Text>
<Text style={GStyles.textLabel}>+{nomor}</Text>
<Spacing />
</View>
<TextInputCustom
@@ -42,17 +97,9 @@ export default function RegisterView() {
onChangeText={(text) => setUsername(text)}
/>
<ButtonCustom onPress={handleRegister}>Daftar</ButtonCustom>
{/* <Spacing />
<ButtonCustom
title="Coba"
backgroundColor={MainColor.yellow}
textColor={MainColor.black}
onPress={() => {
console.log("Home clicked");
router.push("/(application)/coba");
}}
/> */}
<ButtonCustom isLoading={loading} onPress={handleRegister}>
Daftar
</ButtonCustom>
</View>
</View>
</ViewWrapper>

View File

@@ -2,19 +2,74 @@ import Spacing from "@/components/_ShareComponent/Spacing";
import ViewWrapper from "@/components/_ShareComponent/ViewWrapper";
import ButtonCustom from "@/components/Button/ButtonCustom";
import { MainColor } from "@/constants/color-palet";
import { apiCheckCodeOtp, apiValidationCode } from "@/service/api";
import { GStyles } from "@/styles/global-styles";
import { router, useLocalSearchParams } from "expo-router";
import { useEffect, useState } from "react";
import { Text, View } from "react-native";
import { OtpInput } from "react-native-otp-entry";
import Toast from "react-native-toast-message";
export default function VerificationView() {
const { kodeId } = useLocalSearchParams();
console.log("kodeId ", kodeId);
const handleVerification = () => {
console.log("Verification clicked");
router.push("/register");
const [codeOtp, setCodeOtp] = useState<string>("");
const [inputOtp, setInputOtp] = useState<string>("");
const [nomor, setNomor] = useState<string>("");
const [loading, setLoading] = useState<boolean>(false);
useEffect(() => {
onLoadCheckCodeOtp(kodeId as string);
}, [kodeId]);
async function onLoadCheckCodeOtp(kodeId: string) {
const response = await apiCheckCodeOtp({ kodeId: kodeId });
console.log("response ", JSON.stringify(response, null, 2));
setCodeOtp(response.otp);
setNomor(response.nomor);
}
const handleVerification = async () => {
const codeOtpNumber = parseInt(codeOtp);
const inputOtpNumber = parseInt(inputOtp);
console.log("codeOtpNumber ", codeOtpNumber, typeof codeOtpNumber);
console.log("inputOtpNumber ", inputOtpNumber, typeof inputOtpNumber);
if (inputOtpNumber !== codeOtpNumber) {
Toast.show({
type: "error",
text1: "Gagal",
text2: "Kode OTP tidak sesuai",
});
return;
}
try {
setLoading(true);
const response = await apiValidationCode({ nomor: nomor });
console.log("response ", JSON.stringify(response, null, 2));
if (response.success) {
if (response.active) {
if (response.roleId === "1") {
router.replace("/(application)/(user)/home");
} else {
router.replace("/(application)/admin/dashboard");
}
} else {
router.replace("/(application)/(user)/waiting-room");
}
} else {
router.replace(`/register?nomor=${nomor}`);
}
} catch (error) {
console.log("Error verification", error);
} finally {
setLoading(false);
}
};
return (
<>
<ViewWrapper withBackground>
@@ -24,11 +79,10 @@ export default function VerificationView() {
<Text style={GStyles.authTitle}>Verifikasi KOde OTP</Text>
<Spacing height={30} />
<Text style={GStyles.textLabel}>Masukan 4 digit kode otp</Text>
<Text style={GStyles.textLabel}>
Yang di kirim ke +6282xxxxxxxxx
</Text>
<Text style={GStyles.textLabel}>Yang di kirim ke +{nomor}</Text>
<Spacing height={30} />
<OtpInput
disabled={codeOtp === ""}
numberOfDigits={4}
theme={{
pinCodeContainerStyle: {
@@ -44,6 +98,7 @@ export default function VerificationView() {
paddingRight: 10,
},
}}
onTextChange={(otp: string) => setInputOtp(otp)}
/>
<Spacing height={30} />
<Text style={GStyles.textLabel}>
@@ -55,6 +110,8 @@ export default function VerificationView() {
</View>
<ButtonCustom
isLoading={loading}
disabled={codeOtp === ""}
backgroundColor={MainColor.yellow}
textColor={MainColor.black}
onPress={() => handleVerification()}