upd: project

Deskripsi:
- delete project yg telah dibatalkan
- akses fitur by user role
- tampilan text yg panjang

No Issues
This commit is contained in:
amel
2025-05-15 12:08:24 +08:00
parent a877eec078
commit 9b05c6220c
11 changed files with 174 additions and 80 deletions

View File

@@ -1,18 +1,46 @@
import Styles from "@/constants/Styles"
import { AntDesign, MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons"
import { apiDeleteProject } from "@/lib/api"
import { setUpdateProject } from "@/lib/projectUpdate"
import { useAuthSession } from "@/providers/AuthProvider"
import { AntDesign, Ionicons, MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons"
import { router } from "expo-router"
import { useState } from "react"
import { View } from "react-native"
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[]
status: number | undefined
}
export default function HeaderRightProjectDetail({ id }: Props) {
export default function HeaderRightProjectDetail({ id, status }: Props) {
const entityUser = useSelector((state: any) => state.user)
const { token, decryptToken } = useAuthSession()
const [isVisible, setVisible] = useState(false)
const dispatch = useDispatch()
const update = useSelector((state: any) => state.projectUpdate)
async function handleDelete() {
try {
const hasil = await decryptToken(String(token?.current))
const response = await apiDeleteProject({ user: hasil }, String(id))
if (response.success) {
dispatch(setUpdateProject({ ...update, data: !update.data }))
ToastAndroid.show('Berhasil menghapus kegiatan', ToastAndroid.SHORT)
router.back()
} else {
ToastAndroid.show('Gagal menghapus kegiatan', ToastAndroid.SHORT)
}
} catch (error) {
console.error(error)
} finally {
setVisible(false)
}
}
return (
<>
@@ -23,47 +51,75 @@ export default function HeaderRightProjectDetail({ id }: Props) {
icon={<AntDesign name="pluscircle" color="black" size={25} />}
title="Tambah Tugas"
onPress={() => {
if (status == 3) return
setVisible(false)
router.push(`/project/${id}/add-task`)
}}
disabled={status == 3}
/>
<MenuItemRow
icon={<MaterialCommunityIcons name="file-plus" color="black" size={25} />}
title="Tambah File"
onPress={() => {
if (status == 3) return
setVisible(false)
router.push(`/project/${id}/add-file`)
}}
disabled={status == 3}
/>
<MenuItemRow
icon={<MaterialIcons name="groups" color="black" size={25} />}
title="Tambah Anggota"
onPress={() => {
setVisible(false)
router.push(`/project/${id}/add-member`)
}}
/>
</View>
<View style={[Styles.rowItemsCenter, Styles.mt15]}>
<MenuItemRow
icon={<MaterialCommunityIcons name="pencil-outline" color="black" size={25} />}
title="Edit"
onPress={() => {
setVisible(false)
router.push(`/project/${id}/edit`)
}}
/>
<MenuItemRow
icon={<MaterialIcons name="close" color="black" size={25} />}
title="Batal"
onPress={() => {
setVisible(false)
router.push(`/project/${id}/cancel`)
}}
/>
{
entityUser.role != "user" && entityUser.role != "coadmin" &&
<MenuItemRow
icon={<MaterialIcons name="groups" color="black" size={25} />}
title="Tambah Anggota"
onPress={() => {
if (status == 3) return
setVisible(false)
router.push(`/project/${id}/add-member`)
}}
disabled={status == 3}
/>
}
</View>
{
entityUser.role != "user" && entityUser.role != "coadmin" &&
<View style={[Styles.rowItemsCenter, Styles.mt15]}>
<MenuItemRow
icon={<MaterialCommunityIcons name="pencil-outline" color="black" size={25} />}
title="Edit"
onPress={() => {
if (status == 3) return
setVisible(false)
router.push(`/project/${id}/edit`)
}}
disabled={status == 3}
/>
{
status == 3
?
<MenuItemRow
icon={<Ionicons name="trash" color="black" size={25} />}
title="Hapus"
onPress={() => {
AlertKonfirmasi({
title: 'Konfirmasi',
desc: 'Apakah Anda yakin ingin menghapus kegiatan ini? Kegiatan yang dihapus tidak dapat dikembalikan',
onPress: () => { handleDelete() }
})
}}
/>
:
<MenuItemRow
icon={<MaterialIcons name="close" color="black" size={25} />}
title="Batal"
onPress={() => {
setVisible(false)
router.push(`/project/${id}/cancel`)
}}
/>
}
</View>
}
</DrawerBottom>
</>
)

View File

@@ -5,6 +5,7 @@ import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons";
import { useLocalSearchParams } from "expo-router";
import { useEffect, useState } from "react";
import { Text, ToastAndroid, View } from "react-native";
import { useSelector } from "react-redux";
import AlertKonfirmasi from "../alertKonfirmasi";
import BorderBottomItem from "../borderBottomItem";
import DrawerBottom from "../drawerBottom";
@@ -17,7 +18,8 @@ type Props = {
idStorage: string
}
export default function SectionFile() {
export default function SectionFile({ status, member }: { status: number | undefined, member: boolean }) {
const entityUser = useSelector((state: any) => state.user)
const [isModal, setModal] = useState(false)
const { token, decryptToken } = useAuthSession();
const { id } = useLocalSearchParams<{ id: string }>();
@@ -82,22 +84,27 @@ export default function SectionFile() {
setModal(false)
}}
/>
{
!member && (entityUser.role == "user" || entityUser.role == "coadmin") ? <></>
:
<MenuItemRow
icon={<Ionicons name="trash" color="black" size={25} />}
title="Hapus"
disabled={status == 3}
onPress={() => {
if (status == 3) return
AlertKonfirmasi({
title: 'Konfirmasi',
desc: 'Apakah Anda yakin ingin menghapus file ini? File yang dihapus tidak dapat dikembalikan',
onPress: () => {
setModal(false)
ToastAndroid.show('Berhasil menghapus data', ToastAndroid.SHORT)
}
})
<MenuItemRow
icon={<Ionicons name="trash" color="black" size={25} />}
title="Hapus"
onPress={() => {
AlertKonfirmasi({
title: 'Konfirmasi',
desc: 'Apakah Anda yakin ingin menghapus file ini? File yang dihapus tidak dapat dikembalikan',
onPress: () => {
setModal(false)
ToastAndroid.show('Berhasil menghapus data', ToastAndroid.SHORT)
}
})
}}
/>
}}
/>
}
</View>
</DrawerBottom>
</>

View File

@@ -22,8 +22,9 @@ type Props = {
position: string;
};
export default function SectionMember() {
export default function SectionMember({ status }: { status: number | undefined }) {
const dispatch = useDispatch()
const entityUser = useSelector((state: any) => state.user)
const update = useSelector((state: any) => state.projectUpdate)
const [isModal, setModal] = useState(false);
const { token, decryptToken } = useAuthSession();
@@ -89,9 +90,8 @@ export default function SectionMember() {
borderType="bottom"
icon={<ImageUser src={`https://wibu-storage.wibudev.com/api/files/${item.img}`} />}
title={item.name}
subtitle={item.position}
rightTopInfo="Anggota"
onPress={() => {
if (status == 3) return
setMemberChoose({
id: item.idUser,
name: item.name,
@@ -128,24 +128,26 @@ export default function SectionMember() {
router.push(`/member/${memberChoose.id}`);
}}
/>
<MenuItemRow
icon={
<MaterialCommunityIcons
name="account-remove"
color="black"
size={25}
/>
}
title="Keluarkan"
onPress={() => {
AlertKonfirmasi({
title: "Konfirmasi",
desc: "Apakah Anda yakin ingin mengeluarkan anggota?",
onPress: () => { handleDeleteMember() },
});
}}
/>
{
entityUser.role != "user" && entityUser.role != "coadmin" &&
<MenuItemRow
icon={
<MaterialCommunityIcons
name="account-remove"
color="black"
size={25}
/>
}
title="Keluarkan"
onPress={() => {
AlertKonfirmasi({
title: "Konfirmasi",
desc: "Apakah Anda yakin ingin mengeluarkan anggota?",
onPress: () => { handleDeleteMember() },
});
}}
/>
}
</View>
</DrawerBottom>
</>

View File

@@ -23,7 +23,8 @@ type Props = {
createdAt: string;
};
export default function SectionTanggalTugasProject() {
export default function SectionTanggalTugasProject({ status, member }: { status: number | undefined, member: boolean }) {
const entityUser = useSelector((state: any) => state.user)
const dispatch = useDispatch()
const update = useSelector((state: any) => state.projectUpdate)
const [isModal, setModal] = useState(false);
@@ -110,6 +111,7 @@ export default function SectionTanggalTugasProject() {
dateStart={item.dateStart}
dateEnd={item.dateEnd}
onPress={() => {
if (status == 3 || (!member && (entityUser.role == "user" || entityUser.role == "coadmin"))) return
setTugas({
id: item.id,
status: item.status