import React, { useState, useEffect } from 'react'
import { Head, router } from '@inertiajs/react'
import { usePrevious } from 'react-use'
import { formatIDDate } from '@/utils'
import CustomerLayout from '@/Layouts/CustomerLayout'
import HeaderTrx from '../Components/HeaderTrx'
const EmptyHere = () => {
return (
Transaksi kosong
Yuk kumpulkan poin sebanyak banyaknya dengan share link refferal
kamu
)
}
export default function Index(props) {
const {
poins: { data, next_page_url },
_start_date,
_end_date,
} = props
const [_poins, setpoins] = useState(data)
const [dates, setDates] = useState({
startDate: _start_date,
endDate: _end_date,
})
const preValue = usePrevious(`${dates}`)
const handleNextPage = () => {
router.get(
next_page_url,
{ startDate: dates.startDate, endDate: dates.endDate },
{
replace: true,
preserveState: true,
only: ['poins'],
onSuccess: (res) => {
setpoins(_poins.concat(res.props.poins.data))
},
}
)
}
useEffect(() => {
if (preValue) {
if (isEmpty(dates.endDate)) {
return
}
router.get(
route(route().current()),
{
startDate: dates.startDate,
endDate: dates.endDate,
},
{
replace: true,
preserveState: true,
only: ['poins'],
onSuccess: (res) => {
setpoins(res.props.poins.data)
},
}
)
}
}, [dates])
return (
{_poins.length <= 0 &&
}
{_poins.length > 0 && (
{formatIDDate(dates.startDate)} s/d{' '}
{formatIDDate(dates.endDate)}
)}
{_poins.map((poin) => (
router.get(
route('transactions.poin.show', poin.id)
)
}
>
{poin.format_human_created_at}
{poin.description}
))}
{next_page_url !== null && (
Load more
)}
)
}