Nano Store - Ecommerce Docs
Developer ResourcesProduct Gallery, Delete and Preview

Product Gallery, Delete and Preview Features

Storefront gallery arrows, admin product delete with undo, the deleted-products view with restore, list filters, and the customer preview.

Audience: Product owners, QA, frontend, admin and backend developers Scope: What shipped across the storefront, the admin panel and the backend, and the rules each surface follows

Product Gallery, Delete and Preview

1. Feature Overview

One feature, three repos. The backend change is small and is a prerequisite for the admin work; the storefront change is independent.

RepoWhat shipped
Storefront (nano-store-frontend)Previous/next arrows and keyboard navigation on the product gallery; product video URLs are rewritten to embeddable form (toEmbedUrl); the out-of-stock screen-reader note appears only on option rows that have a sold-out value; the Facebook sign-in button is disabled with an explanatory toast
Admin (Happy-shop-admin)Delete with Undo, a Deleted products view with restore, restore for soft-deleted categories, brands and brand series, On sale and Featured list filters, a deleted banner on the detail page, controls hidden for deleted products, and a storefront-faithful "View as customer" preview
Backend (Nano-store-backend)Restore refuses (409) when the product's category, brand or series is soft-deleted; timestamps.deletedAt on the admin product response

Deploy order: backend first. The admin tolerates an older backend that omits deletedAt (see Backend).

2. Surface Matrix

SurfacePrefix / locationAuth
Storefront gallerysrc/app/products/[slug]/_components/Public
Admin product screens/dashboard/products, /dashboard/products/:productId, .../edit, .../previewAdmin session plus Products_* permission codes
Backend admin API/api/admin/productsJWT + role, @Permissions("Products_*")
  • Previous and next arrows appear when the gallery has more than one slide. Navigation wraps in both directions, so the arrows are never disabled.

  • ArrowLeft and ArrowRight step the gallery. The handler ignores the key when Alt, Ctrl, Meta or Shift is held, when the focus is in an input or a contenteditable element, when the active slide is a video, and when there is a single slide.

  • A polite live region announces the position (for example "Image 2 of 3"). It stays silent until the visitor has navigated and resets when the slide set changes (variant change).

  • The thumbnail rail scrolls to follow the active slide.

  • Video URLs. The backend allowlists only the host of a product video URL, so a watch?v= URL is stored as entered, and YouTube refuses to be framed on that page. toEmbedUrl (src/lib/catalog/embed-url.ts) rewrites the URL before it reaches the gallery. The host allowlist and the CSP are unchanged.

    Stored URLResult
    YouTube /watch?v=ID/embed/ID on the same host. t or start of N or Ns is kept as ?start=N; other values (1m30s) and other params are dropped
    YouTube /shorts/ID/embed/ID
    YouTube /embed/IDPasses through unchanged
    Vimeo player.vimeo.com/video/<digits>Passes through unchanged
    Anything else (other hosts, youtu.be, http, other paths, unparseable)The slide is dropped

    A YouTube id must be exactly 11 characters ([A-Za-z0-9_-]) on watch, shorts and embed, or the slide is dropped. An operator-saved /embed/ URL with a shorter id therefore no longer shows.

  • Out-of-stock note. The screen-reader-only "Currently out of stock" note in product-option-axis-row.tsx renders only when some value in that option row is out of stock. It is aria-hidden and referenced by aria-describedby from the sold-out radios, so it is never read as a product-level statement. Before, every option row carried it, even for a fully in-stock product.

  • The gallery is split into five files: product-gallery.tsx, use-gallery-navigation.ts, gallery-arrows.tsx, gallery-slide-view.tsx, gallery-thumbnail-rail.tsx.

  • The Facebook button in auth-social-buttons.tsx is aria-disabled="true" (not natively disabled, so it stays focusable and clickable). Clicking it shows the toast "Facebook sign-in isn't enabled yet." and sends no request.

4. Admin: Delete, Undo and Restore

4.1 Delete

  • The Delete control appears on the product detail page for users with Products_DELETE and opens a confirmation dialog. The dialog cannot be dismissed while the delete is pending.
  • The delete is a soft delete. The dialog copy says the product is hidden from the store and moved to Deleted products, where it can be restored.
  • On success the admin shows Deleted "{name}" and returns to the list. An Undo action appears on that toast only when the user also has Products_RESTORE.
  • Undo restores the product and moves to its detail page, but only if the user is still on /dashboard/products when the result arrives. Otherwise it only shows a toast.
Backend responseAdmin outcomeToast
200deletedDeleted "{name}"
409 PRODUCT_ALREADY_DELETEDalready_deleted"This product was already deleted"
404 PRODUCT_NOT_FOUNDnot_found"This product no longer exists"
Other 4xxErrorThe described backend error; dialog stays open
5xx, timeout, non-API errorError"Could not confirm the delete. Try again — if it already went through, retrying will confirm it."

4.2 Deleted products view

  • The product list has a filter whose default option is "Active products" and whose only other option is "Deleted products" (URL ?deleted=true).
  • In the deleted view the bulk-selection column and bulk bar are hidden, and each row shows a Restore button for users with Products_RESTORE. Users with only Products_READ see the list read-only.
  • An empty deleted view shows "No deleted products." in preference to the other empty states.
  • Restoring a published or unlisted product asks for confirmation first; draft and archived products restore directly. If the restored row was the only row on page N greater than 1, the URL steps back to page N-1.
  • "Clear filters" returns to the active view.

4.3 Restore outcomes

Backend responseAdmin resultCopy
200restoredRow Restore: "Restored {name}". Undo: "Product restored"
409 PRODUCT_NOT_DELETEDalready_active (counts as success)Row Restore: "Already restored". Undo: "Product restored"
409 PRODUCT_CATEGORY_DELETEDError"Can't restore: its category is deleted. Restore that first."
409 PRODUCT_BRAND_DELETEDError"Can't restore: its brand is deleted. Restore that first."
409 PRODUCT_SERIES_DELETEDError"Can't restore: its series is deleted. Restore that first."
409 RESOURCE_ALREADY_EXISTSError"Can't restore: another active product now uses this product's SKU or slug. Change that product's SKU first."
404 PRODUCT_NOT_FOUNDError"This product no longer exists"

"Restore that first." has a destination: the category, brand and series restore screens in section 4.5. Restore the referent there, then retry the product.

4.4 Detail page for a deleted product

  • A deleted banner and a Restore button replace the edit and delete controls. Create, update and delete permissions are forced off for the page.
  • The stock section is read-only: it shows "Stock status: {label}" and omits the adjustment, overselling and "Open inventory" pointers.
  • The edit page redirects a deleted product back to its detail page.
  • The page makes no variants or options list calls for a deleted product. The backend answers those with 404 anyway (see Backend).
  • The Variants section shows "Variants are not shown for deleted products. Restore the product to see and edit them." A live product with no variants still shows the data-error warning.
  • Upload fields are disabled. MediaUploadField mounts no dropzone and no file input when disabled; it renders a disabled fieldset instead. This covers the thumbnail and the SEO image fields, and applies to any read-only user.
  • A missing product now renders the 404 page through unstable_rethrow; the earlier digest === "NEXT_NOT_FOUND" check never matched on Next 16.
  • deletedAt undefined (older backend) and null both mean the product is not deleted.

4.5 Catalog restore: categories, brands and series

Routes: /dashboard/catalog/categories, /categories/[categoryId], /brands, /brands/[brandId]. All three entities share one CatalogRestoreButton, which renders nothing without the permission.

EntityPermissionHow deleted rows appear (?deleted=true)
CategoryCategories_RESTOREFilter option "Deleted categories" shows a flat list of deleted categories for the current level (root, or the open [categoryId]). No drill-in link, visibility switch, edit or delete. "New category" is hidden. Empty state: "No deleted categories."
BrandBrands_RESTOREFilter option "Active and deleted" shows live plus deleted rows. Deleted rows carry a "Deleted" badge and only a Restore action; edit, delete and the visibility switch are hidden
Brand seriesBrandSeries_RESTORESame as brands, with a new "Deleted" badge

A restore writes to the backend, then calls invalidateStorefrontCache (category.changed, brand.changed, brand-series.changed), then revalidatePath. The cache call never throws, so a committed restore is never reported as a failure.

Restore errors branch on errorCode (describeCatalogError in catalog-action-error.ts):

EntityerrorCodeCopy
CategoryCATEGORY_NOT_DELETED"That category is not deleted, so it cannot be restored."
CategoryCATEGORY_RESTORE_MAX_DEPTH_EXCEEDED"Restoring here would nest the category too deep. Move its parent first."
CategoryCATEGORY_PARENT_DELETED"The parent category is deleted. Restore the parent first, or choose a different parent when creating or moving."
CategoryCATEGORY_NOT_FOUND"That category no longer exists. Refresh the list."
BrandBRAND_NOT_DELETED"That brand is not deleted, so there is nothing to restore. Refresh the list."
BrandBRAND_NOT_FOUND"That brand no longer exists. Refresh the list."
SeriesBRAND_SERIES_NOT_DELETED"That series is not deleted, so there is nothing to restore. Refresh the list."
SeriesBRAND_SERIES_BRAND_DELETED"Its brand is deleted. Restore the brand first."
SeriesBRAND_SERIES_NOT_FOUND"That series no longer exists. Refresh the list."

The create, update, visibility and delete actions in the same catalog modules still show raw server text. This is not changed here.

5. Admin: List Filters

The list has two new selects, On sale (On sale / Not on sale) and Featured (Featured / Not featured), each defaulting to "Any". parseProductListParams forwards onSale and featured only for the literal strings true and false. Any other value is dropped, because the backend would coerce a stray string to false and silently filter the list.

6. Admin: View as Customer Preview

Route: /dashboard/products/:productId/preview, linked from the detail page header as "View as customer". The link is visible to every user who can read the page.

  • The preview renders a copy of the storefront product page body (a snapshot of the storefront at a recorded commit, tracked in _storefront/SOURCE.md and _storefront/source.ts), fed from admin API data through an adapter. It works for drafts, which the storefront never serves.
  • It is inert: commerce controls do nothing and the copied code makes no customer requests. A static test fails on fetch(, "use server", @/lib/mobile-api, @/lib/auth or _actions/ inside the copy.
  • A banner outside the preview root shows the lifecycle through label maps, a count of images in private storage, a degraded-data warning when the variants or options list failed, and "Deleted — not visible to customers" for a deleted product.
  • Swatch URLs are accepted only when they are on the asset origin under /public/; signed, private or foreign URLs become no swatch.
  • Variant availability is an approximation, because the admin variant DTO carries no per-variant inventory.
  • Video embeds render in an iframe with sandbox="allow-scripts allow-same-origin allow-presentation".
  • The Phosphor icon package @phosphor-icons/react was added as a dependency.

7. Error UX Mapping

ConditionWhat the user sees
Restore blocked by a deleted category, brand or seriesError toast naming the referent to restore first (section 4.3)
Session expired during delete"Your session may have expired — reload and sign in again"; dialog stays open
Facebook sign-in clickedToast "Facebook sign-in isn't enabled yet."
Preview of an unknown productNot-found page
Restore of a category, brand or series that is not deleted, or no longer existsMapped toast (section 4.5)
Product video URL that cannot be embeddedThe slide is dropped (section 3)

8. Known Gaps

  • Category restore requires a live parent. The backend answers CATEGORY_PARENT_DELETED (409) when the parent is deleted or missing, and the admin shows the "restore the parent first" copy.
  • deletedOnly lists one tree level. A deleted subcategory under a live parent appears in that parent's Deleted view; one under a deleted parent appears only after the parent is restored.
  • Restore, delete and visibility actions on the catalog screens were not driven in a browser.

See Also