customer level and customer filter
parent
8cbabb91f3
commit
25f837bc79
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\CustomerLevel;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CustomerLevelController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
return CustomerLevel::all();
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 2.4 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.4 KiB |
@ -0,0 +1,121 @@
|
||||
import React, { useEffect, Suspense } from 'react'
|
||||
import { isEmpty } from 'lodash'
|
||||
|
||||
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'
|
||||
import FormInput from '@/Components/FormInput'
|
||||
import Button from '@/Components/Button'
|
||||
import { Head, useForm } from '@inertiajs/react'
|
||||
import FormFile from '@/Components/FormFile'
|
||||
|
||||
const TinyEditor = React.lazy(() => import('@/Components/TinyMCE'))
|
||||
|
||||
export default function Form(props) {
|
||||
const { customer_level } = props
|
||||
|
||||
const { data, setData, post, processing, errors } = useForm({
|
||||
name: '',
|
||||
description: '',
|
||||
min_amount: 0,
|
||||
max_amount: 0,
|
||||
logo: null,
|
||||
logo_url: '',
|
||||
})
|
||||
|
||||
const handleOnChange = (event) => {
|
||||
setData(
|
||||
event.target.name,
|
||||
event.target.type === 'checkbox'
|
||||
? event.target.checked
|
||||
? 1
|
||||
: 0
|
||||
: event.target.value
|
||||
)
|
||||
}
|
||||
const handleSubmit = () => {
|
||||
post(route('customer-level.update', customer_level.id))
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (isEmpty(customer_level) === false) {
|
||||
setData({
|
||||
name: customer_level.name,
|
||||
description: customer_level.description,
|
||||
min_amount: customer_level.min_amount,
|
||||
max_amount: customer_level.max_amount,
|
||||
logo_url: customer_level.logo_url,
|
||||
})
|
||||
}
|
||||
}, [customer_level])
|
||||
|
||||
return (
|
||||
<AuthenticatedLayout
|
||||
page={'Atur Level'}
|
||||
action={'Form'}
|
||||
parent={route('customer-level.index')}
|
||||
>
|
||||
<Head title="Atur Level" />
|
||||
|
||||
<div>
|
||||
<div className="mx-auto sm:px-6 lg:px-8">
|
||||
<div className="overflow-hidden p-4 shadow-sm sm:rounded-lg bg-white dark:bg-gray-800 flex flex-col ">
|
||||
<div className="text-xl font-bold mb-4">Atur Level</div>
|
||||
<FormInput
|
||||
name="name"
|
||||
value={data.name}
|
||||
onChange={handleOnChange}
|
||||
label="Nama"
|
||||
error={errors.name}
|
||||
/>
|
||||
<FormFile
|
||||
label={'Logo'}
|
||||
onChange={(e) => setData('logo', e.target.files[0])}
|
||||
error={errors.logo}
|
||||
preview={
|
||||
isEmpty(data.logo_url) === false && (
|
||||
<img
|
||||
src={data.logo_url}
|
||||
className="mb-1 h-24 object-cover"
|
||||
alt="preview"
|
||||
/>
|
||||
)
|
||||
}
|
||||
/>
|
||||
<div className="py-4">
|
||||
<Suspense fallback={<div>Loading...</div>}>
|
||||
<TinyEditor
|
||||
value={data.description}
|
||||
init={{
|
||||
height: 500,
|
||||
// menubar: false,
|
||||
menubar:
|
||||
'file edit view insert format tools table help',
|
||||
plugins:
|
||||
'preview importcss searchreplace autolink directionality code visualblocks visualchars fullscreen image link media codesample table charmap pagebreak nonbreaking anchor insertdatetime advlist lists wordcount help charmap emoticons',
|
||||
toolbar_mode: 'scrolling',
|
||||
toolbar:
|
||||
'undo redo | insertfile image media link | bold italic underline strikethrough | fontfamily fontsize blocks | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist | forecolor backcolor removeformat | charmap emoticons | fullscreen preview save print | ltr rtl | anchor codesample',
|
||||
}}
|
||||
onEditorChange={(newValue, editor) => {
|
||||
setData(
|
||||
'description',
|
||||
editor.getContent()
|
||||
)
|
||||
}}
|
||||
/>
|
||||
</Suspense>
|
||||
</div>
|
||||
|
||||
<div className="mt-8">
|
||||
<Button
|
||||
onClick={handleSubmit}
|
||||
processing={processing}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AuthenticatedLayout>
|
||||
)
|
||||
}
|
@ -1,104 +0,0 @@
|
||||
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,263 @@
|
||||
import React, { useRef, useEffect, useState } from 'react'
|
||||
import { useDebounce } from '@/hooks'
|
||||
import { usePage } from '@inertiajs/react'
|
||||
import axios from 'axios'
|
||||
import { HiChevronDown, HiChevronUp, HiX } from 'react-icons/hi'
|
||||
import { Spinner } from 'flowbite-react'
|
||||
|
||||
export default function SelectionInput(props) {
|
||||
const ref = useRef()
|
||||
const {
|
||||
props: { auth },
|
||||
} = usePage()
|
||||
|
||||
const {
|
||||
label = '',
|
||||
itemSelected = null,
|
||||
onItemSelected = () => {},
|
||||
disabled = false,
|
||||
placeholder = '',
|
||||
error = '',
|
||||
all = 0,
|
||||
} = props
|
||||
|
||||
const [showItems, setShowItem] = useState([])
|
||||
|
||||
const [isSelected, setIsSelected] = useState(true)
|
||||
const [selected, setSelected] = useState(null)
|
||||
|
||||
const [query, setQuery] = useState('')
|
||||
const q = useDebounce(query, 300)
|
||||
|
||||
const [isOpen, setIsOpen] = useState(false)
|
||||
const [loading, setLoading] = useState(false)
|
||||
|
||||
const toggle = () => {
|
||||
setQuery('')
|
||||
setIsOpen(!isOpen)
|
||||
}
|
||||
|
||||
const onInputMouseDown = () => {
|
||||
setIsSelected(false)
|
||||
setQuery('')
|
||||
setIsOpen(!isOpen)
|
||||
}
|
||||
|
||||
const handleSelectItem = (item) => {
|
||||
setIsSelected(true)
|
||||
onItemSelected(item.id)
|
||||
setSelected(item.name)
|
||||
setIsOpen(false)
|
||||
}
|
||||
|
||||
const removeItem = () => {
|
||||
setIsSelected(false)
|
||||
setSelected('')
|
||||
onItemSelected(null)
|
||||
}
|
||||
|
||||
const filterItems = (value) => {
|
||||
setIsSelected(false)
|
||||
setQuery(value)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (isOpen === true) {
|
||||
const checkIfClickedOutside = (e) => {
|
||||
if (isOpen && ref.current && !ref.current.contains(e.target)) {
|
||||
setIsOpen(false)
|
||||
if (selected !== null) {
|
||||
setIsSelected(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
document.addEventListener('mousedown', checkIfClickedOutside)
|
||||
return () => {
|
||||
document.removeEventListener('mousedown', checkIfClickedOutside)
|
||||
}
|
||||
}
|
||||
}, [isOpen])
|
||||
|
||||
const fetch = (q = '') => {
|
||||
setLoading(true)
|
||||
axios
|
||||
.get(route('api.customer-level.index', { q: q, all: all }), {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
// 'Authorization': 'Bearer ' + auth.user.jwt_token
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
setShowItem(response.data)
|
||||
})
|
||||
.catch((err) => {
|
||||
alert(err)
|
||||
})
|
||||
.finally(() => setLoading(false))
|
||||
}
|
||||
|
||||
// every select item open
|
||||
useEffect(() => {
|
||||
if (isOpen) {
|
||||
fetch(q)
|
||||
}
|
||||
}, [q, isOpen])
|
||||
|
||||
// once page load
|
||||
useEffect(() => {
|
||||
fetch()
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
if (disabled) {
|
||||
setSelected('')
|
||||
}
|
||||
}, [disabled])
|
||||
|
||||
useEffect(() => {
|
||||
if (itemSelected !== null) {
|
||||
const item = showItems.find((item) => item.id === itemSelected)
|
||||
if (item) {
|
||||
setSelected(item.name)
|
||||
setIsSelected(true)
|
||||
}
|
||||
return
|
||||
}
|
||||
setIsSelected(false)
|
||||
}, [itemSelected, loading])
|
||||
|
||||
useEffect(() => {
|
||||
if (isSelected && selected === '') {
|
||||
setSelected('')
|
||||
setIsSelected(false)
|
||||
}
|
||||
}, [isSelected])
|
||||
|
||||
return (
|
||||
<div className="flex flex-col items-center" ref={ref}>
|
||||
<div className="w-full flex flex-col items-center">
|
||||
<div className="w-full">
|
||||
<div className="flex flex-col relative">
|
||||
{label !== '' && (
|
||||
<label
|
||||
htmlFor="first_name"
|
||||
className="mb-2 block text-sm font-medium text-gray-900 dark:text-white"
|
||||
>
|
||||
{label}
|
||||
</label>
|
||||
)}
|
||||
<div className="w-full">
|
||||
<div
|
||||
className={`p-1.5 bg-gray-50 dark:bg-gray-700 flex border rounded-lg
|
||||
${
|
||||
error
|
||||
? 'border-red-500'
|
||||
: 'border-gray-300 dark:border-gray-600'
|
||||
}
|
||||
${disabled ? 'bg-gray-50' : ''}`}
|
||||
>
|
||||
<input
|
||||
className="block w-full text-sm bg-gray-50 text-gray-900 dark:border-gray-700 border cursor-pointer dark:text-gray-300 outline-none border-transparent dark:bg-gray-700 dark:placeholder-gray-400 px-1"
|
||||
onMouseDown={onInputMouseDown}
|
||||
placeholder={placeholder}
|
||||
value={`${
|
||||
isSelected
|
||||
? selected === null
|
||||
? ''
|
||||
: selected
|
||||
: query
|
||||
}`}
|
||||
onChange={(e) =>
|
||||
filterItems(e.target.value)
|
||||
}
|
||||
disabled={disabled}
|
||||
/>
|
||||
{isSelected && (
|
||||
<div
|
||||
onClick={
|
||||
disabled ? () => {} : removeItem
|
||||
}
|
||||
>
|
||||
<button className="cursor-pointer w-6 h-6 text-red-300 outline-none focus:outline-none">
|
||||
<HiX />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
<div onClick={disabled ? () => {} : toggle}>
|
||||
<button className="cursor-pointer w-6 h-6 text-gray-300 outline-none focus:outline-none">
|
||||
{isOpen ? (
|
||||
<HiChevronUp />
|
||||
) : (
|
||||
<HiChevronDown />
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{error && (
|
||||
<p className="mb-2 text-sm text-red-600 dark:text-red-500">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
{isOpen && (
|
||||
<div
|
||||
className="absolute mt-1 shadow-lg bg-gray-50 dark:bg-gray-700 dark:text-gray-200 top-100 z-40 w-full lef-0 rounded overflow-y-auto"
|
||||
style={{ maxHeight: '300px', top: '100%' }}
|
||||
>
|
||||
<div className="flex flex-col w-full">
|
||||
{loading ? (
|
||||
<div>
|
||||
<div className="flex w-full items-center p-2 pl-2 border-transparent border-l-2 relative hover:border-neutral-content">
|
||||
<div className="w-full items-center justify-center flex">
|
||||
<div className="mx-2 my-5">
|
||||
<Spinner className="mr-2" />
|
||||
<span>Loading...</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
{showItems.map((item, index) => (
|
||||
<div
|
||||
key={index}
|
||||
onClick={() =>
|
||||
handleSelectItem(item)
|
||||
}
|
||||
>
|
||||
<div className="flex w-full items-center p-2 pl-2 border-transparent border-l-2 relative hover:border-neutral-content hover:bg-gray-400 bg-opacity-10 dark:hover:bg-gray-200 dark:hover:bg-opacity-10 dark:hover:text-gray-100">
|
||||
<div className="w-full items-center flex">
|
||||
<div className="mx-2">
|
||||
<span>
|
||||
{item.name}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{showItems.length <= 0 && (
|
||||
<div>
|
||||
<div className="flex w-full items-center p-2 pl-2 border-transparent border-l-2 relative hover:border-neutral-content">
|
||||
<div className="w-full items-center justify-center flex">
|
||||
<div className="mx-2 my-5">
|
||||
<span>
|
||||
No Items
|
||||
Found
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue