upd: announcement
Deskripsi: - load all announcement - pencarian announcement - tambah announcement - get detail one announcement No Issues
This commit is contained in:
@@ -4,11 +4,43 @@ import ButtonBackHeader from "@/components/buttonBackHeader";
|
||||
import InputSearch from "@/components/inputSearch";
|
||||
import { ColorsStatus } from "@/constants/ColorsStatus";
|
||||
import Styles from "@/constants/Styles";
|
||||
import { apiGetAnnouncement } from "@/lib/api";
|
||||
import { useAuthSession } from "@/providers/AuthProvider";
|
||||
import { MaterialIcons } from "@expo/vector-icons";
|
||||
import { router, Stack } from "expo-router";
|
||||
import { SafeAreaView, ScrollView, View } from "react-native";
|
||||
import { useEffect, useState } from "react";
|
||||
import { SafeAreaView, ScrollView, Text, View } from "react-native";
|
||||
import { useSelector } from "react-redux";
|
||||
|
||||
type Props = {
|
||||
id: string,
|
||||
title: string,
|
||||
desc: string,
|
||||
createdAt: string
|
||||
}
|
||||
|
||||
|
||||
export default function Announcement() {
|
||||
const { token, decryptToken } = useAuthSession()
|
||||
const [data, setData] = useState<Props[]>([])
|
||||
const [search, setSearch] = useState('')
|
||||
const entityUser = useSelector((state: any) => state.user)
|
||||
const update = useSelector((state: any) => state.announcementUpdate)
|
||||
|
||||
async function handleLoad() {
|
||||
try {
|
||||
const hasil = await decryptToken(String(token?.current))
|
||||
const response = await apiGetAnnouncement({ user: hasil, search: search })
|
||||
setData(response.data)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
handleLoad()
|
||||
}, [search, update])
|
||||
|
||||
return (
|
||||
<SafeAreaView>
|
||||
<Stack.Screen
|
||||
@@ -16,97 +48,36 @@ export default function Announcement() {
|
||||
headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
||||
headerTitle: 'Pengumuman',
|
||||
headerTitleAlign: 'center',
|
||||
headerRight: () => <HeaderRightAnnouncementList />
|
||||
headerRight: () => entityUser.role != 'user' && entityUser.role != 'coadmin' ? <HeaderRightAnnouncementList /> : <></>
|
||||
}}
|
||||
/>
|
||||
|
||||
<ScrollView>
|
||||
<View style={[Styles.p15, Styles.mb100]}>
|
||||
<InputSearch />
|
||||
<BorderBottomItem
|
||||
onPress={() => {router.push('/announcement/7493')}}
|
||||
borderType="bottom"
|
||||
icon={
|
||||
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
|
||||
<MaterialIcons name="campaign" size={25} color={'#384288'} />
|
||||
</View>
|
||||
}
|
||||
title="Libur Nyepi"
|
||||
desc="Pengumuman terkait libur nyepi"
|
||||
rightTopInfo="23 Mar 2025"
|
||||
/>
|
||||
<BorderBottomItem
|
||||
onPress={() => {router.push('/announcement/7493')}}
|
||||
borderType="bottom"
|
||||
icon={
|
||||
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
|
||||
<MaterialIcons name="campaign" size={25} color={'#384288'} />
|
||||
</View>
|
||||
}
|
||||
title="Libur Nyepi"
|
||||
desc="Pengumuman terkait libur nyepi"
|
||||
rightTopInfo="23 Mar 2025"
|
||||
/>
|
||||
<BorderBottomItem
|
||||
onPress={() => {router.push('/announcement/7493')}}
|
||||
borderType="bottom"
|
||||
icon={
|
||||
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
|
||||
<MaterialIcons name="campaign" size={25} color={'#384288'} />
|
||||
</View>
|
||||
}
|
||||
title="Libur Nyepi"
|
||||
desc="Pengumuman terkait libur nyepi"
|
||||
rightTopInfo="23 Mar 2025"
|
||||
/>
|
||||
<BorderBottomItem
|
||||
onPress={() => {router.push('/announcement/7493')}}
|
||||
borderType="bottom"
|
||||
icon={
|
||||
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
|
||||
<MaterialIcons name="campaign" size={25} color={'#384288'} />
|
||||
</View>
|
||||
}
|
||||
title="Libur Nyepi"
|
||||
desc="Pengumuman terkait libur nyepi"
|
||||
rightTopInfo="23 Mar 2025"
|
||||
/>
|
||||
<BorderBottomItem
|
||||
onPress={() => {router.push('/announcement/7493')}}
|
||||
borderType="bottom"
|
||||
icon={
|
||||
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
|
||||
<MaterialIcons name="campaign" size={25} color={'#384288'} />
|
||||
</View>
|
||||
}
|
||||
title="Libur Nyepi"
|
||||
desc="Pengumuman terkait libur nyepi"
|
||||
rightTopInfo="23 Mar 2025"
|
||||
/>
|
||||
<BorderBottomItem
|
||||
onPress={() => {router.push('/announcement/7493')}}
|
||||
borderType="bottom"
|
||||
icon={
|
||||
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
|
||||
<MaterialIcons name="campaign" size={25} color={'#384288'} />
|
||||
</View>
|
||||
}
|
||||
title="Libur Nyepi"
|
||||
desc="Pengumuman terkait libur nyepi"
|
||||
rightTopInfo="23 Mar 2025"
|
||||
/>
|
||||
<BorderBottomItem
|
||||
onPress={() => {router.push('/announcement/7493')}}
|
||||
borderType="bottom"
|
||||
icon={
|
||||
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
|
||||
<MaterialIcons name="campaign" size={25} color={'#384288'} />
|
||||
</View>
|
||||
}
|
||||
title="Libur Nyepi"
|
||||
desc="Pengumuman terkait libur nyepi"
|
||||
rightTopInfo="23 Mar 2025"
|
||||
/>
|
||||
<InputSearch onChange={setSearch} />
|
||||
{
|
||||
data.length > 0
|
||||
?
|
||||
data.map((item, index) => {
|
||||
return (
|
||||
<BorderBottomItem
|
||||
key={index}
|
||||
onPress={() => { router.push(`/announcement/${item.id}`) }}
|
||||
borderType="bottom"
|
||||
icon={
|
||||
<View style={[Styles.iconContent, ColorsStatus.lightGreen]}>
|
||||
<MaterialIcons name="campaign" size={25} color={'#384288'} />
|
||||
</View>
|
||||
}
|
||||
title={item.title}
|
||||
desc={item.desc}
|
||||
rightTopInfo={item.createdAt}
|
||||
/>
|
||||
)
|
||||
})
|
||||
:
|
||||
<Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada pengumuman</Text>
|
||||
}
|
||||
</View>
|
||||
</ScrollView>
|
||||
</SafeAreaView>
|
||||
|
||||
Reference in New Issue
Block a user