Concept explainers
My react app is adding a new item instead of updating and replacing the item. Instead of replacing the item it adds another new item underneath it.
The code:
import Button from "./Button" import Input from "./Input" import { useForm } from 'react-hook-form' import { server_calls } from '../api/server' import { useDispatch, useStore } from 'react-redux'; import { chooseISBN, chooseAuthor, chooseTitle, chooseLength, chooseCover } from "../redux/slices/RootSlice"; interface ContactFormProps { id?: string[] } const ContactForm = (props:ContactFormProps) => { const { register, handleSubmit } = useForm({}) const dispatch = useDispatch(); const store = useStore(); const onSubmit = (data: any, event: any) => { console.log(`ID: ${typeof props.id}`); console.log(props.id) console.log(data) if (props.id && props.id.length > 0 ) { server_calls.update(props.id[0], data) console.log(`Updated: ${ data.name } ${ props.id }`) setTimeout(() => {window.location.reload()}, 1000); event.target.reset() } else { dispatch(chooseISBN(data.isbn_number)); dispatch(chooseAuthor(data.author_name)); dispatch(chooseTitle(data.book_title)); dispatch(chooseLength(data.book_length)); dispatch(chooseCover(data.hardcover_or_paperback)); server_calls.create(store.getState()) setTimeout( () => {window.location.reload()}, 1000); } } return ( <div> <form onSubmit={handleSubmit(onSubmit)}> <div> <label htmlFor="isbn_number">ISBN</label> <Input {...register('isbn_number')} name='isbn_number' placeholder="ISBN"/> </div> <div> <label htmlFor="author_name">Author</label> <Input {...register('author_name')} name='author_name' placeholder="Author"/> </div> <div> <label htmlFor="book_title">Title</label> <Input {...register('book_title')} name='book_title' placeholder="Title"/> </div> <div> <label htmlFor="book_length">Length</label> <Input {...register('book_length')} name='book_length' placeholder="Length"/> </div> <div> <label htmlFor="hardcover_or_paperback">Cover</label> <Input {...register('hardcover_or_paperback')} name='hardcover_or_paperback' placeholder="Cover"/> </div> <div className="flex p-1"> <Button className="flex justify-start m-3 bg-slate-300 p-2 rounded hover:bg-slate-800 text-white" > Submit </Button> </div> </form> </div> ) } export default ContactForm
Step by stepSolved in 3 steps
- Study the scenario and complete the questions that follow: Hotel Application Shawn owner of a small hotel has asked that a new online-based application be built that would permit potential visitors to make a room reservation, indicating the dates and type of room- they want. The system is supposed to distinguish already registered customers to speed up the process; else, they must register as a new client. Each reservation is given a reservation ID or code. Before clients checking into the hotel, they may enter the reservation ID to alter or cancel their reservation. The changes might include changing the dates, room number or type, or the number of visitors per room. The administrator must use the reservation ID to check the client in when they arrive. The same ID is supposed to be used by the proposed system when the clients check-out to record their payment. An electronic printed invoice must be generated to the client's email. The system must allow the hotel manager to view reports…arrow_forwardCreate a new javascript file called cart.js and make a product object for each of your products and store it in a products array when the script loads. Create an empty array to store the items added to the cart. Program the "add to cart button" to take the product id, finds the product object in the products array and adds it to the items added to cart array. Program the "remove from cart button" to take the product id and remove the project object from the items purchased array. Existing code: <!DOCTYPE html><html> <head> <div id="product1" class="card"><img src="img/clorox.jpg"><h1>Clorox</h1><p class="price">$20.00</p><p>Household Cleaner</p><p><button id="product1Btn1">Add to Cart</button></p><p><button id="product1Btn2">Remove from Cart</button></p></div> <div id="product2" class="card"><img src="img/oxiclean.jpg"><h1>Oxiclean</h1><p…arrow_forwardomplete this javascript file according to the individual instructionsgiven in the comments. *** DO NOT CHANGE any of the code that you are not instructed to. */ ////////////////////////// NOTE: Use the API endpoints available at// https://jsonplaceholder.typicode.com/// to get the data required in these exercises.// HINT: Read the documented Resources and Routes.// Also the guide:// https://jsonplaceholder.typicode.com/guide//////////////////////// Create a function named "getUser".// This function needs to accept a "userID"// parameter.// Use Fetch with Async/Await to request// the data for the requested user.// The function should return JSON data.arrow_forward
- I need help with the part below and please add comments in the code to help me understand better what I am doing wrong in my own code. I have already created my database and the connection and some of the code but am stuck on these parts."Home" and "Create Account" pages The index.php file will ask the user to log in to the system with a login form If they're already logged in, the home page will NOT show the login form. It will show a "welcome to our store" type of message instead even if they click on the "home" button in the navigation. The create-account.php page has them fill out a form for creating an account. Use real-time JavaScript validation (and regex) to: Verify that the password and "verify password" match as they are typing. Verify that the password contains at least one number and is at least 8 characters long Be sure to display user feedback messages on the screen as they type, e.g.: Password must contain a number Password must be 8 characters long Password and…arrow_forwardI have posted this multiple times and people keep giving me answers that don't correspond to the question or is unloadable. So please read this carefully. Answer the operand given below on the bottom left and the fill in its value that is on the bottom right. Please make it loadable before sending as previous tutors sent a black page and please answer what is being asked in the question !! Again bottom left is the operand and please fill in its value which is on the bottom right..arrow_forwardEvent Listeners Return to the mas_register.js file in your editor. Directly below the initial comment section, insert an event listener for the window load event. Run an anonymous function in response to the event containing the following commands: Call the calcCart() function (which you will create shortly.) Create an onclick event handler for the regSubmit button that runs the sessionTest() function when the button is clicked. Create onblur event handlers for the input boxes with the ids: fnBox, lnBox, groupBox, mailBox, phoneBox, and banquetBox, running the calcCart() function in response to each event. Create an onchange event handler for the sessionBox selection list, running the calcCart() function when the selection list is changed. Create an onclick event handler for the mediaCB check box, running the calcCart() function in response. JavaScript Functions Create the sessionTest() function. The purpose of this function is to provide a validation test for the conference session…arrow_forward
- The last one is RESIGN INACCURACIES this relates to the type of machine or the process used during printing; the printers have a low tolerance meaning that the final product or parts after printing looks different from the original design. It could be fixed but this will increase the time and cost of production.arrow_forwardCreate an application that lets you enter a new customer or a new employee. ConsoleWelcome to the Person ManagerCreate customer or employee? (c/e):Error! This entry is required. Try again.Create customer or employee? (c/e): pError! Entry must be 'c' or 'e'. Try again.Create customer or employee? (c/e): cFirst name: SteveLast name: TrevorCustomer number: M10293You entered a new Customer:Name: Steve TrevorCustomer Number: M10293Continue? (y/n): yCreate customer or employee? (c/e): eFirst name: DianaLast name: PrinceSSN: 111-22-3333You entered a new Employee:Name: Diana PrinceSSN: xxx-xx-3333Continue? (y/n): OKError! Entry must be 'y' or 'n'. Try again.Continue? (y/n): n SpecificationsCreate a class named Person with these constructors and methods: public Person(String first, String last)public String getFirstName()public void setFirstName(String first)public String getLastName()public void setLastName()The Person class should override the toString() method so it returns the first name…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education