upd: upload link

Deskripsi:
- tampilan section link pada project dan tugas divisi
- tampilan tambah link pada project dan tugas divisi
- integrasi api tambah data link pada project dan tugas divisi
- integrasi api hapus data link pada project dan tugas divisi

No Issues
This commit is contained in:
2025-08-14 12:13:41 +08:00
parent acc464bfc8
commit 7015e92366
10 changed files with 413 additions and 29 deletions

View File

@@ -1,8 +1,8 @@
import Styles from "@/constants/Styles"
import { apiDeleteTask, apiGetDivisionOneFeature } from "@/lib/api"
import { apiAddLinkTask, apiDeleteTask, apiGetDivisionOneFeature } from "@/lib/api"
import { setUpdateTask } from "@/lib/taskUpdate"
import { useAuthSession } from "@/providers/AuthProvider"
import { AntDesign, Ionicons, MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons"
import { AntDesign, Feather, Ionicons, MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons"
import { router } from "expo-router"
import { useEffect, useState } from "react"
import { View } from "react-native"
@@ -11,7 +11,9 @@ import { useDispatch, useSelector } from "react-redux"
import AlertKonfirmasi from "../alertKonfirmasi"
import ButtonMenuHeader from "../buttonMenuHeader"
import DrawerBottom from "../drawerBottom"
import { InputForm } from "../inputForm"
import MenuItemRow from "../menuItemRow"
import ModalFloat from "../modalFloat"
type Props = {
id: string | string[]
@@ -27,6 +29,8 @@ export default function HeaderRightTaskDetail({ id, division, status }: Props) {
const [isAdminDivision, setIsAdminDivision] = useState(false);
const dispatch = useDispatch()
const update = useSelector((state: any) => state.taskUpdate)
const [isAddLink, setAddLink] = useState(false)
const [link, setLink] = useState("")
async function handleCheckMember() {
try {
@@ -72,6 +76,23 @@ export default function HeaderRightTaskDetail({ id, division, status }: Props) {
}
}
async function handleAddLink() {
try {
const hasil = await decryptToken(String(token?.current))
const response = await apiAddLinkTask({ user: hasil, link, idDivision: division }, String(id))
if (response.success) {
dispatch(setUpdateTask({ ...update, link: !update.link }))
Toast.show({ type: 'small', text1: 'Berhasil menambahkan link', })
} else {
Toast.show({ type: 'small', text1: 'Gagal menambahkan link', })
}
} catch (error) {
console.error(error)
} finally {
setAddLink(false)
}
}
return (
<>
{
@@ -102,9 +123,25 @@ export default function HeaderRightTaskDetail({ id, division, status }: Props) {
}}
disabled={status == 3}
/>
{
((entityUser.role != "user" && entityUser.role != "coadmin") || isAdminDivision)
&&
<MenuItemRow
icon={<Feather name="link" color="black" size={25} />}
title="Tambah Link"
onPress={() => {
if (status == 3) return
setVisible(false)
setTimeout(() => {
setAddLink(true)
}, 600)
}}
disabled={status == 3}
/>
</View>
{
((entityUser.role != "user" && entityUser.role != "coadmin") || isAdminDivision)
&&
<View style={[Styles.rowItemsCenter, Styles.mt15]}>
<MenuItemRow
icon={<MaterialIcons name="groups" color="black" size={25} />}
title="Tambah Anggota"
@@ -115,15 +152,6 @@ export default function HeaderRightTaskDetail({ id, division, status }: Props) {
}}
disabled={status == 3}
/>
}
</View>
{
((entityUser.role != "user" && entityUser.role != "coadmin") || isAdminDivision)
&&
<View style={[Styles.rowItemsCenter, Styles.mt15]}>
<MenuItemRow
icon={<MaterialCommunityIcons name="pencil-outline" color="black" size={25} />}
title="Edit"
@@ -163,6 +191,23 @@ export default function HeaderRightTaskDetail({ id, division, status }: Props) {
</View>
}
</DrawerBottom>
<ModalFloat
title="Tambah Link"
isVisible={isAddLink}
setVisible={() => { setAddLink(false) }}
onSubmit={() => { handleAddLink() }}
disableSubmit={link == ""}
>
<View>
<InputForm
type="default"
placeholder="Masukkan link"
value={link}
onChange={(text) => { setLink(text) }}
/>
</View>
</ModalFloat>
</>
)
}

View File

@@ -0,0 +1,122 @@
import Styles from "@/constants/Styles";
import { apiDeleteLinkTask, apiGetTaskOne } from "@/lib/api";
import { urlCompleted } from "@/lib/fun_urlCompleted";
import { setUpdateTask } from "@/lib/taskUpdate";
import { useAuthSession } from "@/providers/AuthProvider";
import { Feather, Ionicons } from "@expo/vector-icons";
import { useLocalSearchParams } from "expo-router";
import { useEffect, useState } from "react";
import { Linking, View } from "react-native";
import Toast from "react-native-toast-message";
import { useDispatch, useSelector } from "react-redux";
import AlertKonfirmasi from "../alertKonfirmasi";
import BorderBottomItem from "../borderBottomItem";
import DrawerBottom from "../drawerBottom";
import MenuItemRow from "../menuItemRow";
import Text from "../Text";
type Props = {
id: string
link: string
}
export default function SectionLinkTask({ refreshing }: { refreshing: boolean }) {
const [isModal, setModal] = useState(false)
const { token, decryptToken } = useAuthSession()
const { detail } = useLocalSearchParams<{ detail: string }>()
const [data, setData] = useState<Props[]>([])
const update = useSelector((state: any) => state.taskUpdate)
const dispatch = useDispatch()
const [selectLink, setSelectLink] = useState<Props | null>(null)
async function handleLoad() {
try {
const hasil = await decryptToken(String(token?.current))
const response = await apiGetTaskOne({ id: detail, user: hasil, cat: 'link' })
setData(response.data)
} catch (error) {
console.error(error)
}
}
useEffect(() => {
handleLoad()
}, [update.link])
useEffect(() => {
if (refreshing)
handleLoad();
}, [refreshing]);
async function handleDelete() {
try {
const hasil = await decryptToken(String(token?.current));
const response = await apiDeleteLinkTask({ user: hasil, idLink: String(selectLink?.id) }, String(detail));
if (response.success) {
Toast.show({ type: 'small', text1: 'Berhasil menghapus link', })
dispatch(setUpdateTask({ ...update, link: !update.link }))
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error) {
console.error(error);
Toast.show({ type: 'small', text1: 'Terjadi kesalahan', })
} finally {
setModal(false)
}
}
return (
<>
{
data.length > 0 &&
<>
<View style={[Styles.mb15]}>
<Text style={[Styles.textDefaultSemiBold, Styles.mv05]}>Link</Text>
<View style={[Styles.wrapPaper]}>
{
data.map((item, index) => {
return (
<BorderBottomItem
key={index}
borderType="all"
icon={<Feather name="link" size={25} color="black" />}
title={item.link}
titleWeight="normal"
onPress={() => { setSelectLink(item); setModal(true) }}
width={65}
/>
)
})
}
</View>
</View>
<DrawerBottom animation="slide" isVisible={isModal} setVisible={setModal} title="Menu">
<View style={Styles.rowItemsCenter}>
<MenuItemRow
icon={<Feather name="external-link" color="black" size={25} />}
title="Buka Link"
onPress={() => {
Linking.openURL(urlCompleted(String(selectLink?.link)))
}}
/>
<MenuItemRow
icon={<Ionicons name="trash" color="black" size={25} />}
title="Hapus"
onPress={() => {
setModal(false)
AlertKonfirmasi({
title: 'Konfirmasi',
desc: 'Apakah Anda yakin ingin menghapus link ini? Link yang dihapus tidak dapat dikembalikan',
onPress: () => { handleDelete() }
})
}}
/>
</View>
</DrawerBottom>
</>
}
</>
)
}