updd: announcement

Deskripsi:
- edit pengumuman
- delete pengumuman

No Issues
This commit is contained in:
amel
2025-05-08 11:27:11 +08:00
parent 6cae53cbc7
commit e64f7c7e14
6 changed files with 263 additions and 45 deletions

View File

@@ -1,18 +1,44 @@
import Styles from "@/constants/Styles"
import { setUpdateAnnouncement } from "@/lib/announcementUpdate"
import { apiDeleteAnnouncement } from "@/lib/api"
import { useAuthSession } from "@/providers/AuthProvider"
import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons"
import { router } from "expo-router"
import { useState } from "react"
import { ToastAndroid, View } from "react-native"
import { useDispatch, useSelector } from "react-redux"
import AlertKonfirmasi from "../alertKonfirmasi"
import ButtonMenuHeader from "../buttonMenuHeader"
import DrawerBottom from "../drawerBottom"
import MenuItemRow from "../menuItemRow"
type Props = {
id: string | string[]
id: string
}
export default function HeaderRightAnnouncementDetail({ id }: Props) {
const { token, decryptToken } = useAuthSession()
const [isVisible, setVisible] = useState(false)
const update = useSelector((state: any) => state.announcementUpdate)
const dispatch = useDispatch()
async function handleDelete() {
try {
const hasil = await decryptToken(String(token?.current))
const response = await apiDeleteAnnouncement({ user: hasil }, id)
if (response.success) {
dispatch(setUpdateAnnouncement(!update))
setVisible(false)
ToastAndroid.show('Berhasil menghapus data', ToastAndroid.SHORT)
router.back()
}
} catch (error) {
console.error(error)
} finally {
setVisible(false)
}
}
return (
<>
<ButtonMenuHeader onPress={() => { setVisible(true) }} />
@@ -34,9 +60,7 @@ export default function HeaderRightAnnouncementDetail({ id }: Props) {
title: 'Konfirmasi',
desc: 'Apakah anda yakin ingin menghapus pengumuman ini?',
onPress: () => {
setVisible(false)
ToastAndroid.show('Berhasil menghapus data', ToastAndroid.SHORT)
router.push('/announcement')
handleDelete()
}
})
}}

View File

@@ -14,6 +14,7 @@ type Props = {
category: 'share-division' | 'choose-division'
choose: string
onSelect: (value: any[]) => void
value?: any
}
type CheckedState = {
@@ -29,7 +30,7 @@ type GroupData = {
}[];
}
export default function ModalSelectMultiple({ open, close, title, category, choose, onSelect }: Props) {
export default function ModalSelectMultiple({ open, close, title, category, choose, onSelect, value }: Props) {
const [isChoose, setChoose] = useState(choose)
const { token, decryptToken } = useAuthSession()
const [data, setData] = useState<any>([])
@@ -40,6 +41,14 @@ export default function ModalSelectMultiple({ open, close, title, category, choo
const hasil = await decryptToken(String(token?.current))
const response = await apiGetDivisionGroup({ user: hasil })
setData(response.data)
if (value.length > 0) {
const formatArray = value.reduce((result: any, obj: any) => {
result[obj.id] = obj.Division.map((item: any) => item.id);
return result;
}, {})
setChecked(formatArray)
}
} catch (error) {
console.error(error)
}
@@ -112,7 +121,7 @@ export default function ModalSelectMultiple({ open, close, title, category, choo
<Text style={[Styles.textDefaultSemiBold]}>Sosial Kemasyarakatan</Text>
<AntDesign name="check" size={20} />
</Pressable>
<Pressable style={[Styles.itemSelectModal]}>
{/* <Pressable style={[Styles.itemSelectModal]}>
<Text>Kaur Pemerintahan</Text>
</Pressable>
<Pressable style={[Styles.itemSelectModal]}>
@@ -120,7 +129,7 @@ export default function ModalSelectMultiple({ open, close, title, category, choo
</Pressable>
<Pressable style={[Styles.itemSelectModal]}>
<Text>PKK</Text>
</Pressable>
</Pressable> */}
</>
:
data.map((item: any, index: number) => {