Add:
- service/api-client/api-file.ts: upload & delete

Portofolio
Fix:
- user)/portofolio/[id]/create.tsx: Loading submit
- (user)/portofolio/[id]/index.tsx: Delete button recode

Profile
Fix:
- (user)/profile/[id]/update-photo && upload-backgroud: delete image yang kama

### No Issue
This commit is contained in:
2025-09-01 12:11:21 +08:00
parent 41a4a94255
commit bb95e8ccbd
12 changed files with 195 additions and 86 deletions

View File

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

View File

@@ -39,7 +39,6 @@ export default function PortofolioCreate() {
const [data, setData] = useState({
namaBisnis: "",
masterBidangBisnisId: "",
// sub_bidang_usaha: "",
alamatKantor: "",
tlpn: "",
deskripsi: "",
@@ -67,6 +66,8 @@ export default function PortofolioCreate() {
tiktok: "",
});
const [isLoadingCreate, setIsLoadingCreate] = useState(false);
function handleInputValue(phoneNumber: string) {
setInputValue(phoneNumber);
const callingCode = selectedCountry?.callingCode.replace(/^\+/, "") || "";
@@ -111,6 +112,8 @@ export default function PortofolioCreate() {
dataMedsos={dataMedsos}
imageUri={imageUri}
subBidangSelected={listSubBidangSelected}
isLoadingCreate={isLoadingCreate}
setIsLoadingCreate={setIsLoadingCreate}
/>
}
>
@@ -220,7 +223,7 @@ export default function PortofolioCreate() {
maxRows={5}
required
showCount
maxLength={100}
maxLength={1000}
/>
<Spacing />

View File

@@ -1,4 +1,4 @@
import { AlertCustom, DrawerCustom, Spacing, StackCustom } from "@/components";
import { DrawerCustom, Spacing, StackCustom } from "@/components";
import LeftButtonCustom from "@/components/Button/BackButton";
import ViewWrapper from "@/components/_ShareComponent/ViewWrapper";
import { MainColor } from "@/constants/color-palet";
@@ -12,12 +12,7 @@ import Portofolio_SocialMediaSection from "@/screens/Portofolio/SocialMediaSecti
import { apiGetOnePortofolio } from "@/service/api-client/api-portofolio";
import { GStyles } from "@/styles/global-styles";
import { Ionicons } from "@expo/vector-icons";
import {
router,
Stack,
useFocusEffect,
useLocalSearchParams,
} from "expo-router";
import { Stack, useFocusEffect, useLocalSearchParams } from "expo-router";
import { useCallback, useState } from "react";
import { TouchableOpacity } from "react-native";
@@ -25,7 +20,7 @@ export default function Portofolio() {
const { id } = useLocalSearchParams();
const { user } = useAuth();
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
const [deleteAlert, setDeleteAlert] = useState(false);
const [isLoadingDelete, setIsLoadingDelete] = useState(false);
const [data, setData] = useState<any>();
const openDrawer = () => {
@@ -43,6 +38,10 @@ export default function Portofolio() {
async function onLoadData(id: string) {
const response = await apiGetOnePortofolio({ id: id });
console.log(
"Response portofolio >>",
JSON.stringify(response.data.namaBisnis, null, 2)
);
setData(response.data);
}
@@ -79,7 +78,11 @@ export default function Portofolio() {
<Portofolio_Data data={data} />
<Portofolio_BusinessLocation />
<Portofolio_SocialMediaSection data={data?.Portofolio_MediaSosial} />
<Portofolio_ButtonDelete setShowDeleteAlert={setDeleteAlert} />
<Portofolio_ButtonDelete
id={id as string}
isLoadingDelete={isLoadingDelete}
setIsLoadingDelete={setIsLoadingDelete}
/>
<Spacing />
</StackCustom>
</ViewWrapper>
@@ -95,22 +98,6 @@ export default function Portofolio() {
setIsDrawerOpen={setIsDrawerOpen}
/>
</DrawerCustom>
{/* Alert Delete */}
<AlertCustom
isVisible={deleteAlert}
onLeftPress={() => setDeleteAlert(false)}
onRightPress={() => {
setDeleteAlert(false);
console.log("Hapus portofolio");
router.back();
}}
title="Hapus Portofolio"
message="Apakah Anda yakin ingin menghapus portofolio ini?"
textLeft="Batal"
textRight="Hapus"
colorRight={MainColor.red}
/>
</>
);
}

View File

@@ -8,6 +8,8 @@ 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 { useAuth } from "@/hooks/use-auth";
import { apiFileDelete } from "@/service/api-client/api-file";
import { apiProfile, apiUpdateProfile } from "@/service/api-client/api-profile";
import { uploadImageService } from "@/service/upload-service";
import { IProfile } from "@/types/Type-Profile";
@@ -22,6 +24,7 @@ export default function UpdateBackgroundProfile() {
const [data, setData] = useState<IProfile>();
const [imageUri, setImageUri] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(false);
const { token } = useAuth();
useFocusEffect(
useCallback(() => {
@@ -32,10 +35,6 @@ export default function UpdateBackgroundProfile() {
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);
@@ -68,12 +67,23 @@ export default function UpdateBackgroundProfile() {
return;
}
if (data?.imageBackgroundId) {
const deletePrevFile = await apiFileDelete({
token: token as string,
id: data?.imageBackgroundId as string,
});
if (!deletePrevFile.success) {
console.log("error delete prev file >>", deletePrevFile.message);
}
}
Toast.show({
type: "success",
text1: "Sukses",
text2: "Background berhasil diupdate",
});
router.back();
}
} catch (error) {

View File

@@ -16,12 +16,15 @@ import { router, useFocusEffect, useLocalSearchParams } from "expo-router";
import { useCallback, useState } from "react";
import { Image } from "react-native";
import Toast from "react-native-toast-message";
import { useAuth } from "@/hooks/use-auth";
import { apiFileDelete } from "@/service/api-client/api-file";
export default function UpdatePhotoProfile() {
const { id } = useLocalSearchParams();
const [data, setData] = useState<IProfile>();
const [imageUri, setImageUri] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(false);
const { token } = useAuth();
useFocusEffect(
useCallback(() => {
@@ -32,6 +35,7 @@ export default function UpdatePhotoProfile() {
async function onLoadData(id: string) {
try {
const response = await apiProfile({ id });
setData(response.data);
} catch (error) {
console.log("error get profile >>", error);
@@ -47,8 +51,6 @@ export default function UpdatePhotoProfile() {
dirId: DIRECTORY_ID.profile_foto,
});
console.log("response upload photo>>", JSON.stringify(response, null, 2));
if (response.success) {
const fileId = response.data.id;
const responseUpdate = await apiUpdateProfile({
@@ -66,12 +68,23 @@ export default function UpdatePhotoProfile() {
return;
}
if (data?.imageId) {
const deletePrevFile = await apiFileDelete({
token: token as string,
id: data?.imageId as string,
});
if (!deletePrevFile.success) {
console.log("error delete prev file >>", deletePrevFile.message);
}
}
Toast.show({
type: "success",
text1: "Sukses",
text2: "Photo berhasil diupdate",
});
router.back();
}
} catch (error) {

View File

@@ -2,7 +2,7 @@
import { apiConfig } from "@/service/api-config";
import Toast from "react-native-toast-message";
export async function tryUploadService({
export default async function tryUploadService({
dirId,
imageUri,
}: {