Deposit manual approve done
parent
0cf29e6911
commit
2f9cd2994c
@ -0,0 +1,162 @@
|
||||
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, processing, errors, reset, clearErrors } =
|
||||
useForm({
|
||||
amount: '',
|
||||
image_prove_url: '',
|
||||
status: '',
|
||||
account: {
|
||||
name: '',
|
||||
bank_name: '',
|
||||
holder_name: '',
|
||||
account_number: '',
|
||||
},
|
||||
payment_channel: '',
|
||||
is_valid: 0,
|
||||
status: '',
|
||||
status_text: '',
|
||||
text_color: '',
|
||||
customer_name: '',
|
||||
customer_phone: '',
|
||||
description: '',
|
||||
})
|
||||
|
||||
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 deposit = modalState.data
|
||||
post(route('deposit.update', deposit), {
|
||||
onSuccess: () => handleClose(),
|
||||
})
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const deposit = modalState.data
|
||||
if (isEmpty(deposit) === false) {
|
||||
setData({
|
||||
amount: deposit.amount,
|
||||
account: deposit.account,
|
||||
image_prove_url: deposit.image_prove_url,
|
||||
payment_channel: deposit.payment_channel,
|
||||
is_valid: deposit.is_valid,
|
||||
status_text: deposit.status.text,
|
||||
text_color: deposit.status.text_color,
|
||||
customer_name: `${deposit.customer.name} ( ${
|
||||
deposit.customer.phone ?? deposit.customer.email
|
||||
} )`,
|
||||
description: deposit.description,
|
||||
})
|
||||
return
|
||||
}
|
||||
}, [modalState])
|
||||
|
||||
return (
|
||||
<Modal
|
||||
isOpen={modalState.isOpen}
|
||||
toggle={handleClose}
|
||||
title={'Deposit'}
|
||||
>
|
||||
<table className="relative w-full overflow-x-auto border-collapse border p-2 rounded">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td className="font-bold">Customer</td>
|
||||
<td>:</td>
|
||||
<td>{data.customer_name}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td className="font-bold">Deskripsi</td>
|
||||
<td>:</td>
|
||||
<td>{data.description}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td className="font-bold">Metode Pembayaran</td>
|
||||
<td>:</td>
|
||||
<td>{data.payment_channel}</td>
|
||||
</tr>
|
||||
{data.account !== null && (
|
||||
<tr>
|
||||
<td className="font-bold">Bank Akun</td>
|
||||
<td>:</td>
|
||||
<td>
|
||||
{data.account.name} ({data.account.bank_name})
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
<tr>
|
||||
<td className="font-bold">Jumlah</td>
|
||||
<td>:</td>
|
||||
<td>{data.amount}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td className="font-bold">Status</td>
|
||||
<td>:</td>
|
||||
<td className={data.text_color}>{data.status_text}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{isEmpty(data.image_prove_url) === false && (
|
||||
<div>
|
||||
<img
|
||||
src={data.image_prove_url}
|
||||
className="w-full object-fill h-96"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{+data.is_valid !== 0 && (
|
||||
<>
|
||||
<div className="my-4">
|
||||
<div className="mb-1 text-sm">Status </div>
|
||||
<select
|
||||
className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5"
|
||||
onChange={handleOnChange}
|
||||
value={+data.status}
|
||||
name="status"
|
||||
>
|
||||
<option value=""></option>
|
||||
<option value={0}>Approve</option>
|
||||
<option value={5}>Reject</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="flex items-center">
|
||||
<Button onClick={handleSubmit} processing={processing}>
|
||||
Simpan
|
||||
</Button>
|
||||
<Button onClick={handleClose} type="secondary">
|
||||
Batal
|
||||
</Button>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</Modal>
|
||||
)
|
||||
}
|
@ -0,0 +1,169 @@
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { router } from '@inertiajs/react'
|
||||
import { usePrevious } from 'react-use'
|
||||
import { Head } from '@inertiajs/react'
|
||||
import { Button, Dropdown } from 'flowbite-react'
|
||||
import { HiPencil, HiTrash } from 'react-icons/hi'
|
||||
import { useModalState } from '@/hooks'
|
||||
|
||||
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'
|
||||
import Pagination from '@/Components/Pagination'
|
||||
import ModalConfirm from '@/Components/ModalConfirm'
|
||||
import FormModal from './FormModal'
|
||||
import SearchInput from '@/Components/SearchInput'
|
||||
import { formatIDR, hasPermission } from '@/utils'
|
||||
import { HiEye } from 'react-icons/hi2'
|
||||
|
||||
export default function Info(props) {
|
||||
const {
|
||||
query: { links, data },
|
||||
auth,
|
||||
} = props
|
||||
|
||||
const [search, setSearch] = useState('')
|
||||
const preValue = usePrevious(search)
|
||||
|
||||
const formModal = useModalState()
|
||||
|
||||
const toggleFormModal = (deposit = null) => {
|
||||
formModal.setData(deposit)
|
||||
formModal.toggle()
|
||||
}
|
||||
|
||||
const params = { q: search }
|
||||
useEffect(() => {
|
||||
if (preValue) {
|
||||
router.get(
|
||||
route(route().current()),
|
||||
{ q: search },
|
||||
{
|
||||
replace: true,
|
||||
preserveState: true,
|
||||
}
|
||||
)
|
||||
}
|
||||
}, [search])
|
||||
|
||||
const canUpdate = hasPermission(auth, 'update-deposit')
|
||||
|
||||
return (
|
||||
<AuthenticatedLayout
|
||||
auth={props.auth}
|
||||
errors={props.errors}
|
||||
flash={props.flash}
|
||||
page={'Deposit'}
|
||||
action={''}
|
||||
>
|
||||
<Head title="Deposit" />
|
||||
|
||||
<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 className="flex items-center">
|
||||
<SearchInput
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
value={search}
|
||||
/>
|
||||
</div>
|
||||
</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"
|
||||
>
|
||||
Customer
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
className="py-3 px-6"
|
||||
>
|
||||
Deposit
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
className="py-3 px-6"
|
||||
>
|
||||
Deskripsi
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
className="py-3 px-6"
|
||||
>
|
||||
Status
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
className="py-3 px-6"
|
||||
/>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data.map((deposit) => (
|
||||
<tr
|
||||
className="bg-white border-b dark:bg-gray-800 dark:border-gray-700"
|
||||
key={deposit.id}
|
||||
>
|
||||
<td
|
||||
scope="row"
|
||||
className="py-4 px-6 font-medium text-gray-900 whitespace-nowrap dark:text-white"
|
||||
>
|
||||
{deposit.customer.name}
|
||||
</td>
|
||||
<td className="py-4 px-6">
|
||||
{deposit.amount}
|
||||
</td>
|
||||
<td className="py-4 px-6">
|
||||
{deposit.description}
|
||||
</td>
|
||||
<td
|
||||
className={`py-4 px-6 ${deposit.status.text_color}`}
|
||||
>
|
||||
{deposit.status.text}
|
||||
</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(
|
||||
deposit
|
||||
)
|
||||
}
|
||||
>
|
||||
<div className="flex space-x-1 items-center">
|
||||
<HiEye />
|
||||
<div>
|
||||
Lihat
|
||||
</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