diff --git a/app/(application)/project/[id]/index.tsx b/app/(application)/project/[id]/index.tsx
index b7b65e6..45fb2c4 100644
--- a/app/(application)/project/[id]/index.tsx
+++ b/app/(application)/project/[id]/index.tsx
@@ -35,6 +35,8 @@ export default function DetailProject() {
const [progress, setProgress] = useState(0)
const [loading, setLoading] = useState(true)
const update = useSelector((state: any) => state.projectUpdate)
+ const [isMember, setIsMember] = useState(false)
+ const entityUser = useSelector((state: any) => state.user)
async function handleLoad() {
try {
@@ -51,10 +53,25 @@ export default function DetailProject() {
}
}
+ async function checkMember() {
+ try {
+ const hasil = await decryptToken(String(token?.current))
+ const response = await apiGetProjectOne({ user: hasil, cat: 'member', id: id })
+ const cekMember = response.data.some((i: any) => i.idUser == hasil)
+ setIsMember(cekMember)
+ } catch (error) {
+ console.error(error)
+ }
+ }
+
useEffect(() => {
handleLoad()
}, [update.data, update.progress])
+ useEffect(() => {
+ checkMember()
+ }, [])
+
return (
@@ -63,7 +80,7 @@ export default function DetailProject() {
headerLeft: () => { router.back() }} />,
headerTitle: loading ? '' : data?.title,
headerTitleAlign: 'center',
- headerRight: () => ,
+ headerRight: () => (entityUser.role == "user" || entityUser.role == "coadmin") && !isMember ? null : ,
}}
/>
@@ -72,9 +89,9 @@ export default function DetailProject() {
data?.reason != null && data?.reason != "" &&
}
-
-
-
+
+
+
diff --git a/components/borderBottomItem.tsx b/components/borderBottomItem.tsx
index 07e73ff..f7ee2e9 100644
--- a/components/borderBottomItem.tsx
+++ b/components/borderBottomItem.tsx
@@ -30,7 +30,7 @@ export default function BorderBottomItem({ title, subtitle, icon, desc, onPress,
{icon}
- {title}
+ {title}
{
subtitle &&
typeof subtitle == "string"
diff --git a/components/itemSectionTanggalTugas.tsx b/components/itemSectionTanggalTugas.tsx
index 65eee7b..5ffedad 100644
--- a/components/itemSectionTanggalTugas.tsx
+++ b/components/itemSectionTanggalTugas.tsx
@@ -35,7 +35,9 @@ export default function ItemSectionTanggalTugas({ done, title, dateStart, dateEn
- {title}
+
+ {title}
+
diff --git a/components/menuItemRow.tsx b/components/menuItemRow.tsx
index 2d9ee6a..42b5bcd 100644
--- a/components/menuItemRow.tsx
+++ b/components/menuItemRow.tsx
@@ -7,11 +7,12 @@ type Props = {
title: string
column?: 'many' | 'three'
color?: string
+ disabled?: boolean
}
-export default function MenuItemRow({ onPress, icon, title, column, color }: Props) {
+export default function MenuItemRow({ onPress, icon, title, column, color, disabled }: Props) {
return (
- { onPress() }} style={[column == 'many' ? Styles.btnMenuRowMany : Styles.btnMenuRow]}>
+ { onPress() }} style={[column == 'many' ? Styles.btnMenuRowMany : Styles.btnMenuRow, disabled && { opacity: 0.5 }]}>
{icon}
{title}
diff --git a/components/paperGridContent.tsx b/components/paperGridContent.tsx
index d06932e..8341902 100644
--- a/components/paperGridContent.tsx
+++ b/components/paperGridContent.tsx
@@ -15,7 +15,7 @@ export default function PaperGridContent({ content, children, title, headerColor
- {title}
+ {title}
{children}
diff --git a/components/project/headerProjectDetail.tsx b/components/project/headerProjectDetail.tsx
index b23957e..5721221 100644
--- a/components/project/headerProjectDetail.tsx
+++ b/components/project/headerProjectDetail.tsx
@@ -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={}
title="Tambah Tugas"
onPress={() => {
+ if (status == 3) return
setVisible(false)
router.push(`/project/${id}/add-task`)
}}
+ disabled={status == 3}
/>
}
title="Tambah File"
onPress={() => {
+ if (status == 3) return
setVisible(false)
router.push(`/project/${id}/add-file`)
}}
+ disabled={status == 3}
/>
-
- }
- title="Tambah Anggota"
- onPress={() => {
- setVisible(false)
- router.push(`/project/${id}/add-member`)
- }}
- />
-
-
-
- }
- title="Edit"
- onPress={() => {
- setVisible(false)
- router.push(`/project/${id}/edit`)
- }}
- />
- }
- title="Batal"
- onPress={() => {
- setVisible(false)
- router.push(`/project/${id}/cancel`)
- }}
- />
+ {
+ entityUser.role != "user" && entityUser.role != "coadmin" &&
+ }
+ title="Tambah Anggota"
+ onPress={() => {
+ if (status == 3) return
+ setVisible(false)
+ router.push(`/project/${id}/add-member`)
+ }}
+ disabled={status == 3}
+ />
+ }
+ {
+ entityUser.role != "user" && entityUser.role != "coadmin" &&
+
+ }
+ title="Edit"
+ onPress={() => {
+ if (status == 3) return
+ setVisible(false)
+ router.push(`/project/${id}/edit`)
+ }}
+ disabled={status == 3}
+ />
+ {
+ status == 3
+ ?
+ }
+ title="Hapus"
+ onPress={() => {
+ AlertKonfirmasi({
+ title: 'Konfirmasi',
+ desc: 'Apakah Anda yakin ingin menghapus kegiatan ini? Kegiatan yang dihapus tidak dapat dikembalikan',
+ onPress: () => { handleDelete() }
+ })
+ }}
+ />
+ :
+ }
+ title="Batal"
+ onPress={() => {
+ setVisible(false)
+ router.push(`/project/${id}/cancel`)
+ }}
+ />
+ }
+
+ }
>
)
diff --git a/components/project/sectionFile.tsx b/components/project/sectionFile.tsx
index 03c9449..04bc169 100644
--- a/components/project/sectionFile.tsx
+++ b/components/project/sectionFile.tsx
@@ -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") ? <>>
+ :
+ }
+ 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)
+ }
+ })
- }
- 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)
- }
- })
-
- }}
- />
+ }}
+ />
+ }
>
diff --git a/components/project/sectionMember.tsx b/components/project/sectionMember.tsx
index 978cde0..d47b5ad 100644
--- a/components/project/sectionMember.tsx
+++ b/components/project/sectionMember.tsx
@@ -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={}
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}`);
}}
/>
-
-
- }
- title="Keluarkan"
- onPress={() => {
- AlertKonfirmasi({
- title: "Konfirmasi",
- desc: "Apakah Anda yakin ingin mengeluarkan anggota?",
- onPress: () => { handleDeleteMember() },
- });
- }}
- />
+ {
+ entityUser.role != "user" && entityUser.role != "coadmin" &&
+
+ }
+ title="Keluarkan"
+ onPress={() => {
+ AlertKonfirmasi({
+ title: "Konfirmasi",
+ desc: "Apakah Anda yakin ingin mengeluarkan anggota?",
+ onPress: () => { handleDeleteMember() },
+ });
+ }}
+ />
+ }
>
diff --git a/components/project/sectionTanggalTugas.tsx b/components/project/sectionTanggalTugas.tsx
index ab04542..1f5409a 100644
--- a/components/project/sectionTanggalTugas.tsx
+++ b/components/project/sectionTanggalTugas.tsx
@@ -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
diff --git a/constants/Styles.ts b/constants/Styles.ts
index fd0822c..7e57cef 100644
--- a/constants/Styles.ts
+++ b/constants/Styles.ts
@@ -161,6 +161,9 @@ const Styles = StyleSheet.create({
w100: {
width: '100%'
},
+ w95: {
+ width: '95%'
+ },
w90: {
width: '90%'
},
@@ -300,6 +303,7 @@ const Styles = StyleSheet.create({
},
headerPaperGrid: {
paddingVertical: 25,
+ paddingHorizontal: 20,
alignItems: 'center',
borderTopStartRadius: 15,
borderTopEndRadius: 15
diff --git a/lib/api.ts b/lib/api.ts
index bfac090..46277ee 100644
--- a/lib/api.ts
+++ b/lib/api.ts
@@ -32,13 +32,11 @@ export const apiGetBanner = async ({ user }: { user: string }) => {
export const apiCreateBanner = async (data: FormData) => {
- console.log('jalan', data)
const response = await api.post('mobile/banner', data, {
headers: {
'Content-Type': 'multipart/form-data',
},
})
- console.log('api',response.data)
return response.data;
};
@@ -294,4 +292,9 @@ export const apiCreateProject = async (data: FormData) => {
},
})
return response.data;
+};
+
+export const apiDeleteProject = async (data: { user: string }, id: string) => {
+ const response = await api.delete(`/mobile/project/${id}/lainnya`, { data })
+ return response.data;
};
\ No newline at end of file