You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
163 lines
5.4 KiB
React
163 lines
5.4 KiB
React
1 year ago
|
import React, { useState } from 'react'
|
||
1 year ago
|
import { Head, router, usePage } from '@inertiajs/react'
|
||
1 year ago
|
|
||
1 year ago
|
import CustomerLayout from '@/Layouts/CustomerLayout'
|
||
1 year ago
|
import { HiOutlineBell } from 'react-icons/hi2'
|
||
1 year ago
|
import UserBanner from './UserBanner'
|
||
1 year ago
|
import VoucherCard from './VoucherCard'
|
||
1 year ago
|
|
||
1 year ago
|
const GuestBanner = () => {
|
||
|
const {
|
||
|
props: { app_name },
|
||
|
} = usePage()
|
||
1 year ago
|
return (
|
||
1 year ago
|
<div>
|
||
|
{/* user */}
|
||
|
<div className="flex flex-row justify-between items-center px-5 py-6 text-lg bg-blue-600">
|
||
|
<div className="flex flex-col text-white">
|
||
|
<div className="font-bold">Welcome to {app_name}</div>
|
||
1 year ago
|
</div>
|
||
1 year ago
|
<div className="flex flex-row">
|
||
|
<HiOutlineBell className="text-white w-7 h-7" />
|
||
|
<div>
|
||
|
<div className="bg-white text-blue-700 rounded-lg px-1 text-xs -ml-2.5">
|
||
|
0
|
||
1 year ago
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
1 year ago
|
</div>
|
||
|
</div>
|
||
|
)
|
||
|
}
|
||
|
|
||
1 year ago
|
export default function Index(props) {
|
||
|
const {
|
||
|
auth: { user },
|
||
|
infos,
|
||
|
banners,
|
||
|
locations,
|
||
|
vouchers: { data, next_page_url },
|
||
|
_location_id,
|
||
|
} = props
|
||
|
|
||
1 year ago
|
const [locId, setLocId] = useState(_location_id)
|
||
|
const [v, setV] = useState(data)
|
||
|
|
||
1 year ago
|
const handleBanner = (banner) => {
|
||
|
router.get(route('home.banner', banner))
|
||
|
}
|
||
|
|
||
1 year ago
|
const handleSelectLoc = (loc) => {
|
||
|
if (loc.id === locId) {
|
||
|
setLocId('')
|
||
1 year ago
|
fetch('')
|
||
1 year ago
|
return
|
||
|
}
|
||
|
setLocId(loc.id)
|
||
1 year ago
|
fetch(loc.id)
|
||
1 year ago
|
}
|
||
|
|
||
1 year ago
|
const handleNextPage = () => {
|
||
1 year ago
|
router.get(
|
||
|
next_page_url,
|
||
|
{
|
||
|
location_id: locId,
|
||
|
},
|
||
|
{
|
||
|
replace: true,
|
||
|
preserveState: true,
|
||
|
only: ['vouchers'],
|
||
|
onSuccess: (res) => {
|
||
|
setV(v.concat(res.props.vouchers.data))
|
||
|
},
|
||
|
}
|
||
|
)
|
||
|
}
|
||
|
|
||
1 year ago
|
const fetch = (locId) => {
|
||
1 year ago
|
router.get(
|
||
|
route(route().current()),
|
||
|
{ location_id: locId },
|
||
|
{
|
||
|
replace: true,
|
||
|
preserveState: true,
|
||
|
onSuccess: (res) => {
|
||
|
setV(res.props.vouchers.data)
|
||
|
},
|
||
|
}
|
||
|
)
|
||
1 year ago
|
}
|
||
1 year ago
|
|
||
1 year ago
|
return (
|
||
|
<CustomerLayout>
|
||
|
<Head title="Home" />
|
||
1 year ago
|
<div className="flex flex-col min-h-[calc(95dvh)]">
|
||
1 year ago
|
{user !== null ? <UserBanner user={user} /> : <GuestBanner />}
|
||
1 year ago
|
|
||
|
{/* banner */}
|
||
|
<div className="w-full">
|
||
|
<div className="flex flex-row overflow-y-scroll space-x-2 py-3 px-2">
|
||
1 year ago
|
{banners.map((banner) => (
|
||
|
<img
|
||
|
onClick={() => handleBanner(banner)}
|
||
|
key={banner.id}
|
||
|
src={banner.image_url}
|
||
|
className={`rounded w-${
|
||
|
banners.length === 1 ? 'full' : '[80%]'
|
||
|
} min-w-[340px] h-28 object-cover`}
|
||
|
/>
|
||
|
))}
|
||
1 year ago
|
</div>
|
||
|
</div>
|
||
|
|
||
|
{/* info */}
|
||
|
<div className="w-full px-3">
|
||
1 year ago
|
{infos.map((info) => (
|
||
1 year ago
|
<div
|
||
|
className="p-4 mb-4 text-sm text-blue-800 rounded-lg bg-blue-50"
|
||
|
role="alert"
|
||
1 year ago
|
key={info.id}
|
||
1 year ago
|
>
|
||
1 year ago
|
{info.title}
|
||
1 year ago
|
</div>
|
||
|
))}
|
||
|
</div>
|
||
|
|
||
|
<div className="w-full flex flex-col">
|
||
|
{/* chips */}
|
||
|
<div className="w-full flex flex-row overflow-y-scroll space-x-2 px-2">
|
||
1 year ago
|
{locations.map((location) => (
|
||
|
<div
|
||
1 year ago
|
onClick={() => handleSelectLoc(location)}
|
||
1 year ago
|
key={location.id}
|
||
1 year ago
|
className={`px-2 py-1 rounded-2xl ${
|
||
|
location.id === locId
|
||
|
? 'text-white bg-blue-600 border border-blue-800'
|
||
|
: 'bg-blue-100 border border-blue-200'
|
||
|
}`}
|
||
1 year ago
|
>
|
||
|
{location.name}
|
||
|
</div>
|
||
|
))}
|
||
1 year ago
|
</div>
|
||
|
|
||
|
{/* voucher */}
|
||
|
<div className="flex flex-col w-full px-3 mt-3 space-y-2">
|
||
1 year ago
|
{v.map((voucher) => (
|
||
|
<VoucherCard key={voucher.id} voucher={voucher} />
|
||
|
))}
|
||
|
{next_page_url !== null && (
|
||
1 year ago
|
<div
|
||
1 year ago
|
onClick={handleNextPage}
|
||
1 year ago
|
className="w-full text-center px-2 py-1 border mt-5 hover:bg-blue-600 hover:text-white"
|
||
1 year ago
|
>
|
||
1 year ago
|
Load more
|
||
1 year ago
|
</div>
|
||
1 year ago
|
)}
|
||
1 year ago
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
1 year ago
|
</CustomerLayout>
|
||
|
)
|
||
|
}
|