Files
mobile-darmasaba/components/home/projectHome.tsx
amel b4c560b88e upd: home
Deskripsi:
- update progress pada kegiatan terupdate home

No Issues
2025-04-29 10:40:34 +08:00

84 lines
3.2 KiB
TypeScript

import { ColorsStatus } from "@/constants/ColorsStatus";
import Styles from "@/constants/Styles";
import { apiGetDataHome } from "@/lib/api";
import { useAuthSession } from "@/providers/AuthProvider";
import { router } from "expo-router";
import React, { useEffect, useState } from "react";
import { Dimensions, Text, View } from "react-native";
import Carousel, { ICarouselInstance } from "react-native-reanimated-carousel";
import PaperGridContent from "../paperGridContent";
import ProgressBar from "../progressBar";
type Props = {
id: string
title: string
desc: string
status: number
progress: number
createdAt: string
}
export default function ProjectHome() {
const { decryptToken, token } = useAuthSession()
const ref = React.useRef<ICarouselInstance>(null);
const width = Dimensions.get("window").width;
const [data, setData] = useState<Props[]>([])
async function handleData() {
try {
const hasil = await decryptToken(String(token?.current))
const response = await apiGetDataHome({ cat: "kegiatan", user: hasil })
setData(response.data)
} catch (error) {
console.error(error)
}
}
useEffect(() => {
handleData()
}, []);
return (
<View style={[Styles.mb15]}>
<Text style={[Styles.textDefaultSemiBold, Styles.mv10]}>Kegiatan Terupdate</Text>
<Carousel
ref={ref}
style={{ width: "100%" }}
width={width * 0.8}
height={235}
data={data}
loop={true}
autoPlay={false}
autoPlayReverse={false}
pagingEnabled={true}
snapEnabled={true}
vertical={false}
renderItem={({ index }) => (
<PaperGridContent content="carousel" onPress={() => { router.push(`/project/${data[index].id}`) }} title={data[index].title} headerColor="primary">
<ProgressBar value={data[index].progress}/>
<View style={[Styles.rowSpaceBetween]}>
<Text style={[Styles.textDefault, Styles.cGray]}>{data[index].createdAt}</Text>
<View style={[Styles.labelStatus,
data[index].status === 0 ? ColorsStatus.primary :
data[index].status === 1 ? ColorsStatus.warning :
data[index].status === 2 ? ColorsStatus.success :
data[index].status === 3 ? ColorsStatus.error :
ColorsStatus.primary
]}>
<Text style={[Styles.textMediumSemiBold, Styles.cWhite]}>
{
data[index].status === 0 ? 'SEGERA' :
data[index].status === 1 ? 'DIKERJAKAN' :
data[index].status === 2 ? 'SELESAI' :
data[index].status === 3 ? 'DIBATALKAN' :
"SEGERA"
}
</Text>
</View>
</View>
</PaperGridContent>
)}
/>
</View>
)
}