import React, { useEffect, useState } from 'react'
import { router, usePage, useForm } from '@inertiajs/react'
import { HiOutlineStar } from 'react-icons/hi2'
import VoucherCard from '../Partials/VoucherCard'
const EmptyFavorite = () => {
return (
Belum ada favorite
pilih lokasi favorite di daftar semua lokasi
)
}
const EmptyVoucher = () => {
return (
Voucher belum tersedia
sepertinya voucher di lokasimu sedang tidak tersedia
)
}
export default function FavoriteVoucher() {
const {
props: {
vouchers: { data, next_page_url },
_flocations,
},
} = usePage()
const { post, processing } = useForm({})
const nextPageUrl = next_page_url === undefined ? null : next_page_url
const [items, setItems] = useState(data === undefined ? [] : data)
const handleRemoveLocation = (location) => {
if (processing) {
return
}
post(route('customer.location.favorite', location), {
onSuccess: () => {
router.visit(route(route().current()))
},
})
}
const handleNextPage = () => {
router.get(
nextPageUrl,
{},
{
replace: true,
preserveState: true,
only: ['vouchers'],
onSuccess: (res) => {
if (res.props.vouchers.data !== undefined) {
setItems(items.concat(res.props.vouchers.data))
}
},
}
)
}
useEffect(() => {
setItems(data)
}, [_flocations])
return (
<>
{_flocations.map((location) => (
handleRemoveLocation(location)}
>
{location.name}
))}
{_flocations.length <= 0 && }
{/* voucher */}
{items.map((voucher) => (
))}
{nextPageUrl !== null && (
Load more
)}
{items.length <= 0 && _flocations.length > 0 && }
>
)
}