Skip to content

Commit

Permalink
chore(sa): next@15
Browse files Browse the repository at this point in the history
  • Loading branch information
ddaoxuan committed Nov 12, 2024
1 parent 50347c3 commit 495da83
Show file tree
Hide file tree
Showing 25 changed files with 650 additions and 466 deletions.
8 changes: 4 additions & 4 deletions starters/shopify-algolia/app/actions/cart.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { isDemoMode } from "utils/demo-utils"
import { createCart, createCartItem, deleteCartItem, getCart, getProduct, updateCartItem } from "lib/shopify"

export async function getOrCreateCart() {
const cartId = cookies().get(COOKIE_CART_ID)?.value
const cartId = (await cookies()).get(COOKIE_CART_ID)?.value
const cart = cartId ? await getCart(cartId) : await createCart()

if (!cartId) {
const newCartId = cart?.id
if (newCartId) {
cookies().set(COOKIE_CART_ID, newCartId)
(await cookies()).set(COOKIE_CART_ID, newCartId)
revalidateTag(TAGS.CART)
}
}
Expand Down Expand Up @@ -81,7 +81,7 @@ export async function addCartItem(prevState: any, variantId: string, productId:
}

export async function removeCartItem(prevState: any, itemId: string) {
const cartId = cookies().get(COOKIE_CART_ID)?.value
const cartId = (await cookies()).get(COOKIE_CART_ID)?.value
if (!cartId) return { ok: false }

await deleteCartItem(cartId, [itemId])
Expand All @@ -91,7 +91,7 @@ export async function removeCartItem(prevState: any, itemId: string) {
}

export async function updateItemQuantity(prevState: any, payload: { itemId: string; variantId: string; quantity: number; productId: string }) {
const cartId = cookies().get(COOKIE_CART_ID)?.value
const cartId = (await cookies()).get(COOKIE_CART_ID)?.value
if (!cartId) return { ok: false }

const { itemId, variantId, quantity, productId } = payload
Expand Down
5 changes: 3 additions & 2 deletions starters/shopify-algolia/app/actions/favorites.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ export async function toggleFavoriteProduct(prevState: any, handle: string) {
const isFavorite = handles.includes(handle)
const newFavorites = handles.includes(handle) ? handles.filter((i) => i !== handle) : [...handles, handle]

cookies().set(COOKIE_FAVORITES, JSON.stringify(newFavorites))
const cookieStore = await cookies()
cookieStore.set(COOKIE_FAVORITES, JSON.stringify(newFavorites))

return !isFavorite
}

export async function getParsedFavoritesHandles() {
const favoritesCookie = cookies().get(COOKIE_FAVORITES)?.value || "[]"
const favoritesCookie = (await cookies()).get(COOKIE_FAVORITES)?.value || "[]"
const favoritesHandles = JSON.parse(favoritesCookie) as string[]
return favoritesHandles
}
2 changes: 1 addition & 1 deletion starters/shopify-algolia/app/actions/reviews.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { headers } from "next/headers"

export const submitReview = async (payload: Omit<ProductReviewBody, "ip_addr">) => {
try {
const ipAddress = headers().get("x-forwarded-for") || null
const ipAddress = (await headers()).get("x-forwarded-for") || null
await createProductReview({ ...payload, ip_addr: ipAddress })
} catch (err) {
throw new Error(err as string)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ export const revalidate = 86400
export const dynamic = "force-static"

interface CategoryPageProps {
params: { slug: string; page: string }
params: Promise<{ slug: string; page: string }>
}

export async function generateMetadata({ params }: CategoryPageProps): Promise<Metadata> {
export async function generateMetadata(props: CategoryPageProps): Promise<Metadata> {
const params = await props.params;
return {
title: `${params.slug} | Enterprise Commerce`,
description: "In excepteur elit mollit in.",
Expand All @@ -19,6 +20,7 @@ export async function generateStaticParams() {
return []
}

export default async function CategoryPage({ params }: CategoryPageProps) {
export default async function CategoryPage(props: CategoryPageProps) {
const params = await props.params;
return <CategoryView searchParams={{ page: params.page }} params={params} />
}
8 changes: 5 additions & 3 deletions starters/shopify-algolia/app/category/clp/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ export const revalidate = 86400
export const dynamic = "force-static"

interface CategoryPageProps {
params: { slug: string }
params: Promise<{ slug: string }>
}

export async function generateMetadata({ params }: CategoryPageProps): Promise<Metadata> {
export async function generateMetadata(props: CategoryPageProps): Promise<Metadata> {
const params = await props.params;
return {
title: `${params.slug} | Enterprise Commerce`,
description: "In excepteur elit mollit in.",
Expand All @@ -28,6 +29,7 @@ export async function generateStaticParams() {
return hits.map(({ handle }) => ({ slug: handle }))
}

export default async function CategoryPage({ params }: CategoryPageProps) {
export default async function CategoryPage(props: CategoryPageProps) {
const params = await props.params;
return <CategoryView params={params} />
}
11 changes: 7 additions & 4 deletions starters/shopify-algolia/app/category/plp/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ export const runtime = "nodejs"
export const revalidate = 86400

interface ProductListingPageProps {
searchParams: SearchParamsType
params: { slug: string }
searchParams: Promise<SearchParamsType>
params: Promise<{ slug: string }>
}

export async function generateMetadata({ params }: ProductListingPageProps): Promise<Metadata> {
export async function generateMetadata(props: ProductListingPageProps): Promise<Metadata> {
const params = await props.params;
return {
title: `${params.slug} | Enterprise Commerce`,
description: "In excepteur elit mollit in.",
}
}

export default async function ProductListingPage({ searchParams, params }: ProductListingPageProps) {
export default async function ProductListingPage(props: ProductListingPageProps) {
const params = await props.params;
const searchParams = await props.searchParams;
return <CategoryView params={params} searchParams={searchParams} />
}
2 changes: 1 addition & 1 deletion starters/shopify-algolia/app/favorites/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default async function Favorites() {

async function FavoritesView() {
let favoritesHandles: string[] = []
const favoritesCookie = cookies().get(COOKIE_FAVORITES)?.value
const favoritesCookie = (await cookies()).get(COOKIE_FAVORITES)?.value

if (favoritesCookie) {
favoritesHandles = JSON.parse(favoritesCookie) as string[]
Expand Down
8 changes: 7 additions & 1 deletion starters/shopify-algolia/app/home/[bucket]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ export const dynamic = "force-static"

export const dynamicParams = true

export default async function Homepage({ params: { bucket } }: { params: { bucket: string } }) {
export default async function Homepage(props: { params: Promise<{ bucket: string }> }) {
const params = await props.params;

const {
bucket
} = params;

const heroTitles = {
a: "Discover Your Next Favorite Thing",
b: "Shop the best Deals on Top Brands & Unique Finds",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ export async function CategoriesSection() {
{categories.map((category, index) => {
return (
<CategoryCard
key={index}
className={cn("bg-white shadow-md md:shadow-none", {
"md:border-r": index === 0 || index === 2,
"md:border-l": index === 1 || index === 3,
"md:border-b": index === 0 || index === 1,
"md:border-t": index === 2 || index === 3,
})}
index={index + 3}
key={category.id}
{...category}
/>
)
Expand Down
3 changes: 2 additions & 1 deletion starters/shopify-algolia/app/pages/[slug]/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { getPage } from "lib/shopify"
import { Metadata } from "next"

export async function generateMetadata({ params: { slug } }: { params: { slug: string } }): Promise<Metadata> {
export async function generateMetadata(props: { params: Promise<{ slug: string }> }): Promise<Metadata> {
const slug = (await props.params).slug
const page = await getPage(slug)

return {
Expand Down
6 changes: 5 additions & 1 deletion starters/shopify-algolia/app/pages/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export const dynamicParams = true

export { generateMetadata } from "./metadata"

export default async function StaticPage({ params: { slug } }: { params: { slug: string } }) {
export default async function StaticPage(props: { params: Promise<{ slug: string }> }) {
const params = await props.params

const { slug } = params

const page = await getPage(slug)

if (!page) return null
Expand Down
12 changes: 9 additions & 3 deletions starters/shopify-algolia/app/product/[slug]/draft/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ export const revalidate = 86400
export const dynamicParams = true

interface ProductProps {
params: { slug: string }
params: Promise<{ slug: string }>
}

export default async function Product({ params: { slug } }: ProductProps) {
export default async function Product(props: ProductProps) {
const params = await props.params;

const {
slug
} = params;

return <ProductView slug={slug} />
}

Expand Down Expand Up @@ -86,7 +92,7 @@ async function ProductView({ slug }: { slug: string }) {
}

async function getDraftAwareProduct(slug: string) {
const draft = draftMode()
const draft = await draftMode()

let product = await getProductByHandle(removeOptionsFromUrl(slug))
if (draft.isEnabled && product) product = await getAdminProduct(product?.id)
Expand Down
10 changes: 8 additions & 2 deletions starters/shopify-algolia/app/product/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const dynamic = "force-static"
export const dynamicParams = true

interface ProductProps {
params: { slug: string }
params: Promise<{ slug: string }>
}

export async function generateStaticParams() {
Expand All @@ -44,7 +44,13 @@ export async function generateStaticParams() {
return hits.map(({ handle }) => ({ slug: handle }))
}

export default async function Product({ params: { slug } }: ProductProps) {
export default async function Product(props: ProductProps) {
const params = await props.params;

const {
slug
} = params;

const product = await getProduct(removeOptionsFromUrl(slug))

const { color } = getOptionsFromUrl(slug)
Expand Down
3 changes: 2 additions & 1 deletion starters/shopify-algolia/app/reviews/[slug]/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { Metadata } from "next"
import { getProduct } from "lib/algolia"
import { env } from "env.mjs"

export async function generateMetadata({ params: { slug } }: ProductReviewsPageProps): Promise<Metadata> {
export async function generateMetadata(props: ProductReviewsPageProps): Promise<Metadata> {
const slug = (await props.params).slug
const product = await getProduct(removeOptionsFromUrl(slug))

const originalTitle = product?.seo?.title
Expand Down
11 changes: 8 additions & 3 deletions starters/shopify-algolia/app/reviews/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ export { generateMetadata } from "./metadata"
export const revalidate = 86400

export interface ProductReviewsPageProps {
params: { slug: string }
searchParams: { [key: string]: string | string[] | undefined }
params: Promise<{ slug: string }>
searchParams: Promise<{ [key: string]: string | string[] | undefined }>
}

export default async function ProductReviews({ params: { slug }, searchParams }: ProductReviewsPageProps) {
export default async function ProductReviews(props: ProductReviewsPageProps) {
const searchParams = await props.searchParams
const params = await props.params

const { slug } = params

const page = searchParams.page ? parseInt(searchParams.page as string) : 1

const [product, { reviews, total: totalReviews }] = await Promise.all([
Expand Down
5 changes: 3 additions & 2 deletions starters/shopify-algolia/app/search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ export const revalidate = 86400
export const runtime = "nodejs"

interface SearchPageProps {
searchParams: SearchParamsType
searchParams: Promise<SearchParamsType>
}

export default async function SearchPage({ searchParams }: SearchPageProps) {
export default async function SearchPage(props: SearchPageProps) {
const searchParams = await props.searchParams;
return (
<Suspense fallback={<PageSkeleton />}>
<SearchView searchParams={searchParams} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ export function FacetsContent({ independentFacetDistribution, facetDistribution,
<AccordionTrigger className="py-2 text-base">Price</AccordionTrigger>
<AccordionContent className="px-2">
<PriceFacet
initMin={minPrice}
initMax={maxPrice}
minPrice={minPrice}
maxPrice={maxPrice}
setFacet={({ minPrice, maxPrice }) => {
setMinPrice(minPrice)
setMaxPrice(maxPrice)
Expand Down
Loading

0 comments on commit 495da83

Please sign in to comment.