diff --git a/app/(application)/division/[id]/(fitur-division)/discussion/[detail]/edit.tsx b/app/(application)/division/[id]/(fitur-division)/discussion/[detail]/edit.tsx
index fdb9b67..139fa83 100644
--- a/app/(application)/division/[id]/(fitur-division)/discussion/[detail]/edit.tsx
+++ b/app/(application)/division/[id]/(fitur-division)/discussion/[detail]/edit.tsx
@@ -2,40 +2,92 @@ import ButtonBackHeader from "@/components/buttonBackHeader";
import ButtonSaveHeader from "@/components/buttonSaveHeader";
import { InputForm } from "@/components/inputForm";
import Styles from "@/constants/Styles";
-import { router, Stack } from "expo-router";
+import { apiEditDiscussion, apiGetDiscussionOne } from "@/lib/api";
+import { setUpdateDiscussion } from "@/lib/discussionUpdate";
+import { useAuthSession } from "@/providers/AuthProvider";
+import { router, Stack, useLocalSearchParams } from "expo-router";
+import { useEffect, useState } from "react";
import { SafeAreaView, ScrollView, ToastAndroid, View } from "react-native";
+import { useDispatch, useSelector } from "react-redux";
export default function DiscussionDivisionEdit() {
+ const { id, detail } = useLocalSearchParams<{ id: string; detail: string }>();
+ const { token, decryptToken } = useAuthSession();
+ const [data, setData] = useState("");
+ const update = useSelector((state: any) => state.discussionUpdate);
+ const dispatch = useDispatch();
+
+ async function handleLoad() {
+ try {
+ const hasil = await decryptToken(String(token?.current));
+ const response = await apiGetDiscussionOne({
+ id: detail,
+ user: hasil,
+ cat: "data",
+ });
+ setData(response.data.desc);
+ } catch (error) {
+ console.error(error);
+ }
+ }
+
+ useEffect(() => {
+ handleLoad();
+ }, []);
+
+ async function handleUpdate() {
+ try {
+ const hasil = await decryptToken(String(token?.current));
+ const response = await apiEditDiscussion({
+ data: { user: hasil, desc: data },
+ id: detail,
+ });
+ if (response.success) {
+ ToastAndroid.show("Berhasil mengubah data", ToastAndroid.SHORT);
+ dispatch(setUpdateDiscussion({ ...update, data: !update.data }));
+ router.back();
+ }
+ } catch (error) {
+ console.error(error);
+ }
+ }
+
return (
{ router.back() }} />,
- headerTitle: 'Edit Diskusi',
- headerTitleAlign: 'center',
- headerRight: () => {
- ToastAndroid.show('Berhasil mengubah data', ToastAndroid.SHORT)
- router.back()
- }} />
+ headerLeft: () => (
+ {
+ router.back();
+ }}
+ />
+ ),
+ headerTitle: "Edit Diskusi",
+ headerTitleAlign: "center",
+ headerRight: () => (
+ {
+ handleUpdate();
+ }}
+ />
+ ),
}}
/>
-
- {/* {
- AlertKonfirmasi({
- title: 'Konfirmasi',
- desc: 'Apakah anda yakin ingin mengubah data?',
- onPress: () => {
- ToastAndroid.show('Berhasil mengubah data', ToastAndroid.SHORT)
- router.back()
- }
- })
- }} /> */}
+
- )
-}
\ No newline at end of file
+ );
+}
diff --git a/app/(application)/division/[id]/(fitur-division)/discussion/[detail]/index.tsx b/app/(application)/division/[id]/(fitur-division)/discussion/[detail]/index.tsx
index d0232fa..a3920e0 100644
--- a/app/(application)/division/[id]/(fitur-division)/discussion/[detail]/index.tsx
+++ b/app/(application)/division/[id]/(fitur-division)/discussion/[detail]/index.tsx
@@ -1,152 +1,278 @@
import BorderBottomItem from "@/components/borderBottomItem";
import ButtonBackHeader from "@/components/buttonBackHeader";
import HeaderRightDiscussionDetail from "@/components/discussion/headerDiscussionDetail";
+import ImageUser from "@/components/imageNew";
import { InputForm } from "@/components/inputForm";
import LabelStatus from "@/components/labelStatus";
import Styles from "@/constants/Styles";
+import {
+ apiGetDiscussionOne,
+ apiGetDivisionOneFeature,
+ apiSendDiscussionCommentar,
+} from "@/lib/api";
+import { useAuthSession } from "@/providers/AuthProvider";
import { Ionicons, MaterialIcons } from "@expo/vector-icons";
import { router, Stack, useLocalSearchParams } from "expo-router";
-import { Image, ScrollView, Text, View } from "react-native";
+import { useEffect, useState } from "react";
+import { Pressable, ScrollView, Text, View } from "react-native";
+import { useSelector } from "react-redux";
+
+type Props = {
+ id: string;
+ title: string;
+ desc: string;
+ status: number;
+ createdAt: string;
+ createdBy: string;
+ username: string;
+ user_img: string;
+ isCreator: boolean;
+ isActive: boolean;
+};
+
+type PropsComment = {
+ id: string;
+ comment: string;
+ createdAt: string;
+ username: string;
+ img: string;
+};
export default function DiscussionDetail() {
- const { id, detail } = useLocalSearchParams();
+ const { id, detail } = useLocalSearchParams<{ id: string; detail: string }>();
+ const [data, setData] = useState();
+ const [dataComment, setDataComment] = useState([]);
+ const { token, decryptToken } = useAuthSession();
+ const [komentar, setKomentar] = useState("");
+ const [loadingSend, setLoadingSend] = useState(false);
+ const update = useSelector((state: any) => state.discussionUpdate);
+ const entityUser = useSelector((state: any) => state.user);
+ const [isMemberDivision, setIsMemberDivision] = useState(false);
+ const [isAdminDivision, setIsAdminDivision] = useState(false);
+ const [isCreator, setIsCreator] = useState(false);
+
+ async function handleLoad() {
+ try {
+ const hasil = await decryptToken(String(token?.current));
+ const response = await apiGetDiscussionOne({
+ id: detail,
+ user: hasil,
+ cat: "data",
+ });
+ setData(response.data);
+ setIsCreator(response.data.createdBy == hasil);
+ } catch (error) {
+ console.error(error);
+ }
+ }
+
+ async function handleLoadComment() {
+ try {
+ const hasil = await decryptToken(String(token?.current));
+ const response = await apiGetDiscussionOne({
+ id: detail,
+ user: hasil,
+ cat: "comment",
+ });
+ setDataComment(response.data);
+ } catch (error) {
+ console.error(error);
+ }
+ }
+
+ async function handleCheckMember() {
+ try {
+ const hasil = await decryptToken(String(token?.current));
+ const response = await apiGetDivisionOneFeature({
+ id,
+ user: hasil,
+ cat: "check-member",
+ });
+
+ const response2 = await apiGetDivisionOneFeature({
+ id,
+ user: hasil,
+ cat: "check-admin",
+ });
+ setIsMemberDivision(response.data);
+ setIsAdminDivision(response2.data);
+ } catch (error) {
+ console.error(error);
+ }
+ }
+
+ useEffect(() => {
+ handleLoad();
+ }, [update.data]);
+
+ useEffect(() => {
+ handleLoadComment();
+ handleCheckMember();
+ }, []);
+
+ async function handleKomentar() {
+ try {
+ setLoadingSend(true);
+ const hasil = await decryptToken(String(token?.current));
+ const response = await apiSendDiscussionCommentar({
+ id: detail,
+ data: { comment: komentar, user: hasil },
+ });
+ if (response.success) {
+ setKomentar("");
+ handleLoadComment();
+ }
+ } catch (error) {
+ console.error(error);
+ } finally {
+ setLoadingSend(false);
+ }
+ }
return (
<>
{ router.back() }} />,
- headerTitle: 'Diskusi',
- headerTitleAlign: 'center',
- headerRight: () => ,
+ headerLeft: () => (
+ {
+ router.back();
+ }}
+ />
+ ),
+ headerTitle: "Diskusi",
+ headerTitleAlign: "center",
+ headerRight: () =>
+ (entityUser.role != "user" && entityUser.role != "coadmin") || isAdminDivision || isCreator ?
+ : (<>>)
+ ,
}}
/>
}
- title="Amalia Dwi"
+ title={data?.username}
subtitle={
-
+ data?.isActive ? (
+ data?.status == 1 ? (
+
+ ) : (
+
+ )
+ ) : (
+
+ )
}
- rightTopInfo="3 Jan 2025"
- desc="Bagaimana dampak yg dirasakan akibat efisiensi?"
+ rightTopInfo={data?.createdAt}
+ desc={data?.desc}
leftBottomInfo={
-
- 15 Komentar
+
+
+ {dataComment.length} Komentar
+
}
/>
-
- }
- title="Amalia Dwi"
- rightTopInfo="3 Jan 2025"
- desc="sangat berdampak dari berbagai sisi"
- />
-
- }
- title="Amalia Dwi"
- rightTopInfo="3 Jan 2025"
- desc="semua menjadi terbatas.."
- />
-
- }
- title="Amalia Dwi"
- rightTopInfo="3 Jan 2025"
- desc="semua menjadi terbatas.."
- />
-
- }
- title="Amalia Dwi"
- rightTopInfo="3 Jan 2025"
- desc="semua menjadi terbatas.."
- />
-
- }
- title="Amalia Dwi"
- rightTopInfo="3 Jan 2025"
- desc="semua menjadi terbatas.."
- />
-
- }
- title="Amalia Dwi"
- rightTopInfo="3 Jan 2025"
- desc="semua menjadi terbatas.."
- />
-
-
- }
- title="Amalia Dwi"
- rightTopInfo="3 Jan 2025"
- desc="semua menjadi terbatas.."
- />
-
+ {dataComment.map((item, index) => (
+
+ }
+ title={item.username}
+ rightTopInfo={item.createdAt}
+ desc={item.comment}
+ descEllipsize={false}
+ />
+ ))}
-
+
+ {
+ komentar != "" &&
+ !loadingSend &&
+ data?.status != 2 &&
+ data?.isActive &&
+ (((entityUser.role == "user" ||
+ entityUser.role == "coadmin") &&
+ isMemberDivision) ||
+ entityUser.role == "admin" ||
+ entityUser.role == "superadmin" ||
+ entityUser.role == "developer" ||
+ entityUser.role == "cosupadmin") &&
+ handleKomentar();
+ }}
+ >
+
+
}
/>
>
- )
-}
\ No newline at end of file
+ );
+}
diff --git a/app/(application)/division/[id]/(fitur-division)/discussion/create.tsx b/app/(application)/division/[id]/(fitur-division)/discussion/create.tsx
index 9cf49a5..374c1d9 100644
--- a/app/(application)/division/[id]/(fitur-division)/discussion/create.tsx
+++ b/app/(application)/division/[id]/(fitur-division)/discussion/create.tsx
@@ -2,10 +2,38 @@ import ButtonBackHeader from "@/components/buttonBackHeader"
import ButtonSaveHeader from "@/components/buttonSaveHeader"
import { InputForm } from "@/components/inputForm"
import Styles from "@/constants/Styles"
-import { router, Stack } from "expo-router"
+import { apiCreateDiscussion } from "@/lib/api"
+import { setUpdateDiscussion } from "@/lib/discussionUpdate"
+import { useAuthSession } from "@/providers/AuthProvider"
+import { router, Stack, useLocalSearchParams } from "expo-router"
+import { useState } from "react"
import { SafeAreaView, ScrollView, ToastAndroid, View } from "react-native"
+import { useDispatch, useSelector } from "react-redux"
export default function CreateDiscussionDivision() {
+ const { id } = useLocalSearchParams<{ id: string }>()
+ const [desc, setDesc] = useState('')
+ const { token, decryptToken } = useAuthSession()
+ const update = useSelector((state: any) => state.discussionUpdate)
+ const dispatch = useDispatch();
+
+ async function handleCreate() {
+ try {
+ const hasil = await decryptToken(String(token?.current))
+ const response = await apiCreateDiscussion({ data: { user: hasil, desc, idDivision: id } })
+ if (response.success) {
+ ToastAndroid.show('Berhasil menambahkan data', ToastAndroid.SHORT)
+ dispatch(setUpdateDiscussion({ ...update, data: !update.data }));
+ router.back()
+ } else {
+ ToastAndroid.show(response.message, ToastAndroid.SHORT)
+ }
+ } catch (error) {
+ console.error(error)
+ ToastAndroid.show('Terjadi kesalahan', ToastAndroid.SHORT)
+ }
+ }
+
return (
{ router.back() }} />,
headerTitle: 'Tambah Diskusi',
headerTitleAlign: 'center',
- headerRight: () => {
- ToastAndroid.show('Berhasil menambahkan data', ToastAndroid.SHORT)
- router.push('./')
- }} />
+ headerRight: () => {
+ handleCreate()
+ }} />
}}
/>
-
+
diff --git a/app/(application)/division/[id]/(fitur-division)/discussion/index.tsx b/app/(application)/division/[id]/(fitur-division)/discussion/index.tsx
index ef37c6e..a2a19f2 100644
--- a/app/(application)/division/[id]/(fitur-division)/discussion/index.tsx
+++ b/app/(application)/division/[id]/(fitur-division)/discussion/index.tsx
@@ -1,15 +1,52 @@
import BorderBottomItem from "@/components/borderBottomItem";
import ButtonTab from "@/components/buttonTab";
+import ImageUser from "@/components/imageNew";
import InputSearch from "@/components/inputSearch";
import LabelStatus from "@/components/labelStatus";
import Styles from "@/constants/Styles";
+import { apiGetDiscussion, apiGetDivisionOneFeature } from "@/lib/api";
+import { useAuthSession } from "@/providers/AuthProvider";
import { AntDesign, Feather, Ionicons } from "@expo/vector-icons";
import { router, useLocalSearchParams } from "expo-router";
-import { Image, SafeAreaView, ScrollView, Text, 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,
+ status: number,
+ user_name: string,
+ img: string,
+ total_komentar: number,
+ createdAt: string,
+ isActive: boolean
+}
export default function DiscussionDivision() {
- const { active } = useLocalSearchParams<{ active?: string }>()
+ const { id, active } = useLocalSearchParams<{ id: string, active?: string }>()
+ const [data, setData] = useState([])
+ const { token, decryptToken } = useAuthSession()
+ const [search, setSearch] = useState('')
+ const update = useSelector((state: any) => state.discussionUpdate);
+
+ async function handleLoad() {
+ try {
+ const hasil = await decryptToken(String(token?.current))
+ const response = await apiGetDiscussion({ user: hasil, search, division: id, active })
+ setData(response.data)
+ } catch (error) {
+ console.error(error)
+ }
+ }
+
+
+ useEffect(() => {
+ handleLoad()
+ }, [active, search, update.data])
return (
@@ -19,121 +56,49 @@ export default function DiscussionDivision() {
{ router.push('./discussion?active=true') }}
+ onPress={() => { router.replace('./discussion?active=true') }}
label="Aktif"
icon={}
n={2} />
{ router.push('./discussion?active=false') }}
+ onPress={() => { router.replace('./discussion?active=false') }}
label="Arsip"
icon={}
n={2} />
-
+
- { router.push('./discussion/1') }}
- borderType="bottom"
- icon={
-
- }
- title="Amalia Dwi"
- subtitle={
-
- }
- rightTopInfo="3 Jan 2025"
- desc="Bagaimana dampak yg dirasakan akibat efisiensi?"
- leftBottomInfo={
-
-
- Diskusikan
-
- }
- rightBottomInfo='15 Komentar'
- />
- { router.push('./discussion/1') }}
- borderType="bottom"
- icon={
-
- }
- title="Amalia Dwi"
- subtitle={
-
- }
- rightTopInfo="3 Jan 2025"
- desc="Bagaimana dampak yg dirasakan akibat efisiensi?"
- leftBottomInfo={
-
-
- Diskusikan
-
- }
- rightBottomInfo='15 Komentar'
- />
- { router.push('./discussion/1') }}
- borderType="bottom"
- icon={
-
- }
- title="Amalia Dwi"
- subtitle={
-
- }
- rightTopInfo="3 Jan 2025"
- desc="Bagaimana dampak yg dirasakan akibat efisiensi?"
- leftBottomInfo={
-
-
- Diskusikan
-
- }
- rightBottomInfo='15 Komentar'
- />
- { router.push('./discussion/1') }}
- borderType="bottom"
- icon={
-
- }
- title="Amalia Dwi"
- subtitle={
-
- }
- rightTopInfo="3 Jan 2025"
- desc="Bagaimana dampak yg dirasakan akibat efisiensi?"
- leftBottomInfo={
-
-
- Diskusikan
-
- }
- rightBottomInfo='15 Komentar'
- />
- { router.push('./discussion/1') }}
- borderType="bottom"
- icon={
-
- }
- title="Amalia Dwi"
- subtitle={
-
- }
- rightTopInfo="3 Jan 2025"
- desc="Bagaimana dampak yg dirasakan akibat efisiensi?"
- leftBottomInfo={
-
-
- Diskusikan
-
- }
- rightBottomInfo='15 Komentar'
- />
-
+ {data.length > 0 ?
+ data.map((item, index) => (
+ { router.push(`./discussion/${item.id}`) }}
+ borderType="bottom"
+ icon={
+
+ }
+ title={item.user_name}
+ subtitle={
+ active == "true" ? item.status == 1 ? : : <>>
+ }
+ rightTopInfo={item.createdAt}
+ desc={item.desc}
+ leftBottomInfo={
+
+
+ Diskusikan
+
+ }
+ rightBottomInfo={item.total_komentar + ' Komentar'}
+ />
+ ))
+ :
+ (
+ Tidak ada diskusi
+ )}
diff --git a/components/borderBottomItem.tsx b/components/borderBottomItem.tsx
index a67d930..a71cf96 100644
--- a/components/borderBottomItem.tsx
+++ b/components/borderBottomItem.tsx
@@ -16,9 +16,10 @@ type Props = {
titleWeight?: 'normal' | 'bold'
bgColor?: 'white' | 'transparent'
width?: number
+ descEllipsize?: boolean
}
-export default function BorderBottomItem({ title, subtitle, icon, desc, onPress, rightTopInfo, borderType, leftBottomInfo, rightBottomInfo, titleWeight, bgColor, width }: Props) {
+export default function BorderBottomItem({ title, subtitle, icon, desc, onPress, rightTopInfo, borderType, leftBottomInfo, rightBottomInfo, titleWeight, bgColor, width, descEllipsize }: Props) {
const lebarDim = Dimensions.get("window").width;
const lebar = width ? lebarDim * width / 100 : 'auto';
@@ -44,7 +45,7 @@ export default function BorderBottomItem({ title, subtitle, icon, desc, onPress,
- {desc && {desc}}
+ {desc && {desc}}
{
(leftBottomInfo || rightBottomInfo) &&
(
diff --git a/components/discussion/headerDiscussionDetail.tsx b/components/discussion/headerDiscussionDetail.tsx
index e4d5e51..b2dc428 100644
--- a/components/discussion/headerDiscussionDetail.tsx
+++ b/components/discussion/headerDiscussionDetail.tsx
@@ -1,8 +1,12 @@
import Styles from "@/constants/Styles"
+import { apiArchiveDiscussion, apiOpenCloseDiscussion } from "@/lib/api"
+import { setUpdateDiscussion } from "@/lib/discussionUpdate"
+import { useAuthSession } from "@/providers/AuthProvider"
import { MaterialCommunityIcons, MaterialIcons } 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"
@@ -10,48 +14,94 @@ import MenuItemRow from "../menuItemRow"
type Props = {
id: string | string[]
+ status: number | undefined,
+ isActive: boolean | undefined
}
-export default function HeaderRightDiscussionDetail({ id }: Props) {
+export default function HeaderRightDiscussionDetail({ id, status, isActive }: Props) {
const [isVisible, setVisible] = useState(false)
+ const { token, decryptToken } = useAuthSession()
+ const update = useSelector((state: any) => state.discussionUpdate)
+ const dispatch = useDispatch()
+
+ const handleOpenClose = async () => {
+ try {
+ const hasil = await decryptToken(String(token?.current))
+ const response = await apiOpenCloseDiscussion({ status: Number(status), user: hasil }, String(id))
+ if (response.success) {
+ ToastAndroid.show('Berhasil mengubah data', ToastAndroid.SHORT)
+ dispatch(setUpdateDiscussion({ ...update, data: !update.data }))
+ setVisible(false)
+ } else {
+ ToastAndroid.show(response.message, ToastAndroid.SHORT)
+ }
+ } catch (error) {
+ console.error(error)
+ ToastAndroid.show('Terjadi kesalahan', ToastAndroid.SHORT)
+ } finally {
+ setVisible(false)
+ }
+ }
+
+ const handleArchive = async () => {
+ try {
+ const hasil = await decryptToken(String(token?.current))
+ const response = await apiArchiveDiscussion({ user: hasil, active: !isActive }, String(id))
+ if (response.success) {
+ ToastAndroid.show('Berhasil mengubah data', ToastAndroid.SHORT)
+ dispatch(setUpdateDiscussion({ ...update, data: !update.data }))
+ setVisible(false)
+ } else {
+ ToastAndroid.show(response.message, ToastAndroid.SHORT)
+ }
+ } catch (error) {
+ console.error(error)
+ ToastAndroid.show('Terjadi kesalahan', ToastAndroid.SHORT)
+ } finally {
+ setVisible(false)
+ }
+ }
return (
<>
{ setVisible(true) }} />
- }
- title="Edit"
- onPress={() => {
- setVisible(false)
- router.push(`./${id}/edit`)
- }}
- />
- }
- title="Tutup Diskusi"
- onPress={() => {
- AlertKonfirmasi({
- title: 'Konfirmasi',
- desc: 'Apakah anda yakin ingin menutup diskusi?',
- onPress: () => {
+ {
+ isActive &&
+ <>
+ }
+ title="Edit"
+ onPress={() => {
setVisible(false)
- ToastAndroid.show('Berhasil mengubah data', ToastAndroid.SHORT)
- }
- })
- }}
- />
+ router.push(`./${id}/edit`)
+ }}
+ />
+ }
+ title={status == 1 ? 'Tutup Diskusi' : 'Buka Diskusi'}
+ onPress={() => {
+ AlertKonfirmasi({
+ title: 'Konfirmasi',
+ desc: `Apakah anda yakin ingin ${status == 1 ? 'menutup' : 'membuka'} diskusi?`,
+ onPress: () => {
+ handleOpenClose()
+ }
+ })
+ }}
+ />
+ >
+ }
}
- title="Arsipkan"
+ title={isActive ? 'Arsipkan' : 'Aktifkan Diskusi'}
onPress={() => {
AlertKonfirmasi({
title: 'Konfirmasi',
- desc: 'Apakah anda yakin ingin mengarsipkan diskusi?',
+ desc: isActive ? 'Apakah anda yakin ingin mengarsipkan diskusi?' : 'Apakah anda yakin ingin mengaktifkan diskusi?',
onPress: () => {
- setVisible(false)
- ToastAndroid.show('Berhasil mengubah data', ToastAndroid.SHORT)
+ handleArchive()
}
})
}}
diff --git a/components/discussion/headerDiscussionList.tsx b/components/discussion/headerDiscussionList.tsx
index 4c71215..54b876f 100644
--- a/components/discussion/headerDiscussionList.tsx
+++ b/components/discussion/headerDiscussionList.tsx
@@ -1,18 +1,47 @@
import Styles from "@/constants/Styles"
+import { apiGetDivisionOneFeature } from "@/lib/api"
+import { useAuthSession } from "@/providers/AuthProvider"
import { AntDesign } from "@expo/vector-icons"
-import { router } from "expo-router"
-import { useState } from "react"
+import { router, useLocalSearchParams } from "expo-router"
+import { useEffect, useState } from "react"
import { View } from "react-native"
+import { useSelector } from "react-redux"
import ButtonMenuHeader from "../buttonMenuHeader"
import DrawerBottom from "../drawerBottom"
import MenuItemRow from "../menuItemRow"
export default function HeaderRightDiscussionList() {
const [isVisible, setVisible] = useState(false)
+ const [isAdminDivision, setIsAdminDivision] = useState(false);
+ const { token, decryptToken } = useAuthSession()
+ const { id } = useLocalSearchParams<{ id: string }>();
+ const entityUser = useSelector((state: any) => state.user);
+
+ async function handleCheckAdmin() {
+ try {
+ const hasil = await decryptToken(String(token?.current));
+ const response = await apiGetDivisionOneFeature({
+ id,
+ user: hasil,
+ cat: "check-admin",
+ });
+ setIsAdminDivision(response.data);
+ } catch (error) {
+ console.error(error);
+ }
+ }
+
+ useEffect(() => {
+ handleCheckAdmin()
+ }, [])
return (
<>
- { setVisible(true) }} />
+ {
+ (entityUser.role == "user" || entityUser.role == "coadmin") && !isAdminDivision
+ ? <>> :
+ { setVisible(true) }} />
+ }
void
}
-export default function DiscussionItem({ title, user, date }: Props) {
+export default function DiscussionItem({ title, user, date, onPress }: Props) {
return (
-
+
{title}
@@ -25,6 +26,6 @@ export default function DiscussionItem({ title, user, date }: Props) {
{date}
-
+
)
}
\ No newline at end of file
diff --git a/components/division/discussionDivisionDetail.tsx b/components/division/discussionDivisionDetail.tsx
index 41ec47e..0169516 100644
--- a/components/division/discussionDivisionDetail.tsx
+++ b/components/division/discussionDivisionDetail.tsx
@@ -1,50 +1,65 @@
import Styles from "@/constants/Styles";
import { apiGetDivisionOneFeature } from "@/lib/api";
import { useAuthSession } from "@/providers/AuthProvider";
-import { useLocalSearchParams } from "expo-router";
+import { router, useLocalSearchParams } from "expo-router";
import { useEffect, useState } from "react";
import { Text, View } from "react-native";
import DiscussionItem from "../discussionItem";
type Props = {
- id: string
- title: string
- desc: string
- user: string
- date: string
-}
+ id: string;
+ title: string;
+ desc: string;
+ user: string;
+ date: string;
+};
export default function DiscussionDivisionDetail() {
- const { token, decryptToken } = useAuthSession()
- const { id } = useLocalSearchParams<{ id: string }>()
- const [data, setData] = useState([])
+ const { token, decryptToken } = useAuthSession();
+ const { id } = useLocalSearchParams<{ id: string }>();
+ const [data, setData] = useState([]);
- async function handleLoad() {
- try {
- const hasil = await decryptToken(String(token?.current))
- const response = await apiGetDivisionOneFeature({ user: hasil, id, cat: 'new-discussion' })
- setData(response.data)
- } catch (error) {
- console.error(error)
- }
- }
+ async function handleLoad() {
+ try {
+ const hasil = await decryptToken(String(token?.current));
+ const response = await apiGetDivisionOneFeature({
+ user: hasil,
+ id,
+ cat: "new-discussion",
+ });
+ setData(response.data);
+ } catch (error) {
+ console.error(error);
+ }
+ }
- useEffect(() => {
- handleLoad()
- }, [])
- return (
-
- Diskusi
-
- {
- data.length > 0 ?
- data.map((item, index) => (
-
- ))
- :
- Tidak ada diskusi
- }
-
+ useEffect(() => {
+ handleLoad();
+ }, []);
+ return (
+
+ Diskusi
+
+ {data.length > 0 ? (
+ data.map((item, index) => (
+ {
+ router.push(`/division/${id}/discussion/${item.id}`);
+ }}
+ />
+ ))
+ ) : (
+
+ Tidak ada diskusi
+
+ )}
- )
-}
\ No newline at end of file
+
+ );
+}
diff --git a/components/labelStatus.tsx b/components/labelStatus.tsx
index 51deb32..24d89f5 100644
--- a/components/labelStatus.tsx
+++ b/components/labelStatus.tsx
@@ -4,13 +4,13 @@ import { Text, View } from "react-native";
type Props = {
- category: 'error' | 'success' | 'warning' | 'primary'
+ category: 'error' | 'success' | 'warning' | 'primary' | 'secondary'
text: string
size: 'small' | 'default'
}
export default function LabelStatus({ category, text, size }: Props) {
return (
-
+
{text}
)
diff --git a/constants/ColorsStatus.ts b/constants/ColorsStatus.ts
index 7058573..a8f4a17 100644
--- a/constants/ColorsStatus.ts
+++ b/constants/ColorsStatus.ts
@@ -14,6 +14,9 @@ export const ColorsStatus = {
error: {
backgroundColor: '#DB1514'
},
+ secondary: {
+ backgroundColor: 'gray'
+ },
orange: {
backgroundColor: 'orange'
},
diff --git a/lib/api.ts b/lib/api.ts
index ea1103b..68f7127 100644
--- a/lib/api.ts
+++ b/lib/api.ts
@@ -359,7 +359,7 @@ export const apiGetDivisionReport = async ({ user, cat, date, dateEnd, division,
return response.data;
};
-export const apiGetDivisionOneFeature = async ({ user, cat, id }: { user: string, cat: 'jumlah' | 'today-task' | 'new-file' | 'new-discussion', id: string }) => {
+export const apiGetDivisionOneFeature = async ({ user, cat, id }: { user: string, cat: 'jumlah' | 'today-task' | 'new-file' | 'new-discussion' | 'check-member' | 'check-admin', id: string }) => {
const response = await api.get(`mobile/division/${id}/detail?user=${user}&cat=${cat}`);
return response.data;
};
@@ -393,3 +393,38 @@ export const apiUpdateStatusDivision = async ({ data, id }: { data: { user: stri
const response = await api.post(`/mobile/division/${id}/status`, data)
return response.data;
};
+
+export const apiGetDiscussion = async ({ user, search, division, active }: { user: string, search: string, division: string, active?: string }) => {
+ const response = await api.get(`mobile/discussion?user=${user}&active=${active}&search=${search}&division=${division}`);
+ return response.data;
+};
+
+export const apiGetDiscussionOne = async ({ id, user, cat }: { id: string, user: string, cat: 'data' | 'comment' }) => {
+ const response = await api.get(`mobile/discussion/${id}?user=${user}&cat=${cat}`);
+ return response.data;
+};
+
+export const apiSendDiscussionCommentar = async ({ data, id }: { data: { user: string, comment: string }, id: string }) => {
+ const response = await api.post(`/mobile/discussion/${id}/comment`, data)
+ return response.data;
+};
+
+export const apiEditDiscussion = async ({ data, id }: { data: { user: string, desc: string }, id: string }) => {
+ const response = await api.post(`/mobile/discussion/${id}`, data)
+ return response.data;
+};
+
+export const apiArchiveDiscussion = async (data: { user: string, active: boolean }, id: string) => {
+ const response = await api.put(`mobile/discussion/${id}`, data)
+ return response.data
+};
+
+export const apiOpenCloseDiscussion = async (data: { user: string, status: number }, id: string) => {
+ const response = await api.delete(`mobile/discussion/${id}`, { data })
+ return response.data
+};
+
+export const apiCreateDiscussion = async ({ data }: { data: { user: string, desc: string, idDivision: string } }) => {
+ const response = await api.post(`/mobile/discussion`, data)
+ return response.data;
+};
\ No newline at end of file
diff --git a/lib/discussionUpdate.ts b/lib/discussionUpdate.ts
new file mode 100644
index 0000000..dd8ebd2
--- /dev/null
+++ b/lib/discussionUpdate.ts
@@ -0,0 +1,17 @@
+import { createSlice } from '@reduxjs/toolkit';
+
+const discussionUpdate = createSlice({
+ name: 'discussionUpdate',
+ initialState: {
+ data: false,
+ comment: false,
+ },
+ reducers: {
+ setUpdateDiscussion: (state, action) => {
+ return action.payload;
+ },
+ },
+});
+
+export const { setUpdateDiscussion } = discussionUpdate.actions;
+export default discussionUpdate.reducer;
\ No newline at end of file
diff --git a/lib/store.ts b/lib/store.ts
index aed8bf8..d4c9778 100644
--- a/lib/store.ts
+++ b/lib/store.ts
@@ -2,6 +2,8 @@ import { configureStore } from '@reduxjs/toolkit';
import announcementUpdate from './announcementUpdate';
import bannerReducer from './bannerSlice';
import discussionGeneralDetailUpdate from './discussionGeneralDetail';
+import discussionUpdate from './discussionUpdate';
+import divisionUpdate from './divisionUpdate';
import entitiesReducer from './entitiesSlice';
import filterSlice from './filterSlice';
import groupUpdate from './groupSlice';
@@ -11,7 +13,6 @@ import positionUpdate from './positionSlice';
import projectUpdate from './projectUpdate';
import taskCreate from './taskCreate';
import userReducer from './userSlice';
-import divisionUpdate from './divisionUpdate';
const store = configureStore({
reducer: {
@@ -28,6 +29,7 @@ const store = configureStore({
projectUpdate: projectUpdate,
taskCreate: taskCreate,
divisionUpdate: divisionUpdate,
+ discussionUpdate: discussionUpdate,
}
});