Compare commits

...

2 Commits

Author SHA1 Message Date
88527d5bb6 Image : fix dummy user
### No Issue
2025-08-28 17:02:38 +08:00
40441c929f API Upload Image
Profile:
- (user)/profile/[id]/update-background.tsx : perbaikan api
-  app/(application)/(user)/profile/[id]/update-photo.tsx

Fix:
-   service/upload-service.ts : ganti Toast menjadi throw untuk dapatkna error

### No Issue
2025-08-28 15:18:15 +08:00
8 changed files with 94 additions and 99 deletions

View File

@@ -8,7 +8,7 @@ import {
Spacing,
StackCustom,
TextCustom,
ViewWrapper
ViewWrapper,
} from "@/components";
import { IconEdit } from "@/components/_Icon";
import Collaboration_BoxDetailSection from "@/screens/Collaboration/BoxDetailSection";

View File

@@ -22,6 +22,7 @@ export default function Application() {
async function onLoadData() {
const response = await apiUser(user?.id as string);
console.log("User >>", JSON.stringify(response.data, null, 2));
setData(response.data);
}

View File

@@ -15,6 +15,7 @@ import pickImage from "@/utils/pickImage";
import { router, useFocusEffect, useLocalSearchParams } from "expo-router";
import { useCallback, useState } from "react";
import { Image } from "react-native";
import Toast from "react-native-toast-message";
export default function UpdateBackgroundProfile() {
const { id } = useLocalSearchParams();
@@ -52,15 +53,35 @@ export default function UpdateBackgroundProfile() {
if (response.success) {
const fileId = response.data.id;
await apiUpdateProfile({
const responseUpdate = await apiUpdateProfile({
id: id as string,
data: { fileId },
category: "background",
});
if (!responseUpdate.success) {
Toast.show({
type: "error",
text1: "Info",
text2: responseUpdate.message,
});
return;
}
Toast.show({
type: "success",
text1: "Sukses",
text2: "Background berhasil diupdate",
});
router.back();
}
} catch (error) {
console.log("error upload >>", error);
Toast.show({
type: "error",
text1: "Gagal",
text2: error as string,
});
} finally {
setIsLoading(false);
}

View File

@@ -15,6 +15,7 @@ import pickImage from "@/utils/pickImage";
import { router, useFocusEffect, useLocalSearchParams } from "expo-router";
import { useCallback, useState } from "react";
import { Image } from "react-native";
import Toast from "react-native-toast-message";
export default function UpdatePhotoProfile() {
const { id } = useLocalSearchParams();
@@ -31,10 +32,6 @@ export default function UpdatePhotoProfile() {
async function onLoadData(id: string) {
try {
const response = await apiProfile({ id });
console.log(
"response image id >>",
JSON.stringify(response.data.imageId, null, 2)
);
setData(response.data);
} catch (error) {
console.log("error get profile >>", error);
@@ -50,22 +47,39 @@ export default function UpdatePhotoProfile() {
dirId: DIRECTORY_ID.profile_foto,
});
console.log(
"response upload photo>>",
JSON.stringify(response, null, 2)
);
console.log("response upload photo>>", JSON.stringify(response, null, 2));
if (response.success) {
const fileId = response.data.id;
await apiUpdateProfile({
const responseUpdate = await apiUpdateProfile({
id: id as string,
data: { fileId },
category: "photo",
});
if (!responseUpdate.success) {
Toast.show({
type: "error",
text1: "Info",
text2: responseUpdate.message,
});
return;
}
Toast.show({
type: "success",
text1: "Sukses",
text2: "Photo berhasil diupdate",
});
router.back();
}
} catch (error) {
console.log("error upload >>", error);
Toast.show({
type: "error",
text1: "Gagal",
text2: error as string,
});
} finally {
setIsLoading(false);
}
@@ -77,8 +91,6 @@ export default function UpdatePhotoProfile() {
isLoading={isLoading}
onPress={() => {
onUpload();
// console.log("Simpan foto profile >>", id);
// router.back();
}}
>
Update
@@ -87,10 +99,7 @@ export default function UpdatePhotoProfile() {
);
const image = imageUri ? (
<Image
source={{ uri: imageUri }}
style={{ width: "100%", height: "100%" }}
/>
<Image source={{ uri: imageUri }} style={{ width: 200, height: 200 }} />
) : (
<Image
source={
@@ -98,7 +107,7 @@ export default function UpdatePhotoProfile() {
? { uri: API_STRORAGE.GET({ fileId: data.imageId }) }
: DUMMY_IMAGE.avatar
}
style={{ width: "100%", height: "100%" }}
style={{ width: 200, height: 200 }}
/>
);

View File

@@ -6,21 +6,19 @@ import {
Spacing,
StackCustom,
TextInputCustom,
ViewWrapper
ViewWrapper,
} from "@/components";
import BoxButtonOnFooter from "@/components/Box/BoxButtonOnFooter";
import InformationBox from "@/components/Box/InformationBox";
import DIRECTORY_ID from "@/constants/directory-id";
import DUMMY_IMAGE from "@/constants/dummy-image-value";
import { useAuth } from "@/hooks/use-auth";
import {
apiCreateProfile
} from "@/service/api-client/api-profile";
import { apiCreateProfile } from "@/service/api-client/api-profile";
import { apiValidationEmail } from "@/service/api-client/api-validation";
import { uploadImageService } from "@/service/upload-service";
import pickImage from "@/utils/pickImage";
import { router } from "expo-router";
import { useEffect, useState } from "react";
import { useState } from "react";
import { Image, View } from "react-native";
import { Avatar } from "react-native-paper";
import Toast from "react-native-toast-message";
@@ -39,14 +37,6 @@ export default function CreateProfile() {
jenisKelamin: "",
});
useEffect(() => {
Toast.show({
type: "info",
text1: "Lengkapi Profile Anda",
text2: "Untuk menjelajahi fitur-fitur yang ada",
});
}, []);
const handlerSave = async () => {
let IMG = {
imageId: "",
@@ -77,49 +67,44 @@ export default function CreateProfile() {
return;
}
console.log(
"responseValidateEmail >>",
JSON.stringify(responseValidateEmail, null, 2)
);
if (imagePhoto) {
const responseUploadPhoto = await uploadImageService({
imageUri: imagePhoto,
dirId: DIRECTORY_ID.profile_foto,
});
try {
const responseUploadPhoto = await uploadImageService({
imageUri: imagePhoto,
dirId: DIRECTORY_ID.profile_foto,
});
console.log(
"responseUploadPhoto >>",
JSON.stringify(responseUploadPhoto, null, 2)
);
if (responseUploadPhoto.success) {
const fileIdPhoto = responseUploadPhoto.data.id;
if (responseUploadPhoto.success) {
const fileIdPhoto = responseUploadPhoto.data.id;
IMG.imageId = fileIdPhoto;
IMG.imageId = fileIdPhoto;
}
} catch (error) {
Toast.show({
type: "error",
text1: "Gagal",
text2: error as string,
});
}
}
if (imageBackground) {
const responseUploadBackground = await uploadImageService({
imageUri: imageBackground,
dirId: DIRECTORY_ID.profile_background,
});
try {
const responseUploadBackground = await uploadImageService({
imageUri: imageBackground,
dirId: DIRECTORY_ID.profile_background,
});
if (responseUploadBackground.success) {
const fileIdBackground = responseUploadBackground.data.id;
console.log(
"responseUploadBackground >>",
JSON.stringify(responseUploadBackground, null, 2)
);
if (responseUploadBackground.success) {
const fileIdBackground = responseUploadBackground.data.id;
IMG.imageBackgroundId = fileIdBackground;
IMG.imageBackgroundId = fileIdBackground;
}
} catch (error) {
Toast.show({
type: "error",
text1: "Gagal",
text2: error as string,
});
}
}
@@ -144,11 +129,14 @@ export default function CreateProfile() {
text2: "Profile berhasil dibuat",
});
console.log("fixResponse >>", JSON.stringify(response, null, 2));
router.push("/(application)/(user)/home");
return;
} catch (error) {
console.log("error create profile >>", error);
Toast.show({
type: "error",
text1: "Gagal membuat profile",
});
} finally {
setIsLoading(false);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 30 KiB

View File

@@ -6,8 +6,8 @@ export default function IconEdit({
size,
color,
}: {
size: number;
color: string;
size?: number;
color?: string;
}) {
return (
<>

View File

@@ -1,8 +1,6 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { API_BASE_URL, apiConfig } from "@/service/api-config";
import { API_BASE_URL } from "@/service/api-config";
import AsyncStorage from "@react-native-async-storage/async-storage";
import axios from "axios";
import Toast from "react-native-toast-message";
export async function uploadImageService({
dirId,
@@ -17,12 +15,7 @@ export async function uploadImageService({
console.log("url >>", url);
if (!imageUri) {
Toast.show({
type: "error",
text1: "Gagal",
text2: "Harap pilih gambar terlebih dahulu",
});
return;
throw new Error("Harap pilih gambar terlebih dahulu");
}
try {
@@ -40,8 +33,6 @@ export async function uploadImageService({
});
formData.append("dirId", dirId);
console.log("Form data >>", JSON.stringify(formData, null, 2));
const response = await axios.post(url, formData, {
headers: {
"Content-Type": "multipart/form-data",
@@ -51,28 +42,13 @@ export async function uploadImageService({
});
const { data } = response;
console.log("response upload >>", JSON.stringify(data, null, 2));
if (!data.success) {
Toast.show({
type: "error",
text1: "Gagal",
text2: data.message,
});
return;
throw new Error(data.message);
}
// Toast.show({
// type: "success",
// text1: "File berhasil diunggah",
// });
return data;
} catch (error) {
Toast.show({
type: "error",
text1: "File gagal diunggah",
});
throw error;
}
}