Add:
- service/api-client/ : api route setting
- service/api-config.ts : api base url

Profil & User
Fix:
- auth logic
- crate profile

### No Issue
This commit is contained in:
2025-08-22 17:32:48 +08:00
parent 014cf387fd
commit ebcf16efba
14 changed files with 195 additions and 138 deletions

View File

@@ -10,28 +10,6 @@ export default function UserLayout() {
return (
<>
<Stack screenOptions={HeaderStyles}>
<Stack.Screen
name="home"
options={{
title: "HIPMI",
headerLeft: () => (
<Ionicons
name="search"
size={20}
color={MainColor.yellow}
onPress={() => router.push("/user-search")}
/>
),
headerRight: () => (
<Ionicons
name="notifications"
size={20}
color={MainColor.yellow}
onPress={() => router.push("/notifications")}
/>
),
}}
/>
<Stack.Screen
name="waiting-room"

View File

@@ -1,9 +1,71 @@
import UiHome from "@/screens/Home/UiHome";
/* eslint-disable react-hooks/exhaustive-deps */
import { StackCustom, ViewWrapper } from "@/components";
import { MainColor } from "@/constants/color-palet";
import { useAuth } from "@/hooks/use-auth";
import Home_BottomFeatureSection from "@/screens/Home/bottomFeatureSection";
import Home_ImageSection from "@/screens/Home/imageSection";
import TabSection from "@/screens/Home/tabSection";
import { tabsHome } from "@/screens/Home/tabsList";
import Home_FeatureSection from "@/screens/Home/topFeatureSection";
import { apiUser } from "@/service/api-client/api-user";
import { Ionicons } from "@expo/vector-icons";
import { Redirect, router, Stack } from "expo-router";
import { useEffect, useState } from "react";
export default function Application() {
const { user } = useAuth();
const [data, setData] = useState<any>({});
useEffect(() => {
onLoadData();
}, []);
async function onLoadData() {
const response = await apiUser(user?.id as string);
console.log("data user >>", JSON.stringify(response.active, null, 2));
setData(response.data);
}
if (data?.active === false) {
return <Redirect href={`/waiting-room`} />;
}
return (
<>
<UiHome />
<Stack.Screen
options={{
title: "HIPMI",
headerLeft: () => (
<Ionicons
name="search"
size={20}
color={MainColor.yellow}
onPress={() => {
router.push("/user-search");
}}
/>
),
headerRight: () => (
<Ionicons
name="notifications"
size={20}
color={MainColor.yellow}
onPress={() => {
router.push("/notifications");
}}
/>
),
}}
/>
<ViewWrapper footerComponent={<TabSection tabs={tabsHome} />}>
<StackCustom>
<Home_ImageSection />
<Home_FeatureSection />
<Home_BottomFeatureSection />
</StackCustom>
</ViewWrapper>
</>
);
}

View File

@@ -11,22 +11,27 @@ export default function ProfileLayout() {
headerTitleStyle: GStyles.headerTitleStyle,
headerTitleAlign: "center",
headerBackButtonDisplayMode: "minimal",
headerLeft: () => <BackButton />,
}}
>
{/* <Stack.Screen name="[id]/index" options={{ headerShown: false }} /> */}
<Stack.Screen name="[id]/edit" options={{ title: "Edit Profile" }} />
<Stack.Screen
name="[id]/edit"
options={{ title: "Edit Profile", headerLeft: () => <BackButton /> }}
/>
<Stack.Screen
name="[id]/update-photo"
options={{ title: "Update Foto" }}
options={{ title: "Update Foto", headerLeft: () => <BackButton /> }}
/>
<Stack.Screen
name="[id]/update-background"
options={{ title: "Update Latar Belakang" }}
options={{
title: "Update Latar Belakang",
headerLeft: () => <BackButton />,
}}
/>
<Stack.Screen
name="[id]/create"
options={{ title: "Buat Profile" }}
name="create"
options={{ title: "Buat Profile", headerBackVisible: false }}
/>
</Stack>
</>

View File

@@ -11,27 +11,66 @@ import {
import BoxButtonOnFooter from "@/components/Box/BoxButtonOnFooter";
import InformationBox from "@/components/Box/InformationBox";
import LandscapeFrameUploaded from "@/components/Image/LandscapeFrameUploaded";
import { router, useLocalSearchParams } from "expo-router";
import { useAuth } from "@/hooks/use-auth";
import { apiCreateProfile } from "@/service/api-client/api-profile";
import { router } from "expo-router";
import { useState } from "react";
import { View } from "react-native";
import Toast from "react-native-toast-message";
export default function CreateProfile() {
const { id } = useLocalSearchParams();
const { user } = useAuth();
const [isLoading, setIsLoading] = useState<boolean>(false);
const [data, setData] = useState({
id: user?.id,
name: "",
email: "",
address: "",
gender: "",
alamat: "",
jenisKelamin: "",
});
const handlerSave = () => {
console.log("data create profile >>", data);
router.back();
const handlerSave = async () => {
if (!data.name || !data.email || !data.alamat || !data.jenisKelamin) {
Toast.show({
type: "info",
text1: "Info",
text2: "Harap isi semua data",
});
return;
}
try {
setIsLoading(true);
const response = await apiCreateProfile(data);
console.log("data create profile >>", JSON.stringify(response, null, 2));
if (response.status === 400) {
Toast.show({
type: "error",
text1: "Email sudah terdaftar",
text2: "Gunakan email lain",
});
return;
}
Toast.show({
type: "success",
text1: "Success",
text2: "Profile berhasil dibuat",
});
router.push("/(application)/(user)/home");
} catch (error) {
console.log("error create profile >>", error);
} finally {
setIsLoading(false);
}
};
const footerComponent = (
<BoxButtonOnFooter>
<ButtonCustom
isLoading={isLoading}
onPress={handlerSave}
// disabled={!data.name || !data.email || !data.address || !data.gender}
>
@@ -49,7 +88,7 @@ export default function CreateProfile() {
<Spacing />
<ButtonCenteredOnly
icon="upload"
onPress={() => router.navigate(`/take-picture/${id}`)}
onPress={() => router.navigate(`/take-picture/${user?.id}`)}
>
Upload
</ButtonCenteredOnly>
@@ -63,7 +102,7 @@ export default function CreateProfile() {
<Spacing />
<ButtonCenteredOnly
icon="upload"
onPress={() => router.navigate(`/take-picture/${id}`)}
onPress={() => router.navigate(`/take-picture/${user?.id}`)}
>
Upload
</ButtonCenteredOnly>
@@ -89,8 +128,8 @@ export default function CreateProfile() {
required
label="Alamat"
placeholder="Masukkan alamat"
value={data.address}
onChangeText={(text) => setData({ ...data, address: text })}
value={data.alamat}
onChangeText={(text) => setData({ ...data, alamat: text })}
/>
<SelectCustom
label="Jenis Kelamin"
@@ -99,9 +138,11 @@ export default function CreateProfile() {
{ label: "Laki-laki", value: "laki-laki" },
{ label: "Perempuan", value: "perempuan" },
]}
value={data.gender}
value={data.jenisKelamin}
required
onChange={(value) => setData({ ...(data as any), gender: value })}
onChange={(value) =>
setData({ ...(data as any), jenisKelamin: value })
}
/>
<Spacing />
</StackCustom>

View File

@@ -14,18 +14,17 @@ import { router } from "expo-router";
import Toast from "react-native-toast-message";
export default function WaitingRoom() {
const { token, userData, isLoading, logout } = useAuth();
const { token, isLoading, logout, userData } = useAuth();
async function handleCheck() {
try {
const response = await userData(token as string);
console.log("response check", JSON.stringify(response, null, 2));
if (response.active) {
Toast.show({
type: "success",
text1: "Akun anda telah aktif", // text2: "Anda berhasil login",
});
router.replace("/(application)/(user)/home");
router.replace(`/(application)/(user)/profile/create`);
} else {
Toast.show({
type: "error",
@@ -57,7 +56,7 @@ export default function WaitingRoom() {
onPressRight: () => {
logout();
},
})
});
}}
>
Keluar