/* OpenBills-web - Web based libre billing software * Copyright (C) 2022 Vidhu Kant Sharma * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ import { Item, InvoiceItem, getAllItems } from '../../classes/item'; import './scss/item-picker.scss'; import { useState, useEffect } from 'react'; import { Link } from 'react-router-dom'; //import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' //import { faPhone, faEnvelope, faGlobe } from '@fortawesome/free-solid-svg-icons' const ItemPicker = ({invoiceItems, addInvoiceItem}) => { const [items, setItems] = useState([new Item()]); const [item, setItem] = useState(new InvoiceItem()); useEffect(() => refreshItems, []); const refreshItems = () => getAllItems(setItems, () => {}); const handleItemSelect = e => { const i = items.find(i => i.Id === e.target.value); setItem(prevItem => i ? ({...prevItem, ...i}) : new InvoiceItem()); } const handleInput = e => { const { name, value } = e.target; setItem(prevItem => ({ ...prevItem, [name]: value })); } // add item to the invoice items list const addItem = (e) => { e.preventDefault(); addInvoiceItem(item); setItem(new InvoiceItem()); } // input elements are sorted on the basis of // how likely they are going to be edited return (

Add an Item

{items.length > 0 ? <> : }

); } export default ItemPicker;