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, Spacing,
StackCustom, StackCustom,
TextCustom, TextCustom,
ViewWrapper ViewWrapper,
} from "@/components"; } from "@/components";
import { IconEdit } from "@/components/_Icon"; import { IconEdit } from "@/components/_Icon";
import Collaboration_BoxDetailSection from "@/screens/Collaboration/BoxDetailSection"; import Collaboration_BoxDetailSection from "@/screens/Collaboration/BoxDetailSection";

View File

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

View File

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

View File

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

View File

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

View File

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