diff --git a/app/(application)/(image)/preview-image/[id]/index.tsx b/app/(application)/(image)/preview-image/[id]/index.tsx
index f47dafe..62a5455 100644
--- a/app/(application)/(image)/preview-image/[id]/index.tsx
+++ b/app/(application)/(image)/preview-image/[id]/index.tsx
@@ -1,13 +1,33 @@
-import { ViewWrapper } from "@/components";
+import { CenterCustom, TextCustom, ViewWrapper } from "@/components";
import API_STRORAGE from "@/constants/base-url-api-strorage";
import { Image } from "expo-image";
import { useLocalSearchParams } from "expo-router";
+import React, { useState } from "react";
export default function PreviewImage() {
const { id } = useLocalSearchParams();
+ const [isLoading, setIsLoading] = useState(true);
+
return (
-
+ {id ? (
+ {
+ setIsLoading(false);
+ }}
+ source={
+ isLoading
+ ? require("@/assets/images/loading.gif")
+ : API_STRORAGE.GET({ fileId: id as string })
+ }
+ contentFit="contain"
+ style={{ width: "100%", height: "100%" }}
+ />
+ ) : (
+
+ File not found
+
+ )}
);
}
diff --git a/app/(application)/(user)/profile/[id]/update-background.tsx b/app/(application)/(user)/profile/[id]/update-background.tsx
index 7de2220..b65b8a4 100644
--- a/app/(application)/(user)/profile/[id]/update-background.tsx
+++ b/app/(application)/(user)/profile/[id]/update-background.tsx
@@ -5,40 +5,111 @@ import {
ButtonCustom,
} from "@/components";
import ViewWrapper from "@/components/_ShareComponent/ViewWrapper";
+import API_STRORAGE from "@/constants/base-url-api-strorage";
+import DIRECTORY_ID from "@/constants/directory-id";
import DUMMY_IMAGE from "@/constants/dummy-image-value";
-import { router, useLocalSearchParams } from "expo-router";
+import { apiProfile, apiUpdateProfile } from "@/service/api-client/api-profile";
+import { uploadImageService } from "@/service/upload-service";
+import { IProfile } from "@/types/Type-Profile";
+import pickImage from "@/utils/pickImage";
+import { router, useFocusEffect, useLocalSearchParams } from "expo-router";
+import { useCallback, useState } from "react";
import { Image } from "react-native";
export default function UpdateBackgroundProfile() {
const { id } = useLocalSearchParams();
+ const [data, setData] = useState();
+ const [imageUri, setImageUri] = useState(null);
+ const [isLoading, setIsLoading] = useState(false);
+
+ useFocusEffect(
+ useCallback(() => {
+ onLoadData(id as string);
+ }, [id])
+ );
+
+ async function onLoadData(id: string) {
+ try {
+ const response = await apiProfile({ id });
+ console.log(
+ "response image id >>",
+ JSON.stringify(response.data.backgroundId, null, 2)
+ );
+ setData(response.data);
+ } catch (error) {
+ console.log("error get profile >>", error);
+ }
+ }
+
+ async function onUpload() {
+ try {
+ setIsLoading(true);
+
+ const response = await uploadImageService({
+ imageUri,
+ dirId: DIRECTORY_ID.profile_background,
+ });
+
+ if (response.success) {
+ const fileId = response.data.id;
+ await apiUpdateProfile({
+ id: id as string,
+ data: { fileId },
+ category: "background",
+ });
+ router.back();
+ }
+ } catch (error) {
+ console.log("error upload >>", error);
+ } finally {
+ setIsLoading(false);
+ }
+ }
+
const buttonFooter = (
{
- console.log("Simpan foto background >>", id);
- router.back();
+ onUpload();
}}
>
- Simpan
+ Update
);
+ const image = imageUri ? (
+
+ ) : (
+
+ );
+
return (
-
+ {image}
router.navigate(`/(application)/take-picture/${id}`)}
+ onPress={() => {
+ pickImage({
+ setImageUri,
+ });
+ }}
>
Update
diff --git a/app/(application)/(user)/profile/[id]/update-photo.tsx b/app/(application)/(user)/profile/[id]/update-photo.tsx
index 53bf251..1aa2a41 100644
--- a/app/(application)/(user)/profile/[id]/update-photo.tsx
+++ b/app/(application)/(user)/profile/[id]/update-photo.tsx
@@ -2,7 +2,7 @@ import {
BaseBox,
BoxButtonOnFooter,
ButtonCenteredOnly,
- ButtonCustom
+ ButtonCustom,
} from "@/components";
import ViewWrapper from "@/components/_ShareComponent/ViewWrapper";
import API_STRORAGE from "@/constants/base-url-api-strorage";
@@ -50,12 +50,11 @@ export default function UpdatePhotoProfile() {
dirId: DIRECTORY_ID.profile_foto,
});
- console.log("Upload res >>", JSON.stringify(response, null, 2));
if (response.success) {
- const imageId = response.data.id;
+ const fileId = response.data.id;
await apiUpdateProfile({
id: id as string,
- data: { imageId },
+ data: { fileId },
category: "photo",
});
router.back();
@@ -83,7 +82,10 @@ export default function UpdatePhotoProfile() {
);
const image = imageUri ? (
-
+
) : (
{
return (
- console.log("backgroundId", backgroundId),
- (
-
- {/* Background Image */}
- {
- router.navigate(
- `/(application)/(image)/preview-image/${backgroundId}`
- );
- }}
- >
-
-
+
+ {/* Background Image */}
+ {
+ router.navigate(
+ `/(application)/(image)/preview-image/${backgroundId}`
+ );
+ }}
+ >
+
+
- {/* Avatar yang sedikit keluar */}
-
-
-
+ {/* Avatar yang sedikit keluar */}
+
+
- )
+
);
};
diff --git a/screens/Profile/ProfileSection.tsx b/screens/Profile/ProfileSection.tsx
index 6824426..2ef7053 100644
--- a/screens/Profile/ProfileSection.tsx
+++ b/screens/Profile/ProfileSection.tsx
@@ -47,9 +47,6 @@ export default function ProfileSection({ data }: { data: IProfile }) {
return (
<>
- {/*
- {JSON.stringify(data.imageBackgroundId, null, 2)}
- */}