import React, { useState, useEffect } from 'react' import { router, useForm, usePage } from '@inertiajs/react' import { isEmpty } from 'lodash' import { HiOutlineClipboardDocumentList } from 'react-icons/hi2' import { toastSuccess } from '@/Customer/utils' import FormFile from '@/Components/FormFile' import Alert from '@/Components/Alert' export const FormUploadCashDeposit = () => { const { props: { deposit_locations, deposit, flash }, } = 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)), 3000 ), }) } useEffect(() => { if (deposit.deposit_location !== null) { handleSelectLocation(deposit.deposit_location_id) } }, [deposit]) if (isEmpty(imageUrl) == false) { return (
Total Deposit | : | {deposit.amount} |
|