add dummy voucher

dev
Aji Kamaludin 1 year ago
parent 673f4bf57f
commit 6e880dda99
No known key found for this signature in database
GPG Key ID: 19058F67F0083AD3

@ -29,7 +29,7 @@ class HomeController extends Controller
'banners' => $banners,
'locations' => $locations,
'vouchers' => $vouchers->paginate(10),
'_location_id' => $request->location_id
'_location_id' => $request->location_id ?? ''
]);
}

@ -71,6 +71,6 @@ class Voucher extends Model
public function location()
{
return $this->belongsTo(Location::class);
return $this->belongsTo(Location::class)->withTrashed();
}
}

@ -6,7 +6,11 @@ use App\Models\Account;
use App\Models\Banner;
use App\Models\Info;
use App\Models\Location;
use App\Models\Voucher;
use App\Services\GeneralService;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
class DummySeeder extends Seeder
{
@ -21,6 +25,7 @@ class DummySeeder extends Seeder
$this->banner();
$this->account();
$this->location();
$this->voucher();
}
public function info()
@ -71,4 +76,30 @@ class DummySeeder extends Seeder
]);
}
}
public function voucher()
{
$batchId = Str::ulid();
$vouchers = GeneralService::script_parser(file_get_contents(public_path('example.md')));
$location = Location::first();
DB::beginTransaction();
foreach ($vouchers as $voucher) {
Voucher::create([
'location_id' => $location->id,
'username' => $voucher['username'],
'password' => $voucher['password'],
'discount' => 10,
'display_price' => 100000,
'quota' => $voucher['quota'],
'profile' => $voucher['profile'],
'comment' => $voucher['comment'],
'expired' => 30,
'expired_unit' => 'Hari',
'batch_id' => $batchId,
]);
}
DB::commit();
}
}

@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react'
import React, { useState } from 'react'
import { Head, router, usePage } from '@inertiajs/react'
import CustomerLayout from '@/Layouts/CustomerLayout'
@ -30,14 +30,16 @@ const GuestBanner = () => {
)
}
export default function Index({
export default function Index(props) {
const {
auth: { user },
infos,
banners,
locations,
vouchers: { data, next_page_url },
_location_id,
}) {
} = props
const [locId, setLocId] = useState(_location_id)
const [v, setV] = useState(data)
@ -48,12 +50,14 @@ export default function Index({
const handleSelectLoc = (loc) => {
if (loc.id === locId) {
setLocId('')
fetch('')
return
}
setLocId(loc.id)
fetch(loc.id)
}
const loadMore = () => {
const handleNextPage = () => {
router.get(
next_page_url,
{
@ -70,7 +74,7 @@ export default function Index({
)
}
useEffect(() => {
const fetch = (locId) => {
router.get(
route(route().current()),
{ location_id: locId },
@ -82,7 +86,7 @@ export default function Index({
},
}
)
}, [locId])
}
return (
<CustomerLayout>
@ -144,7 +148,7 @@ export default function Index({
))}
{next_page_url !== null && (
<div
onClick={loadMore}
onClick={handleNextPage}
className="w-full text-center px-2 py-1 border mt-5 hover:bg-blue-600 hover:text-white"
>
Load more

Loading…
Cancel
Save