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
This commit is contained in:
@@ -8,7 +8,7 @@ import {
|
||||
Spacing,
|
||||
StackCustom,
|
||||
TextCustom,
|
||||
ViewWrapper
|
||||
ViewWrapper,
|
||||
} from "@/components";
|
||||
import { IconEdit } from "@/components/_Icon";
|
||||
import Collaboration_BoxDetailSection from "@/screens/Collaboration/BoxDetailSection";
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 }}
|
||||
/>
|
||||
);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user