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

@@ -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>