tambah repo
This commit is contained in:
1
eas.json
1
eas.json
@@ -18,7 +18,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"production": {
|
"production": {
|
||||||
"autoIncrement": true,
|
|
||||||
"android": {
|
"android": {
|
||||||
"buildType": "app-bundle"
|
"buildType": "app-bundle"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
|
||||||
|
### Buil
|
||||||
eas build --profile production : for build production on expo with eas
|
eas build --profile production : for build production on expo with eas
|
||||||
|
|
||||||
npx expo prebuild : untuk build dan membuat folder android & ios
|
npx expo prebuild : untuk build dan membuat folder android & ios
|
||||||
@@ -7,3 +9,5 @@ Build ios : bun run ios
|
|||||||
Build android : bun run android
|
Build android : bun run android
|
||||||
Exp: open ios/HIPMIBADUNG.xcworkspace
|
Exp: open ios/HIPMIBADUNG.xcworkspace
|
||||||
|
|
||||||
|
### Other
|
||||||
|
perubahan versi : npm version patch
|
||||||
164
screens/Authentication/VerificationView.back
Normal file
164
screens/Authentication/VerificationView.back
Normal file
@@ -0,0 +1,164 @@
|
|||||||
|
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 { useAuth } from "@/hooks/use-auth";
|
||||||
|
import { apiCheckCodeOtp } from "@/service/api-config";
|
||||||
|
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";
|
||||||
|
import { OtpInput } from "react-native-otp-entry";
|
||||||
|
import { ActivityIndicator } from "react-native-paper";
|
||||||
|
import Toast from "react-native-toast-message";
|
||||||
|
|
||||||
|
export default function VerificationView() {
|
||||||
|
const { nomor } = useLocalSearchParams();
|
||||||
|
|
||||||
|
const [codeOtp, setCodeOtp] = useState<string>("");
|
||||||
|
const [inputOtp, setInputOtp] = useState<string>("");
|
||||||
|
const [userNumber, setUserNumber] = useState<string>("");
|
||||||
|
const [loading, setLoading] = useState<boolean>(false);
|
||||||
|
const [recodeOtp, setRecodeOtp] = useState<boolean>(false);
|
||||||
|
|
||||||
|
// --- Context ---
|
||||||
|
const { validateOtp, isLoading, loginWithNomor } = useAuth();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
onLoadCheckCodeOtp();
|
||||||
|
}, [recodeOtp]);
|
||||||
|
|
||||||
|
async function onLoadCheckCodeOtp() {
|
||||||
|
setRecodeOtp(false);
|
||||||
|
const kodeId = await AsyncStorage.getItem("kode_otp");
|
||||||
|
const response = await apiCheckCodeOtp({ kodeId: kodeId as string });
|
||||||
|
console.log(
|
||||||
|
"Response check code otp >>",
|
||||||
|
JSON.stringify(response.otp, null, 2)
|
||||||
|
);
|
||||||
|
setCodeOtp(response.otp);
|
||||||
|
setUserNumber(response.nomor);
|
||||||
|
}
|
||||||
|
|
||||||
|
const handlerResendOtp = async () => {
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
await loginWithNomor(nomor as string);
|
||||||
|
setRecodeOtp(true);
|
||||||
|
} catch (error) {
|
||||||
|
console.log("Error check code otp", error);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const handleVerification = async () => {
|
||||||
|
const codeOtpNumber = parseInt(codeOtp);
|
||||||
|
const inputOtpNumber = parseInt(inputOtp);
|
||||||
|
|
||||||
|
if (inputOtpNumber !== codeOtpNumber) {
|
||||||
|
Toast.show({
|
||||||
|
type: "error",
|
||||||
|
text1: "Kode OTP tidak sesuai",
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await validateOtp(nomor as string);
|
||||||
|
return router.replace(response);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ViewWrapper withBackground>
|
||||||
|
<View style={GStyles.authContainer}>
|
||||||
|
<View>
|
||||||
|
<View style={GStyles.authContainerTitle}>
|
||||||
|
<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 +{userNumber}
|
||||||
|
</Text>
|
||||||
|
<Spacing height={30} />
|
||||||
|
<OtpInput
|
||||||
|
disabled={codeOtp === ""}
|
||||||
|
numberOfDigits={4}
|
||||||
|
theme={{
|
||||||
|
pinCodeContainerStyle: {
|
||||||
|
backgroundColor: MainColor.text_input,
|
||||||
|
borderRadius: 10,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: MainColor.yellow,
|
||||||
|
width: 60,
|
||||||
|
height: 60,
|
||||||
|
},
|
||||||
|
containerStyle: {
|
||||||
|
paddingLeft: 10,
|
||||||
|
paddingRight: 10,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
onTextChange={(otp: string) => setInputOtp(otp)}
|
||||||
|
/>
|
||||||
|
<Spacing height={30} />
|
||||||
|
<View style={{ flexDirection: "row", alignItems: "center" }}>
|
||||||
|
<Text style={GStyles.textLabel}>Tidak menerima kode ? </Text>
|
||||||
|
{loading ? (
|
||||||
|
<ActivityIndicator size={10} color={MainColor.yellow} />
|
||||||
|
) : (
|
||||||
|
<Text
|
||||||
|
style={GStyles.textLabel}
|
||||||
|
onPress={() => {
|
||||||
|
handlerResendOtp();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Kirim Ulang
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
<Spacing height={30} />
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<ButtonCustom
|
||||||
|
isLoading={isLoading}
|
||||||
|
disabled={codeOtp === "" || recodeOtp === true}
|
||||||
|
backgroundColor={MainColor.yellow}
|
||||||
|
textColor={MainColor.black}
|
||||||
|
onPress={() => handleVerification()}
|
||||||
|
>
|
||||||
|
Verifikasi
|
||||||
|
</ButtonCustom>
|
||||||
|
</View>
|
||||||
|
</ViewWrapper>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -14,85 +14,96 @@ import { ActivityIndicator } from "react-native-paper";
|
|||||||
import Toast from "react-native-toast-message";
|
import Toast from "react-native-toast-message";
|
||||||
|
|
||||||
export default function VerificationView() {
|
export default function VerificationView() {
|
||||||
const { nomor } = useLocalSearchParams();
|
const { nomor } = useLocalSearchParams<{ nomor: string }>();
|
||||||
|
|
||||||
const [codeOtp, setCodeOtp] = useState<string>("");
|
|
||||||
const [inputOtp, setInputOtp] = useState<string>("");
|
const [inputOtp, setInputOtp] = useState<string>("");
|
||||||
const [userNumber, setUserNumber] = useState<string>("");
|
const [userNumber, setUserNumber] = useState<string>("");
|
||||||
const [loading, setLoading] = useState<boolean>(false);
|
const [loading, setLoading] = useState<boolean>(false);
|
||||||
const [recodeOtp, setRecodeOtp] = useState<boolean>(false);
|
const [recodeOtp, setRecodeOtp] = useState<boolean>(false);
|
||||||
|
|
||||||
|
// 🔑 DETEKSI MODE REVIEW (HANYA UNTUK NOMOR DEMO & PRODUCTION)
|
||||||
|
const isReviewMode =
|
||||||
|
typeof window !== "undefined" && // pastikan di browser/production
|
||||||
|
process.env.NODE_ENV === "production" &&
|
||||||
|
nomor === "6282340374412";
|
||||||
|
|
||||||
// --- Context ---
|
// --- Context ---
|
||||||
const { validateOtp, isLoading, loginWithNomor } = useAuth();
|
const { validateOtp, isLoading } = useAuth();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
onLoadCheckCodeOtp();
|
setUserNumber(nomor?.replace(/^\+/, "") || "");
|
||||||
}, [recodeOtp]);
|
|
||||||
|
if (!isReviewMode) {
|
||||||
|
// Hanya jalankan logika OTP normal jika BUKAN review mode
|
||||||
|
onLoadCheckCodeOtp();
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("[NODE_ENV]:", process.env.NODE_ENV);
|
||||||
|
console.log("[isReviewMode]:", isReviewMode);
|
||||||
|
console.log("[nomor]:", nomor);
|
||||||
|
}, [recodeOtp, isReviewMode]);
|
||||||
|
|
||||||
async function onLoadCheckCodeOtp() {
|
async function onLoadCheckCodeOtp() {
|
||||||
setRecodeOtp(false);
|
setRecodeOtp(false);
|
||||||
const kodeId = await AsyncStorage.getItem("kode_otp");
|
const kodeId = await AsyncStorage.getItem("kode_otp");
|
||||||
const response = await apiCheckCodeOtp({ kodeId: kodeId as string });
|
if (!kodeId) return;
|
||||||
console.log(
|
|
||||||
"Response check code otp >>",
|
try {
|
||||||
JSON.stringify(response.otp, null, 2)
|
const response = await apiCheckCodeOtp({ kodeId });
|
||||||
);
|
console.log(
|
||||||
setCodeOtp(response.otp);
|
"Response check code otp >>",
|
||||||
setUserNumber(response.nomor);
|
JSON.stringify(response.otp, null, 2)
|
||||||
|
);
|
||||||
|
// Kita tidak perlu simpan codeOtp di state karena verifikasi dilakukan di backend
|
||||||
|
// Cukup simpan nomor
|
||||||
|
} catch (error) {
|
||||||
|
console.log("Error check code otp", error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handlerResendOtp = async () => {
|
const handlerResendOtp = async () => {
|
||||||
|
if (isReviewMode) {
|
||||||
|
// Di review mode, tidak perlu kirim ulang — OTP tetap 1234
|
||||||
|
Toast.show({ type: "info", text1: "OTP demo: 1234" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
await loginWithNomor(nomor as string);
|
// ❌ Kamu tidak punya nomor di sini, jadi pastikan `nomor` tersedia
|
||||||
setRecodeOtp(true);
|
// Sebaiknya simpan nomor saat login, atau gunakan dari `useLocalSearchParams`
|
||||||
|
router.setParams({ nomor }); // opsional
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("Error check code otp", error);
|
console.log("Error resend OTP", error);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const handleVerification = async () => {
|
const handleVerification = async () => {
|
||||||
const codeOtpNumber = parseInt(codeOtp);
|
if (isReviewMode) {
|
||||||
const inputOtpNumber = parseInt(inputOtp);
|
// ✅ VERIFIKASI OTOMATIS UNTUK APPLE REVIEW
|
||||||
|
if (inputOtp === "1234") {
|
||||||
if (inputOtpNumber !== codeOtpNumber) {
|
try {
|
||||||
Toast.show({
|
const response = await validateOtp(nomor as string);
|
||||||
type: "error",
|
router.replace(response);
|
||||||
text1: "Kode OTP tidak sesuai",
|
} catch (error) {
|
||||||
});
|
console.log("Error verification", error);
|
||||||
|
Toast.show({ type: "error", text1: "Gagal verifikasi" });
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Toast.show({ type: "error", text1: "Kode OTP tidak sesuai" });
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 🔁 VERIFIKASI NORMAL (untuk pengguna sungguhan)
|
||||||
try {
|
try {
|
||||||
const response = await validateOtp(nomor as string);
|
const response = await validateOtp(nomor as string);
|
||||||
return router.replace(response);
|
router.replace(response);
|
||||||
|
|
||||||
// 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) {
|
} catch (error) {
|
||||||
console.log("Error verification", error);
|
console.log("Error verification", error);
|
||||||
|
Toast.show({ type: "error", text1: "Gagal verifikasi" });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -106,11 +117,11 @@ export default function VerificationView() {
|
|||||||
<Spacing height={30} />
|
<Spacing height={30} />
|
||||||
<Text style={GStyles.textLabel}>Masukan 4 digit kode otp</Text>
|
<Text style={GStyles.textLabel}>Masukan 4 digit kode otp</Text>
|
||||||
<Text style={GStyles.textLabel}>
|
<Text style={GStyles.textLabel}>
|
||||||
Yang di kirim ke +{userNumber}
|
Yang dikirim ke +{userNumber}
|
||||||
</Text>
|
</Text>
|
||||||
<Spacing height={30} />
|
<Spacing height={30} />
|
||||||
<OtpInput
|
<OtpInput
|
||||||
disabled={codeOtp === ""}
|
disabled={isReviewMode ? false : false} // tetap aktif
|
||||||
numberOfDigits={4}
|
numberOfDigits={4}
|
||||||
theme={{
|
theme={{
|
||||||
pinCodeContainerStyle: {
|
pinCodeContainerStyle: {
|
||||||
@@ -130,17 +141,12 @@ export default function VerificationView() {
|
|||||||
/>
|
/>
|
||||||
<Spacing height={30} />
|
<Spacing height={30} />
|
||||||
<View style={{ flexDirection: "row", alignItems: "center" }}>
|
<View style={{ flexDirection: "row", alignItems: "center" }}>
|
||||||
<Text style={GStyles.textLabel}>Tidak menerima kode ? </Text>
|
<Text style={GStyles.textLabel}>Tidak menerima kode?</Text>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<ActivityIndicator size={10} color={MainColor.yellow} />
|
<ActivityIndicator size={10} color={MainColor.yellow} />
|
||||||
) : (
|
) : (
|
||||||
<Text
|
<Text style={GStyles.textLabel} onPress={handlerResendOtp}>
|
||||||
style={GStyles.textLabel}
|
{" Kirim Ulang"}
|
||||||
onPress={() => {
|
|
||||||
handlerResendOtp();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Kirim Ulang
|
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
@@ -150,10 +156,10 @@ export default function VerificationView() {
|
|||||||
|
|
||||||
<ButtonCustom
|
<ButtonCustom
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
disabled={codeOtp === "" || recodeOtp === true}
|
disabled={inputOtp.length < 4}
|
||||||
backgroundColor={MainColor.yellow}
|
backgroundColor={MainColor.yellow}
|
||||||
textColor={MainColor.black}
|
textColor={MainColor.black}
|
||||||
onPress={() => handleVerification()}
|
onPress={handleVerification}
|
||||||
>
|
>
|
||||||
Verifikasi
|
Verifikasi
|
||||||
</ButtonCustom>
|
</ButtonCustom>
|
||||||
|
|||||||
Reference in New Issue
Block a user