Fix Alur Login & Load data forum , user search
Admin – User Access - app/(application)/admin/user-access/[id]/index.tsx Authentication - context/AuthContext.tsx - screens/Authentication/EULASection.tsx - screens/Authentication/LoginView.tsx Forum - screens/Forum/ViewBeranda3.tsx Profile & UI Components - components/Image/AvatarComp.tsx - screens/Profile/AvatarAndBackground.tsx ### No Issue
This commit is contained in:
@@ -10,14 +10,10 @@ import {
|
||||
import AdminBackButtonAntTitle from "@/components/_ShareComponent/Admin/BackButtonAntTitle";
|
||||
import GridTwoView from "@/components/_ShareComponent/GridTwoView";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
import { routeUser } from "@/lib/routeApp";
|
||||
import {
|
||||
apiAdminUserAccessGetById,
|
||||
apiAdminUserAccessUpdateStatus,
|
||||
} from "@/service/api-admin/api-admin-user-access";
|
||||
import {
|
||||
apiNotificationsSendById
|
||||
} from "@/service/api-notifications";
|
||||
import { router, useFocusEffect, useLocalSearchParams } from "expo-router";
|
||||
import { useCallback, useState } from "react";
|
||||
import Toast from "react-native-toast-message";
|
||||
@@ -70,20 +66,6 @@ export default function AdminUserAccessDetail() {
|
||||
text1: "Update aktifasi berhasil ",
|
||||
});
|
||||
|
||||
if (data.active === false) {
|
||||
await apiNotificationsSendById({
|
||||
data: {
|
||||
title: "Akun anda telah diaktifkan",
|
||||
body: "Selamat menjelajahi HIConnect",
|
||||
userLoginId: user?.id || "",
|
||||
kategoriApp: "OTHER",
|
||||
type: "announcement",
|
||||
deepLink: routeUser.home,
|
||||
},
|
||||
id: id as string,
|
||||
});
|
||||
}
|
||||
|
||||
router.back();
|
||||
} catch (error) {
|
||||
console.log("[ERROR UPDATE STATUS]", error);
|
||||
|
||||
@@ -30,7 +30,6 @@ export default function AvatarComp({
|
||||
href = `/(application)/(image)/preview-image/${fileId}`,
|
||||
}: AvatarCompProps) {
|
||||
const dimension = sizeMap[size];
|
||||
|
||||
const avatarImage = () => {
|
||||
return (
|
||||
<Avatar.Image
|
||||
@@ -54,6 +53,7 @@ export default function AvatarComp({
|
||||
onPress={
|
||||
href || fileId ? () => router.navigate(href as any) : onPress
|
||||
}
|
||||
disabled={!fileId}
|
||||
>
|
||||
{avatarImage()}
|
||||
</TouchableOpacity>
|
||||
|
||||
@@ -30,7 +30,10 @@ type AuthContextType = {
|
||||
termsOfServiceAccepted: boolean;
|
||||
}) => Promise<void>;
|
||||
userData: (token: string) => Promise<any>;
|
||||
acceptedTerms: (nomor: string, onSetModalVisible: (visible: boolean) => void) => Promise<any>;
|
||||
acceptedTerms: (
|
||||
nomor: string,
|
||||
onSetModalVisible: (visible: boolean) => void,
|
||||
) => Promise<any>;
|
||||
};
|
||||
|
||||
// --- Create Context ---
|
||||
@@ -80,34 +83,12 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
console.log("[RESPONSE AUTH]", JSON.stringify(response, null, 2));
|
||||
|
||||
if (response.success && response.isAcceptTerms) {
|
||||
|
||||
await AsyncStorage.setItem("kode_otp", response.kodeId);
|
||||
router.push(`/verification?nomor=${nomor}`);
|
||||
return true;
|
||||
} else {
|
||||
// router.push(`/eula?nomor=${nomor}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
// if (response.success) {
|
||||
// if (response.isAcceptTerms) {
|
||||
// Toast.show({
|
||||
// type: "success",
|
||||
// text1: "Sukses",
|
||||
// text2: "Kode OTP berhasil dikirim",
|
||||
// });
|
||||
|
||||
// await AsyncStorage.setItem("kode_otp", response.kodeId);
|
||||
// router.push(`/verification?nomor=${nomor}`);
|
||||
// return false
|
||||
// } else {
|
||||
// // router.push(`/eula?nomor=${nomor}`);
|
||||
// return true
|
||||
// }
|
||||
// } else {
|
||||
// router.push(`/eula?nomor=${nomor}`);
|
||||
// return true;
|
||||
// }
|
||||
} catch (error: any) {
|
||||
throw new Error(error.response?.data?.message || "Gagal kirim OTP");
|
||||
} finally {
|
||||
@@ -266,29 +247,24 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
|
||||
};
|
||||
|
||||
// --- 6. Accept Terms ---
|
||||
const acceptedTerms = async (nomor: string, onSetModalVisible: (visible: boolean) => void) => {
|
||||
const acceptedTerms = async (
|
||||
nomor: string,
|
||||
onSetModalVisible: (visible: boolean) => void,
|
||||
) => {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
const response = await apiUpdatedTermCondition({ nomor: nomor });
|
||||
|
||||
if (response.success) {
|
||||
router.replace(`/verification?nomor=${nomor}`);
|
||||
return `/verification?nomor=${nomor}`;
|
||||
} else {
|
||||
if (response.status === 404) {
|
||||
router.replace(`/register?nomor=${nomor}`);
|
||||
} else {
|
||||
Toast.show({
|
||||
type: "error",
|
||||
text1: "Error",
|
||||
text2: response.message,
|
||||
});
|
||||
}
|
||||
return `/register?nomor=${nomor}`;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Error accept terms", error);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
// onSetModalVisible(false);
|
||||
onSetModalVisible(false);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -7,13 +7,21 @@ import {
|
||||
StyleSheet,
|
||||
} from "react-native";
|
||||
import { useState, useRef } from "react";
|
||||
import { useLocalSearchParams, useRouter } from "expo-router";
|
||||
import { router, useLocalSearchParams, useRouter } from "expo-router";
|
||||
import { SafeAreaView } from "react-native-safe-area-context";
|
||||
import { AccentColor, MainColor } from "@/constants/color-palet";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
import Toast from "react-native-toast-message";
|
||||
|
||||
|
||||
export default function EULASection({ nomor, onSetModalVisible }: { nomor: string, onSetModalVisible: (visible: boolean) => void }) {
|
||||
export default function EULASection({
|
||||
nomor,
|
||||
onSetModalVisible,
|
||||
setLoadingTerm,
|
||||
}: {
|
||||
nomor: string;
|
||||
onSetModalVisible: (visible: boolean) => void;
|
||||
setLoadingTerm: (loading: boolean) => void;
|
||||
}) {
|
||||
const { acceptedTerms } = useAuth();
|
||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||
const [isAtBottom, setIsAtBottom] = useState(false);
|
||||
@@ -35,12 +43,26 @@ export default function EULASection({ nomor, onSetModalVisible }: { nomor: strin
|
||||
if (!isAtBottom) return;
|
||||
|
||||
setIsLoading(true);
|
||||
await acceptedTerms(nomor as string, onSetModalVisible);
|
||||
const responseAccept = await acceptedTerms(
|
||||
nomor as string,
|
||||
onSetModalVisible,
|
||||
);
|
||||
|
||||
console.log("Accept terms", responseAccept);
|
||||
setLoadingTerm(true);
|
||||
|
||||
setTimeout(() => {
|
||||
router.replace(responseAccept);
|
||||
}, 500);
|
||||
} catch (error) {
|
||||
console.log("Error accept terms", error);
|
||||
Toast.show({
|
||||
type: "error",
|
||||
text1: "Error",
|
||||
text2: "Terjadi kesalahan saat menerima syarat dan ketentuan",
|
||||
});
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
import { NewWrapper, TextCustom } from "@/components";
|
||||
import { NewWrapper } from "@/components";
|
||||
import ButtonCustom from "@/components/Button/ButtonCustom";
|
||||
import ModalReactNative from "@/components/Modal/ModalReactNative";
|
||||
import Spacing from "@/components/_ShareComponent/Spacing";
|
||||
import ViewWrapper from "@/components/_ShareComponent/ViewWrapper";
|
||||
import { MainColor } from "@/constants/color-palet";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
import { apiVersion, BASE_URL } from "@/service/api-config";
|
||||
import { GStyles } from "@/styles/global-styles";
|
||||
import { openBrowser } from "@/utils/openBrower";
|
||||
import versionBadge from "@/utils/viersionBadge";
|
||||
import VersionBadge from "@/utils/viersionBadge";
|
||||
import { Redirect } from "expo-router";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Modal, RefreshControl, Text, View } from "react-native";
|
||||
import { RefreshControl, Text, View } from "react-native";
|
||||
import PhoneInput, { ICountry } from "react-native-international-phone-number";
|
||||
import Toast from "react-native-toast-message";
|
||||
import EULASection from "./EULASection";
|
||||
@@ -26,6 +24,7 @@ export default function LoginView() {
|
||||
const [refreshing, setRefreshing] = useState<boolean>(false);
|
||||
const [modalVisible, setModalVisible] = useState(false);
|
||||
const [numberToEULA, setNumberToEULA] = useState<string>("");
|
||||
const [loadingTerm, setLoadingTerm] = useState<boolean>(false);
|
||||
|
||||
const { loginWithNomor, token, isAdmin, isUserActive } = useAuth();
|
||||
|
||||
@@ -90,7 +89,6 @@ export default function LoginView() {
|
||||
let fixNumber = inputValue.replace(/\s+/g, "").replace(/^0+/, "");
|
||||
|
||||
const realNumber = callingCode + fixNumber;
|
||||
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
@@ -129,6 +127,8 @@ export default function LoginView() {
|
||||
return <Redirect href={"/(application)/(user)/home"} />;
|
||||
}
|
||||
|
||||
console.log("load term", loadingTerm);
|
||||
|
||||
return (
|
||||
<NewWrapper
|
||||
withBackground
|
||||
@@ -137,7 +137,6 @@ export default function LoginView() {
|
||||
}
|
||||
>
|
||||
<View style={GStyles.authContainer}>
|
||||
|
||||
<View>
|
||||
<View style={GStyles.authContainerTitle}>
|
||||
<Text style={GStyles.authSubTitle}>WELCOME TO</Text>
|
||||
@@ -172,21 +171,15 @@ export default function LoginView() {
|
||||
|
||||
<Spacing />
|
||||
|
||||
<ButtonCustom onPress={handleLogin} isLoading={loading}>
|
||||
<ButtonCustom
|
||||
onPress={handleLogin}
|
||||
disabled={loadingTerm}
|
||||
isLoading={loading || loadingTerm}
|
||||
>
|
||||
Login
|
||||
</ButtonCustom>
|
||||
<Spacing height={50} />
|
||||
|
||||
{/* <ButtonCustom
|
||||
onPress={() => {
|
||||
setModalVisible(true);
|
||||
console.log("Show modal", modalVisible);
|
||||
}}
|
||||
>
|
||||
Show Modal
|
||||
</ButtonCustom> */}
|
||||
{/* <CheckboxCustom value={term} onChange={() => setTerm(!term)} /> */}
|
||||
|
||||
<Text
|
||||
style={{ ...GStyles.textLabel, textAlign: "center", fontSize: 12 }}
|
||||
>
|
||||
@@ -208,7 +201,11 @@ export default function LoginView() {
|
||||
</View>
|
||||
|
||||
<ModalReactNative isVisible={modalVisible}>
|
||||
<EULASection nomor={numberToEULA || ""} onSetModalVisible={setModalVisible} />
|
||||
<EULASection
|
||||
nomor={numberToEULA || ""}
|
||||
onSetModalVisible={setModalVisible}
|
||||
setLoadingTerm={setLoadingTerm}
|
||||
/>
|
||||
</ModalReactNative>
|
||||
</NewWrapper>
|
||||
);
|
||||
|
||||
@@ -2,21 +2,20 @@ import {
|
||||
AvatarComp,
|
||||
BackButton,
|
||||
FloatingButton,
|
||||
SearchInput,
|
||||
TextCustom,
|
||||
SearchInput
|
||||
} from "@/components";
|
||||
import NewWrapper from "@/components/_ShareComponent/NewWrapper";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
import { MainColor } from "@/constants/color-palet";
|
||||
import { createPaginationComponents } from "@/helpers/paginationHelpers";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
import { usePagination } from "@/hooks/use-pagination";
|
||||
import Forum_BoxDetailSection from "@/screens/Forum/DiscussionBoxSection";
|
||||
import { apiForumGetAll } from "@/service/api-client/api-forum";
|
||||
import { apiUser } from "@/service/api-client/api-user";
|
||||
import { router, Stack } from "expo-router";
|
||||
import _ from "lodash";
|
||||
import { useEffect, useState } from "react";
|
||||
import { RefreshControl, View } from "react-native";
|
||||
import { MainColor } from "@/constants/color-palet";
|
||||
import { usePagination } from "@/hooks/use-pagination";
|
||||
import { RefreshControl, TouchableOpacity, View } from "react-native";
|
||||
|
||||
const PAGE_SIZE = 5;
|
||||
|
||||
@@ -36,7 +35,7 @@ export default function Forum_ViewBeranda3() {
|
||||
const pagination = usePagination({
|
||||
fetchFunction: async (page, searchQuery) => {
|
||||
if (!user?.id) return { data: [] };
|
||||
|
||||
|
||||
return await apiForumGetAll({
|
||||
category: "beranda",
|
||||
search: searchQuery || "",
|
||||
@@ -51,16 +50,17 @@ export default function Forum_ViewBeranda3() {
|
||||
});
|
||||
|
||||
// Generate komponen (menggantikan 40+ lines code!)
|
||||
const { ListEmptyComponent, ListFooterComponent } = createPaginationComponents({
|
||||
loading: pagination.loading,
|
||||
refreshing: pagination.refreshing,
|
||||
listData: pagination.listData,
|
||||
searchQuery: search,
|
||||
emptyMessage: "Tidak ada diskusi",
|
||||
emptySearchMessage: "Tidak ada hasil pencarian",
|
||||
skeletonCount: 5,
|
||||
skeletonHeight: 150,
|
||||
});
|
||||
const { ListEmptyComponent, ListFooterComponent } =
|
||||
createPaginationComponents({
|
||||
loading: pagination.loading,
|
||||
refreshing: pagination.refreshing,
|
||||
listData: pagination.listData,
|
||||
searchQuery: search,
|
||||
emptyMessage: "Tidak ada diskusi",
|
||||
emptySearchMessage: "Tidak ada hasil pencarian",
|
||||
skeletonCount: 5,
|
||||
skeletonHeight: 150,
|
||||
});
|
||||
|
||||
// Render item forum
|
||||
const renderForumItem = ({ item }: { item: any }) => (
|
||||
@@ -74,11 +74,11 @@ export default function Forum_ViewBeranda3() {
|
||||
/>
|
||||
);
|
||||
|
||||
// const ListHeaderComponent = (
|
||||
// <View style={{ paddingVertical: 8, alignItems: "center" }}>
|
||||
// <TextCustom>Diskusi Terbaru</TextCustom>
|
||||
// </View>
|
||||
// );
|
||||
// const ListHeaderComponent = (
|
||||
// <View style={{ paddingVertical: 8, alignItems: "center" }}>
|
||||
// <TextCustom>Diskusi Terbaru</TextCustom>
|
||||
// </View>
|
||||
// );
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -87,11 +87,15 @@ export default function Forum_ViewBeranda3() {
|
||||
title: "Forum",
|
||||
headerLeft: () => <BackButton />,
|
||||
headerRight: () => (
|
||||
<AvatarComp
|
||||
fileId={dataUser?.Profile?.imageId}
|
||||
size="base"
|
||||
href={`/forum/${user?.id}/forumku`}
|
||||
/>
|
||||
<TouchableOpacity
|
||||
onPress={() => router.navigate(`/forum/${user?.id}/forumku`)}
|
||||
>
|
||||
<AvatarComp
|
||||
fileId={dataUser?.Profile?.imageId}
|
||||
size="base"
|
||||
href={`/forum/${user?.id}/forumku`}
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
@@ -129,4 +133,4 @@ export default function Forum_ViewBeranda3() {
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ const AvatarAndBackground = ({
|
||||
`/(application)/(image)/preview-image/${backgroundId}`
|
||||
);
|
||||
}}
|
||||
disabled={!backgroundId}
|
||||
>
|
||||
<ImageBackground
|
||||
source={
|
||||
|
||||
Reference in New Issue
Block a user