import React, { useEffect, useRef } from 'react' import NumberFormat from 'react-number-format' import { useForm } from '@inertiajs/inertia-react' import { toast } from 'react-toastify' import { formatIDR } from '@/utils' export default function FormProductModal(props) { const { isOpen, toggle = () => {}, product = null } = props const { data, setData, post, processing, errors, clearErrors } = useForm({ name: '', price: 0, description: '', photo: null, img_alt: null, }) const inputPhoto = useRef() const handleOnChange = (event) => { setData(event.target.name, event.target.value) } const handleReset = () => { setData({ name: '', price: 0, description: '', photo: null, img_alt: null, }) clearErrors() } const handleCancel = () => { handleReset() toggle() } const handleSubmit = () => { if (product !== null) { post(route('products.update', product), { forceFormData: true, onSuccess: () => Promise.all([ handleReset(), toggle(), toast.success('The Data has been changed'), ]), }) return } post(route('products.store'), { onSuccess: () => Promise.all([ handleReset(), toggle(), toast.success('The Data has been saved'), ]), }) } useEffect(() => { setData({ name: product?.name ? product.name : '', price: formatIDR(product?.price ? product.price : 0), description: product?.description ? product.description : '', img_alt: product?.photo_url ? product.photo_url : null, }) }, [product]) return (

Barang

setData('price', value)} placeholder="harga" />