API
Add: - hooks/ - ios.build.device : untuk mendownload di ios Fix: - service/api.t : mengatur api - context/AuthContext.tsx: Provider untuk access token ### No Issue
This commit is contained in:
@@ -2,10 +2,10 @@ 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 { useAuth } from "@/hook/use-auth";
|
||||
import { apiVersion } from "@/service/api";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
import { apiClient, apiVersion } from "@/service/api";
|
||||
import { GStyles } from "@/styles/global-styles";
|
||||
import { router } from "expo-router";
|
||||
import { Redirect, router } from "expo-router";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Text, View } from "react-native";
|
||||
import PhoneInput, { ICountry } from "react-native-international-phone-number";
|
||||
@@ -17,16 +17,25 @@ export default function LoginView() {
|
||||
const [inputValue, setInputValue] = useState<string>("");
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
|
||||
const { loginWithNomor } = useAuth();
|
||||
const { loginWithNomor, token, isAdmin, isUserActive } = useAuth();
|
||||
|
||||
// console.log("Token state:", token ? "AVAILABLE" : "NOT AVAILABLE");
|
||||
// console.log("isAdmin state:", isAdmin);
|
||||
// console.log("isUserActive state:", isUserActive);
|
||||
// console.log("isAuthenticated state:", isAuthenticated);
|
||||
|
||||
useEffect(() => {
|
||||
onLoadVersion();
|
||||
}, []);
|
||||
|
||||
async function onLoadVersion() {
|
||||
// const token = await AsyncStorage.getItem("authToken");
|
||||
// console.log("Token Version:", token);
|
||||
const res = await apiVersion();
|
||||
console.log("Version", res.data);
|
||||
setVersion(res.data);
|
||||
|
||||
const seasonKey = await apiClient.get("/mobile/season-key");
|
||||
console.log("seasonKey", seasonKey.data);
|
||||
}
|
||||
|
||||
function handleInputValue(phoneNumber: string) {
|
||||
@@ -94,6 +103,18 @@ export default function LoginView() {
|
||||
}
|
||||
}
|
||||
|
||||
if (token && !isUserActive) {
|
||||
return <Redirect href={"/(application)/(user)/waiting-room"} />;
|
||||
}
|
||||
|
||||
if (token && !isAdmin) {
|
||||
return <Redirect href={"/(application)/(user)/home"} />;
|
||||
}
|
||||
|
||||
if (token && isAdmin) {
|
||||
return <Redirect href={"/(application)/admin/dashboard"} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<ViewWrapper withBackground>
|
||||
<View style={GStyles.authContainer}>
|
||||
|
||||
@@ -3,18 +3,20 @@ import ViewWrapper from "@/components/_ShareComponent/ViewWrapper";
|
||||
import ButtonCustom from "@/components/Button/ButtonCustom";
|
||||
import TextInputCustom from "@/components/TextInput/TextInputCustom";
|
||||
import { MainColor } from "@/constants/color-palet";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
import { GStyles } from "@/styles/global-styles";
|
||||
import { MaterialCommunityIcons } from "@expo/vector-icons";
|
||||
import { router, useLocalSearchParams } from "expo-router";
|
||||
import { Text, View } from "react-native";
|
||||
import { useLocalSearchParams } from "expo-router";
|
||||
import { useState } from "react";
|
||||
import { apiRegister } from "@/service/api";
|
||||
import { Text, View } from "react-native";
|
||||
import Toast from "react-native-toast-message";
|
||||
|
||||
export default function RegisterView() {
|
||||
const { nomor } = useLocalSearchParams();
|
||||
const [username, setUsername] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
// const [loading, setLoading] = useState(false);
|
||||
|
||||
const { registerUser, isLoading } = useAuth();
|
||||
|
||||
const validasiData = () => {
|
||||
if (!nomor) {
|
||||
@@ -39,35 +41,13 @@ export default function RegisterView() {
|
||||
async function handleRegister() {
|
||||
const isValid = validasiData();
|
||||
if (!isValid) return;
|
||||
const data = {
|
||||
|
||||
const response = await registerUser({
|
||||
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);
|
||||
}
|
||||
console.log("Success register page", JSON.stringify(response, null, 2));
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -97,7 +77,7 @@ export default function RegisterView() {
|
||||
onChangeText={(text) => setUsername(text)}
|
||||
/>
|
||||
|
||||
<ButtonCustom isLoading={loading} onPress={handleRegister}>
|
||||
<ButtonCustom isLoading={isLoading} onPress={handleRegister}>
|
||||
Daftar
|
||||
</ButtonCustom>
|
||||
</View>
|
||||
|
||||
@@ -2,8 +2,10 @@ 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 { useAuth } from "@/hooks/use-auth";
|
||||
import { apiCheckCodeOtp } from "@/service/api";
|
||||
import { GStyles } from "@/styles/global-styles";
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
import { router, useLocalSearchParams } from "expo-router";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Text, View } from "react-native";
|
||||
@@ -11,21 +13,23 @@ import { OtpInput } from "react-native-otp-entry";
|
||||
import Toast from "react-native-toast-message";
|
||||
|
||||
export default function VerificationView() {
|
||||
const { kodeId, nomor } = useLocalSearchParams();
|
||||
console.log("nomor", nomor);
|
||||
const { nomor } = useLocalSearchParams();
|
||||
|
||||
const [codeOtp, setCodeOtp] = useState<string>("");
|
||||
const [inputOtp, setInputOtp] = useState<string>("");
|
||||
const [userNumber, setUserNumber] = useState<string>("");
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
|
||||
// --- Context ---
|
||||
const { validateOtp, isLoading } = useAuth();
|
||||
|
||||
useEffect(() => {
|
||||
onLoadCheckCodeOtp(kodeId as string);
|
||||
}, [kodeId]);
|
||||
onLoadCheckCodeOtp();
|
||||
}, []);
|
||||
|
||||
async function onLoadCheckCodeOtp(kodeId: string) {
|
||||
const response = await apiCheckCodeOtp({ kodeId: kodeId });
|
||||
console.log("response ", JSON.stringify(response, null, 2));
|
||||
async function onLoadCheckCodeOtp() {
|
||||
const kodeId = await AsyncStorage.getItem("kode_otp");
|
||||
const response = await apiCheckCodeOtp({ kodeId: kodeId as string });
|
||||
console.log("response kode otp :", JSON.stringify(response.otp, null, 2));
|
||||
setCodeOtp(response.otp);
|
||||
setUserNumber(response.nomor);
|
||||
}
|
||||
@@ -34,41 +38,41 @@ export default function VerificationView() {
|
||||
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",
|
||||
text1: "Kode OTP tidak sesuai",
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await apiValidationCode({ nomor: userNumber });
|
||||
console.log("response ", JSON.stringify(response, null, 2));
|
||||
const response = await validateOtp(nomor as string);
|
||||
return router.replace(response);
|
||||
|
||||
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=${userNumber}`);
|
||||
}
|
||||
// if (response.success) {
|
||||
// await userData(response.token);
|
||||
|
||||
// if (response.active) {
|
||||
// if (response.roleId === "1") {
|
||||
// return "/(application)/(user)/home";
|
||||
// } else {
|
||||
// return "/(application)/admin/dashboard";
|
||||
// }
|
||||
// } else {
|
||||
// return "/(application)/(user)/waiting-room";
|
||||
// }
|
||||
// } else {
|
||||
// Toast.show({
|
||||
// type: "info",
|
||||
// text1: "Anda belum terdaftar",
|
||||
// text2: "Silahkan daftar terlebih dahulu",
|
||||
// });
|
||||
// return `/register?nomor=${nomor}`;
|
||||
// }
|
||||
} catch (error) {
|
||||
console.log("Error verification", error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -114,7 +118,7 @@ export default function VerificationView() {
|
||||
</View>
|
||||
|
||||
<ButtonCustom
|
||||
isLoading={loading}
|
||||
isLoading={isLoading}
|
||||
disabled={codeOtp === ""}
|
||||
backgroundColor={MainColor.yellow}
|
||||
textColor={MainColor.black}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { AlertDefaultSystem } from "@/components";
|
||||
import { IMenuDrawerItem } from "@/components/_Interface/types";
|
||||
import MenuDrawerDynamicGrid from "@/components/Drawer/MenuDrawerDynamicGird";
|
||||
import { router } from "expo-router";
|
||||
@@ -6,15 +7,28 @@ export default function Profile_MenuDrawerSection({
|
||||
drawerItems,
|
||||
setShowLogoutAlert,
|
||||
setIsDrawerOpen,
|
||||
logout,
|
||||
}: {
|
||||
drawerItems: IMenuDrawerItem[];
|
||||
setShowLogoutAlert: (value: boolean) => void;
|
||||
setIsDrawerOpen: (value: boolean) => void;
|
||||
logout: () => Promise<void>;
|
||||
}) {
|
||||
const handlePress = (item: IMenuDrawerItem) => {
|
||||
if (item.label === "Keluar") {
|
||||
// console.log("Logout clicked");
|
||||
setShowLogoutAlert(true);
|
||||
// setShowLogoutAlert(true);
|
||||
AlertDefaultSystem({
|
||||
title: "Apakah anda yakin ingin keluar?",
|
||||
message: "Anda akan keluar dari akun ini",
|
||||
textLeft: "Batal",
|
||||
textRight: "Keluar",
|
||||
onPressRight: () => {
|
||||
logout();
|
||||
setIsDrawerOpen(false);
|
||||
},
|
||||
onPressLeft: () => setIsDrawerOpen(false),
|
||||
});
|
||||
} else {
|
||||
console.log("PATH >> ", item.path);
|
||||
router.push(item.path as any);
|
||||
|
||||
Reference in New Issue
Block a user