Portofolio
Fix: API edit detail data ### No Issue
This commit is contained in:
@@ -220,52 +220,88 @@ export default function PortofolioEdit() {
|
|||||||
}
|
}
|
||||||
}, [subBidangBisnis, data.masterBidangBisnisId]);
|
}, [subBidangBisnis, data.masterBidangBisnisId]);
|
||||||
|
|
||||||
|
function validateData(data: any) {
|
||||||
|
if (
|
||||||
|
!data.namaBisnis ||
|
||||||
|
!data.alamatKantor ||
|
||||||
|
!data.tlpn ||
|
||||||
|
!data.deskripsi ||
|
||||||
|
!data.masterBidangBisnisId
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateDataSubBidang(dataArray: any[]) {
|
||||||
|
return !dataArray.some(
|
||||||
|
(item: any) =>
|
||||||
|
!item.MasterSubBidangBisnis.id ||
|
||||||
|
item.MasterSubBidangBisnis.id.trim() === ""
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const handleSubmitUpdate = async () => {
|
const handleSubmitUpdate = async () => {
|
||||||
console.log("LIST >>", JSON.stringify(listSubBidangSelected, null, 2));
|
const callingCode = selectedCountry?.callingCode.replace(/^\+/, "") || "";
|
||||||
// try {
|
const fixNumber = data.tlpn.replace(/\s+/g, "");
|
||||||
// setIsLoading(true);
|
const realNumber = callingCode + fixNumber;
|
||||||
// const callingCode = selectedCountry?.callingCode.replace(/^\+/, "") || "";
|
|
||||||
// const fixNumber = data.tlpn.replace(/\s+/g, "");
|
|
||||||
// const realNumber = callingCode + fixNumber;
|
|
||||||
|
|
||||||
// const newData: IFormData = {
|
const newData: IFormData = {
|
||||||
// id_Portofolio: data.id_Portofolio,
|
id_Portofolio: data.id_Portofolio,
|
||||||
// namaBisnis: data.namaBisnis,
|
namaBisnis: data.namaBisnis,
|
||||||
// alamatKantor: data.alamatKantor,
|
alamatKantor: data.alamatKantor,
|
||||||
// tlpn: realNumber,
|
tlpn: realNumber,
|
||||||
// deskripsi: data.deskripsi,
|
deskripsi: data.deskripsi,
|
||||||
// masterBidangBisnisId: data.masterBidangBisnisId,
|
masterBidangBisnisId: data.masterBidangBisnisId,
|
||||||
// subBidang: listSubBidangSelected,
|
subBidang: listSubBidangSelected,
|
||||||
// };
|
};
|
||||||
|
|
||||||
// const response = await apiUpdatePortofolio({
|
if (!validateData(newData)) {
|
||||||
// id: id as string,
|
return Toast.show({
|
||||||
// data: newData,
|
type: "error",
|
||||||
// category: "detail",
|
text1: "Harap lengkapi data",
|
||||||
// });
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// if (!response.success) {
|
if (!validateDataSubBidang(listSubBidangSelected as any)) {
|
||||||
// Toast.show({
|
return Toast.show({
|
||||||
// type: "info",
|
type: "error",
|
||||||
// text1: "Info",
|
text1: "Harap lengkapi sub bidang",
|
||||||
// text2: response.message,
|
});
|
||||||
// });
|
}
|
||||||
|
|
||||||
// return;
|
try {
|
||||||
// }
|
setIsLoading(true);
|
||||||
|
|
||||||
// Toast.show({
|
const response = await apiUpdatePortofolio({
|
||||||
// type: "success",
|
id: id as string,
|
||||||
// text1: "Sukses",
|
data: newData,
|
||||||
// text2: "Data terupdate",
|
category: "detail",
|
||||||
// });
|
});
|
||||||
|
|
||||||
// router.back();
|
if (!response.success) {
|
||||||
// } catch (error) {
|
Toast.show({
|
||||||
// console.log("Error handleSubmitUpdate", error);
|
type: "info",
|
||||||
// } finally {
|
text1: "Info",
|
||||||
// setIsLoading(false);
|
text2: response.message,
|
||||||
// }
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Toast.show({
|
||||||
|
type: "success",
|
||||||
|
text1: "Sukses",
|
||||||
|
text2: "Data terupdate",
|
||||||
|
});
|
||||||
|
|
||||||
|
router.back();
|
||||||
|
} catch (error) {
|
||||||
|
console.log("Error handleSubmitUpdate", error);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const buttonUpdate = (
|
const buttonUpdate = (
|
||||||
@@ -281,7 +317,13 @@ export default function PortofolioEdit() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!bidangBisnis || !subBidangBisnis) {
|
if (!bidangBisnis || !subBidangBisnis) {
|
||||||
return <ActivityIndicator size="large" color={MainColor.yellow} />;
|
return (
|
||||||
|
<>
|
||||||
|
<ViewWrapper>
|
||||||
|
<ActivityIndicator size="large" color={MainColor.yellow} />
|
||||||
|
</ViewWrapper>
|
||||||
|
</>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -384,36 +426,6 @@ export default function PortofolioEdit() {
|
|||||||
</CenterCustom>
|
</CenterCustom>
|
||||||
<Spacing />
|
<Spacing />
|
||||||
|
|
||||||
{/* <Grid>
|
|
||||||
<Grid.Col span={10}>
|
|
||||||
<SelectCustom
|
|
||||||
// disabled
|
|
||||||
label="Sub Bidang Usaha"
|
|
||||||
required
|
|
||||||
data={dummyMasterSubBidangBisnis.map((item) => ({
|
|
||||||
label: item.name,
|
|
||||||
value: item.id,
|
|
||||||
}))}
|
|
||||||
value={data.masterSubBidangBisnisId}
|
|
||||||
onChange={(value) => {
|
|
||||||
setData({ ...(data as any), masterSubBidangBisnisId: value });
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Grid.Col>
|
|
||||||
<Grid.Col
|
|
||||||
span={2}
|
|
||||||
style={{ alignItems: "center", justifyContent: "center" }}
|
|
||||||
>
|
|
||||||
<TouchableOpacity onPress={() => console.log("delete")}>
|
|
||||||
<Ionicons name="trash" size={24} color={MainColor.red} />
|
|
||||||
</TouchableOpacity>
|
|
||||||
</Grid.Col>
|
|
||||||
</Grid> */}
|
|
||||||
{/* <ButtonCenteredOnly onPress={() => console.log("add")}>
|
|
||||||
Tambah Pilihan
|
|
||||||
</ButtonCenteredOnly>
|
|
||||||
<Spacing /> */}
|
|
||||||
|
|
||||||
<View>
|
<View>
|
||||||
<View style={{ flexDirection: "row", alignItems: "center" }}>
|
<View style={{ flexDirection: "row", alignItems: "center" }}>
|
||||||
<TextCustom semiBold style={{ color: MainColor.white_gray }}>
|
<TextCustom semiBold style={{ color: MainColor.white_gray }}>
|
||||||
@@ -458,8 +470,6 @@ export default function PortofolioEdit() {
|
|||||||
maxLength={1000}
|
maxLength={1000}
|
||||||
/>
|
/>
|
||||||
<Spacing />
|
<Spacing />
|
||||||
|
|
||||||
<TextCustom>{JSON.stringify(subBidangBisnis, null, 2)}</TextCustom>
|
|
||||||
</StackCustom>
|
</StackCustom>
|
||||||
</ViewWrapper>
|
</ViewWrapper>
|
||||||
</>
|
</>
|
||||||
|
|||||||
Reference in New Issue
Block a user