import React, { useState, useEffect } from 'react' import { router, useForm, usePage } from '@inertiajs/react' import { HiOutlineClipboardDocumentList } from 'react-icons/hi2' import { isEmpty } from 'lodash' import { toastSuccess } from '@/Customer/utils' import { formatIDR } from '@/utils' import FormFile from '@/Components/FormFile' import Alert from '@/Components/Alert' export const FormUploadManual = () => { const { props: { accounts, deposit, flash, bank_admin_fee }, } = usePage() const [imageUrl, setImageUrl] = useState(deposit.image_prove_url) const [account, setAccount] = useState(null) const { data, setData, errors, processing, post } = useForm({ account_id: '', image: null, image_url: deposit.image_prove_url, }) const handleSelectAccount = (id) => { if (id === '') { setData('account_id', '') setAccount(null) return } const account = accounts.find((acc) => acc.id === id) setData('account_id', account.id) setAccount(account) } const handleCopyToClipboard = (text) => { toastSuccess('copied to clipboard') navigator.clipboard.writeText(text) } const handleSubmit = () => { if (processing) { return } post(route('transactions.deposit.update', deposit), { replace: true, preserveState: true, onSuccess: () => setTimeout( () => router.get(route(route().current(), deposit)), 3000 ), }) } useEffect(() => { if (deposit.account !== null) { handleSelectAccount(deposit.account.id) } }, [deposit]) if (isEmpty(imageUrl) == false) { return (
Bukti Transfer
bukti transfer
setImageUrl(null)} > Ubah Bukti Transfer
) } return (
{flash.message.message}
Bank
{account !== null ? (
handleSelectAccount(account.id)} >
logo bank
{account.name} - {account.bank_name}
handleSelectAccount('')} >
Ubah
) : (
{accounts.map((account) => (
handleSelectAccount(account.id)} >
logo bank
{account.name} - {account.bank_name}
))}
)}
{account !== null && ( <>
{account.bank_name}
Atas Nama :{' '} {account.holder_name}
handleCopyToClipboard( account.account_number ) } >
Nomor Rekening :
{account.account_number}
Rincian
handleCopyToClipboard( +bank_admin_fee + +deposit.debit ) } >
Jumlah Deposit : {deposit.amount}
Biaya Admin : {+bank_admin_fee === 0 ? ( 'Gratis' ) : ( <> Rp.{' '} {formatIDR( +bank_admin_fee )} )}
Total Transfer : Rp.{' '} {formatIDR( +bank_admin_fee + +deposit.debit )}
Bukti Transfer
{isEmpty(data.image_url) == false && ( bukti transfer )}
setData('image', e.target.files[0])} error={errors.image} />
upload gambar dalam ekstensi jpg, png, jpeg
handleSubmit()} > Upload
)}
) }