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>
This commit is contained in:
@@ -10,19 +10,17 @@ import { startActivityAsync } from 'expo-intent-launcher';
|
||||
import { useLocalSearchParams } from "expo-router";
|
||||
import * as Sharing from 'expo-sharing';
|
||||
import { useEffect, useState } from "react";
|
||||
import { Alert, Platform, View } from "react-native";
|
||||
import { Alert, Platform, Pressable, View } from "react-native";
|
||||
import * as mime from 'react-native-mime-types';
|
||||
import Toast from "react-native-toast-message";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import ModalConfirmation from "../ModalConfirmation";
|
||||
import BorderBottomItem from "../borderBottomItem";
|
||||
import DrawerBottom from "../drawerBottom";
|
||||
import MenuItemRow from "../menuItemRow";
|
||||
import ModalConfirmation from "../ModalConfirmation";
|
||||
import ModalLoading from "../modalLoading";
|
||||
import Skeleton from "../skeleton";
|
||||
import Text from "../Text";
|
||||
|
||||
|
||||
type Props = {
|
||||
id: string
|
||||
name: string
|
||||
@@ -30,6 +28,28 @@ type Props = {
|
||||
idStorage: string
|
||||
}
|
||||
|
||||
function getFileIcon(extension: string): keyof typeof MaterialCommunityIcons.glyphMap {
|
||||
const ext = extension.toLowerCase()
|
||||
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'heic', 'heif'].includes(ext)) return 'image-outline'
|
||||
if (ext === 'pdf') return 'file-pdf-box'
|
||||
if (['mp4', 'mov', 'avi', 'mkv'].includes(ext)) return 'video-outline'
|
||||
if (['doc', 'docx'].includes(ext)) return 'file-word-outline'
|
||||
if (['xls', 'xlsx'].includes(ext)) return 'file-excel-outline'
|
||||
if (['zip', 'rar', '7z'].includes(ext)) return 'zip-box-outline'
|
||||
return 'file-outline'
|
||||
}
|
||||
|
||||
function getFileColor(extension: string): string {
|
||||
const ext = extension.toLowerCase()
|
||||
if (['jpg', 'jpeg', 'png', 'gif', 'webp', 'heic', 'heif'].includes(ext)) return '#339AF0'
|
||||
if (ext === 'pdf') return '#F03E3E'
|
||||
if (['mp4', 'mov', 'avi', 'mkv'].includes(ext)) return '#AE3EC9'
|
||||
if (['doc', 'docx'].includes(ext)) return '#1C7ED6'
|
||||
if (['xls', 'xlsx'].includes(ext)) return '#2F9E44'
|
||||
if (['zip', 'rar', '7z'].includes(ext)) return '#E8590C'
|
||||
return '#868E96'
|
||||
}
|
||||
|
||||
export default function SectionFile({ status, member, refreshing }: { status: number | undefined, member: boolean, refreshing?: boolean }) {
|
||||
const { colors } = useTheme();
|
||||
const entityUser = useSelector((state: any) => state.user)
|
||||
@@ -40,7 +60,7 @@ export default function SectionFile({ status, member, refreshing }: { status: nu
|
||||
const update = useSelector((state: any) => state.projectUpdate)
|
||||
const dispatch = useDispatch()
|
||||
const [loading, setLoading] = useState(true)
|
||||
const arrSkeleton = Array.from({ length: 3 })
|
||||
const arrSkeleton = Array.from({ length: 4 })
|
||||
const [selectFile, setSelectFile] = useState<Props | null>(null)
|
||||
const [showDeleteModal, setShowDeleteModal] = useState(false)
|
||||
const [loadingOpen, setLoadingOpen] = useState(false)
|
||||
@@ -49,11 +69,7 @@ export default function SectionFile({ status, member, refreshing }: { status: nu
|
||||
try {
|
||||
setLoading(loading)
|
||||
const hasil = await decryptToken(String(token?.current));
|
||||
const response = await apiGetProjectOne({
|
||||
user: hasil,
|
||||
cat: "file",
|
||||
id: id,
|
||||
});
|
||||
const response = await apiGetProjectOne({ user: hasil, cat: "file", id });
|
||||
setData(response.data);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -62,110 +78,90 @@ export default function SectionFile({ status, member, refreshing }: { status: nu
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
handleLoad(false);
|
||||
}, [update.file]);
|
||||
|
||||
useEffect(() => {
|
||||
if (refreshing)
|
||||
handleLoad(false);
|
||||
}, [refreshing]);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
handleLoad(true);
|
||||
}, []);
|
||||
useEffect(() => { handleLoad(false) }, [update.file]);
|
||||
useEffect(() => { if (refreshing) handleLoad(false) }, [refreshing]);
|
||||
useEffect(() => { handleLoad(true) }, []);
|
||||
|
||||
async function handleDelete() {
|
||||
try {
|
||||
const hasil = await decryptToken(String(token?.current));
|
||||
const response = await apiDeleteFileProject({ user: hasil }, String(selectFile?.id));
|
||||
if (response.success) {
|
||||
Toast.show({ type: 'small', text1: 'Berhasil menghapus file', })
|
||||
Toast.show({ type: 'small', text1: 'Berhasil menghapus file' })
|
||||
dispatch(setUpdateProject({ ...update, file: !update.file }))
|
||||
} else {
|
||||
Toast.show({ type: 'small', text1: response.message, })
|
||||
Toast.show({ type: 'small', text1: response.message })
|
||||
}
|
||||
} catch (error : any ) {
|
||||
console.error(error);
|
||||
const message = error?.response?.data?.message || "Gagal menghapus file"
|
||||
|
||||
Toast.show({ type: 'small', text1: message })
|
||||
} catch (error: any) {
|
||||
Toast.show({ type: 'small', text1: error?.response?.data?.message || "Gagal menghapus file" })
|
||||
} finally {
|
||||
setModal(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const openFile = () => {
|
||||
setModal(false)
|
||||
setLoadingOpen(true)
|
||||
let remoteUrl = ConstEnv.url_storage + '/files/' + selectFile?.idStorage;
|
||||
const fileName = selectFile?.name + '.' + selectFile?.extension;
|
||||
let localPath = `${FileSystem.documentDirectory}/${fileName}`;
|
||||
const remoteUrl = ConstEnv.url_storage + '/files/' + selectFile?.idStorage
|
||||
const fileName = selectFile?.name + '.' + selectFile?.extension
|
||||
const localPath = `${FileSystem.documentDirectory}/${fileName}`
|
||||
const mimeType = mime.lookup(fileName)
|
||||
|
||||
FileSystem.downloadAsync(remoteUrl, localPath).then(async ({ uri }) => {
|
||||
const contentURL = await FileSystem.getContentUriAsync(uri);
|
||||
const contentURL = await FileSystem.getContentUriAsync(uri)
|
||||
try {
|
||||
|
||||
if (Platform.OS == 'android') {
|
||||
// open with android intent
|
||||
await startActivityAsync(
|
||||
'android.intent.action.VIEW',
|
||||
{
|
||||
data: contentURL,
|
||||
flags: 1,
|
||||
type: mimeType as string,
|
||||
}
|
||||
);
|
||||
// or
|
||||
// Sharing.shareAsync(localPath);
|
||||
|
||||
} else if (Platform.OS == 'ios') {
|
||||
Sharing.shareAsync(localPath);
|
||||
if (Platform.OS === 'android') {
|
||||
await startActivityAsync('android.intent.action.VIEW', { data: contentURL, flags: 1, type: mimeType as string })
|
||||
} else {
|
||||
Sharing.shareAsync(localPath)
|
||||
}
|
||||
} catch (error) {
|
||||
Alert.alert('INFO', 'Gagal membuka file, tidak ada aplikasi yang dapat membuka file ini');
|
||||
} catch {
|
||||
Alert.alert('INFO', 'Gagal membuka file, tidak ada aplikasi yang dapat membuka file ini')
|
||||
} finally {
|
||||
setLoadingOpen(false)
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<ModalLoading isVisible={loadingOpen} setVisible={setLoadingOpen} />
|
||||
<View style={[Styles.mb15]}>
|
||||
<Text style={[Styles.textDefaultSemiBold, Styles.mv05]}>File</Text>
|
||||
<View style={[Styles.wrapPaper, { backgroundColor: colors.card, borderColor: colors.background }]}>
|
||||
{
|
||||
loading ?
|
||||
arrSkeleton.map((item, index) => {
|
||||
return (
|
||||
<Skeleton key={index} width={100} height={40} widthType="percent" borderRadius={10} />
|
||||
)
|
||||
})
|
||||
:
|
||||
data.length > 0 ?
|
||||
data.map((item, index) => {
|
||||
return (
|
||||
<BorderBottomItem
|
||||
key={index}
|
||||
borderType="all"
|
||||
icon={<MaterialCommunityIcons name="file-outline" size={25} color={colors.text} />}
|
||||
title={item.name + '.' + item.extension}
|
||||
titleWeight="normal"
|
||||
onPress={() => { setSelectFile(item); setModal(true) }}
|
||||
/>
|
||||
)
|
||||
})
|
||||
:
|
||||
<Text style={[Styles.textDefault, { textAlign: 'center', color: colors.dimmed }]}>Tidak ada file</Text>
|
||||
}
|
||||
</View>
|
||||
|
||||
{loading ? (
|
||||
<View style={Styles.fileGrid}>
|
||||
{arrSkeleton.map((_, index) => (
|
||||
<Skeleton key={index} width={48} height={68} widthType="percent" borderRadius={10} />
|
||||
))}
|
||||
</View>
|
||||
) : data.length > 0 ? (
|
||||
<View style={Styles.fileGrid}>
|
||||
{data.map((item, index) => {
|
||||
const iconName = getFileIcon(item.extension)
|
||||
const iconColor = getFileColor(item.extension)
|
||||
return (
|
||||
<Pressable
|
||||
key={index}
|
||||
onPress={() => { setSelectFile(item); setModal(true) }}
|
||||
style={[Styles.fileCard, { backgroundColor: colors.card, borderColor: colors.icon + '18' }]}
|
||||
>
|
||||
<View style={[Styles.sectionIconBox, { backgroundColor: iconColor + '20' }]}>
|
||||
<MaterialCommunityIcons name={iconName} size={18} color={iconColor} />
|
||||
</View>
|
||||
<View style={Styles.flex1}>
|
||||
<Text style={Styles.textDefault} numberOfLines={1}>{item.name}</Text>
|
||||
<Text style={[Styles.textSmallSemiBold, { color: colors.dimmed }]}>
|
||||
{item.extension.toUpperCase()}
|
||||
</Text>
|
||||
</View>
|
||||
</Pressable>
|
||||
)
|
||||
})}
|
||||
</View>
|
||||
) : (
|
||||
<Text style={[Styles.textDefault, { textAlign: 'center', color: colors.dimmed }]}>Tidak ada file</Text>
|
||||
)}
|
||||
</View>
|
||||
|
||||
<DrawerBottom animation="slide" isVisible={isModal} setVisible={setModal} title="Menu">
|
||||
@@ -173,26 +169,20 @@ export default function SectionFile({ status, member, refreshing }: { status: nu
|
||||
<MenuItemRow
|
||||
icon={<MaterialCommunityIcons name="file-eye" color={colors.text} size={25} />}
|
||||
title="Lihat / Share"
|
||||
onPress={() => {
|
||||
openFile()
|
||||
}}
|
||||
onPress={openFile}
|
||||
/>
|
||||
{
|
||||
!member && (entityUser.role == "user" || entityUser.role == "coadmin") ? <></>
|
||||
:
|
||||
<MenuItemRow
|
||||
icon={<Ionicons name="trash-outline" color={colors.text} size={25} />}
|
||||
title="Hapus"
|
||||
disabled={status == 3}
|
||||
onPress={() => {
|
||||
if (status == 3) return
|
||||
setModal(false)
|
||||
setTimeout(() => {
|
||||
setShowDeleteModal(true)
|
||||
}, 600)
|
||||
}}
|
||||
/>
|
||||
}
|
||||
{(!member && (entityUser.role === "user" || entityUser.role === "coadmin")) ? null : (
|
||||
<MenuItemRow
|
||||
icon={<Ionicons name="trash-outline" color={colors.text} size={25} />}
|
||||
title="Hapus"
|
||||
disabled={status === 3}
|
||||
onPress={() => {
|
||||
if (status === 3) return
|
||||
setModal(false)
|
||||
setTimeout(() => setShowDeleteModal(true), 600)
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</View>
|
||||
</DrawerBottom>
|
||||
|
||||
@@ -200,14 +190,11 @@ export default function SectionFile({ status, member, refreshing }: { status: nu
|
||||
visible={showDeleteModal}
|
||||
title="Konfirmasi"
|
||||
message="Apakah Anda yakin ingin menghapus file ini? File yang dihapus tidak dapat dikembalikan"
|
||||
onConfirm={() => {
|
||||
setShowDeleteModal(false)
|
||||
handleDelete()
|
||||
}}
|
||||
onConfirm={() => { setShowDeleteModal(false); handleDelete() }}
|
||||
onCancel={() => setShowDeleteModal(false)}
|
||||
confirmText="Hapus"
|
||||
cancelText="Batal"
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user