> To build or manage a Wix site with an AI agent, follow https://www.wix.com/headless/skill.md
> It builds a new Wix site or puts your own site online, from a prompt, and keeps changing it afterwards. The pages are code in any web technology, and Wix runs the backend.
> It works through the Wix plugin (the Wix MCP and the Wix skills), the Wix CLI or no Wix login, and puts the site live on Wix hosting or on another host.
> Business features include a store, bookings, events and tickets, a restaurant, a blog, forms, members and many more.
> Read the Wix skills online at https://www.wix.com/skills
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: Tutorial | Create a Custom Products Catalog App with the CLI

## Article: Tutorial | Create a Custom Products Catalog App with the CLI

## Article Link: https://dev.wix.com/docs/build-apps/get-started/tutorials/tutorial-create-a-custom-products-catalog-app-with-the-cli.md

## Article Content:

# Tutorial | Create a Custom Products Catalog App with the CLI

This tutorial demonstrates how to use the [Wix CLI](https://dev.wix.com/docs/wix-cli/cli-for-apps/about-the-wix-cli-for-apps.md) to build a Custom Products Catalog app on the [Wix Platform](https://dev.wix.com/docs/build-apps/get-started/overview/the-wix-ecosystem.md). The app contains a dashboard page that lists, searches, sorts, adds, and deletes products in a Wix Stores catalog.

> **Note:** This tutorial uses the [Stores Catalog V3 API](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v3/products-v3/introduction.md) only. This is sufficient for private apps. However, apps published to the Wix App Market should support both the [V1](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v1/catalog/introduction.md) and [V3](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v3/products-v3/introduction.md) Stores Catalog APIs. For more details, see [Exposing Apps Publicly and Privately](https://dev.wix.com/docs/build-apps/get-started/overview/exposing-apps-publicly-and-privately.md).

By following this tutorial, you'll learn how to:

- Build a collection-style dashboard page (with toolbar, filters, sorting, bulk actions) using the [Wix Design System](https://www.wixdesignsystem.com/) and Wix Patterns.
- Read, write, and bulk-delete products using the [Wix Stores Products V3 API](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v3/products-v3/introduction?apiView=SDK.md).
- Manage SDK call state with React Query.

The end result will look like this:

![App preview](https://wixmp-833713b177cebf373f611808.wixmp.com/images/9376e20a870d954427e43694f3428287.png)

We'll use the following steps to build the Custom Products Catalog app:

1. [Initialize the app](#step-1--initialize-the-app).
1. [Create the dashboard page](#step-2--create-the-dashboard-page).
1. [Run a local development server](#step-3--run-a-local-development-server).
1. [Add permissions](#step-4--add-permissions).
1. [Set up Wix Stores](#step-5--set-up-wix-stores).
1. [Install dependencies](#step-6--install-dependencies).
1. [Set up wrappers for our dashboard page component](#step-7--set-up-wrappers-for-our-dashboard-page-component).
1. [Create hooks for our SDK calls](#step-8--create-hooks-for-our-sdk-calls).
1. [Create a "Create Product" modal](#step-9--create-a-create-product-modal).
1. [Create a dashboard page component](#step-10--create-a-dashboard-page-component).
1. [Test the app](#step-11--test-the-app).
1. [Build and deploy the app](#step-12--build-and-deploy-the-app).

## Before you begin

Before getting started, make sure that:

- You install [Node.js](https://nodejs.org/en/download/) (v24.22.1 or higher).
- You install [npm](https://www.npmjs.com/package/npm) or [yarn](https://www.npmjs.com/package/yarn).
- You're logged into your Wix Studio account. If you don't already have one, [sign up for a Wix Studio account](https://manage.wix.com/account/custom-apps).

We also recommend that you check out the [Patterns documentation](https://www.wix-pages.com/wix-patterns/?path=/story/getting-started--overview). Patterns is a complex React library. Familiarizing yourself with the basics will help you better understand the code in this tutorial.

## Step 1 | Initialize the app

We use the Wix CLI to initialize our Custom Products Catalog app. In the process of initializing our app, the Wix CLI automatically:

- Creates a new app in the [Custom Apps page](https://manage.wix.com/account/custom-apps) of your Wix Studio workspace.
- Sets up a new folder for your app in your local file system. The folder includes:
  - A `src` folder containing initial boilerplate code for an app with a dashboard page.
  - A `package.json` file containing your app dependencies.
- Creates a local Git repository for your app.

To initialize the app:

1. Open a terminal and navigate to the folder where you want to create your app.
1. Run the following command:

    ```bash
    npm create @wix/new@latest app
    ```

    If prompted to install the `@wix/create-new` package, press `y`.

1. Select **Create a new Wix app**.
1. Select **Create a basic app**.
1. Enter a name for your app. Let’s name our app `Custom Products Catalog`.
1. Press `Enter` to accept the default folder name (`custom-products-catalog`).
1. When asked to configure Wix MCP for your IDE, select your preferred MCP.

    A green **Success** message confirms that your app has been registered in the [Custom Apps page](https://manage.wix.com/account/custom-apps).

1. Press `Enter` to accept the default namespace (`custom-products-catalog`).
1. Press `Enter` to accept the default code identifier (`custom_products_catalog`).

You now have a new app in the [Custom Apps page](https://manage.wix.com/account/custom-apps), a new folder in your local file system, and a local Git repository for developing and testing your app.

## Step 2 | Create the dashboard page

We use the CLI's `generate` command to create a dashboard page for our app.

To create the dashboard page:

1. Navigate to your newly created folder for your app.

    ```bash
    cd custom-products-catalog
    ```

2. Run the following command and follow the prompts:

    ```bash
    wix app generate
    ```

3. When prompted for the kind of extension, select **Dashboard Page**.

4. When prompted for a page title, enter **Custom Products Catalog**.

5. When prompted for the page route, press `Enter` to accept the default (`custom-products-catalog`).

Upon completion, the extension files are created at `src/extensions/dashboard/pages/custom-products-catalog/`:

```bash
src
└── extensions
    └── dashboard
        └── pages
            └── custom-products-catalog
                ├── custom-products-catalog.extension.ts
                └── custom-products-catalog.tsx
```

For more information about these files, see [Dashboard Page Extension Files and Code](https://dev.wix.com/docs/build-apps/develop-your-app/develop-an-app-with-the-cli/supported-extensions/dashboard/dashboard-pages/dashboard-page-extension-files-and-code.md).

<blockquote class="tip">

**Tip:** The CLI's default scaffold also created a `my-page` extension at `src/extensions/dashboard/pages/my-page/`. You can leave it (it won't interfere with this tutorial) or delete the `my-page/` folder to keep the dashboard sidebar showing only the **Custom Products Catalog** page.

</blockquote>

## Step 3 | Run a local development server

Now that you’ve initialized your app, you can run a local development server to see the app in action, and view local changes as you develop your app.

To run a local development server for your app:

1. In the terminal, from your app's folder, run the following command:

    ```bash
    wix app dev
    ```

<blockquote class="important">

__Important:__ This tutorial uses Stores Catalog V3. New Wix sites use V3 by default. If you choose an existing site instead, confirm it uses V3 with the [Catalog Versioning API](https://dev.wix.com/docs/rest/business-solutions/stores/catalog-versioning/introduction.md).

</blockquote>

1. The first time you run the command, the CLI tells you that you don't have a development site configured. Press `Enter` to open the app installation page in your default browser. If the browser doesn't open, [install your app on your test site](https://dev.wix.com/docs/build-apps/launch-your-app/app-distribution/test-your-app-on-a-premium-site.md) manually, and then run `wix app dev` again.

1. In the **Select a development site** dialog, select the development site you'll use throughout this tutorial to run and test your app. To create a new one, click **Create Dev Site**. The newly created development site is automatically named **Dev Sitex** followed by a number, such as **Dev Sitex 12345**, and appears in your Wix account's list of sites.

1. Click **Test App** to install your app on your development site.

1. In the terminal, click the **Dashboard** link to open your development site's dashboard.

1. In the dashboard sidebar, click **Apps > Custom Products Catalog** to see your newly created app’s dashboard page. We add the content of our app’s dashboard page in the next step.

The page shows a header and an empty state.

Your app is now running on your development site. As you develop your app, any changes made to your app’s code are reflected in real time on your development site.

If your changes don’t show up, try refreshing the page, or closing and reopening the development site.

## Step 4 | Add permissions

In this step, we'll add permissions for the app. Every SDK API requires specific permissions to use. In this app, we will use the [`searchProducts()`](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v3/products-v3/search-products.md), [`createProduct()`](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v3/products-v3/create-product.md), and [`deleteProduct()`](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v3/products-v3/delete-product.md) functions in the [Wix Stores Products V3 API](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v3/products-v3/introduction.md) to get a list of all products, and to add and delete them.

To use these functions, we need to give our app permission requirements in the app dashboard. Once we do this, anyone installing the app will be prompted to grant the specified permissions.

Our app calls `searchProducts()` to read products and `createProduct()`/`deleteProduct()` to add and remove them, so it needs both a read and a write product scope. Each method's reference page (linked above) lists the exact scope it requires in its **Permission Scopes** section, including the scope's ID (for example, `SCOPE.STORES.PRODUCT_READ`).

To add a scope:

1. Go to the [**Permissions** tab](https://manage.wix.com/app-selector?title=Select+an+App&primaryButtonText=Select+Site&actionUrl=https%3A%2F%2Fdev.wix.com%2Fapps%2F%7BappId%7D%2Fdev-center-permissions) in your app's dashboard.
1. Click **Add Permissions**.
1. Search for the scope. Several scopes can have similar names, so match the one whose ID matches the scope ID shown on the method's reference page.
1. Check its checkbox under **Choose Permission Scopes** and click **Save**.
1. Repeat for each scope your methods require: a read scope for `searchProducts()`, and a write scope for `createProduct()` and `deleteProduct()`.

For more information on configuring permissions, see [Configure permissions for your app](https://dev.wix.com/docs/build-apps/develop-your-app/access/authorization/configure-permissions-for-your-app.md).

## Step 5 | Set up Wix Stores

Our app integrates with Wix Stores, so we need to set up Wix Stores on our site, then reinstall the app so that our site requests the required permissions:

1. Install the [Wix Stores](https://www.wix.com/app-market/wix-stores?searchLocation=home) app on your test site. You can create some new products, or use the sample ones provided by Wix.
1. Open your app’s dashboard in the [Custom Apps page](https://manage.wix.com/account/custom-apps).
1. Click **Test App**, then select **Test on dev site**. In the **Select a development site** dialog, choose your dev site and click **Test App**. The app is reinstalled on your dev site with the latest permissions.

## Step 6 | Install dependencies

Before we start coding our app, we need to install some npm packages. The `@wix/dashboard` and `@wix/design-system` packages come pre-installed in the project that the CLI generated.

In your terminal, run the following commands to install the remaining packages:

```bash
npm install @wix/patterns
npm install @wix/stores
```

The purpose of each of these packages will become clear as we progress.

## Step 7 | Set up wrappers for our dashboard page component

It’s finally time to start writing some code!

Our plan in this tutorial is to create a React component that defines our dashboard page. We’re going to wrap this component with providers that will manage our data fetching and provide Wix styling for our dashboard page component. 

To do this, we’ll create a higher-order component that will accept our dashboard page component and return it wrapped in the necessary providers.

To create the higher-order component:

1. Create a new file in your app's repo under `src > extensions > dashboard` named `withProviders.tsx`.

1. Import `FC` from React, `WixDesignSystemProvider` from the design system, and `WixPatternsProvider` from Patterns:

    ```js
    import type { FC } from 'react';
    import { WixDesignSystemProvider } from '@wix/design-system';
    import { WixPatternsProvider } from '@wix/patterns/provider';
    ```

   - `WixDesignSystemProvider` provides styling for Wix Design System components.
   - `WixPatternsProvider` provides styling and data manipulation for Wix Patterns components.

1. Write a function named `withProviders` to wrap our dashboard page component in `WixDesignSystemProvider` and `WixPatternsProvider`:

    ```js
    export function withProviders<P extends {} = {}>(Component: FC<P>) {
      return function WithProviders(props: P) {
        return (
          <WixDesignSystemProvider features={{ newColorsBranding: true }}>
            <WixPatternsProvider>
              <Component {...props} />
            </WixPatternsProvider>
          </WixDesignSystemProvider>
        );
      };
    }
    ```

Your complete **withProviders.tsx** file should look like this:

```js
import type { FC } from 'react';
import { WixDesignSystemProvider } from '@wix/design-system';
import { WixPatternsProvider } from '@wix/patterns/provider';

export function withProviders<P extends {} = {}>(Component: FC<P>) {
  return function WithProviders(props: P) {
    return (
      <WixDesignSystemProvider features={{ newColorsBranding: true }}>
        <WixPatternsProvider>
          <Component {...props} />
        </WixPatternsProvider>
      </WixDesignSystemProvider>
    );
  };
}
```

## Step 8 | Create hooks for our SDK calls

Our dashboard page component will need to make SDK calls to create and delete Wix Stores product data using React hooks. To simplify our component code, we define these in a separate TypeScript file.

To create your app’s React hooks:

1. Create a new folder in your app's repo under `src > extensions > dashboard` named `hooks`.
1. Create a new file in `src > extensions > dashboard > hooks` named `stores.ts`.
1. Import `productsV3` from Wix Stores so we can use the Wix Stores Products V3 API:

    ```js
    import { productsV3 } from '@wix/stores';
    ```

1. Import `useCallback`:

    ```js
    import { useCallback } from 'react';
    ```

    [`useCallback`](https://react.dev/reference/react/useCallback) is a react hook that caches a callback function, returning a memorized version of the function that changes only if one of the dependencies has changed. 
    
    We use this hook to define how a new product is created and how a product is deleted using the `optimisticActions` prop and `createProduct`/`deleteProduct` from `productsV3`. 
    Whenever any of these dependencies change, `useCallback` redefines the callback function.

1. Import `CollectionOptimisticActions`:

    ```js
    import { CollectionOptimisticActions } from '@wix/patterns';
    ```

    `CollectionOptimisticActions` is a class that provides a set of utilities for managing optimistic actions on a [Wix Collection](https://support.wix.com/en/article/cms-formerly-content-manager-creating-a-collection). It allows us to perform various actions, such as adding, updating, and deleting items from a collection while assuming that these actions will succeed, even before confirming with the server. Learn more about the [CollectionOptimisticActions class](https://www.wix-pages.com/wix-patterns/?path=/story/features-actions-updates--collectionoptimisticactions).

1. Create a function to create new products named `useCreateProduct`:

    ```js
    export function useCreateProduct(optimisticActions: CollectionOptimisticActions<productsV3.V3Product, {}>) {}
    ```

   Inside this function:

      1. Use `productsV3` to get the `createProduct()` function.
          
          ```js
          const { createProduct } = productsV3;
          ```
  
      1. Use `useCallback()` to manage our `createProduct()` call:

          ```js
          return useCallback((productName: string) => {
            const newProduct: productsV3.V3Product = {
              name: productName,
              productType: productsV3.ProductType.PHYSICAL,
              physicalProperties: {},
              variantsInfo: {
                variants: [{
                  choices: [],
                  price: {
                    actualPrice: { amount: '10' },
                  },
                }],
              },
            };

            optimisticActions.createOne(newProduct, {
              submit: async () => {
                const created = await createProduct(newProduct);
                return [created];
              },
              successToast: {
                message: `${newProduct.name} was successfully created`,
                type: 'SUCCESS',
              },
              errorToast: () => 'Failed to create product',
            });
          }, [optimisticActions, createProduct]);
          ```

          > **Note:** The [Products V3 API](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v3/products-v3/create-product.md) requires several fields on every product:
          >
          > - `productType`
          > - The matching properties block (`physicalProperties` when `productType` is `PHYSICAL`)
          > - `variantsInfo.variants` with at least one variant
          >
          > A production app would normally collect these values from the user. To keep the **Create Product** modal minimal, this tutorial only asks for a product name and hardcodes the rest in `useCreateProduct`, so every new product is a physical product priced at $10.

          Let's break down the above code:
          - **Lines 2-14**: Define the properties of the new product. Only `name` comes from user input; the other fields satisfy the V3 API's required-fields contract with fixed defaults.
          - **Lines 16-27**: Use `optimisticActions.createOne()` to create the new product.
            - **Lines 17-20**: Define the `submit` function. `createProduct` takes the V3 product object directly and returns the created product, so we pass `newProduct` from the closure and wrap the response in an array for the optimistic collection.
            - **Lines 21-24**: Define the toast to show when a product is created successfully.
            - **Line 25**: Define the toast to show when product creation fails.
          - **Line 28**: Define the dependencies for `useCallback()`.

    Your function should look like this:

    ```js
    export function useCreateProduct(optimisticActions: CollectionOptimisticActions<productsV3.V3Product, {}>) {
      const { createProduct } = productsV3;

      return useCallback((productName: string) => {
        const newProduct: productsV3.V3Product = {
          name: productName,
          productType: productsV3.ProductType.PHYSICAL,
          physicalProperties: {},
          variantsInfo: {
            variants: [{
              choices: [],
              price: {
                actualPrice: { amount: '10' },
              },
            }],
          },
        };

        optimisticActions.createOne(newProduct, {
          submit: async () => {
            const created = await createProduct(newProduct);
            return [created];
          },
          successToast: {
            message: `${newProduct.name} was successfully created`,
            type: 'SUCCESS',
          },
          errorToast: () => 'Failed to create product',
        });
      }, [optimisticActions, createProduct]);
    }
    ```

1. Create a function to delete products named `useDeleteProducts()`:

    ```js
    export function useDeleteProducts(optimisticActions: CollectionOptimisticActions<productsV3.V3Product, {}>) {}
    ```

   Inside this function:

      1. Use `productsV3` to get the `deleteProduct()` function.

          ```js
          const { deleteProduct } = productsV3;
          ```
  
      1. Use `useCallback()` to manage our `deleteProduct()` calls:

          ```js
          return useCallback((productsToDelete: productsV3.V3Product[]) => {
            optimisticActions.deleteMany(productsToDelete, {
              submit: async (deletedProducts: productsV3.V3Product[]) => (
                await Promise.all(
                  deletedProducts.map((product) => deleteProduct(product._id!))
                )
              ),
              successToast: {
                message: `${
                  productsToDelete.length > 1 ? 'Products' : 'Product'
                } deleted successfully`,
                type: 'SUCCESS',
              },
              errorToast: () => `Failed to delete ${
                productsToDelete.length > 1 ? 'Products' : 'Product'
              }`,
            });
          }, [optimisticActions, deleteProduct]);
          ```

          Let's break down the above code:
          - **Lines 2-17**: Use `optimisticActions.deleteMany()` to delete the products.
            - **Lines 3-7**: Define the submit function to handle product deletion. This function iterates over the array of products to delete and calls `deleteProduct()` for each one. `deleteProduct` takes the product ID directly as a string.
            - **Lines 8-13**: Define the toast to show when products are deleted successfully.
            - **Lines 14-16**: Define the toast to show when product deletion fails.
          - **Line 18**: Define the dependencies for `useCallback()`.

    Your function should look like this:

    ```js
    export function useDeleteProducts(optimisticActions: CollectionOptimisticActions<productsV3.V3Product, {}>) {
      const { deleteProduct } = productsV3;

      return useCallback((productsToDelete: productsV3.V3Product[]) => {
        optimisticActions.deleteMany(productsToDelete, {
          submit: async (deletedProducts: productsV3.V3Product[]) => (
            await Promise.all(
              deletedProducts.map((product) => deleteProduct(product._id!))
            )
          ),
          successToast: {
            message: `${
              productsToDelete.length > 1 ? 'Products' : 'Product'
            } deleted successfully`,
            type: 'SUCCESS',
          },
          errorToast: () => `Failed to delete ${
            productsToDelete.length > 1 ? 'Products' : 'Product'
          }`,
        });
      }, [optimisticActions, deleteProduct]);
    }
    ```

Your complete `stores.ts` file should look like this:

```js
import { productsV3 } from '@wix/stores';
import { useCallback } from 'react';
import { CollectionOptimisticActions } from '@wix/patterns';

export function useCreateProduct(optimisticActions: CollectionOptimisticActions<productsV3.V3Product, {}>) {
  const { createProduct } = productsV3;

  return useCallback((productName: string) => {
    const newProduct: productsV3.V3Product = {
      name: productName,
      productType: productsV3.ProductType.PHYSICAL,
      physicalProperties: {},
      variantsInfo: {
        variants: [{
          choices: [],
          price: {
            actualPrice: { amount: '10' },
          },
        }],
      },
    };

    optimisticActions.createOne(newProduct, {
      submit: async () => {
        const created = await createProduct(newProduct);
        return [created];
      },
      successToast: {
        message: `${newProduct.name} was successfully created`,
        type: 'SUCCESS',
      },
      errorToast: () => 'Failed to create product',
    });
  }, [optimisticActions, createProduct]);
}

export function useDeleteProducts(optimisticActions: CollectionOptimisticActions<productsV3.V3Product, {}>) {
  const { deleteProduct } = productsV3;

  return useCallback((productsToDelete: productsV3.V3Product[]) => {
    optimisticActions.deleteMany(productsToDelete, {
      submit: async (deletedProducts: productsV3.V3Product[]) => (
        await Promise.all(
          deletedProducts.map((product) => deleteProduct(product._id!))
        )
      ),
      successToast: {
        message: `${
          productsToDelete.length > 1 ? 'Products' : 'Product'
        } deleted successfully`,
        type: 'SUCCESS',
      },
      errorToast: () => `Failed to delete ${
        productsToDelete.length > 1 ? 'Products' : 'Product'
      }`,
    });
  }, [optimisticActions, deleteProduct]);
}
```

## Step 9 | Create a "Create Product" modal

We need a modal where the user can enter the name of the new product and confirm or cancel. This modal will be opened using a button on the dashboard page.
To build this modal:

1. Create a new folder in your app's repo under `src > extensions > dashboard` named `components`.
1. Create a new file in `src > extensions > dashboard > components` named `create-product.tsx`.
1. Import:
    - `React`, `useEffect`, and `useState`.
    - The components of the Wix Design System required to create our modal. Learn more about the [`Modal` component](https://www.wix-pages.com/design-system-documentation/#/component/modal).

    ```js
    import React, { useEffect, useState } from 'react';
    import {
      Modal,
      CustomModalLayout,
      FormField,
      Input,
    } from '@wix/design-system';
    import '@wix/design-system/styles.global.css';
    ```


1. Create a `CreateProductModal` component to define the appearance and functionality of the modal. Use the following code:

    ```js
    export function CreateProductModal({ showModal, onSave }: { showModal: boolean, onSave: (name: string) => void }) {
      const [productName, setProductName] = useState('');
      const [shown, setShown] = useState(showModal);
    
      useEffect(() => {
        setShown(showModal);
      }, [showModal])
    
      const toggleModal = () => {
        setShown(!shown);
        setProductName('');
      };
    
      return (
        <Modal
          isOpen={shown}
          onRequestClose={toggleModal}
          shouldCloseOnOverlayClick
          screen="desktop"
        >
          <CustomModalLayout
            title="Create Product"
            primaryButtonProps={{
              disabled: !productName,
              children: 'Save',
            }}
            primaryButtonOnClick={() => {
              onSave(productName)
              setProductName('')
            }}
            secondaryButtonText="Cancel"
            secondaryButtonOnClick={toggleModal}
            onCloseButtonClick={toggleModal}
            content={
              <FormField label="Name">
                <Input
                  value={productName}
                  onChange={(e) => setProductName(e.currentTarget.value)}
                />
              </FormField>
            }
          />
        </Modal>
      );
    }
    ```

    Let’s break down the above code:

    - **Lines 2-3**: Initialize state variables to manage the product name and the visibility of the modal.
    - **Lines 5-7**: Use `useEffect()` to ensure that when the `showModal` prop updates, the `shown` state variable aligns with it.
    - **Lines 9-12**: Set up a function to toggle the visibility of the modal and reset the product name input whenever the modal is shown or hidden.
    - **Lines 15-20**: Configure the modal to close when it’s toggled or if the site owner clicks outside of it on the page.
    - **Lines 21-42**: Configure the modal’s layout and content.
      - **Lines 23-30**: Add a primary **Save** button that is enabled when a product name has been entered. When clicked, it creates a product, and then resets `productName`. 
      - **Lines 31-32**: Add a secondary **Cancel** button. When clicked, it closes the modal.
      - **Lines 35-40**: Add a `FormField` component that takes an input for the product name.

Your complete `create-product.tsx` file should look like this:

```js
import React, { useEffect, useState } from 'react';
import {
  Modal,
  CustomModalLayout,
  FormField,
  Input,
} from '@wix/design-system';
import '@wix/design-system/styles.global.css';

export function CreateProductModal({ showModal, onSave }: { showModal: boolean, onSave: (name: string) => void }) {
  const [productName, setProductName] = useState('');
  const [shown, setShown] = useState(showModal);

  useEffect(() => {
    setShown(showModal);
  }, [showModal])

  const toggleModal = () => {
    setShown(!shown);
    setProductName('');
  };

  return (
    <Modal
      isOpen={shown}
      onRequestClose={toggleModal}
      shouldCloseOnOverlayClick
      screen="desktop"
    >
      <CustomModalLayout
        title="Create Product"
        primaryButtonProps={{
          disabled: !productName,
          children: 'Save',
        }}
        primaryButtonOnClick={() => {
          onSave(productName)
          setProductName('')
        }}
        secondaryButtonText="Cancel"
        secondaryButtonOnClick={toggleModal}
        onCloseButtonClick={toggleModal}
        content={
          <FormField label="Name">
            <Input
              value={productName}
              onChange={(e) => setProductName(e.currentTarget.value)}
            />
          </FormField>
        }
      />
    </Modal>
  );
}
```

## Step 10 | Create a dashboard page component

Finally, we have all the pieces in place to set up our dashboard page.

Open the `custom-products-catalog.tsx` file at `src/extensions/dashboard/pages/custom-products-catalog/`.
1. Delete all the contents - we're starting from scratch.
1. Add the following import statements:

    ```js
    import React, { useState } from 'react';
    import {
      Box,
      Text,
      Image,
      Breadcrumbs
    } from '@wix/design-system';
    import '@wix/design-system/styles.global.css';
    import { productsV3 } from '@wix/stores';
    import { CollectionPage } from '@wix/patterns/page';
    import {
      useTableCollection,
      Table,
      PrimaryActions,
      useOptimisticActions,
      deleteSecondaryAction,
      MultiBulkActionToolbar,
      CustomColumns,
      CollectionToolbarFilters,
      dateRangeFilter,
      DateRangeFilter,
    } from '@wix/patterns';
    import type { Filter, RangeItem } from '@wix/patterns';
    ```

    This file is where we start to use [Patterns](https://www.wix-pages.com/wix-patterns/).

    Patterns is a React library with advanced components that extend the functionality of the core UI React components from the [Wix Design System](https://www.wix-pages.com/design-system-documentation/). It simplifies Wix app development by enabling you to easily and consistently implement complex functionalities like querying, displaying, and filtering collection data from remote servers.

    In our code, we use Patterns components to create a table of products that you can query, filter, and sort. The table also has functionality to create new products, delete existing products, and choose which columns to display.

1. Import everything we set up in the previous sections:

    ```js
    import { withProviders } from '../../withProviders';
    import { useCreateProduct, useDeleteProducts } from '../../hooks/stores';
    import { CreateProductModal } from '../../components/create-product';
    ```

1. Define a type for filtering the table's data:

    ```js
    type TableFilters = {
      updatedDate: Filter<RangeItem<Date>>;
    }
    ```

    This is the product property by which the table can be filtered. We'll pass this type to the `useTableCollection` hook later.

1. Define a map from column IDs to the field paths that `searchProducts` accepts for sorting:

    ```js
    type ProductSearch = Parameters<typeof productsV3.searchProducts>[0];
    type SortableField = NonNullable<NonNullable<ProductSearch['sort']>[number]['fieldName']>;

    const sortFieldByColumnId: Record<string, SortableField> = {
      price: 'actualPriceRange.minValue.amount',
    };
    ```

    The `SortableField` type narrows the allowed values to the field paths that the V3 `searchProducts` endpoint accepts as sort fields. The map then translates between the table column's `id`, which we use as a short human-friendly slug, and the API's full field path.

    For example, the **Price** column has `id: 'price'`, but the SDK expects the full path `actualPriceRange.minValue.amount` when sorting by price. The map entry `price: 'actualPriceRange.minValue.amount'` makes the translation explicit. Columns whose `id` already equals a sortable field path don't need an entry.

1. Map product types to strings so that they display in a readable way in the table:

    ```js
    const productTypeToDisplayName: {[key in productsV3.ProductType]: string} = {
      [productsV3.ProductType.PHYSICAL]: 'Physical',
      [productsV3.ProductType.DIGITAL]: 'Digital',
    }
    ```

### Create the `Products()` component

It's finally time to make our dashboard page component. We will:

- [Define and export our dashboard page component](#define-and-export-our-dashboard-page-component)
- [Define the component's states, hooks, and functions](#define-the-components-states-hooks-and-functions)
- [Create the page structure](#create-the-page-structure)

#### Define and export our dashboard page component

1. Create a function for our dashboard page component named `Products`:

    ```js
    function Products() {}
    ```

1. Export the component wrapped by `withProviders()`:

    ```js
    export default withProviders(Products);
    ```

The rest of the code on this page will be written inside the `Products()` function.

#### Define the component's states, hooks, and functions

1. Initialize the `shown` state variable to manage the visibility of the modal we created [earlier](#step-8--create-a-create-product-modal).

    ```js
    const [shown, setShown] = useState(false);
    ```

1. Use `productsV3` to get the `searchProducts()` and `deleteProduct()` functions.

    ```js
    const { searchProducts, deleteProduct } = productsV3;
    ```

1. Create the [`tableState`](https://www.wix-pages.com/wix-patterns/?path=/story/base-components-collections-table-tablestate--tablestate) using [`useTableCollection`](https://www.wix-pages.com/wix-patterns/?path=%2Fstory%2Fbase-components-collections-table-usetablecollection--usetablecollection).

    `useTableCollection` is a hook that returns a `tableState` object. This is where we define:
    - Where to retrieve the data from to display in the table.
    - How much data to retrieve.
    - How to build the search request that retrieves the table data, depending on what filters and sorting are applied in the table.
    - The error message to display if no data is found.
    - How the filters are applied.

    ```js
    const tableState = useTableCollection<productsV3.V3Product, TableFilters>({
      queryName: 'products-catalog',
      itemKey: (product: productsV3.V3Product) => product._id!,
      itemName: (product: productsV3.V3Product) => product.name!,
      limit: 20,

      fetchData: async (query) => {
        const { limit, sort, filters } = query;

        const filter: Record<string, any> = {};
        const updatedDate = filters?.updatedDate;
        if (updatedDate?.from || updatedDate?.to) {
          const conditions: Record<string, any>[] = [];
          if (updatedDate.from) {
            conditions.push({ _updatedDate: { $gt: updatedDate.from.toISOString() } });
          }
          if (updatedDate.to) {
            conditions.push({ _updatedDate: { $lt: updatedDate.to.toISOString() } });
          }
          if (conditions.length === 1) {
            Object.assign(filter, conditions[0]);
          } else {
            filter['$and'] = conditions;
          }
        }

        const sortSpec = (sort ?? [])
          .map(s => {
            const fieldName = (sortFieldByColumnId[s.fieldName] ?? s.fieldName) as SortableField;
            return { fieldName, order: s.order === 'desc' ? 'DESC' as const : 'ASC' as const };
          });

        const response = await searchProducts(
          {
            cursorPaging: { limit },
            ...(Object.keys(filter).length > 0 ? { filter } : {}),
            ...(sortSpec.length > 0 ? { sort: sortSpec } : {}),
          },
          { fields: ['THUMBNAIL', 'PLAIN_DESCRIPTION'] }
        );

        return {
          items: response.products ?? [],
          total: response.products?.length ?? 0,
        };
      },

      fetchErrorMessage: () => 'Error fetching products',

      filters: {
        updatedDate: dateRangeFilter(),
      },
    });
    ```

    Let's break down the above code:

    - **Lines 2-5**: Define basic data necessary for retrieving and identifying the items used to populate the table.
    - **Lines 7-46**: Define the function that fetches the collection data used to populate the table. It receives a `query` object and returns the matching products plus a total count.
      - **Line 8**: Deconstruct the `query` parameter. It contains the requested `limit`, the active `sort`, and any `filters` the user has applied.
      - **Lines 10-25**: Build the filter object. If the user has applied a **Last Updated** range, translate it into the V3 search filter syntax. A range with both `from` and `to` becomes two separate `_updatedDate` conditions combined with `$and`, because the V3 search filter requires a single operator per field per condition.
      - **Lines 27-31**: Build the sort spec. For each sort entry from the table, look up the column's `id` in `sortFieldByColumnId` to get the field path the SDK accepts, and translate the order from the patterns library's lowercase format (`asc`/`desc`) into the SDK's uppercase enum (`ASC`/`DESC`).
      - **Lines 33-40**: Call `searchProducts`. Pass the cursor paging limit, the filter, and the sort spec as the first argument. In the second argument, request the additional response fields `THUMBNAIL` and `PLAIN_DESCRIPTION`. These aren't returned by default, but the **Avatar** and **Description** columns need them.
      - **Lines 42-45**: Return the items. This sample fetches a single page of up to 20 products. V3 cursor-paginated responses don't include a total count, so we use the length of the returned page as `total`. A production app should implement cursor-based pagination using `pagingMetadata.cursors.next` from the response, and call `countProducts` to display a true total.
    - **Line 48**: Define the error message that will be shown if the fetch fails.
    - **Lines 50-52**: Define which filter factories are used with the filters. The `updatedDate` filter uses the [`dateRangeFilter`](https://wix-pages.com/wix-patterns/?path=%2Fstory%2Ffeatures-filter-factories--daterangefilter) factory.

1. Create the [`optimisticActions`](https://www.wix-pages.com/wix-patterns/?path=%2Fstory%2Ffeatures-actions-updates--collectionoptimisticactions) class using [`useOptimisticActions`](https://www.wix-pages.com/wix-patterns/?path=%2Fstory%2Ffeatures-actions-updates--useoptimisticactions).

    `useOptimisticActions` is a hook that returns a `CollectionOptimisticActions` class. The code below defines logic that anticipates the results of the query that we defined in the previous step. When there is a change that sends a new query to the server (for example, a new filter), this logic will be applied to the data already in the page's memory while we're waiting for the server's response.

    ```js
    const optimisticActions = useOptimisticActions(tableState.collection,
      {
        orderBy: () => [],

        predicate: ({ filters }) => {
          return (product) => {
            if (filters.updatedDate && product._updatedDate) {
              const from = filters.updatedDate.from;
              const to = filters.updatedDate.to;
              const productUpdatedDate = (new Date(product._updatedDate)).getTime();

              if (from && productUpdatedDate < from.getTime()) {
                return false;
              }
              if (to && productUpdatedDate > to.getTime()) {
                return false;
              }
            }

            return true;
          }
        },
      }
    );
    ```

    Let's break down the above code:

    - **Line 3**: Define that there is no default sorting for the data, apart from what is defined in the query.
    - **Lines 5-22**: Define a function that simulates the filtering on the server, as defined in the `tableState` above. It returns a function that returns `true` if the product would pass the filters, and `false` if it wouldn't.
      - **Lines 7-18**: Return `false` if the product wouldn't pass the **Last Updated** filter.
      - **Line 20**: Return `true` if the product would pass all of the filters.

1. Define the `createProduct()` and `deleteProducts()` functions using the hooks we created in [Step 7](#step-7--create-hooks-for-our-sdk-calls):

    ```js
    const createProduct = useCreateProduct(optimisticActions);
    const deleteProducts = useDeleteProducts(optimisticActions);
    ```

At this stage, your `Products()` function should look like this:

```js
function Products() {
  const [shown, setShown] = useState(false);

  const { searchProducts, deleteProduct } = productsV3;

  const tableState = useTableCollection<productsV3.V3Product, TableFilters>({
    queryName: 'products-catalog',
    itemKey: (product: productsV3.V3Product) => product._id!,
    itemName: (product: productsV3.V3Product) => product.name!,
    limit: 20,

    fetchData: async (query) => {
      const { limit, sort, filters } = query;

      const filter: Record<string, any> = {};
      const updatedDate = filters?.updatedDate;
      if (updatedDate?.from || updatedDate?.to) {
        const conditions: Record<string, any>[] = [];
        if (updatedDate.from) {
          conditions.push({ _updatedDate: { $gt: updatedDate.from.toISOString() } });
        }
        if (updatedDate.to) {
          conditions.push({ _updatedDate: { $lt: updatedDate.to.toISOString() } });
        }
        if (conditions.length === 1) {
          Object.assign(filter, conditions[0]);
        } else {
          filter['$and'] = conditions;
        }
      }

      const sortSpec = (sort ?? [])
        .map(s => {
          const fieldName = (sortFieldByColumnId[s.fieldName] ?? s.fieldName) as SortableField;
          return { fieldName, order: s.order === 'desc' ? 'DESC' as const : 'ASC' as const };
        });

      const response = await searchProducts(
        {
          cursorPaging: { limit },
          ...(Object.keys(filter).length > 0 ? { filter } : {}),
          ...(sortSpec.length > 0 ? { sort: sortSpec } : {}),
        },
        { fields: ['THUMBNAIL', 'PLAIN_DESCRIPTION'] }
      );

      return {
        items: response.products ?? [],
        total: response.products?.length ?? 0,
      };
    },

    fetchErrorMessage: () => 'Error fetching products',

    filters: {
      updatedDate: dateRangeFilter(),
    },
  });

  const optimisticActions = useOptimisticActions(tableState.collection,
    {
      orderBy: () => [],

      predicate: ({ filters }) => {
        return (product) => {
          if (filters.updatedDate && product._updatedDate) {
            const from = filters.updatedDate.from;
            const to = filters.updatedDate.to;
            const productUpdatedDate = (new Date(product._updatedDate)).getTime();

            if (from && productUpdatedDate < from.getTime()) {
              return false;
            }
            if (to && productUpdatedDate > to.getTime()) {
              return false;
            }
          }

          return true;
        }
      },
    }
  );

  const createProduct = useCreateProduct(optimisticActions);
  const deleteProducts = useDeleteProducts(optimisticActions);

  return ()
}
```

#### Create the page structure

We define our page as follows:

1. Define the [`CollectionPage`](https://www.wix-pages.com/wix-patterns/?path=%2Fstory%2Fbase-components-page-layouts-collection-page--collectionpage) component that will wrap all our components on this page:

    ```js
    <CollectionPage height="100vh">
      // All page components will go here.
    </CollectionPage>
    ```

1. Add a [`CollectionPage.Header`](https://www.wix-pages.com/wix-patterns/?path=%2Fstory%2Fbase-components-page-layouts-collection-page--collectionpage-header) component that contains the page title, breadcrumbs, and a button that opens our **Add Product** modal:

    ```js
    <CollectionPage.Header
      title={{ text: 'Products' }}
      breadcrumbs={
        <Breadcrumbs
          activeId="2"
          items={[
            { id: '1', value: 'Apps', disabled: true },
            { id: '2', value: 'Products' },
          ]}
        />
      }
      primaryAction={
        <PrimaryActions
          label="Add Product"
          onClick={() => setShown(!shown)}
        />
      }
    />
    ```

1. Add a [`CollectionPage.Content`](https://www.wix-pages.com/wix-patterns/?path=%2Fstory%2Fbase-components-page-layouts-collection-page--collectionpage-content) component below the `CollectionPage.Header`. This will wrap the rest of the components on this page.

    ```js
    <CollectionPage.Content>
      // The rest of the page components will go here.
    </CollectionPage.Content>
    ```

1. Add the `CreateProductModal` component that we created in [Step 8](#step-8--create-a-create-product-modal):

    ```js
    <CreateProductModal showModal={shown} onSave={(productName: string) => {
      createProduct(productName);
      setShown(false);
    }}/>
    ```

1. Add a [`Table`](https://www.wix-pages.com/wix-patterns/?path=%2Fstory%2Fbase-components-collections-table-table--table) component.

    The following code displays a table containing our columns and fetched data.
    When no items are selected, there is also a button that opens an accordion to customize the columns displayed, and a button that opens an accordion to filter the data.
    When at least one product is selected, the table displays the number of selected products, the maximum number of products that can be selected, a **Select All** option, and a **Delete** button.

    ```js
    <Table
      state={tableState}
      maxSelection={20}
      filters={
        <CollectionToolbarFilters>
          <DateRangeFilter
            filter={tableState.collection.filters.updatedDate}
            accordionItemProps={{ label: 'Last Updated' }}
          />
        </CollectionToolbarFilters>
      }

      bulkActionToolbar={({ selectedValues, openConfirmModal }) => {
        const disabled = selectedValues.length > 20;
        return (
          <MultiBulkActionToolbar
            primaryActionItems={[
              {
                label: 'Delete',
                tooltip: disabled
                  ? 'Deleting is supported for up to 20 items'
                  : undefined,
                disabled,
                onClick: () => {
                  openConfirmModal({
                    theme: 'destructive',
                    primaryButtonOnClick: () => {
                      deleteProducts(selectedValues);
                    },
                  });
                },
              },
            ]}
          />)
      }}

      customColumns={<CustomColumns />}
      columns={[
        {
          id: 'avatar',
          name: 'Avatar',
          title: '',
          width: '72px',
          render: (product) => <Image src={product.media?.main?.thumbnail?.url}/>,
          reorderDisabled: true,
          hiddenFromCustomColumnsSelection: true
        },
        {
          id: 'name',
          title: 'Product / Description',
          render: (row: productsV3.V3Product) => (
            <Box direction="vertical" gap="3px">
              <Text size="medium" weight="normal">
                {row.name}
              </Text>
              <Text size="tiny" weight="thin" secondary>
                {row.plainDescription}
              </Text>
            </Box>
          ),
          width: 'auto',
          reorderDisabled: true,
          hideable: false
        },
        {
          id: 'price',
          title: 'Price',
          render: (row: productsV3.V3Product) => {
            const amount = row.actualPriceRange?.minValue?.amount;
            return amount ? `$${amount}` : '';
          },
          width: '100px',
          sortable: true,
        },
        {
          id: 'type',
          title: 'Type',
          render: (row: productsV3.V3Product) => {
            if (!row.productType) return '';
            return productTypeToDisplayName[row.productType as productsV3.ProductType] ?? row.productType;
          },
          width: '100px',
        },
        {
          id: 'last-updated',
          title: 'Last Updated',
          render: (row: productsV3.V3Product) =>
            row._updatedDate
              ? new Date(row._updatedDate).toLocaleDateString()
              : '',
          width: '100px',
          defaultHidden: true,
        },
      ]}

      actionCell={(_product, _index, actionCellAPI) => ({
        secondaryActions: [
          deleteSecondaryAction({
            optimisticActions,
            actionCellAPI,
            submit: (products: productsV3.V3Product[]) => (
              Promise.all(
                products.map((product: productsV3.V3Product) => deleteProduct(product._id!))
              )
            ),
            successToast: {
              message: `${_product.name} deleted successfully.`,
              type: 'SUCCESS',
            },
            errorToast: () => 'Product deletion failed.',
          }),
        ]
      })}
    />
    ```

    Let's identify where some of our key functionality is implemented in the above code. For more information on all the `Table` props, see [Patterns Table Component](https://www.wix-pages.com/wix-patterns/?path=%2Fstory%2Fbase-components-collections-table-table--table&tab=API).

    - **Lines 4-12**: Define the table's filters. We use a [`CollectionToolbarFilters`](https://www.wix-pages.com/wix-patterns/?path=%2Fstory%2Ffeatures-filter-components--toolbarfilters) component to display an accordion with the filtering options. The **Last Updated** filter uses the [`DateRangeFilter`](https://www.wix-pages.com/wix-patterns/?path=/story/features-filter-components--daterangefilter) component.
    - **Lines 13-35**: Use the [`MultiBulkActionToolbar`](https://www.wix-pages.com/wix-patterns/?path=%2Fstory%2Ffeatures-actions-bulk-actions--multibulkactiontoolbar) component to create a button in the toolbar that deletes all selected products. When the button is clicked, the user is asked to confirm their decision in a modal (**line 25**).
    - **Lines 37-94**: Define the table's columns.
      - **Lines 39-47**: **Product avatar** - Use the [`Image`](https://www.wix-pages.com/design-system-documentation/#/component/image) component from the Wix Design System and feed it the URL from the product's `media.main.thumbnail.url` field. To make this field appear in the response, we requested it via the `THUMBNAIL` field in the `searchProducts` call.
      - **Lines 48-64**: **Product name and description** - Use a `Box` for layout with direction set to `vertical` and gap to `3px`, indicating vertical stacking with a gap of 3px. Inside this box, add two `Text` components for the product's `name` and `plainDescription`. The description comes from the `PLAIN_DESCRIPTION` requested field.
      - **Lines 65-74**: **Product price** - Read the product's price from `actualPriceRange.minValue.amount` and prefix it with a dollar sign. The column is `sortable: true`; sorting maps to the `actualPriceRange.minValue.amount` field path via `sortFieldByColumnId`.
      - **Lines 75-83**: **Product type** - Format the `productType` field using `productTypeToDisplayName` which we defined earlier. If there is no product type, return an empty string.
      - **Lines 84-93**: **Product last updated date** - Format the product's `_updatedDate` as a readable date. This column is `defaultHidden: true`, so the user must opt in via the columns control to see it.
    - **Lines 96-113**: Create a **Delete** action in the per-row action menu (**line 99**). Add success (**lines 107-110**) and error (**line 111**) toasts.

Your page structure code should look like this:

```js
<CollectionPage height="100vh">
  <CollectionPage.Header
    title={{ text: 'Products' }}
    breadcrumbs={
      <Breadcrumbs
        activeId="2"
        items={[
          { id: '1', value: 'Apps', disabled: true },
          { id: '2', value: 'Products' },
        ]}
      />
    }
    primaryAction={
      <PrimaryActions
        label="Add Product"
        onClick={() => setShown(!shown)}
      />
    }
  />
  <CollectionPage.Content>
    <CreateProductModal showModal={shown} onSave={(productName: string) => {
      createProduct(productName);
      setShown(false);
    }}/>

    <Table
      state={tableState}
      maxSelection={20}
      filters={
        <CollectionToolbarFilters>
          <DateRangeFilter
            filter={tableState.collection.filters.updatedDate}
            accordionItemProps={{ label: 'Last Updated' }}
          />
        </CollectionToolbarFilters>
      }

      bulkActionToolbar={({ selectedValues, openConfirmModal }) => {
        const disabled = selectedValues.length > 20;
        return (
          <MultiBulkActionToolbar
            primaryActionItems={[
              {
                label: 'Delete',
                tooltip: disabled
                  ? 'Deleting is supported for up to 20 items'
                  : undefined,
                disabled,
                onClick: () => {
                  openConfirmModal({
                    theme: 'destructive',
                    primaryButtonOnClick: () => {
                      deleteProducts(selectedValues);
                    },
                  });
                },
              },
            ]}
          />)
      }}

      customColumns={<CustomColumns />}
      columns={[
        {
          id: 'avatar',
          name: 'Avatar',
          title: '',
          width: '72px',
          render: (product) => <Image src={product.media?.main?.thumbnail?.url}/>,
          reorderDisabled: true,
          hiddenFromCustomColumnsSelection: true
        },
        {
          id: 'name',
          title: 'Product / Description',
          render: (row: productsV3.V3Product) => (
            <Box direction="vertical" gap="3px">
              <Text size="medium" weight="normal">
                {row.name}
              </Text>
              <Text size="tiny" weight="thin" secondary>
                {row.plainDescription}
              </Text>
            </Box>
          ),
          width: 'auto',
          reorderDisabled: true,
          hideable: false
        },
        {
          id: 'price',
          title: 'Price',
          render: (row: productsV3.V3Product) => {
            const amount = row.actualPriceRange?.minValue?.amount;
            return amount ? `$${amount}` : '';
          },
          width: '100px',
          sortable: true,
        },
        {
          id: 'type',
          title: 'Type',
          render: (row: productsV3.V3Product) => {
            if (!row.productType) return '';
            return productTypeToDisplayName[row.productType as productsV3.ProductType] ?? row.productType;
          },
          width: '100px',
        },
        {
          id: 'last-updated',
          title: 'Last Updated',
          render: (row: productsV3.V3Product) =>
            row._updatedDate
              ? new Date(row._updatedDate).toLocaleDateString()
              : '',
          width: '100px',
          defaultHidden: true,
        },
      ]}

      actionCell={(_product, _index, actionCellAPI) => ({
        secondaryActions: [
          deleteSecondaryAction({
            optimisticActions,
            actionCellAPI,
            submit: (products: productsV3.V3Product[]) => (
              Promise.all(
                products.map((product: productsV3.V3Product) => deleteProduct(product._id!))
              )
            ),
            successToast: {
              message: `${_product.name} deleted successfully.`,
              type: 'SUCCESS',
            },
            errorToast: () => 'Product deletion failed.',
          }),
        ]
      })}
    />
  </CollectionPage.Content>
</CollectionPage>
```

#### Complete page code

Your complete code should look like this:

```js
import React, { useState } from 'react';
import {
  Box,
  Text,
  Image,
  Breadcrumbs
} from '@wix/design-system';
import '@wix/design-system/styles.global.css';
import { productsV3 } from '@wix/stores';
import { CollectionPage } from '@wix/patterns/page';
import {
  useTableCollection,
  Table,
  PrimaryActions,
  useOptimisticActions,
  deleteSecondaryAction,
  MultiBulkActionToolbar,
  CustomColumns,
  CollectionToolbarFilters,
  dateRangeFilter,
  DateRangeFilter,
} from '@wix/patterns';
import type { Filter, RangeItem } from '@wix/patterns';
import { withProviders } from '../../withProviders';
import { useCreateProduct, useDeleteProducts } from '../../hooks/stores';
import { CreateProductModal } from '../../components/create-product';

type TableFilters = {
  updatedDate: Filter<RangeItem<Date>>;
}

type ProductSearch = Parameters<typeof productsV3.searchProducts>[0];
type SortableField = NonNullable<NonNullable<ProductSearch['sort']>[number]['fieldName']>;

const sortFieldByColumnId: Record<string, SortableField> = {
  price: 'actualPriceRange.minValue.amount',
};

const productTypeToDisplayName: {[key in productsV3.ProductType]: string} = {
  [productsV3.ProductType.PHYSICAL]: 'Physical',
  [productsV3.ProductType.DIGITAL]: 'Digital',
}

function Products() {
  const [shown, setShown] = useState(false);

  const { searchProducts, deleteProduct } = productsV3;

  const tableState = useTableCollection<productsV3.V3Product, TableFilters>({
    queryName: 'products-catalog',
    itemKey: (product: productsV3.V3Product) => product._id!,
    itemName: (product: productsV3.V3Product) => product.name!,
    limit: 20,

    fetchData: async (query) => {
      const { limit, sort, filters } = query;

      const filter: Record<string, any> = {};
      const updatedDate = filters?.updatedDate;
      if (updatedDate?.from || updatedDate?.to) {
        const conditions: Record<string, any>[] = [];
        if (updatedDate.from) {
          conditions.push({ _updatedDate: { $gt: updatedDate.from.toISOString() } });
        }
        if (updatedDate.to) {
          conditions.push({ _updatedDate: { $lt: updatedDate.to.toISOString() } });
        }
        if (conditions.length === 1) {
          Object.assign(filter, conditions[0]);
        } else {
          filter['$and'] = conditions;
        }
      }

      const sortSpec = (sort ?? [])
        .map(s => {
          const fieldName = (sortFieldByColumnId[s.fieldName] ?? s.fieldName) as SortableField;
          return { fieldName, order: s.order === 'desc' ? 'DESC' as const : 'ASC' as const };
        });

      const response = await searchProducts(
        {
          cursorPaging: { limit },
          ...(Object.keys(filter).length > 0 ? { filter } : {}),
          ...(sortSpec.length > 0 ? { sort: sortSpec } : {}),
        },
        { fields: ['THUMBNAIL', 'PLAIN_DESCRIPTION'] }
      );

      return {
        items: response.products ?? [],
        total: response.products?.length ?? 0,
      };
    },

    fetchErrorMessage: () => 'Error fetching products',

    filters: {
      updatedDate: dateRangeFilter(),
    },
  });

  const optimisticActions = useOptimisticActions(tableState.collection,
    {
      orderBy: () => [],

      predicate: ({ filters }) => {
        return (product) => {
          if (filters.updatedDate && product._updatedDate) {
            const from = filters.updatedDate.from;
            const to = filters.updatedDate.to;
            const productUpdatedDate = (new Date(product._updatedDate)).getTime();

            if (from && productUpdatedDate < from.getTime()) {
              return false;
            }
            if (to && productUpdatedDate > to.getTime()) {
              return false;
            }
          }

          return true;
        }
      },
    }
  );

  const createProduct = useCreateProduct(optimisticActions);
  const deleteProducts = useDeleteProducts(optimisticActions);

  return (
    <CollectionPage height="100vh">
      <CollectionPage.Header
        title={{ text: 'Products' }}
        breadcrumbs={
          <Breadcrumbs
            activeId="2"
            items={[
              { id: '1', value: 'Apps', disabled: true },
              { id: '2', value: 'Products' },
            ]}
          />
        }
        primaryAction={
          <PrimaryActions
            label="Add Product"
            onClick={() => setShown(!shown)}
          />
        }
      />
      <CollectionPage.Content>
        <CreateProductModal showModal={shown} onSave={(productName: string) => {
          createProduct(productName);
          setShown(false);
        }}/>

        <Table
          state={tableState}
          maxSelection={20}
          filters={
            <CollectionToolbarFilters>
              <DateRangeFilter
                filter={tableState.collection.filters.updatedDate}
                accordionItemProps={{ label: 'Last Updated' }}
              />
            </CollectionToolbarFilters>
          }

          bulkActionToolbar={({ selectedValues, openConfirmModal }) => {
            const disabled = selectedValues.length > 20;
            return (
              <MultiBulkActionToolbar
                primaryActionItems={[
                  {
                    label: 'Delete',
                    tooltip: disabled
                      ? 'Deleting is supported for up to 20 items'
                      : undefined,
                    disabled,
                    onClick: () => {
                      openConfirmModal({
                        theme: 'destructive',
                        primaryButtonOnClick: () => {
                          deleteProducts(selectedValues);
                        },
                      });
                    },
                  },
                ]}
              />)
          }}

          customColumns={<CustomColumns />}
          columns={[
            {
              id: 'avatar',
              name: 'Avatar',
              title: '',
              width: '72px',
              render: (product) => <Image src={product.media?.main?.thumbnail?.url}/>,
              reorderDisabled: true,
              hiddenFromCustomColumnsSelection: true
            },
            {
              id: 'name',
              title: 'Product / Description',
              render: (row: productsV3.V3Product) => (
                <Box direction="vertical" gap="3px">
                  <Text size="medium" weight="normal">
                    {row.name}
                  </Text>
                  <Text size="tiny" weight="thin" secondary>
                    {row.plainDescription}
                  </Text>
                </Box>
              ),
              width: 'auto',
              reorderDisabled: true,
              hideable: false
            },
            {
              id: 'price',
              title: 'Price',
              render: (row: productsV3.V3Product) => {
                const amount = row.actualPriceRange?.minValue?.amount;
                return amount ? `$${amount}` : '';
              },
              width: '100px',
              sortable: true,
            },
            {
              id: 'type',
              title: 'Type',
              render: (row: productsV3.V3Product) => {
                if (!row.productType) return '';
                return productTypeToDisplayName[row.productType as productsV3.ProductType] ?? row.productType;
              },
              width: '100px',
            },
            {
              id: 'last-updated',
              title: 'Last Updated',
              render: (row: productsV3.V3Product) =>
                row._updatedDate
                  ? new Date(row._updatedDate).toLocaleDateString()
                  : '',
              width: '100px',
              defaultHidden: true,
            },
          ]}

          actionCell={(_product, _index, actionCellAPI) => ({
            secondaryActions: [
              deleteSecondaryAction({
                optimisticActions,
                actionCellAPI,
                submit: (products: productsV3.V3Product[]) => (
                  Promise.all(
                    products.map((product: productsV3.V3Product) => deleteProduct(product._id!))
                  )
                ),
                successToast: {
                  message: `${_product.name} deleted successfully.`,
                  type: 'SUCCESS',
                },
                errorToast: () => 'Product deletion failed.',
              }),
            ]
          })}
        />
      </CollectionPage.Content>
    </CollectionPage>
  );
}

export default withProviders(Products);
```

## Step 11 | Test the app

Now that the app’s code is ready, you can test it locally using the Wix CLI.

To test your app, do the following:

1. Run a local development server for your app using the `wix app dev` command in your terminal. Your app’s dashboard page will now look like this:

    ![App preview](https://wixmp-833713b177cebf373f611808.wixmp.com/images/9376e20a870d954427e43694f3428287.png)

1. Click the **Add Product** button and use the modal to add a product.
1. Select some products and click the **Delete** button.
1. If things don’t look right, open your browser’s developer tools and check for errors in the console.

## Step 12 | Build and deploy the app

You have now fully developed an app that allows users to add or remove products from a Wix Stores products catalog through a dashboard page.

After testing your app and seeing that it works as expected, you can [build and deploy your app](https://dev.wix.com/docs/build-apps/develop-your-app/develop-an-app-with-the-cli/project-development/build-and-deploy.md).