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
127 lines
2.9 KiB
TypeScript
127 lines
2.9 KiB
TypeScript
import { BoxButtonOnFooter, ButtonCustom } from "@/components";
|
|
import DIRECTORY_ID from "@/constants/directory-id";
|
|
import { apiPortofolioCreate } from "@/service/api-client/api-portofolio";
|
|
import { uploadImageService } from "@/service/upload-service";
|
|
import { router } from "expo-router";
|
|
import Toast from "react-native-toast-message";
|
|
|
|
interface Props {
|
|
id: string;
|
|
data: any;
|
|
dataMedsos: any;
|
|
imageUri: string | null;
|
|
subBidangSelected: any[];
|
|
isLoadingCreate: boolean;
|
|
setIsLoadingCreate: (value: boolean) => void;
|
|
}
|
|
|
|
interface ICreatePortofolio {
|
|
id: string;
|
|
namaBisnis: string;
|
|
masterBidangBisnisId: string;
|
|
alamatKantor: string;
|
|
tlpn: string;
|
|
deskripsi: string;
|
|
fileId: string;
|
|
facebook: string;
|
|
twitter: string;
|
|
instagram: string;
|
|
tiktok: string;
|
|
youtube: string;
|
|
subBidang: any[];
|
|
}
|
|
export default function Portofolio_ButtonCreate({
|
|
id,
|
|
data,
|
|
dataMedsos,
|
|
imageUri,
|
|
subBidangSelected,
|
|
isLoadingCreate,
|
|
setIsLoadingCreate,
|
|
}: Props) {
|
|
const validaasiData = () => {
|
|
if (
|
|
!data.namaBisnis ||
|
|
!data.masterBidangBisnisId ||
|
|
!data.alamatKantor ||
|
|
!data.tlpn ||
|
|
!data.deskripsi
|
|
) {
|
|
return false;
|
|
}
|
|
return true;
|
|
};
|
|
|
|
const handleCreatePortofolio = async () => {
|
|
if (!validaasiData()) {
|
|
Toast.show({
|
|
type: "info",
|
|
text1: "Info",
|
|
text2: "Harap lengkapi data",
|
|
});
|
|
return;
|
|
}
|
|
|
|
try {
|
|
setIsLoadingCreate(true);
|
|
let fileId = "";
|
|
if (imageUri) {
|
|
const response = await uploadImageService({
|
|
imageUri: imageUri,
|
|
dirId: DIRECTORY_ID.portofolio_logo,
|
|
});
|
|
|
|
fileId = response.data.id;
|
|
}
|
|
|
|
// Fix Data
|
|
const newData: ICreatePortofolio = {
|
|
id: id,
|
|
namaBisnis: data.namaBisnis,
|
|
masterBidangBisnisId: data.masterBidangBisnisId,
|
|
alamatKantor: data.alamatKantor,
|
|
tlpn: data.tlpn,
|
|
deskripsi: data.deskripsi,
|
|
fileId: fileId,
|
|
facebook: dataMedsos.facebook,
|
|
twitter: dataMedsos.twitter,
|
|
instagram: dataMedsos.instagram,
|
|
tiktok: dataMedsos.tiktok,
|
|
youtube: dataMedsos.youtube,
|
|
subBidang: subBidangSelected,
|
|
};
|
|
|
|
try {
|
|
const response = await apiPortofolioCreate({
|
|
data: newData,
|
|
});
|
|
console.log("Response >>", JSON.stringify(response, null, 2));
|
|
// return router.replace(`/maps/create`);
|
|
// return router.push(`/maps/create`);
|
|
return router.back();
|
|
} catch (error) {
|
|
throw error;
|
|
}
|
|
} catch (error) {
|
|
Toast.show({
|
|
type: "error",
|
|
text1: "Error",
|
|
text2: error as string,
|
|
});
|
|
} finally {
|
|
setIsLoadingCreate(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<BoxButtonOnFooter>
|
|
<ButtonCustom
|
|
isLoading={isLoadingCreate}
|
|
onPress={handleCreatePortofolio}
|
|
>
|
|
Selanjutnya
|
|
</ButtonCustom>
|
|
</BoxButtonOnFooter>
|
|
);
|
|
}
|