diff --git a/app/(application)/announcement/[id].tsx b/app/(application)/announcement/[id].tsx index c6db8c2..096f612 100644 --- a/app/(application)/announcement/[id].tsx +++ b/app/(application)/announcement/[id].tsx @@ -3,6 +3,7 @@ import AppHeader from "@/components/AppHeader"; import BorderBottomItem from "@/components/borderBottomItem"; import Skeleton from "@/components/skeleton"; import Text from '@/components/Text'; +import ErrorView from "@/components/ErrorView"; import { ConstEnv } from "@/constants/ConstEnv"; import { isImageFile } from "@/constants/FileExtensions"; import Styles from "@/constants/Styles"; @@ -65,6 +66,7 @@ export default function DetailAnnouncement() { const [loadingOpen, setLoadingOpen] = useState(false) const [preview, setPreview] = useState(false) const [chooseFile, setChooseFile] = useState() + const [isError, setIsError] = useState(false) /** * Opens the image preview modal for the selected image file @@ -79,6 +81,7 @@ export default function DetailAnnouncement() { async function handleLoad(loading: boolean) { try { + setIsError(false) setLoading(loading) const hasil = await decryptToken(String(token?.current)) const response: ApiResponse = await apiGetAnnouncementOne({ id: id, user: hasil }) @@ -87,10 +90,12 @@ export default function DetailAnnouncement() { setDataMember(response.member) setDataFile(response.file) } else { + setIsError(true) Toast.show({ type: 'small', text1: response.message }) } } catch (error: any) { console.error(error); + setIsError(true) const message = error?.response?.data?.message || "Gagal mengambil data" Toast.show({ type: 'small', text1: message }) @@ -206,104 +211,110 @@ export default function DetailAnnouncement() { /> } > - - - { - loading ? - - - - - - - - - - - - : - <> - - - {data?.title} - - - { - hasHtmlTags(data?.desc) ? - - : - {data?.desc} - } - - - } - + {isError && !loading ? ( + + - { - dataFile.length > 0 && ( - - - File - - {dataFile.map((item, index) => ( - } - title={item.name + '.' + item.extension} - titleWeight="normal" - onPress={() => { - isImageFile(item.extension) ? - handleChooseFile(item) - : openFile(item) - }} - /> - ))} - - ) - } - - { - loading ? - arrSkeleton.map((item, index) => { - return ( - - - - + ) : ( + + + { + loading ? + + + + + + - ) - }) - : - Object.keys(dataMember).map((v: any, i: any) => { - return ( - - {dataMember[v]?.[0].group} + + + + + : + <> + + + {data?.title} + + { - dataMember[v].map((item: any, x: any) => { - return ( - - - {item.division} - - ) - }) + hasHtmlTags(data?.desc) ? + + : + {data?.desc} } - - ) - }) + + } + + + { + dataFile.length > 0 && ( + + + File + + {dataFile.map((item, index) => ( + } + title={item.name + '.' + item.extension} + titleWeight="normal" + onPress={() => { + isImageFile(item.extension) ? + handleChooseFile(item) + : openFile(item) + }} + /> + ))} + + ) } + + { + loading ? + arrSkeleton.map((item, index) => { + return ( + + + + + + ) + }) + : + Object.keys(dataMember).map((v: any, i: any) => { + return ( + + {dataMember[v]?.[0].group} + { + dataMember[v].map((item: any, x: any) => { + return ( + + + {item.division} + + ) + }) + } + + + ) + }) + } + - + )} + + + + + {title} + + + {message} + + + ); +}