diff --git a/web/sdk/admin/views/products/index.tsx b/web/sdk/admin/views/products/index.tsx index 9fbb73a73..c6daf0031 100644 --- a/web/sdk/admin/views/products/index.tsx +++ b/web/sdk/admin/views/products/index.tsx @@ -1,5 +1,5 @@ import { EmptyState, Flex, DataTable } from "@raystack/apsara"; -import type { ReactNode } from "react"; +import { useEffect, type ReactNode } from "react"; import { useQuery } from "@connectrpc/connect-query"; import { FrontierServiceQueries } from "@raystack/proton/frontier"; import type { Product } from "@raystack/proton/frontier"; @@ -47,6 +47,14 @@ export default function ProductsView({ const productMapById = reduceByKey(products ?? [], "id"); const product = selectedProductId ? productMapById[selectedProductId] ?? null : null; + // Unknown product id (e.g. /products/create): drop it from the URL. + // Skip on error, when the list load — not the id — is what failed. + useEffect(() => { + if (selectedProductId && !isProductsLoading && !isError && !product) { + onCloseDetail?.(); + } + }, [selectedProductId, isProductsLoading, isError, product, onCloseDetail]); + const columns = getColumns(onNavigateToPrices); const handleRowClick = (p: Product) => {