82 lines
3.0 KiB
TypeScript
82 lines
3.0 KiB
TypeScript
import Styles from "@/constants/Styles";
|
|
import { apiGetDivisionOneFeature } from "@/lib/api";
|
|
import { useAuthSession } from "@/providers/AuthProvider";
|
|
import { Feather } from "@expo/vector-icons";
|
|
import { useLocalSearchParams } from "expo-router";
|
|
import React, { useEffect, useState } from "react";
|
|
import { Dimensions, View } from "react-native";
|
|
import Text from "../Text";
|
|
import Carousel, { ICarouselInstance } from "react-native-reanimated-carousel";
|
|
import Skeleton from "../skeleton";
|
|
|
|
type Props = {
|
|
id: string
|
|
idProject: string
|
|
title: string
|
|
dateStart: string
|
|
dateEnd: string
|
|
projectTitle: string
|
|
}
|
|
|
|
export default function TaskDivisionDetail() {
|
|
const { token, decryptToken } = useAuthSession()
|
|
const { id } = useLocalSearchParams<{ id: string }>()
|
|
const [data, setData] = useState<Props[]>([])
|
|
const ref = React.useRef<ICarouselInstance>(null);
|
|
const width = Dimensions.get("window").width;
|
|
const [loading, setLoading] = useState(true)
|
|
|
|
async function handleLoad() {
|
|
try {
|
|
setLoading(true)
|
|
const hasil = await decryptToken(String(token?.current))
|
|
const response = await apiGetDivisionOneFeature({ user: hasil, id, cat: 'today-task' })
|
|
setData(response.data)
|
|
} catch (error) {
|
|
console.error(error)
|
|
} finally {
|
|
setLoading(false)
|
|
}
|
|
}
|
|
|
|
useEffect(() => {
|
|
handleLoad()
|
|
}, [])
|
|
|
|
return (
|
|
<View>
|
|
<Text style={[Styles.textDefaultSemiBold, Styles.mb05]}>Tugas Hari Ini</Text>
|
|
|
|
{
|
|
loading ?
|
|
<Skeleton width={100} widthType="percent" height={60} borderRadius={10} />
|
|
:
|
|
data.length > 0 ?
|
|
<Carousel
|
|
ref={ref}
|
|
style={{ width: "100%" }}
|
|
width={width * 0.8}
|
|
height={100}
|
|
data={data}
|
|
loop={true}
|
|
autoPlay={false}
|
|
autoPlayReverse={false}
|
|
pagingEnabled={true}
|
|
snapEnabled={true}
|
|
vertical={false}
|
|
renderItem={({ index }) => (
|
|
<View style={[Styles.wrapPaper, { width: '95%' }]}>
|
|
<Text style={[Styles.textDefaultSemiBold]} numberOfLines={1} ellipsizeMode="tail">{data[index].title} - {data[index].projectTitle}</Text>
|
|
<View style={[Styles.rowItemsCenter, Styles.mt10]}>
|
|
<Feather name="clock" size={18} color="grey" style={Styles.mr05} />
|
|
<Text style={[Styles.textInformation]} numberOfLines={1} ellipsizeMode="tail">{data[index].dateStart} - {data[index].dateEnd}</Text>
|
|
</View>
|
|
</View>
|
|
)}
|
|
/>
|
|
:
|
|
<Text style={[Styles.textDefault, Styles.cGray, { textAlign: 'center' }]}>Tidak ada tugas</Text>
|
|
}
|
|
</View>
|
|
)
|
|
} |