git add . && git commit -m

This commit is contained in:
2025-10-03 14:09:31 +08:00
parent 2be4afdcb1
commit a6389174d7
7 changed files with 323 additions and 67 deletions

View File

@@ -1,3 +1,4 @@
/* eslint-disable react-hooks/exhaustive-deps */
import {
AlertDefaultSystem,
BackButton,
@@ -8,37 +9,71 @@ import {
MenuDrawerDynamicGrid,
StackCustom,
TextCustom,
ViewWrapper
ViewWrapper,
} from "@/components";
import { IconTrash } from "@/components/_Icon/IconTrash";
import { router, Stack, useLocalSearchParams } from "expo-router";
import { useState } from "react";
import { useAuth } from "@/hooks/use-auth";
import {
apiInvestmentDeleteNews,
apiInvestmentGetNews,
} from "@/service/api-client/api-investment";
import {
router,
Stack,
useFocusEffect,
useLocalSearchParams,
} from "expo-router";
import { useCallback, useState } from "react";
import Toast from "react-native-toast-message";
export default function InvestmentNews() {
const { id, news } = useLocalSearchParams();
const { user } = useAuth();
const { news } = useLocalSearchParams();
const id = news as string;
const [openDrawer, setOpenDrawer] = useState(false);
const [data, setData] = useState<any | null>(null);
useFocusEffect(
useCallback(() => {
onLoadData();
}, [id])
);
const onLoadData = async () => {
try {
const response = await apiInvestmentGetNews({
id: id,
category: "one-news",
});
setData(response.data);
} catch (error) {
console.log("[ERROR]", error);
}
};
return (
<>
<Stack.Screen
options={{
title: "Detail Berita",
headerLeft: () => <BackButton />,
headerRight: () => <DotButton onPress={() => setOpenDrawer(true)} />,
headerRight: () =>
user?.id === data?.authorId && (
<DotButton onPress={() => setOpenDrawer(true)} />
),
}}
/>
<ViewWrapper>
<BaseBox>
<StackCustom>
<DummyLandscapeImage />
{data && data?.imageId && (
<DummyLandscapeImage imageId={data?.imageId || ""} />
)}
<TextCustom bold align="center" size="large">
Judul Berita {news} Terbaru
</TextCustom>
<TextCustom>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Laborum
fuga mollitia laboriosam voluptatibus quos molestias, illo fugiat
esse repellat, ad officia earum numquam? Aliquid corrupti quam
tempora cum harum est!
{(data && data?.title) || "-"}
</TextCustom>
<TextCustom>{(data && data?.deskripsi) || "-"}</TextCustom>
</StackCustom>
</BaseBox>
</ViewWrapper>
@@ -52,7 +87,7 @@ export default function InvestmentNews() {
data={[
{
label: "Hapus Berita",
path: `/investment/${id}/add-news`,
path: ``,
icon: <IconTrash />,
color: "red",
},
@@ -63,9 +98,26 @@ export default function InvestmentNews() {
message: "Apakah Anda yakin ingin menghapus berita ini?",
textLeft: "Batal",
textRight: "Hapus",
onPressRight: () => {
router.back();
setOpenDrawer(false);
onPressRight: async () => {
try {
const response = await apiInvestmentDeleteNews({ id });
if (response.success) {
Toast.show({
type: "success",
text1: "Berita berhasil dihapus",
});
router.back();
setOpenDrawer(false);
} else {
Toast.show({
type: "error",
text1: "Gagal menghapus berita",
});
}
} catch (error) {
console.log("[ERROR]", error);
}
},
});
}}

View File

@@ -9,17 +9,89 @@ import {
TextInputCustom,
ViewWrapper,
} from "@/components";
import { router } from "expo-router";
import DIRECTORY_ID from "@/constants/directory-id";
import { apiInvestmentCreateNews } from "@/service/api-client/api-investment";
import { uploadFileService } from "@/service/upload-service";
import pickFile, { IFileData } from "@/utils/pickFile";
import { router, useLocalSearchParams } from "expo-router";
import { useState } from "react";
import Toast from "react-native-toast-message";
export default function InvestmentAddNews() {
const { id } = useLocalSearchParams();
const [image, setImage] = useState<IFileData | null>(null);
const [data, setData] = useState({
title: "",
deskripsi: "",
});
const [isLoading, setIsLoading] = useState(false);
const handlerSubmit = async () => {
let imageId = "";
if (!data.title || !data.deskripsi) {
Toast.show({
type: "error",
text1: "Judul dan deskripsi harus diisi",
});
return;
}
try {
setIsLoading(true);
if (image) {
const uploadImage = await uploadFileService({
dirId: DIRECTORY_ID.investasi_berita,
imageUri: image.uri,
});
imageId = uploadImage.data.id;
}
const newData = {
id: id as string,
title: data.title,
deskripsi: data.deskripsi,
imageId: imageId,
};
const response = await apiInvestmentCreateNews({
id: id as string,
data: newData,
});
if (response.success) {
Toast.show({
type: "success",
text1: "Berita berhasil disimpan",
});
router.back();
} else {
Toast.show({
type: "error",
text1: "Gagal menyimpan berita",
});
}
} catch (error) {
console.log("[ERROR]", error);
} finally {
setIsLoading(false);
}
};
return (
<ViewWrapper>
<StackCustom gap={"xs"}>
<InformationBox text="Pengunggahan foto ke aplikasi bersifat opsional dan tidak diwajibkan, Anda dapat menyimpan berita tanpa mengunggah foto." />
<LandscapeFrameUploaded />
<LandscapeFrameUploaded image={image?.uri} />
<ButtonCenteredOnly
onPress={() => {
router.push("/(application)/(image)/take-picture/123");
pickFile({
allowedType: "image",
setImageUri(file) {
setImage(file);
},
});
}}
icon="upload"
>
@@ -30,6 +102,8 @@ export default function InvestmentAddNews() {
label="Judul Berita"
placeholder="Masukan judul berita"
required
value={data.title}
onChangeText={(value) => setData({ ...data, title: value })}
/>
<TextAreaCustom
label="Deskripsi Berita"
@@ -37,13 +111,11 @@ export default function InvestmentAddNews() {
required
showCount
maxLength={1000}
value={data.deskripsi}
onChangeText={(value) => setData({ ...data, deskripsi: value })}
/>
<ButtonCustom
onPress={() => {
router.back();
}}
>
<ButtonCustom isLoading={isLoading} onPress={handlerSubmit}>
Simpan
</ButtonCustom>
</StackCustom>

View File

@@ -1,18 +1,51 @@
/* eslint-disable react-hooks/exhaustive-deps */
import {
BackButton,
BaseBox,
DrawerCustom,
MenuDrawerDynamicGrid,
TextCustom,
ViewWrapper
BackButton,
BaseBox,
DrawerCustom,
LoaderCustom,
MenuDrawerDynamicGrid,
TextCustom,
ViewWrapper,
} from "@/components";
import { IconPlus } from "@/components/_Icon";
import { router, Stack, useLocalSearchParams } from "expo-router";
import { useState } from "react";
import { apiInvestmentGetNews } from "@/service/api-client/api-investment";
import {
router,
Stack,
useFocusEffect,
useLocalSearchParams,
} from "expo-router";
import _ from "lodash";
import { useCallback, useState } from "react";
export default function InvestmentListOfNews() {
const { id } = useLocalSearchParams();
const [openDrawer, setOpenDrawer] = useState(false);
const [list, setList] = useState<any[] | null>(null);
const [loadList, setLoadList] = useState(false);
useFocusEffect(
useCallback(() => {
onLoadList();
}, [id])
);
const onLoadList = async () => {
try {
setLoadList(true);
const response = await apiInvestmentGetNews({
id: id as string,
category: "all-news",
});
setList(response.data);
} catch (error) {
console.log("[ERROR]", error);
} finally {
setLoadList(false);
}
};
return (
<>
<Stack.Screen
@@ -22,16 +55,25 @@ export default function InvestmentListOfNews() {
// headerRight: () => <DotButton onPress={() => setOpenDrawer(true)} />,
}}
/>
<ViewWrapper>
{Array.from({ length: 15 }).map((_, index) => (
<BaseBox
key={index}
paddingBlock={5}
href={`/investment/${id}/(news)/${index + 1}`}
>
<TextCustom bold>Berita Terbaru {index + 1}</TextCustom>
</BaseBox>
))}
{loadList ? (
<LoaderCustom />
) : _.isEmpty(list) ? (
<TextCustom align="center" color="gray">
Tidak ada data
</TextCustom>
) : (
list?.map((item: any, index: number) => (
<BaseBox
key={index}
paddingBlock={5}
href={`/investment/[id]/(news)/${item.id}`}
>
<TextCustom bold>{item.title}</TextCustom>
</BaseBox>
))
)}
</ViewWrapper>
<DrawerCustom

View File

@@ -1,19 +1,53 @@
/* eslint-disable react-hooks/exhaustive-deps */
import {
BackButton,
BaseBox,
DotButton,
DrawerCustom,
LoaderCustom,
MenuDrawerDynamicGrid,
TextCustom,
ViewWrapper,
} from "@/components";
import { IconPlus } from "@/components/_Icon";
import { router, Stack, useLocalSearchParams } from "expo-router";
import { useState } from "react";
import { apiInvestmentGetNews } from "@/service/api-client/api-investment";
import {
router,
Stack,
useFocusEffect,
useLocalSearchParams,
} from "expo-router";
import _ from "lodash";
import { useCallback, useState } from "react";
export default function InvestmentRecapOfNews() {
const { id } = useLocalSearchParams();
const [openDrawer, setOpenDrawer] = useState(false);
const [list, setList] = useState<any[] | null>(null);
const [loadList, setLoadList] = useState(false);
useFocusEffect(
useCallback(() => {
onLoadList();
}, [id])
);
const onLoadList = async () => {
try {
setLoadList(true);
const response = await apiInvestmentGetNews({
id: id as string,
category: "all-news",
});
setList(response.data);
} catch (error) {
console.log("[ERROR]", error);
} finally {
setLoadList(false);
}
};
return (
<>
<Stack.Screen
@@ -24,15 +58,23 @@ export default function InvestmentRecapOfNews() {
}}
/>
<ViewWrapper>
{Array.from({ length: 15 }).map((_, index) => (
<BaseBox
key={index}
paddingBlock={5}
href={`/investment/${id}/(news)/${index + 1}`}
>
<TextCustom bold>Berita Terbaru {index + 1}</TextCustom>
</BaseBox>
))}
{loadList ? (
<LoaderCustom />
) : _.isEmpty(list) ? (
<TextCustom align="center" color="gray">
Tidak ada data
</TextCustom>
) : (
list?.map((item: any, index: number) => (
<BaseBox
key={index}
paddingBlock={5}
href={`/investment/[id]/(news)/${item.id}`}
>
<TextCustom bold>{item.title}</TextCustom>
</BaseBox>
))
)}
</ViewWrapper>
<DrawerCustom

View File

@@ -1,6 +1,6 @@
// PdfViewer.tsx
import React, { useState } from "react";
import { ActivityIndicator, StyleSheet, View } from "react-native";
import { ActivityIndicator, Platform, StyleSheet, View } from "react-native";
import WebView from "react-native-webview";
interface PdfViewerProps {
@@ -10,6 +10,13 @@ interface PdfViewerProps {
const PdfViewer: React.FC<PdfViewerProps> = ({ uri }) => {
const [loading, setLoading] = useState(true);
// ✅ Bungkus dengan Google Docs Viewer
const viewerUrl = `https://docs.google.com/gview?embedded=true&url=${encodeURIComponent(
uri
)}`;
const selectedDivice = Platform.OS === "ios" ? uri : viewerUrl;
return (
<>
{loading && (
@@ -18,7 +25,9 @@ const PdfViewer: React.FC<PdfViewerProps> = ({ uri }) => {
</View>
)}
<WebView
source={{ uri }}
source={{
uri: selectedDivice,
}}
style={styles.webView}
onLoadEnd={() => setLoading(false)}
onError={(syntheticEvent) => {
@@ -26,10 +35,10 @@ const PdfViewer: React.FC<PdfViewerProps> = ({ uri }) => {
console.warn("WebView error:", nativeEvent);
setLoading(false);
}}
scalesPageToFit={true}
javaScriptEnabled={true}
domStorageEnabled={true}
originWhitelist={["*"]}
// scalesPageToFit={true}
// javaScriptEnabled={true}
// domStorageEnabled={true}
// originWhitelist={["*"]}
/>
</>
);

View File

@@ -8,11 +8,10 @@ export default function Investment_ButtonInvestasiSection({
id: string;
isMine: boolean;
}) {
console.log("[IS MINE]", isMine);
return (
<>
{isMine ? (
<ButtonCustom disabled>Investasi Ini Milik Anda</ButtonCustom>
<ButtonCustom disabled>Investasi ini milik Anda</ButtonCustom>
) : (
<ButtonCustom
onPress={() => {

View File

@@ -145,12 +145,9 @@ export async function apiInvestmentCreateInvoice({
data: any;
}) {
try {
const response = await apiConfig.post(
`/mobile/investment/${id}/invoice`,
{
data: data,
}
);
const response = await apiConfig.post(`/mobile/investment/${id}/invoice`, {
data: data,
});
return response.data;
} catch (error) {
throw error;
@@ -201,3 +198,46 @@ export async function apiInvestmentUpdateInvoice({
throw error;
}
}
export async function apiInvestmentCreateNews({
id,
data,
}: {
id: string;
data: any;
}) {
try {
const response = await apiConfig.post(`/mobile/investment/${id}/news`, {
data: data,
});
return response.data;
} catch (error) {
throw error;
}
}
export async function apiInvestmentGetNews({
id,
category,
}: {
id: string;
category: "all-news" | "one-news";
}) {
try {
const response = await apiConfig.get(
`/mobile/investment/${id}/news?category=${category}`
);
return response.data;
} catch (error) {
throw error;
}
}
export async function apiInvestmentDeleteNews({ id }: { id: string }) {
try {
const response = await apiConfig.delete(`/mobile/investment/${id}/news`);
return response.data;
} catch (error) {
throw error;
}
}