customer level view done
parent
01f8fbcbc9
commit
f9064ab4d3
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\CustomerLevel;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CustomerLevelController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$query = CustomerLevel::query();
|
||||
return inertia('CustomerLevel/Index', [
|
||||
'query' => $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']);
|
||||
}
|
||||
}
|
@ -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 (
|
||||
<Modal isOpen={modalState.isOpen} toggle={handleClose} title={'Info'}>
|
||||
<FormInput
|
||||
name="name"
|
||||
value={data.name}
|
||||
onChange={handleOnChange}
|
||||
label="Nama"
|
||||
error={errors.name}
|
||||
/>
|
||||
<FormInput
|
||||
name="description"
|
||||
value={data.description}
|
||||
onChange={handleOnChange}
|
||||
label="Description"
|
||||
error={errors.description}
|
||||
/>
|
||||
<FormInput
|
||||
type="number"
|
||||
name="min_amount"
|
||||
value={data.min_amount}
|
||||
onChange={handleOnChange}
|
||||
label="Minimal Deposit"
|
||||
error={errors.min_amount}
|
||||
/>
|
||||
<FormInput
|
||||
type="number"
|
||||
name="max_amount"
|
||||
value={data.max_amount}
|
||||
onChange={handleOnChange}
|
||||
label="Maksimal Deposit"
|
||||
error={errors.max_amount}
|
||||
/>
|
||||
<div className="flex items-center">
|
||||
<Button onClick={handleSubmit} processing={processing}>
|
||||
Simpan
|
||||
</Button>
|
||||
<Button onClick={handleClose} type="secondary">
|
||||
Batal
|
||||
</Button>
|
||||
</div>
|
||||
</Modal>
|
||||
)
|
||||
}
|
@ -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 (
|
||||
<AuthenticatedLayout
|
||||
auth={props.auth}
|
||||
errors={props.errors}
|
||||
flash={props.flash}
|
||||
page={'Customer Level'}
|
||||
action={''}
|
||||
>
|
||||
<Head title="Customer Level" />
|
||||
|
||||
<div>
|
||||
<div className="mx-auto sm:px-6 lg:px-8 ">
|
||||
<div className="p-6 overflow-hidden shadow-sm sm:rounded-lg bg-gray-200 dark:bg-gray-800 space-y-4">
|
||||
<div className="flex justify-between">{/* */}</div>
|
||||
<div className="overflow-auto">
|
||||
<div>
|
||||
<table className="w-full text-sm text-left text-gray-500 dark:text-gray-400 mb-4">
|
||||
<thead className="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
|
||||
<tr>
|
||||
<th
|
||||
scope="col"
|
||||
className="py-3 px-6"
|
||||
>
|
||||
Name
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
className="py-3 px-6"
|
||||
>
|
||||
Description
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
className="py-3 px-6"
|
||||
>
|
||||
Minimal Deposit
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
className="py-3 px-6"
|
||||
>
|
||||
Maximal Deposit
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
className="py-3 px-6"
|
||||
/>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data.map((level) => (
|
||||
<tr
|
||||
className="bg-white border-b dark:bg-gray-800 dark:border-gray-700"
|
||||
key={level.id}
|
||||
>
|
||||
<td
|
||||
scope="row"
|
||||
className="py-4 px-6 font-medium text-gray-900 whitespace-nowrap dark:text-white"
|
||||
>
|
||||
{level.name}
|
||||
</td>
|
||||
<td className="py-4 px-6">
|
||||
{level.description}
|
||||
</td>
|
||||
<td className="py-4 px-6">
|
||||
{formatIDR(
|
||||
level.min_amount
|
||||
)}
|
||||
</td>
|
||||
<td className="py-4 px-6">
|
||||
{formatIDR(
|
||||
level.max_amount
|
||||
)}
|
||||
</td>
|
||||
<td className="py-4 px-6 flex justify-end">
|
||||
<Dropdown
|
||||
label={'Opsi'}
|
||||
floatingArrow={true}
|
||||
arrowIcon={true}
|
||||
dismissOnClick={true}
|
||||
size={'sm'}
|
||||
>
|
||||
{canUpdate && (
|
||||
<Dropdown.Item
|
||||
onClick={() =>
|
||||
toggleFormModal(
|
||||
level
|
||||
)
|
||||
}
|
||||
>
|
||||
<div className="flex space-x-1 items-center">
|
||||
<HiPencil />
|
||||
<div>
|
||||
Ubah
|
||||
</div>
|
||||
</div>
|
||||
</Dropdown.Item>
|
||||
)}
|
||||
</Dropdown>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div className="w-full flex items-center justify-center">
|
||||
<Pagination links={links} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<FormModal modalState={formModal} />
|
||||
</AuthenticatedLayout>
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue