tambah logo di admin bank akun
parent
5a64b99860
commit
dc4a5eea4b
Binary file not shown.
After Width: | Height: | Size: 5.9 KiB |
Binary file not shown.
After Width: | Height: | Size: 90 KiB |
@ -0,0 +1,115 @@
|
||||
import React, { useEffect } from 'react'
|
||||
import { isEmpty } from 'lodash'
|
||||
|
||||
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'
|
||||
import FormInput from '@/Components/FormInput'
|
||||
import FormFile from '@/Components/FormFile'
|
||||
import Button from '@/Components/Button'
|
||||
import { Head, useForm } from '@inertiajs/react'
|
||||
|
||||
export default function Form(props) {
|
||||
const { account } = props
|
||||
|
||||
const { data, setData, post, processing, errors } = useForm({
|
||||
name: '',
|
||||
bank_name: '',
|
||||
holder_name: '',
|
||||
account_number: '',
|
||||
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 = () => {
|
||||
if (isEmpty(account) === false) {
|
||||
post(route('account.update', account))
|
||||
return
|
||||
}
|
||||
post(route('account.store'))
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (isEmpty(account) === false) {
|
||||
setData({
|
||||
name: account.name,
|
||||
bank_name: account.bank_name,
|
||||
holder_name: account.holder_name,
|
||||
account_number: account.account_number,
|
||||
logo_url: account.logo_url
|
||||
})
|
||||
}
|
||||
}, [account])
|
||||
|
||||
return (
|
||||
<AuthenticatedLayout page={'Bank Akun'} action={'Form'}>
|
||||
<Head title="Bank Akun" />
|
||||
|
||||
<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">Bank Akun</div>
|
||||
<FormInput
|
||||
name="name"
|
||||
value={data.name}
|
||||
onChange={handleOnChange}
|
||||
label="Nama"
|
||||
error={errors.name}
|
||||
/>
|
||||
<FormInput
|
||||
name="bank_name"
|
||||
value={data.bank_name}
|
||||
onChange={handleOnChange}
|
||||
label="Nama Bank"
|
||||
error={errors.bank_name}
|
||||
/>
|
||||
<FormInput
|
||||
name="holder_name"
|
||||
value={data.holder_name}
|
||||
onChange={handleOnChange}
|
||||
label="Atas Nama Rekening"
|
||||
error={errors.holder_name}
|
||||
/>
|
||||
<FormInput
|
||||
name="account_number"
|
||||
value={data.account_number}
|
||||
onChange={handleOnChange}
|
||||
label="Nomor Rekening"
|
||||
error={errors.account_number}
|
||||
/>
|
||||
<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="mt-8">
|
||||
<Button
|
||||
onClick={handleSubmit}
|
||||
processing={processing}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AuthenticatedLayout>
|
||||
)
|
||||
}
|
@ -1,95 +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({
|
||||
info: '',
|
||||
is_publish: 1,
|
||||
})
|
||||
|
||||
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 info = modalState.data
|
||||
if (info !== null) {
|
||||
put(route('info.update', info), {
|
||||
onSuccess: () => handleClose(),
|
||||
})
|
||||
return
|
||||
}
|
||||
post(route('info.store'), {
|
||||
onSuccess: () => handleClose(),
|
||||
})
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const info = modalState.data
|
||||
if (isEmpty(info) === false) {
|
||||
setData({
|
||||
info: info.title,
|
||||
is_publish: info.is_publish,
|
||||
})
|
||||
return
|
||||
}
|
||||
}, [modalState])
|
||||
|
||||
return (
|
||||
<Modal isOpen={modalState.isOpen} toggle={handleClose} title={'Info'}>
|
||||
<FormInput
|
||||
name="info"
|
||||
value={data.info}
|
||||
onChange={handleOnChange}
|
||||
label="info"
|
||||
error={errors.info}
|
||||
/>
|
||||
<div className="my-4">
|
||||
<div className="mb-1 text-sm">Publish </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.is_publish}
|
||||
name="is_publish"
|
||||
>
|
||||
<option value={0}>No</option>
|
||||
<option value={1}>Yes</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="flex items-center">
|
||||
<Button onClick={handleSubmit} processing={processing}>
|
||||
Simpan
|
||||
</Button>
|
||||
<Button onClick={handleClose} type="secondary">
|
||||
Batal
|
||||
</Button>
|
||||
</div>
|
||||
</Modal>
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue