Files
mobile-darmasaba/components/project/sectionLink.tsx
amaliadwiy b61cd51628 feat: redesign section progress, report, link, file, dan cancel pada project & division/task
- SectionProgress: progress bar animated, badge persentase, label status, task count
- SectionReport: header ikon, left accent border, TextExpandable dengan label Indonesia
- SectionLink: tap langsung buka URL, ikon per domain, long press untuk hapus
- SectionFile: icon container konsisten 30×30 di semua section
- SectionCancel: card subtle dengan warna error, konsisten dengan visual language baru
- TextExpandable: fix bug show/hide tidak muncul setelah content diupdate
- Tambah 14 style class baru di Styles.ts untuk menggantikan inline style
- Terapkan semua perubahan ke fitur division/task
- Fix menu "Edit Tugas" di sectionTanggalTugasTask yang terpotong karena overflow

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 16:22:52 +08:00

135 lines
4.8 KiB
TypeScript

import Styles from "@/constants/Styles";
import { apiDeleteLinkProject, apiGetProjectOne } from "@/lib/api";
import { setUpdateProject } from "@/lib/projectUpdate";
import { useAuthSession } from "@/providers/AuthProvider";
import { useTheme } from "@/providers/ThemeProvider";
import { Ionicons } from "@expo/vector-icons";
import { useLocalSearchParams } from "expo-router";
import { useEffect, useState } from "react";
import { View } from "react-native";
import Toast from "react-native-toast-message";
import { useDispatch, useSelector } from "react-redux";
import ModalConfirmation from "../ModalConfirmation";
import DrawerBottom from "../drawerBottom";
import MenuItemRow from "../menuItemRow";
import Text from "../Text";
import ItemSectionLink from "./itemSectionLink";
type Props = {
id: string
link: string
}
export default function SectionLink({ status, member, refreshing }: { status: number | undefined, member: boolean, refreshing?: boolean }) {
const { colors } = useTheme();
const entityUser = useSelector((state: any) => state.user)
const [isModal, setModal] = useState(false)
const { token, decryptToken } = useAuthSession();
const { id } = useLocalSearchParams<{ id: string }>();
const [data, setData] = useState<Props[]>([]);
const update = useSelector((state: any) => state.projectUpdate)
const dispatch = useDispatch()
const [selectLink, setSelectLink] = useState<Props | null>(null)
const [showDeleteModal, setShowDeleteModal] = useState(false)
async function handleLoad() {
try {
const hasil = await decryptToken(String(token?.current));
const response = await apiGetProjectOne({
user: hasil,
cat: "link",
id: id,
});
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 apiDeleteLinkProject({ user: hasil, idLink: String(selectLink?.id) }, String(id));
if (response.success) {
Toast.show({ type: 'small', text1: 'Berhasil menghapus link', })
dispatch(setUpdateProject({ ...update, link: !update.link }))
} else {
Toast.show({ type: 'small', text1: response.message, })
}
} catch (error : any ) {
console.error(error);
const message = error?.response?.data?.message || "Gagal menghapus link"
Toast.show({ type: 'small', text1: message })
} finally {
setModal(false)
}
}
return (
<>
{
data.length > 0 &&
<>
<View style={[Styles.mb15]}>
<Text style={[Styles.textDefaultSemiBold, Styles.mv05]}>Link</Text>
<View>
{
data.map((item, index) => {
const canDelete = member || (entityUser.role !== "user" && entityUser.role !== "coadmin")
return (
<ItemSectionLink
key={index}
link={item.link}
canDelete={canDelete && status !== 3}
onLongPress={() => { setSelectLink(item); setModal(true) }}
/>
)
})
}
</View>
</View>
<DrawerBottom animation="slide" isVisible={isModal} setVisible={setModal} title="Menu">
<View style={Styles.rowItemsCenter}>
<MenuItemRow
icon={<Ionicons name="trash-outline" color={colors.text} size={25} />}
title="Hapus Link"
onPress={() => {
setModal(false)
setTimeout(() => setShowDeleteModal(true), 600)
}}
/>
</View>
</DrawerBottom>
<ModalConfirmation
visible={showDeleteModal}
title="Konfirmasi"
message="Apakah Anda yakin ingin menghapus link ini? Link yang dihapus tidak dapat dikembalikan"
onConfirm={() => {
setShowDeleteModal(false)
handleDelete()
}}
onCancel={() => setShowDeleteModal(false)}
confirmText="Hapus"
cancelText="Batal"
/>
</>
}
</>
)
}