upd: diskusi divisi
Deskripsi: - list diskusi - search diskusi - detail diskusi - kirim komentar - edit diskusi - status diskusi - arsip diskusi - tambah diskusi - role akses user diskusi No Issues
This commit is contained in:
@@ -2,40 +2,92 @@ import ButtonBackHeader from "@/components/buttonBackHeader";
|
|||||||
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
import ButtonSaveHeader from "@/components/buttonSaveHeader";
|
||||||
import { InputForm } from "@/components/inputForm";
|
import { InputForm } from "@/components/inputForm";
|
||||||
import Styles from "@/constants/Styles";
|
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 { SafeAreaView, ScrollView, ToastAndroid, View } from "react-native";
|
||||||
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
|
||||||
export default function DiscussionDivisionEdit() {
|
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 (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
headerLeft: () => (
|
||||||
headerTitle: 'Edit Diskusi',
|
<ButtonBackHeader
|
||||||
headerTitleAlign: 'center',
|
onPress={() => {
|
||||||
headerRight: () => <ButtonSaveHeader category="update" onPress={() => {
|
router.back();
|
||||||
ToastAndroid.show('Berhasil mengubah data', ToastAndroid.SHORT)
|
}}
|
||||||
router.back()
|
/>
|
||||||
}} />
|
),
|
||||||
|
headerTitle: "Edit Diskusi",
|
||||||
|
headerTitleAlign: "center",
|
||||||
|
headerRight: () => (
|
||||||
|
<ButtonSaveHeader
|
||||||
|
disable={data == ""}
|
||||||
|
category="update"
|
||||||
|
onPress={() => {
|
||||||
|
handleUpdate();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
<View style={[Styles.p15]}>
|
<View style={[Styles.p15]}>
|
||||||
<InputForm label="Diskusi" type="default" placeholder="Hal yang didiskusikan" required />
|
<InputForm
|
||||||
{/* <ButtonForm
|
label="Diskusi"
|
||||||
text="SIMPAN"
|
type="default"
|
||||||
onPress={() => {
|
placeholder="Hal yang didiskusikan"
|
||||||
AlertKonfirmasi({
|
required
|
||||||
title: 'Konfirmasi',
|
value={data}
|
||||||
desc: 'Apakah anda yakin ingin mengubah data?',
|
onChange={setData}
|
||||||
onPress: () => {
|
/>
|
||||||
ToastAndroid.show('Berhasil mengubah data', ToastAndroid.SHORT)
|
|
||||||
router.back()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}} /> */}
|
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,152 +1,278 @@
|
|||||||
import BorderBottomItem from "@/components/borderBottomItem";
|
import BorderBottomItem from "@/components/borderBottomItem";
|
||||||
import ButtonBackHeader from "@/components/buttonBackHeader";
|
import ButtonBackHeader from "@/components/buttonBackHeader";
|
||||||
import HeaderRightDiscussionDetail from "@/components/discussion/headerDiscussionDetail";
|
import HeaderRightDiscussionDetail from "@/components/discussion/headerDiscussionDetail";
|
||||||
|
import ImageUser from "@/components/imageNew";
|
||||||
import { InputForm } from "@/components/inputForm";
|
import { InputForm } from "@/components/inputForm";
|
||||||
import LabelStatus from "@/components/labelStatus";
|
import LabelStatus from "@/components/labelStatus";
|
||||||
import Styles from "@/constants/Styles";
|
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 { Ionicons, MaterialIcons } from "@expo/vector-icons";
|
||||||
import { router, Stack, useLocalSearchParams } from "expo-router";
|
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() {
|
export default function DiscussionDetail() {
|
||||||
const { id, detail } = useLocalSearchParams();
|
const { id, detail } = useLocalSearchParams<{ id: string; detail: string }>();
|
||||||
|
const [data, setData] = useState<Props>();
|
||||||
|
const [dataComment, setDataComment] = useState<PropsComment[]>([]);
|
||||||
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
options={{
|
options={{
|
||||||
headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
headerLeft: () => (
|
||||||
headerTitle: 'Diskusi',
|
<ButtonBackHeader
|
||||||
headerTitleAlign: 'center',
|
onPress={() => {
|
||||||
headerRight: () => <HeaderRightDiscussionDetail id={detail} />,
|
router.back();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
headerTitle: "Diskusi",
|
||||||
|
headerTitleAlign: "center",
|
||||||
|
headerRight: () =>
|
||||||
|
(entityUser.role != "user" && entityUser.role != "coadmin") || isAdminDivision || isCreator ?
|
||||||
|
<HeaderRightDiscussionDetail
|
||||||
|
id={detail}
|
||||||
|
status={data?.status}
|
||||||
|
isActive={data?.isActive}
|
||||||
|
/> : (<></>)
|
||||||
|
,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<View style={{ flex: 1 }}>
|
<View style={{ flex: 1 }}>
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
<View style={[Styles.p15, Styles.mb100]}>
|
<View style={[Styles.p15, Styles.mb100]}>
|
||||||
<BorderBottomItem
|
<BorderBottomItem
|
||||||
|
descEllipsize={false}
|
||||||
|
width={60}
|
||||||
borderType="bottom"
|
borderType="bottom"
|
||||||
icon={
|
icon={
|
||||||
<Image
|
<ImageUser
|
||||||
source={require("../../../../../../../assets/images/user.jpeg")}
|
src={`https://wibu-storage.wibudev.com/api/files/${data?.user_img}`}
|
||||||
style={[Styles.userProfileSmall]}
|
size="sm"
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
title="Amalia Dwi"
|
title={data?.username}
|
||||||
subtitle={
|
subtitle={
|
||||||
<LabelStatus category='success' text='BUKA' size="small" />
|
data?.isActive ? (
|
||||||
|
data?.status == 1 ? (
|
||||||
|
<LabelStatus category="success" text="BUKA" size="small" />
|
||||||
|
) : (
|
||||||
|
<LabelStatus category="error" text="TUTUP" size="small" />
|
||||||
|
)
|
||||||
|
) : (
|
||||||
|
<LabelStatus category="secondary" text="ARSIP" size="small" />
|
||||||
|
)
|
||||||
}
|
}
|
||||||
rightTopInfo="3 Jan 2025"
|
rightTopInfo={data?.createdAt}
|
||||||
desc="Bagaimana dampak yg dirasakan akibat efisiensi?"
|
desc={data?.desc}
|
||||||
leftBottomInfo={
|
leftBottomInfo={
|
||||||
<View style={[Styles.rowItemsCenter]}>
|
<View style={[Styles.rowItemsCenter]}>
|
||||||
<Ionicons name="chatbox-ellipses-outline" size={18} color="grey" style={Styles.mr05} />
|
<Ionicons
|
||||||
<Text style={[Styles.textInformation, Styles.cGray, Styles.mb05]}>15 Komentar</Text>
|
name="chatbox-ellipses-outline"
|
||||||
|
size={18}
|
||||||
|
color="grey"
|
||||||
|
style={Styles.mr05}
|
||||||
|
/>
|
||||||
|
<Text
|
||||||
|
style={[Styles.textInformation, Styles.cGray, Styles.mb05]}
|
||||||
|
>
|
||||||
|
{dataComment.length} Komentar
|
||||||
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<View style={[Styles.p15]}>
|
<View style={[Styles.p15]}>
|
||||||
<BorderBottomItem
|
{dataComment.map((item, index) => (
|
||||||
borderType="bottom"
|
<BorderBottomItem
|
||||||
icon={
|
key={index}
|
||||||
<Image
|
width={55}
|
||||||
source={require("../../../../../../../assets/images/user.jpeg")}
|
borderType="bottom"
|
||||||
style={[Styles.userProfileExtraSmall]}
|
icon={
|
||||||
/>
|
<ImageUser
|
||||||
}
|
src={`https://wibu-storage.wibudev.com/api/files/${item.img}`}
|
||||||
title="Amalia Dwi"
|
size="xs"
|
||||||
rightTopInfo="3 Jan 2025"
|
/>
|
||||||
desc="sangat berdampak dari berbagai sisi"
|
}
|
||||||
/>
|
title={item.username}
|
||||||
<BorderBottomItem
|
rightTopInfo={item.createdAt}
|
||||||
borderType="bottom"
|
desc={item.comment}
|
||||||
icon={
|
descEllipsize={false}
|
||||||
<Image
|
/>
|
||||||
source={require("../../../../../../../assets/images/user.jpeg")}
|
))}
|
||||||
style={[Styles.userProfileExtraSmall]}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
title="Amalia Dwi"
|
|
||||||
rightTopInfo="3 Jan 2025"
|
|
||||||
desc="semua menjadi terbatas.."
|
|
||||||
/>
|
|
||||||
<BorderBottomItem
|
|
||||||
borderType="bottom"
|
|
||||||
icon={
|
|
||||||
<Image
|
|
||||||
source={require("../../../../../../../assets/images/user.jpeg")}
|
|
||||||
style={[Styles.userProfileExtraSmall]}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
title="Amalia Dwi"
|
|
||||||
rightTopInfo="3 Jan 2025"
|
|
||||||
desc="semua menjadi terbatas.."
|
|
||||||
/>
|
|
||||||
<BorderBottomItem
|
|
||||||
borderType="bottom"
|
|
||||||
icon={
|
|
||||||
<Image
|
|
||||||
source={require("../../../../../../../assets/images/user.jpeg")}
|
|
||||||
style={[Styles.userProfileExtraSmall]}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
title="Amalia Dwi"
|
|
||||||
rightTopInfo="3 Jan 2025"
|
|
||||||
desc="semua menjadi terbatas.."
|
|
||||||
/>
|
|
||||||
<BorderBottomItem
|
|
||||||
borderType="bottom"
|
|
||||||
icon={
|
|
||||||
<Image
|
|
||||||
source={require("../../../../../../../assets/images/user.jpeg")}
|
|
||||||
style={[Styles.userProfileExtraSmall]}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
title="Amalia Dwi"
|
|
||||||
rightTopInfo="3 Jan 2025"
|
|
||||||
desc="semua menjadi terbatas.."
|
|
||||||
/>
|
|
||||||
<BorderBottomItem
|
|
||||||
borderType="bottom"
|
|
||||||
icon={
|
|
||||||
<Image
|
|
||||||
source={require("../../../../../../../assets/images/user.jpeg")}
|
|
||||||
style={[Styles.userProfileExtraSmall]}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
title="Amalia Dwi"
|
|
||||||
rightTopInfo="3 Jan 2025"
|
|
||||||
desc="semua menjadi terbatas.."
|
|
||||||
/>
|
|
||||||
|
|
||||||
<BorderBottomItem
|
|
||||||
borderType="bottom"
|
|
||||||
icon={
|
|
||||||
<Image
|
|
||||||
source={require("../../../../../../../assets/images/user.jpeg")}
|
|
||||||
style={[Styles.userProfileExtraSmall]}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
title="Amalia Dwi"
|
|
||||||
rightTopInfo="3 Jan 2025"
|
|
||||||
desc="semua menjadi terbatas.."
|
|
||||||
/>
|
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
<View style={[Styles.ph15, Styles.absolute0, { backgroundColor: '#f4f4f4' }]}>
|
<View
|
||||||
|
style={[
|
||||||
|
Styles.ph15,
|
||||||
|
Styles.absolute0,
|
||||||
|
{ backgroundColor: "#f4f4f4" },
|
||||||
|
]}
|
||||||
|
>
|
||||||
<InputForm
|
<InputForm
|
||||||
|
disable={
|
||||||
|
data?.status == 2 ||
|
||||||
|
data?.isActive == false ||
|
||||||
|
((entityUser.role == "user" || entityUser.role == "coadmin") &&
|
||||||
|
!isMemberDivision)
|
||||||
|
}
|
||||||
bg="white"
|
bg="white"
|
||||||
type="default"
|
type="default"
|
||||||
round
|
round
|
||||||
placeholder="Kirim Komentar"
|
placeholder="Kirim Komentar"
|
||||||
|
onChange={setKomentar}
|
||||||
|
value={komentar}
|
||||||
itemRight={
|
itemRight={
|
||||||
<MaterialIcons name="send" size={25} color={'#384288'} />
|
<Pressable
|
||||||
|
onPress={() => {
|
||||||
|
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();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<MaterialIcons
|
||||||
|
name="send"
|
||||||
|
size={25}
|
||||||
|
style={
|
||||||
|
komentar == "" ||
|
||||||
|
loadingSend ||
|
||||||
|
data?.status == 2 ||
|
||||||
|
data?.isActive == false ||
|
||||||
|
((entityUser.role == "user" ||
|
||||||
|
entityUser.role == "coadmin") &&
|
||||||
|
!isMemberDivision)
|
||||||
|
? Styles.cGray
|
||||||
|
: Styles.cDefault
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Pressable>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</>
|
</>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,38 @@ import ButtonBackHeader from "@/components/buttonBackHeader"
|
|||||||
import ButtonSaveHeader from "@/components/buttonSaveHeader"
|
import ButtonSaveHeader from "@/components/buttonSaveHeader"
|
||||||
import { InputForm } from "@/components/inputForm"
|
import { InputForm } from "@/components/inputForm"
|
||||||
import Styles from "@/constants/Styles"
|
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 { SafeAreaView, ScrollView, ToastAndroid, View } from "react-native"
|
||||||
|
import { useDispatch, useSelector } from "react-redux"
|
||||||
|
|
||||||
export default function CreateDiscussionDivision() {
|
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 (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
@@ -13,15 +41,17 @@ export default function CreateDiscussionDivision() {
|
|||||||
headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
headerLeft: () => <ButtonBackHeader onPress={() => { router.back() }} />,
|
||||||
headerTitle: 'Tambah Diskusi',
|
headerTitle: 'Tambah Diskusi',
|
||||||
headerTitleAlign: 'center',
|
headerTitleAlign: 'center',
|
||||||
headerRight: () => <ButtonSaveHeader category="create" onPress={() => {
|
headerRight: () => <ButtonSaveHeader
|
||||||
ToastAndroid.show('Berhasil menambahkan data', ToastAndroid.SHORT)
|
disable={desc == ""}
|
||||||
router.push('./')
|
category="create"
|
||||||
}} />
|
onPress={() => {
|
||||||
|
handleCreate()
|
||||||
|
}} />
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
<View style={[Styles.p15, Styles.mb100]}>
|
<View style={[Styles.p15, Styles.mb100]}>
|
||||||
<InputForm label="Diskusi" type="default" placeholder="Hal yang didiskusikan" required />
|
<InputForm label="Diskusi" type="default" placeholder="Hal yang didiskusikan" required onChange={setDesc} />
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</SafeAreaView>
|
</SafeAreaView>
|
||||||
|
|||||||
@@ -1,15 +1,52 @@
|
|||||||
import BorderBottomItem from "@/components/borderBottomItem";
|
import BorderBottomItem from "@/components/borderBottomItem";
|
||||||
import ButtonTab from "@/components/buttonTab";
|
import ButtonTab from "@/components/buttonTab";
|
||||||
|
import ImageUser from "@/components/imageNew";
|
||||||
import InputSearch from "@/components/inputSearch";
|
import InputSearch from "@/components/inputSearch";
|
||||||
import LabelStatus from "@/components/labelStatus";
|
import LabelStatus from "@/components/labelStatus";
|
||||||
import Styles from "@/constants/Styles";
|
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 { AntDesign, Feather, Ionicons } from "@expo/vector-icons";
|
||||||
import { router, useLocalSearchParams } from "expo-router";
|
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() {
|
export default function DiscussionDivision() {
|
||||||
const { active } = useLocalSearchParams<{ active?: string }>()
|
const { id, active } = useLocalSearchParams<{ id: string, active?: string }>()
|
||||||
|
const [data, setData] = useState<Props[]>([])
|
||||||
|
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 (
|
return (
|
||||||
<SafeAreaView>
|
<SafeAreaView>
|
||||||
@@ -19,121 +56,49 @@ export default function DiscussionDivision() {
|
|||||||
<ButtonTab
|
<ButtonTab
|
||||||
active={active == "false" ? "false" : "true"}
|
active={active == "false" ? "false" : "true"}
|
||||||
value="true"
|
value="true"
|
||||||
onPress={() => { router.push('./discussion?active=true') }}
|
onPress={() => { router.replace('./discussion?active=true') }}
|
||||||
label="Aktif"
|
label="Aktif"
|
||||||
icon={<Feather name="check-circle" color={active == "false" ? 'black' : 'white'} size={20} />}
|
icon={<Feather name="check-circle" color={active == "false" ? 'black' : 'white'} size={20} />}
|
||||||
n={2} />
|
n={2} />
|
||||||
<ButtonTab
|
<ButtonTab
|
||||||
active={active == "false" ? "false" : "true"}
|
active={active == "false" ? "false" : "true"}
|
||||||
value="false"
|
value="false"
|
||||||
onPress={() => { router.push('./discussion?active=false') }}
|
onPress={() => { router.replace('./discussion?active=false') }}
|
||||||
label="Arsip"
|
label="Arsip"
|
||||||
icon={<AntDesign name="closecircleo" color={active == "true" ? 'black' : 'white'} size={20} />}
|
icon={<AntDesign name="closecircleo" color={active == "true" ? 'black' : 'white'} size={20} />}
|
||||||
n={2} />
|
n={2} />
|
||||||
</View>
|
</View>
|
||||||
<InputSearch />
|
<InputSearch onChange={setSearch} />
|
||||||
<View>
|
<View>
|
||||||
<BorderBottomItem
|
{data.length > 0 ?
|
||||||
onPress={() => { router.push('./discussion/1') }}
|
data.map((item, index) => (
|
||||||
borderType="bottom"
|
<BorderBottomItem
|
||||||
icon={
|
key={index}
|
||||||
<Image source={require("../../../../../../assets/images/user.jpeg")} style={[Styles.userProfileSmall]} />
|
width={55}
|
||||||
}
|
onPress={() => { router.push(`./discussion/${item.id}`) }}
|
||||||
title="Amalia Dwi"
|
borderType="bottom"
|
||||||
subtitle={
|
icon={
|
||||||
<LabelStatus category='success' text='BUKA' size="small" />
|
<ImageUser src={`https://wibu-storage.wibudev.com/api/files/${item.img}`} size="sm" />
|
||||||
}
|
}
|
||||||
rightTopInfo="3 Jan 2025"
|
title={item.user_name}
|
||||||
desc="Bagaimana dampak yg dirasakan akibat efisiensi?"
|
subtitle={
|
||||||
leftBottomInfo={
|
active == "true" ? item.status == 1 ? <LabelStatus category='success' text='BUKA' size="small" /> : <LabelStatus category='error' text='TUTUP' size="small" /> : <></>
|
||||||
<View style={[Styles.rowItemsCenter]}>
|
}
|
||||||
<Ionicons name="chatbox-ellipses-outline" size={18} color="grey" style={Styles.mr05} />
|
rightTopInfo={item.createdAt}
|
||||||
<Text style={[Styles.textInformation, Styles.cGray, Styles.mb05]}>Diskusikan</Text>
|
desc={item.desc}
|
||||||
</View>
|
leftBottomInfo={
|
||||||
}
|
<View style={[Styles.rowItemsCenter]}>
|
||||||
rightBottomInfo='15 Komentar'
|
<Ionicons name="chatbox-ellipses-outline" size={18} color="grey" style={Styles.mr05} />
|
||||||
/>
|
<Text style={[Styles.textInformation, Styles.cGray, Styles.mb05]}>Diskusikan</Text>
|
||||||
<BorderBottomItem
|
</View>
|
||||||
onPress={() => { router.push('./discussion/1') }}
|
}
|
||||||
borderType="bottom"
|
rightBottomInfo={item.total_komentar + ' Komentar'}
|
||||||
icon={
|
/>
|
||||||
<Image source={require("../../../../../../assets/images/user.jpeg")} style={[Styles.userProfileSmall]} />
|
))
|
||||||
}
|
:
|
||||||
title="Amalia Dwi"
|
(
|
||||||
subtitle={
|
<Text style={[Styles.textDefault, Styles.cGray, Styles.mv10, { textAlign: "center" }]}>Tidak ada diskusi</Text>
|
||||||
<LabelStatus category='success' text='BUKA' size="small" />
|
)}
|
||||||
}
|
|
||||||
rightTopInfo="3 Jan 2025"
|
|
||||||
desc="Bagaimana dampak yg dirasakan akibat efisiensi?"
|
|
||||||
leftBottomInfo={
|
|
||||||
<View style={[Styles.rowItemsCenter]}>
|
|
||||||
<Ionicons name="chatbox-ellipses-outline" size={18} color="grey" style={Styles.mr05} />
|
|
||||||
<Text style={[Styles.textInformation, Styles.cGray, Styles.mb05]}>Diskusikan</Text>
|
|
||||||
</View>
|
|
||||||
}
|
|
||||||
rightBottomInfo='15 Komentar'
|
|
||||||
/>
|
|
||||||
<BorderBottomItem
|
|
||||||
onPress={() => { router.push('./discussion/1') }}
|
|
||||||
borderType="bottom"
|
|
||||||
icon={
|
|
||||||
<Image source={require("../../../../../../assets/images/user.jpeg")} style={[Styles.userProfileSmall]} />
|
|
||||||
}
|
|
||||||
title="Amalia Dwi"
|
|
||||||
subtitle={
|
|
||||||
<LabelStatus category='success' text='BUKA' size="small" />
|
|
||||||
}
|
|
||||||
rightTopInfo="3 Jan 2025"
|
|
||||||
desc="Bagaimana dampak yg dirasakan akibat efisiensi?"
|
|
||||||
leftBottomInfo={
|
|
||||||
<View style={[Styles.rowItemsCenter]}>
|
|
||||||
<Ionicons name="chatbox-ellipses-outline" size={18} color="grey" style={Styles.mr05} />
|
|
||||||
<Text style={[Styles.textInformation, Styles.cGray, Styles.mb05]}>Diskusikan</Text>
|
|
||||||
</View>
|
|
||||||
}
|
|
||||||
rightBottomInfo='15 Komentar'
|
|
||||||
/>
|
|
||||||
<BorderBottomItem
|
|
||||||
onPress={() => { router.push('./discussion/1') }}
|
|
||||||
borderType="bottom"
|
|
||||||
icon={
|
|
||||||
<Image source={require("../../../../../../assets/images/user.jpeg")} style={[Styles.userProfileSmall]} />
|
|
||||||
}
|
|
||||||
title="Amalia Dwi"
|
|
||||||
subtitle={
|
|
||||||
<LabelStatus category='success' text='BUKA' size="small" />
|
|
||||||
}
|
|
||||||
rightTopInfo="3 Jan 2025"
|
|
||||||
desc="Bagaimana dampak yg dirasakan akibat efisiensi?"
|
|
||||||
leftBottomInfo={
|
|
||||||
<View style={[Styles.rowItemsCenter]}>
|
|
||||||
<Ionicons name="chatbox-ellipses-outline" size={18} color="grey" style={Styles.mr05} />
|
|
||||||
<Text style={[Styles.textInformation, Styles.cGray, Styles.mb05]}>Diskusikan</Text>
|
|
||||||
</View>
|
|
||||||
}
|
|
||||||
rightBottomInfo='15 Komentar'
|
|
||||||
/>
|
|
||||||
<BorderBottomItem
|
|
||||||
onPress={() => { router.push('./discussion/1') }}
|
|
||||||
borderType="bottom"
|
|
||||||
icon={
|
|
||||||
<Image source={require("../../../../../../assets/images/user.jpeg")} style={[Styles.userProfileSmall]} />
|
|
||||||
}
|
|
||||||
title="Amalia Dwi"
|
|
||||||
subtitle={
|
|
||||||
<LabelStatus category='success' text='BUKA' size="small" />
|
|
||||||
}
|
|
||||||
rightTopInfo="3 Jan 2025"
|
|
||||||
desc="Bagaimana dampak yg dirasakan akibat efisiensi?"
|
|
||||||
leftBottomInfo={
|
|
||||||
<View style={[Styles.rowItemsCenter]}>
|
|
||||||
<Ionicons name="chatbox-ellipses-outline" size={18} color="grey" style={Styles.mr05} />
|
|
||||||
<Text style={[Styles.textInformation, Styles.cGray, Styles.mb05]}>Diskusikan</Text>
|
|
||||||
</View>
|
|
||||||
}
|
|
||||||
rightBottomInfo='15 Komentar'
|
|
||||||
/>
|
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|||||||
@@ -16,9 +16,10 @@ type Props = {
|
|||||||
titleWeight?: 'normal' | 'bold'
|
titleWeight?: 'normal' | 'bold'
|
||||||
bgColor?: 'white' | 'transparent'
|
bgColor?: 'white' | 'transparent'
|
||||||
width?: number
|
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 lebarDim = Dimensions.get("window").width;
|
||||||
const lebar = width ? lebarDim * width / 100 : 'auto';
|
const lebar = width ? lebarDim * width / 100 : 'auto';
|
||||||
|
|
||||||
@@ -44,7 +45,7 @@ export default function BorderBottomItem({ title, subtitle, icon, desc, onPress,
|
|||||||
</View>
|
</View>
|
||||||
|
|
||||||
</View>
|
</View>
|
||||||
{desc && <Text style={[Styles.textDefault, Styles.mt05, { textAlign: 'justify' }]} numberOfLines={2} ellipsizeMode='tail'>{desc}</Text>}
|
{desc && <Text style={[Styles.textDefault, Styles.mt05, { textAlign: 'justify' }]} numberOfLines={descEllipsize == false ? 0 : 2} ellipsizeMode='tail'>{desc}</Text>}
|
||||||
{
|
{
|
||||||
(leftBottomInfo || rightBottomInfo) &&
|
(leftBottomInfo || rightBottomInfo) &&
|
||||||
(
|
(
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
import Styles from "@/constants/Styles"
|
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 { MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons"
|
||||||
import { router } from "expo-router"
|
import { router } from "expo-router"
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { ToastAndroid, View } from "react-native"
|
import { ToastAndroid, View } from "react-native"
|
||||||
|
import { useDispatch, useSelector } from "react-redux"
|
||||||
import AlertKonfirmasi from "../alertKonfirmasi"
|
import AlertKonfirmasi from "../alertKonfirmasi"
|
||||||
import ButtonMenuHeader from "../buttonMenuHeader"
|
import ButtonMenuHeader from "../buttonMenuHeader"
|
||||||
import DrawerBottom from "../drawerBottom"
|
import DrawerBottom from "../drawerBottom"
|
||||||
@@ -10,48 +14,94 @@ import MenuItemRow from "../menuItemRow"
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
id: string | string[]
|
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 [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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<ButtonMenuHeader onPress={() => { setVisible(true) }} />
|
<ButtonMenuHeader onPress={() => { setVisible(true) }} />
|
||||||
<DrawerBottom animation="slide" isVisible={isVisible} setVisible={setVisible} title="Menu">
|
<DrawerBottom animation="slide" isVisible={isVisible} setVisible={setVisible} title="Menu">
|
||||||
<View style={Styles.rowItemsCenter}>
|
<View style={Styles.rowItemsCenter}>
|
||||||
<MenuItemRow
|
{
|
||||||
icon={<MaterialCommunityIcons name="pencil-outline" color="black" size={25} />}
|
isActive &&
|
||||||
title="Edit"
|
<>
|
||||||
onPress={() => {
|
<MenuItemRow
|
||||||
setVisible(false)
|
icon={<MaterialCommunityIcons name="pencil-outline" color="black" size={25} />}
|
||||||
router.push(`./${id}/edit`)
|
title="Edit"
|
||||||
}}
|
onPress={() => {
|
||||||
/>
|
|
||||||
<MenuItemRow
|
|
||||||
icon={<MaterialIcons name="close" color="black" size={25} />}
|
|
||||||
title="Tutup Diskusi"
|
|
||||||
onPress={() => {
|
|
||||||
AlertKonfirmasi({
|
|
||||||
title: 'Konfirmasi',
|
|
||||||
desc: 'Apakah anda yakin ingin menutup diskusi?',
|
|
||||||
onPress: () => {
|
|
||||||
setVisible(false)
|
setVisible(false)
|
||||||
ToastAndroid.show('Berhasil mengubah data', ToastAndroid.SHORT)
|
router.push(`./${id}/edit`)
|
||||||
}
|
}}
|
||||||
})
|
/>
|
||||||
}}
|
<MenuItemRow
|
||||||
/>
|
icon={<MaterialIcons name={status == 1 ? 'close' : 'check'} color="black" size={25} />}
|
||||||
|
title={status == 1 ? 'Tutup Diskusi' : 'Buka Diskusi'}
|
||||||
|
onPress={() => {
|
||||||
|
AlertKonfirmasi({
|
||||||
|
title: 'Konfirmasi',
|
||||||
|
desc: `Apakah anda yakin ingin ${status == 1 ? 'menutup' : 'membuka'} diskusi?`,
|
||||||
|
onPress: () => {
|
||||||
|
handleOpenClose()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
}
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
icon={<MaterialCommunityIcons name="archive-outline" color="black" size={25} />}
|
icon={<MaterialCommunityIcons name="archive-outline" color="black" size={25} />}
|
||||||
title="Arsipkan"
|
title={isActive ? 'Arsipkan' : 'Aktifkan Diskusi'}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
AlertKonfirmasi({
|
AlertKonfirmasi({
|
||||||
title: 'Konfirmasi',
|
title: 'Konfirmasi',
|
||||||
desc: 'Apakah anda yakin ingin mengarsipkan diskusi?',
|
desc: isActive ? 'Apakah anda yakin ingin mengarsipkan diskusi?' : 'Apakah anda yakin ingin mengaktifkan diskusi?',
|
||||||
onPress: () => {
|
onPress: () => {
|
||||||
setVisible(false)
|
handleArchive()
|
||||||
ToastAndroid.show('Berhasil mengubah data', ToastAndroid.SHORT)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -1,18 +1,47 @@
|
|||||||
import Styles from "@/constants/Styles"
|
import Styles from "@/constants/Styles"
|
||||||
|
import { apiGetDivisionOneFeature } from "@/lib/api"
|
||||||
|
import { useAuthSession } from "@/providers/AuthProvider"
|
||||||
import { AntDesign } from "@expo/vector-icons"
|
import { AntDesign } from "@expo/vector-icons"
|
||||||
import { router } from "expo-router"
|
import { router, useLocalSearchParams } from "expo-router"
|
||||||
import { useState } from "react"
|
import { useEffect, useState } from "react"
|
||||||
import { View } from "react-native"
|
import { View } from "react-native"
|
||||||
|
import { useSelector } from "react-redux"
|
||||||
import ButtonMenuHeader from "../buttonMenuHeader"
|
import ButtonMenuHeader from "../buttonMenuHeader"
|
||||||
import DrawerBottom from "../drawerBottom"
|
import DrawerBottom from "../drawerBottom"
|
||||||
import MenuItemRow from "../menuItemRow"
|
import MenuItemRow from "../menuItemRow"
|
||||||
|
|
||||||
export default function HeaderRightDiscussionList() {
|
export default function HeaderRightDiscussionList() {
|
||||||
const [isVisible, setVisible] = useState(false)
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<ButtonMenuHeader onPress={() => { setVisible(true) }} />
|
{
|
||||||
|
(entityUser.role == "user" || entityUser.role == "coadmin") && !isAdminDivision
|
||||||
|
? <></> :
|
||||||
|
<ButtonMenuHeader onPress={() => { setVisible(true) }} />
|
||||||
|
}
|
||||||
<DrawerBottom animation="slide" isVisible={isVisible} setVisible={setVisible} title="Menu">
|
<DrawerBottom animation="slide" isVisible={isVisible} setVisible={setVisible} title="Menu">
|
||||||
<View style={Styles.rowItemsCenter}>
|
<View style={Styles.rowItemsCenter}>
|
||||||
<MenuItemRow
|
<MenuItemRow
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { Ionicons, Feather } from "@expo/vector-icons";
|
import { Feather, Ionicons } from "@expo/vector-icons";
|
||||||
import { Text, View } from "react-native";
|
import { Pressable, Text, View } from "react-native";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
title: string
|
title: string
|
||||||
user: string
|
user: string
|
||||||
date: string
|
date: string
|
||||||
|
onPress: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function DiscussionItem({ title, user, date }: Props) {
|
export default function DiscussionItem({ title, user, date, onPress }: Props) {
|
||||||
return (
|
return (
|
||||||
<View style={[Styles.wrapItemDiscussion]}>
|
<Pressable style={[Styles.wrapItemDiscussion]} onPress={onPress}>
|
||||||
<View style={[Styles.rowItemsCenter, Styles.mb10]}>
|
<View style={[Styles.rowItemsCenter, Styles.mb10]}>
|
||||||
<Ionicons name="chatbox-ellipses-outline" size={22} color="black" style={Styles.mr10} />
|
<Ionicons name="chatbox-ellipses-outline" size={22} color="black" style={Styles.mr10} />
|
||||||
<Text style={{ fontWeight: 'bold' }} numberOfLines={1} ellipsizeMode="tail">{title}</Text>
|
<Text style={{ fontWeight: 'bold' }} numberOfLines={1} ellipsizeMode="tail">{title}</Text>
|
||||||
@@ -25,6 +26,6 @@ export default function DiscussionItem({ title, user, date }: Props) {
|
|||||||
<Text style={[Styles.textInformation]}>{date}</Text>
|
<Text style={[Styles.textInformation]}>{date}</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</Pressable>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1,50 +1,65 @@
|
|||||||
import Styles from "@/constants/Styles";
|
import Styles from "@/constants/Styles";
|
||||||
import { apiGetDivisionOneFeature } from "@/lib/api";
|
import { apiGetDivisionOneFeature } from "@/lib/api";
|
||||||
import { useAuthSession } from "@/providers/AuthProvider";
|
import { useAuthSession } from "@/providers/AuthProvider";
|
||||||
import { useLocalSearchParams } from "expo-router";
|
import { router, useLocalSearchParams } from "expo-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Text, View } from "react-native";
|
import { Text, View } from "react-native";
|
||||||
import DiscussionItem from "../discussionItem";
|
import DiscussionItem from "../discussionItem";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
id: string
|
id: string;
|
||||||
title: string
|
title: string;
|
||||||
desc: string
|
desc: string;
|
||||||
user: string
|
user: string;
|
||||||
date: string
|
date: string;
|
||||||
}
|
};
|
||||||
|
|
||||||
export default function DiscussionDivisionDetail() {
|
export default function DiscussionDivisionDetail() {
|
||||||
const { token, decryptToken } = useAuthSession()
|
const { token, decryptToken } = useAuthSession();
|
||||||
const { id } = useLocalSearchParams<{ id: string }>()
|
const { id } = useLocalSearchParams<{ id: string }>();
|
||||||
const [data, setData] = useState<Props[]>([])
|
const [data, setData] = useState<Props[]>([]);
|
||||||
|
|
||||||
async function handleLoad() {
|
async function handleLoad() {
|
||||||
try {
|
try {
|
||||||
const hasil = await decryptToken(String(token?.current))
|
const hasil = await decryptToken(String(token?.current));
|
||||||
const response = await apiGetDivisionOneFeature({ user: hasil, id, cat: 'new-discussion' })
|
const response = await apiGetDivisionOneFeature({
|
||||||
setData(response.data)
|
user: hasil,
|
||||||
} catch (error) {
|
id,
|
||||||
console.error(error)
|
cat: "new-discussion",
|
||||||
}
|
});
|
||||||
}
|
setData(response.data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
handleLoad()
|
handleLoad();
|
||||||
}, [])
|
}, []);
|
||||||
return (
|
return (
|
||||||
<View style={[Styles.mb15]}>
|
<View style={[Styles.mb15]}>
|
||||||
<Text style={[Styles.textDefaultSemiBold, Styles.mv10]}>Diskusi</Text>
|
<Text style={[Styles.textDefaultSemiBold, Styles.mv10]}>Diskusi</Text>
|
||||||
<View style={[Styles.wrapPaper]}>
|
<View style={[Styles.wrapPaper]}>
|
||||||
{
|
{data.length > 0 ? (
|
||||||
data.length > 0 ?
|
data.map((item, index) => (
|
||||||
data.map((item, index) => (
|
<DiscussionItem
|
||||||
<DiscussionItem key={index} title={item.desc} user={item.user} date={item.date} />
|
key={index}
|
||||||
))
|
title={item.desc}
|
||||||
:
|
user={item.user}
|
||||||
<Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada diskusi</Text>
|
date={item.date}
|
||||||
}
|
onPress={() => {
|
||||||
</View>
|
router.push(`/division/${id}/discussion/${item.id}`);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<Text
|
||||||
|
style={[Styles.textDefault, Styles.cGray, { textAlign: "center" }]}
|
||||||
|
>
|
||||||
|
Tidak ada diskusi
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
</View>
|
</View>
|
||||||
)
|
</View>
|
||||||
}
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,13 +4,13 @@ import { Text, View } from "react-native";
|
|||||||
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
category: 'error' | 'success' | 'warning' | 'primary'
|
category: 'error' | 'success' | 'warning' | 'primary' | 'secondary'
|
||||||
text: string
|
text: string
|
||||||
size: 'small' | 'default'
|
size: 'small' | 'default'
|
||||||
}
|
}
|
||||||
export default function LabelStatus({ category, text, size }: Props) {
|
export default function LabelStatus({ category, text, size }: Props) {
|
||||||
return (
|
return (
|
||||||
<View style={[size == "small" ? Styles.labelStatusSmall : Styles.labelStatus, ColorsStatus[category]]}>
|
<View style={[size == "small" ? Styles.labelStatusSmall : Styles.labelStatus, ColorsStatus[category], Styles.round10]}>
|
||||||
<Text style={[size == "small" ? Styles.textSmallSemiBold : Styles.textMediumSemiBold, Styles.cWhite, { textAlign: 'center' }]}>{text}</Text>
|
<Text style={[size == "small" ? Styles.textSmallSemiBold : Styles.textMediumSemiBold, Styles.cWhite, { textAlign: 'center' }]}>{text}</Text>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ export const ColorsStatus = {
|
|||||||
error: {
|
error: {
|
||||||
backgroundColor: '#DB1514'
|
backgroundColor: '#DB1514'
|
||||||
},
|
},
|
||||||
|
secondary: {
|
||||||
|
backgroundColor: 'gray'
|
||||||
|
},
|
||||||
orange: {
|
orange: {
|
||||||
backgroundColor: 'orange'
|
backgroundColor: 'orange'
|
||||||
},
|
},
|
||||||
|
|||||||
37
lib/api.ts
37
lib/api.ts
@@ -359,7 +359,7 @@ export const apiGetDivisionReport = async ({ user, cat, date, dateEnd, division,
|
|||||||
return response.data;
|
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}`);
|
const response = await api.get(`mobile/division/${id}/detail?user=${user}&cat=${cat}`);
|
||||||
return response.data;
|
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)
|
const response = await api.post(`/mobile/division/${id}/status`, data)
|
||||||
return response.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;
|
||||||
|
};
|
||||||
17
lib/discussionUpdate.ts
Normal file
17
lib/discussionUpdate.ts
Normal file
@@ -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;
|
||||||
@@ -2,6 +2,8 @@ import { configureStore } from '@reduxjs/toolkit';
|
|||||||
import announcementUpdate from './announcementUpdate';
|
import announcementUpdate from './announcementUpdate';
|
||||||
import bannerReducer from './bannerSlice';
|
import bannerReducer from './bannerSlice';
|
||||||
import discussionGeneralDetailUpdate from './discussionGeneralDetail';
|
import discussionGeneralDetailUpdate from './discussionGeneralDetail';
|
||||||
|
import discussionUpdate from './discussionUpdate';
|
||||||
|
import divisionUpdate from './divisionUpdate';
|
||||||
import entitiesReducer from './entitiesSlice';
|
import entitiesReducer from './entitiesSlice';
|
||||||
import filterSlice from './filterSlice';
|
import filterSlice from './filterSlice';
|
||||||
import groupUpdate from './groupSlice';
|
import groupUpdate from './groupSlice';
|
||||||
@@ -11,7 +13,6 @@ import positionUpdate from './positionSlice';
|
|||||||
import projectUpdate from './projectUpdate';
|
import projectUpdate from './projectUpdate';
|
||||||
import taskCreate from './taskCreate';
|
import taskCreate from './taskCreate';
|
||||||
import userReducer from './userSlice';
|
import userReducer from './userSlice';
|
||||||
import divisionUpdate from './divisionUpdate';
|
|
||||||
|
|
||||||
const store = configureStore({
|
const store = configureStore({
|
||||||
reducer: {
|
reducer: {
|
||||||
@@ -28,6 +29,7 @@ const store = configureStore({
|
|||||||
projectUpdate: projectUpdate,
|
projectUpdate: projectUpdate,
|
||||||
taskCreate: taskCreate,
|
taskCreate: taskCreate,
|
||||||
divisionUpdate: divisionUpdate,
|
divisionUpdate: divisionUpdate,
|
||||||
|
discussionUpdate: discussionUpdate,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user