Advertisement
fabiobiondi

React Pro - Real World App - Ch9. 11. Product Form - gestire EDIT e ADD - part. 2

Mar 23rd, 2023
1,301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // pages/cms/products/CMSProductsPage.tsx
  2. import { useEffect } from 'react';
  3. import { useProductsService } from '@/services/products';
  4. import { ServerError, Spinner } from '@/shared/';
  5. import { CMSProductForm } from './components/CMSProductForm';
  6. import { CMSProductsList } from './components/CMSProductsList';
  7.  
  8. export function CMSProductsPage() {
  9.   const { state, actions } = useProductsService();
  10.  
  11.   useEffect(() => {
  12.     actions.getProducts()
  13.   }, [])
  14.  
  15.   return (
  16.     <div>
  17.       <h1 className="title">CMS</h1>
  18.  
  19.       {state.pending && <Spinner />}
  20.       {state.error && <ServerError message={state.error} />}
  21.  
  22.       <CMSProductForm
  23.         activeItem={state.activeItem}
  24.         onClose={actions.resetActiveItem}
  25.         onAdd={actions.addProduct}
  26.         onEdit={actions.editProduct}
  27.       />
  28.  
  29.       <CMSProductsList
  30.         items={state.products}
  31.         activeItem={state.activeItem}
  32.         onEditItem={actions.setActiveItem}
  33.         onDeleteItem={actions.deleteProduct}
  34.       />
  35.  
  36.       <button
  37.         className="btn primary"
  38.         onClick={() => actions.setActiveItem({})}
  39.       >
  40.         ADD NEW
  41.       </button>
  42.  
  43.     </div>
  44.   )
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement