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 { import {
AlertDefaultSystem, AlertDefaultSystem,
BackButton, BackButton,
@@ -8,37 +9,71 @@ import {
MenuDrawerDynamicGrid, MenuDrawerDynamicGrid,
StackCustom, StackCustom,
TextCustom, TextCustom,
ViewWrapper ViewWrapper,
} from "@/components"; } from "@/components";
import { IconTrash } from "@/components/_Icon/IconTrash"; import { IconTrash } from "@/components/_Icon/IconTrash";
import { router, Stack, useLocalSearchParams } from "expo-router"; import { useAuth } from "@/hooks/use-auth";
import { useState } from "react"; 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() { 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 [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 ( return (
<> <>
<Stack.Screen <Stack.Screen
options={{ options={{
title: "Detail Berita", title: "Detail Berita",
headerLeft: () => <BackButton />, headerLeft: () => <BackButton />,
headerRight: () => <DotButton onPress={() => setOpenDrawer(true)} />, headerRight: () =>
user?.id === data?.authorId && (
<DotButton onPress={() => setOpenDrawer(true)} />
),
}} }}
/> />
<ViewWrapper> <ViewWrapper>
<BaseBox> <BaseBox>
<StackCustom> <StackCustom>
<DummyLandscapeImage /> {data && data?.imageId && (
<DummyLandscapeImage imageId={data?.imageId || ""} />
)}
<TextCustom bold align="center" size="large"> <TextCustom bold align="center" size="large">
Judul Berita {news} Terbaru {(data && data?.title) || "-"}
</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!
</TextCustom> </TextCustom>
<TextCustom>{(data && data?.deskripsi) || "-"}</TextCustom>
</StackCustom> </StackCustom>
</BaseBox> </BaseBox>
</ViewWrapper> </ViewWrapper>
@@ -52,7 +87,7 @@ export default function InvestmentNews() {
data={[ data={[
{ {
label: "Hapus Berita", label: "Hapus Berita",
path: `/investment/${id}/add-news`, path: ``,
icon: <IconTrash />, icon: <IconTrash />,
color: "red", color: "red",
}, },
@@ -63,9 +98,26 @@ export default function InvestmentNews() {
message: "Apakah Anda yakin ingin menghapus berita ini?", message: "Apakah Anda yakin ingin menghapus berita ini?",
textLeft: "Batal", textLeft: "Batal",
textRight: "Hapus", textRight: "Hapus",
onPressRight: () => { onPressRight: async () => {
router.back(); try {
setOpenDrawer(false); 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, TextInputCustom,
ViewWrapper, ViewWrapper,
} from "@/components"; } 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() { 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 ( return (
<ViewWrapper> <ViewWrapper>
<StackCustom gap={"xs"}> <StackCustom gap={"xs"}>
<InformationBox text="Pengunggahan foto ke aplikasi bersifat opsional dan tidak diwajibkan, Anda dapat menyimpan berita tanpa mengunggah foto." /> <InformationBox text="Pengunggahan foto ke aplikasi bersifat opsional dan tidak diwajibkan, Anda dapat menyimpan berita tanpa mengunggah foto." />
<LandscapeFrameUploaded /> <LandscapeFrameUploaded image={image?.uri} />
<ButtonCenteredOnly <ButtonCenteredOnly
onPress={() => { onPress={() => {
router.push("/(application)/(image)/take-picture/123"); pickFile({
allowedType: "image",
setImageUri(file) {
setImage(file);
},
});
}} }}
icon="upload" icon="upload"
> >
@@ -30,6 +102,8 @@ export default function InvestmentAddNews() {
label="Judul Berita" label="Judul Berita"
placeholder="Masukan judul berita" placeholder="Masukan judul berita"
required required
value={data.title}
onChangeText={(value) => setData({ ...data, title: value })}
/> />
<TextAreaCustom <TextAreaCustom
label="Deskripsi Berita" label="Deskripsi Berita"
@@ -37,13 +111,11 @@ export default function InvestmentAddNews() {
required required
showCount showCount
maxLength={1000} maxLength={1000}
value={data.deskripsi}
onChangeText={(value) => setData({ ...data, deskripsi: value })}
/> />
<ButtonCustom <ButtonCustom isLoading={isLoading} onPress={handlerSubmit}>
onPress={() => {
router.back();
}}
>
Simpan Simpan
</ButtonCustom> </ButtonCustom>
</StackCustom> </StackCustom>

View File

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

View File

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

View File

@@ -1,6 +1,6 @@
// PdfViewer.tsx // PdfViewer.tsx
import React, { useState } from "react"; 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"; import WebView from "react-native-webview";
interface PdfViewerProps { interface PdfViewerProps {
@@ -10,6 +10,13 @@ interface PdfViewerProps {
const PdfViewer: React.FC<PdfViewerProps> = ({ uri }) => { const PdfViewer: React.FC<PdfViewerProps> = ({ uri }) => {
const [loading, setLoading] = useState(true); 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 ( return (
<> <>
{loading && ( {loading && (
@@ -18,7 +25,9 @@ const PdfViewer: React.FC<PdfViewerProps> = ({ uri }) => {
</View> </View>
)} )}
<WebView <WebView
source={{ uri }} source={{
uri: selectedDivice,
}}
style={styles.webView} style={styles.webView}
onLoadEnd={() => setLoading(false)} onLoadEnd={() => setLoading(false)}
onError={(syntheticEvent) => { onError={(syntheticEvent) => {
@@ -26,10 +35,10 @@ const PdfViewer: React.FC<PdfViewerProps> = ({ uri }) => {
console.warn("WebView error:", nativeEvent); console.warn("WebView error:", nativeEvent);
setLoading(false); setLoading(false);
}} }}
scalesPageToFit={true} // scalesPageToFit={true}
javaScriptEnabled={true} // javaScriptEnabled={true}
domStorageEnabled={true} // domStorageEnabled={true}
originWhitelist={["*"]} // originWhitelist={["*"]}
/> />
</> </>
); );

View File

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

View File

@@ -145,12 +145,9 @@ export async function apiInvestmentCreateInvoice({
data: any; data: any;
}) { }) {
try { try {
const response = await apiConfig.post( const response = await apiConfig.post(`/mobile/investment/${id}/invoice`, {
`/mobile/investment/${id}/invoice`, data: data,
{ });
data: data,
}
);
return response.data; return response.data;
} catch (error) { } catch (error) {
throw error; throw error;
@@ -201,3 +198,46 @@ export async function apiInvestmentUpdateInvoice({
throw error; 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;
}
}