From f9064ab4d3b9d9d73e23ea51c432ca5391837ecc Mon Sep 17 00:00:00 2001 From: Aji Kamaludin Date: Sat, 3 Jun 2023 09:54:34 +0700 Subject: [PATCH] customer level view done --- TODO.md | 2 +- .../Controllers/CustomerLevelController.php | 36 +++++ database/seeders/InstallationSeed.php | 8 +- database/seeders/PermissionSeeder.php | 2 - resources/js/Layouts/Partials/routes.js | 8 + .../js/Pages/CustomerLevel/FormModal.jsx | 104 +++++++++++++ resources/js/Pages/CustomerLevel/Index.jsx | 142 ++++++++++++++++++ routes/admin.php | 5 + 8 files changed, 300 insertions(+), 7 deletions(-) create mode 100644 app/Http/Controllers/CustomerLevelController.php create mode 100644 resources/js/Pages/CustomerLevel/FormModal.jsx create mode 100644 resources/js/Pages/CustomerLevel/Index.jsx diff --git a/TODO.md b/TODO.md index 790f9b9..3757832 100644 --- a/TODO.md +++ b/TODO.md @@ -10,7 +10,7 @@ - [x] CRUD Voucher - [x] Import Voucher - [x] Setting Web (enable affilate, amount bonus affilate) -- [ ] Setting Level Customer (view levels, edit name of level,minimal saldo, max amount saldo, max hutang) +- [x] Setting Level Customer (view levels, edit name of level,minimal saldo, max amount saldo, max hutang) - [ ] Deposit Menu (view daftar histori deposit) - [ ] Manual Approve Deposit - [ ] Setting Bonus Coin (memasukan amount bonus coin yang didapat dengan level dan harga voucher) - coin rewards diff --git a/app/Http/Controllers/CustomerLevelController.php b/app/Http/Controllers/CustomerLevelController.php new file mode 100644 index 0000000..f3ccd79 --- /dev/null +++ b/app/Http/Controllers/CustomerLevelController.php @@ -0,0 +1,36 @@ + $query->paginate() + ]); + } + + public function update(Request $request, CustomerLevel $customerLevel) + { + $request->validate([ + 'name' => 'required|string', + 'description' => 'nullable|string', + 'min_amount' => 'required|numeric|min:0', + 'max_amount' => 'required|numeric|min:0' + ]); + + $customerLevel->update([ + 'name' => $request->name, + 'description' => $request->description, + 'min_amount' => $request->min_amount, + 'max_amount' => $request->max_amount, + ]); + + session()->flash('message', ['type' => 'success', 'message' => 'Item has beed updated']); + } +} diff --git a/database/seeders/InstallationSeed.php b/database/seeders/InstallationSeed.php index c2d25fb..a0fdd11 100644 --- a/database/seeders/InstallationSeed.php +++ b/database/seeders/InstallationSeed.php @@ -38,10 +38,10 @@ class InstallationSeed extends Seeder public function customer_levels() { $levels = [ - ['name' => 'Basic', 'key' => 'basic'], - ['name' => 'Silver', 'key' => 'silver'], - ['name' => 'Gold', 'key' => 'gold'], - ['name' => 'Platinum', 'key' => 'platinum'], + ['name' => 'Basic', 'key' => 'basic', 'description' => '-', 'min_amount' => '100000', 'max_amount' => '500000'], + ['name' => 'Silver', 'key' => 'silver', 'description' => '-', 'min_amount' => '100000', 'max_amount' => '1000000'], + ['name' => 'Gold', 'key' => 'gold', 'description' => '-', 'min_amount' => '100000', 'max_amount' => '2000000'], + ['name' => 'Platinum', 'key' => 'platinum', 'description' => '-', 'min_amount' => '100000', 'max_amount' => '3000000'], ]; foreach ($levels as $level) { diff --git a/database/seeders/PermissionSeeder.php b/database/seeders/PermissionSeeder.php index 5a12655..562eb22 100644 --- a/database/seeders/PermissionSeeder.php +++ b/database/seeders/PermissionSeeder.php @@ -51,10 +51,8 @@ class PermissionSeeder extends Seeder ['id' => Str::ulid(), 'label' => 'View Customer', 'name' => 'view-customer'], ['id' => Str::ulid(), 'label' => 'Delete Customer', 'name' => 'delete-customer'], - ['id' => Str::ulid(), 'label' => 'Create Customer Level', 'name' => 'create-customer-level'], ['id' => Str::ulid(), 'label' => 'Update Customer Level', 'name' => 'update-customer-level'], ['id' => Str::ulid(), 'label' => 'View Customer Level', 'name' => 'view-customer-level'], - ['id' => Str::ulid(), 'label' => 'Delete Customer Level', 'name' => 'delete-customer-level'], ['id' => Str::ulid(), 'label' => 'Create Customer Verification', 'name' => 'create-customer-verification'], ['id' => Str::ulid(), 'label' => 'Update Customer Verification', 'name' => 'update-customer-verification'], diff --git a/resources/js/Layouts/Partials/routes.js b/resources/js/Layouts/Partials/routes.js index 502cd8c..2fb4418 100644 --- a/resources/js/Layouts/Partials/routes.js +++ b/resources/js/Layouts/Partials/routes.js @@ -32,6 +32,14 @@ export default [ active: 'customer.*', permission: 'view-customer', }, + { + name: 'Customer Level', + show: true, + icon: HiUserCircle, + route: route('customer-level.index'), + active: 'customer-level.*', + permission: 'view-customer-level', + }, { name: 'Bank Akun', show: true, diff --git a/resources/js/Pages/CustomerLevel/FormModal.jsx b/resources/js/Pages/CustomerLevel/FormModal.jsx new file mode 100644 index 0000000..3bcfe88 --- /dev/null +++ b/resources/js/Pages/CustomerLevel/FormModal.jsx @@ -0,0 +1,104 @@ +import React, { useEffect } from 'react' +import Modal from '@/Components/Modal' +import { useForm } from '@inertiajs/react' +import Button from '@/Components/Button' +import FormInput from '@/Components/FormInput' +import RoleSelectionInput from '../Role/SelectionInput' + +import { isEmpty } from 'lodash' + +export default function FormModal(props) { + const { modalState } = props + const { data, setData, post, put, processing, errors, reset, clearErrors } = + useForm({ + name: '', + description: '', + min_amount: 0, + max_amount: 0, + }) + + const handleOnChange = (event) => { + setData( + event.target.name, + event.target.type === 'checkbox' + ? event.target.checked + ? 1 + : 0 + : event.target.value + ) + } + + const handleReset = () => { + modalState.setData(null) + reset() + clearErrors() + } + + const handleClose = () => { + handleReset() + modalState.toggle() + } + + const handleSubmit = () => { + const customerLevel = modalState.data + put(route('customer-level.update', customerLevel.id), { + onSuccess: () => handleClose(), + }) + } + + useEffect(() => { + const customerLevel = modalState.data + if (isEmpty(customerLevel) === false) { + setData({ + name: customerLevel.name, + description: customerLevel.description, + min_amount: customerLevel.min_amount, + max_amount: customerLevel.max_amount, + }) + return + } + }, [modalState]) + + return ( + + + + + +
+ + +
+
+ ) +} diff --git a/resources/js/Pages/CustomerLevel/Index.jsx b/resources/js/Pages/CustomerLevel/Index.jsx new file mode 100644 index 0000000..84f5857 --- /dev/null +++ b/resources/js/Pages/CustomerLevel/Index.jsx @@ -0,0 +1,142 @@ +import React from 'react' +import { Head } from '@inertiajs/react' +import { Dropdown } from 'flowbite-react' +import { HiPencil } from 'react-icons/hi' +import { useModalState } from '@/hooks' + +import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout' +import Pagination from '@/Components/Pagination' +import FormModal from './FormModal' +import { formatIDR, hasPermission } from '@/utils' + +export default function Info(props) { + const { + query: { links, data }, + auth, + } = props + + const formModal = useModalState() + + const toggleFormModal = (customerlevel = null) => { + formModal.setData(customerlevel) + formModal.toggle() + } + + const canUpdate = hasPermission(auth, 'update-customer-level') + + return ( + + + +
+
+
+
{/* */}
+
+
+ + + + + + + + + + + {data.map((level) => ( + + + + + + + + ))} + +
+ Name + + Description + + Minimal Deposit + + Maximal Deposit + +
+ {level.name} + + {level.description} + + {formatIDR( + level.min_amount + )} + + {formatIDR( + level.max_amount + )} + + + {canUpdate && ( + + toggleFormModal( + level + ) + } + > +
+ +
+ Ubah +
+
+
+ )} +
+
+
+
+ +
+
+
+
+
+ +
+ ) +} diff --git a/routes/admin.php b/routes/admin.php index d5c544a..892dea7 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -4,6 +4,7 @@ use App\Http\Controllers\AccountController; use App\Http\Controllers\Auth\AuthenticatedSessionController; use App\Http\Controllers\BannerController; use App\Http\Controllers\CustomerController; +use App\Http\Controllers\CustomerLevelController; use App\Http\Controllers\GeneralController; use App\Http\Controllers\InfoController; use App\Http\Controllers\LocationController; @@ -77,6 +78,10 @@ Route::middleware(['http_secure_aware', 'inertia.admin']) Route::post('/banner/{banner}', [BannerController::class, 'update'])->name('banner.update'); Route::delete('/banner/{banner}', [BannerController::class, 'destroy'])->name('banner.destroy'); + // customer level + Route::get('/customer-levels', [CustomerLevelController::class, 'index'])->name('customer-level.index'); + Route::put('/customer-levels/{customerLevel}', [CustomerLevelController::class, 'update'])->name('customer-level.update'); + // customer Route::get('/customers', [CustomerController::class, 'index'])->name('customer.index'); Route::get('/customers/create', [CustomerController::class, 'create'])->name('customer.create');