Мне нужно чтобы работало создание и изменение сущностей. Также нужно чтобы выполнялось…
- User
Мне нужно чтобы работало создание и изменение сущностей. Также нужно чтобы выполнялось правило: Form submission: ● Values are sent to the server and stored in memory. ● The request payload should contain only what the user filled/changed. ○ On create: if a user filled 4 fields, the request payload must contain only 4 fields. ○ On edit: if a user changed only one field, the request payload must contain 1 field. ListItems.jsx import { useEffect, useState } from 'react'; import { getItems } from '../api'; import { ItemTable } from '../components/ItemTable'; import { Link } from 'react-router-dom';
export const ListItemsPage = () => { const [items, setItems] = useState([]);
useEffect(() => { getItems().then(response => setItems(response.data)); }, []);
return ( Warehouse Items Create New Item ); }; EditItems import { useEffect, useState } from 'react'; import { useParams, useNavigate } from 'react-router-dom'; import { getItems, updateItem } from '../api'; import { ItemForm } from '../components/ItemForm';
export const EditItemPage = () => { const { id } = useParams(); const navigate = useNavigate(); const [item, setItem] = useState(null);
useEffect(() => { getItems().then((response) => { const foundItem = response.data.find((item) => item.id === parseInt(id)); setItem(foundItem); }); }, [id]);
const handleSubmit = (data) => { updateItem(id, data).then(() => navigate('/')); };
return item ? ( Edit Item <button onClick={() => navigate('/')}>Back to List ) : ( Loading... ); }; CreateItem import { useNavigate } from 'react-router-dom'; import { createItem } from '../api'; import { ItemForm } from '../components/ItemForm';
export const CreateItemPage = () => { const navigate = useNavigate();
const handleSubmit = (data) => { createItem(data).then(() => navigate('/')); };
return ( Create Item <ItemForm onSubmit={handleSubmit} defaultValues={{ name: '', category: '', quantity: 1, tasks: [] }} /> <button onClick={() => navigate('/')}>Back to List ); }; ItemTable import { Link } from 'react-router-dom';
export const ItemTable = ({ items = [] }) => { return ( Name Category Quantity Location Supplier Supplier Location Price Type Price Endpoints Actions {items.length > 0 ? ( items.map((item) => ( {item.name} {item.category} {item.quantity} {item.location} {item.supplier || 'N/A'} {item.supplierLocation || 'N/A'} {item.showPriceDetails === 'yes' ? item.priceType : 'N/A'} {item.showPriceDetails === 'yes' && typeof item.price !== 'undefined' ? item.price : 'N/A'} {item.endpoints && item.endpoints.length > 0 ? ( {item.endpoints.map((endpoint, index) => ( {
${endpoint.endpoint} - ${endpoint.status}} ))} ) : ( No endpoints available )} <Link to={/edit/${item.id}}>Edit )) ) : ( No items available )} ); }; ItemForm import { useForm, useFieldArray } from 'react-hook-form'; import { yupResolver } from '@hookform/resolvers/yup'; import * as yup from 'yup'; import { useEffect } from 'react'; - Assistant