diff --git a/apps/web/app/api/sync/route.ts b/apps/web/app/api/sync/route.ts index 06a7dd04..3da6cd9a 100644 --- a/apps/web/app/api/sync/route.ts +++ b/apps/web/app/api/sync/route.ts @@ -31,10 +31,9 @@ export async function POST(req: Request) { if (metadata.action === "UPDATE" || metadata.action === "CREATE") { const originalProduct = await storefrontClient.getProduct(product.id) - const normalizedProduct = normalizeProduct(originalProduct.data?.product) - if (normalizedProduct) { - await index.updateDocuments([normalizedProduct], { + if (originalProduct) { + await index.updateDocuments([originalProduct], { primaryKey: "id", }) } @@ -43,29 +42,6 @@ export async function POST(req: Request) { return Response.json({ status: "ok" }) } -// TODO: provide agnostic type -function normalizeProduct(product: any | undefined | null) { - if (!product) return product - - return { - ...product, - id: normalizeId(product.id), - title: product.title, - descriptionHtml: product.descriptionHtml, - priceRange: product.priceRange, - featuredImage: product.featuredImage, - seo: product.seo, - updatedAt: product.updatedAt, - handle: product.handle, - description: product.description, - options: product.options, - tags: product.tags, - images: product?.images?.edges?.map((image) => image?.node), - variants: product?.variants?.edges?.map((variant) => variant?.node), - collections: product?.collections?.nodes?.map((collection) => collection), - } -} - function normalizeId(id: string) { const shopifyIdPrefix = "gid://shopify/Product/" return id.replace(shopifyIdPrefix, "") diff --git a/apps/web/components/ui/Header.tsx b/apps/web/components/ui/Header.tsx index 58d6b416..649f1fb3 100644 --- a/apps/web/components/ui/Header.tsx +++ b/apps/web/components/ui/Header.tsx @@ -44,9 +44,7 @@ const getCachedMenuItems = unstable_cache(async () => getMenuItems(), ["menu"], async function getMenuItems() { const menu = await storefrontClient.getMenu() - const items = menu.data?.menu?.items - - if (!items || menu.errors?.graphQLErrors) return [] + const items = menu.items return items?.map((singleItem) => ({ ...singleItem, diff --git a/apps/web/views/Product/ProductView.tsx b/apps/web/views/Product/ProductView.tsx index 1c02f414..994335b5 100644 --- a/apps/web/views/Product/ProductView.tsx +++ b/apps/web/views/Product/ProductView.tsx @@ -2,22 +2,20 @@ * This code was generated by v0 by Vercel. * @see https://v0.dev/t/J1swfBP3ZeH */ +import { storefrontClient } from "client/storefrontClient" import { Button } from "components/ui/Button" import { Label } from "components/ui/Label" import { RadioGroup, RadioGroupItem } from "components/ui/RadioGroup" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "components/ui/Select" import { notFound } from "next/navigation" -import { storefrontClient } from "client/storefrontClient" export async function ProductView({ slug }) { - const queriedProducts = await storefrontClient.getProductsByHandle(slug) + const product = await storefrontClient.getProductByHandle(slug) - if (queriedProducts.data?.products.edges.length === 0) { + if (!product) { return notFound() } - const product = queriedProducts.data?.products.edges[0].node - return (