import React, { useState, useEffect } from 'react' import { router, useForm, usePage } from '@inertiajs/react' import { isEmpty } from 'lodash' import { HiOutlineClipboardDocumentList } from 'react-icons/hi2' import { formatIDR } from '@/utils' import { toastSuccess } from '@/Customer/utils' import FormFile from '@/Components/FormFile' import Alert from '@/Components/Alert' export const FormUploadCashDeposit = () => { const { props: { deposit_locations, deposit, flash, cash_admin_fee }, } = usePage() const [imageUrl, setImageUrl] = useState(deposit.image_prove_url) const [location, setLocation] = useState(null) const { data, setData, errors, processing, post } = useForm({ deposit_location_id: '', image: null, image_url: deposit.image_prove_url, }) const handleSelectLocation = (id) => { if (id === '') { setData('deposit_location_id', '') setLocation(null) return } const location = deposit_locations.find((acc) => acc.id === id) setData('deposit_location_id', location.id) setLocation(location) } 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)), 500 ), }) } useEffect(() => { if (deposit.deposit_location !== null) { handleSelectLocation(deposit.deposit_location_id) } }, [deposit]) if (isEmpty(imageUrl) == false) { return (
Bukti Pembayaran
bukti Pembayaran
setImageUrl(null)} > Ubah Bukti Pembayaran
) } return (
{flash.message.message}
Lokasi Pembayaran
{location !== null ? (
handleSelectLocation(location.id)} >
image location
{location.name}
+62{location.phone}
Alamat : {location.address}
Jam Buka :{' '} {location.operational_hour}
handleSelectLocation('')} >
Ubah
) : (
{deposit_locations.map((location) => (
handleSelectLocation(location.id) } >
image location
{location.name}
+62{location.phone}
Alamat : {location.address}
Jam Buka :{' '} {location.operational_hour}
))}
)}
{location !== null && ( <>
{location.name}
Alamat : {location.address}
handleCopyToClipboard( '+62' + location.phone ) } >
Whatsapp :
+62{location.phone}
Rincian
handleCopyToClipboard( +cash_admin_fee + +deposit.debit ) } >
Jumlah Deposit : {deposit.amount}
Biaya Admin : {+cash_admin_fee === 0 ? ( 'Gratis' ) : ( <> Rp.{' '} {formatIDR( +cash_admin_fee )} )}
Total Bayar : Rp.{' '} {formatIDR( +cash_admin_fee + +deposit.debit )}
Bukti Pembayaran
{isEmpty(data.image_url) == false && ( bukti Pembayaran )}
setData('image', e.target.files[0])} error={errors.image} />
upload gambar dalam ekstensi jpg, png, jpeg
handleSubmit()} > Upload
)}
) }