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

@@ -0,0 +1,45 @@
import axios from "axios";
import { API_BASE_URL } from "../api-config";
const url = `${API_BASE_URL}/mobile/file`;
export async function apiFileUpload({
token,
formData,
}: {
token: string;
formData: FormData;
}) {
try {
const response = await axios.post(url, formData, {
headers: {
"Content-Type": "multipart/form-data",
Authorization: `Bearer ${token}`,
},
// timeout: 30000,
});
return response.data;
} catch (error) {
throw error;
}
}
export async function apiFileDelete({
token,
id,
}: {
token: string;
id: string;
}) {
try {
const response = await axios.delete(`${url}/${id}`, {
headers: {
Authorization: `Bearer ${token}`,
},
// timeout: 30000,
});
return response.data;
} catch (error) {
throw error;
}
}

View File

@@ -31,3 +31,14 @@ export async function apiGetOnePortofolio({ id }: { id: string }) {
throw error;
}
}
export async function apiDeletePortofolio({ id }: { id: string }) {
try {
const response = await apiConfig.delete(`/mobile/portofolio/${id}`);
return response.data;
} catch (error) {
throw error;
}
}

View File

@@ -1,6 +1,6 @@
import { API_BASE_URL } from "@/service/api-config";
import AsyncStorage from "@react-native-async-storage/async-storage";
import axios from "axios";
import { apiFileUpload } from "./api-client/api-file";
export async function uploadImageService({
dirId,
@@ -10,7 +10,7 @@ export async function uploadImageService({
imageUri: string | null;
}) {
const token = await AsyncStorage.getItem("authToken");
const url = `${API_BASE_URL}/mobile/upload`;
const url = `${API_BASE_URL}/mobile/file`;
console.log("url >>", url);
@@ -33,21 +33,18 @@ export async function uploadImageService({
});
formData.append("dirId", dirId);
const response = await axios.post(url, formData, {
headers: {
"Content-Type": "multipart/form-data",
Authorization: `Bearer ${token}`,
},
// timeout: 30000,
const response = await apiFileUpload({
token: token as string,
formData,
});
const { data } = response;
console.log("Response upload file >>", JSON.stringify(response, null, 2));
if (!data.success) {
throw new Error(data.message);
if (!response.success) {
throw new Error(response.message);
}
return data;
return response;
} catch (error) {
throw error;
}