diff --git a/components/cart/actions.ts b/components/cart/actions.ts index 3fb013194..72af2b9fc 100644 --- a/components/cart/actions.ts +++ b/components/cart/actions.ts @@ -1,9 +1,11 @@ 'use server'; +import { TAGS } from 'lib/constants'; import { addToCart, createCart, getCart, removeFromCart, updateCart } from 'lib/shopify'; +import { revalidateTag } from 'next/cache'; import { cookies } from 'next/headers'; -export const addItem = async (variantId: string | undefined): Promise => { +export async function addItem(prevState: any, selectedVariantId: string) { let cartId = cookies().get('cartId')?.value; let cart; @@ -17,12 +19,13 @@ export const addItem = async (variantId: string | undefined): Promise + Out Of Stock + + } + + if (!selectedVariantId) { + return + } + + return ( + + ) + +} export function AddToCart({ variants, @@ -15,9 +61,8 @@ export function AddToCart({ variants: ProductVariant[]; availableForSale: boolean; }) { - const router = useRouter(); + const [message, formAction] = useFormState(addItem, null) const searchParams = useSearchParams(); - const [isPending, startTransition] = useTransition(); const defaultVariantId = variants.length === 1 ? variants[0]?.id : undefined; const variant = variants.find((variant: ProductVariant) => variant.selectedOptions.every( @@ -25,44 +70,15 @@ export function AddToCart({ ) ); const selectedVariantId = variant?.id || defaultVariantId; - const title = !availableForSale - ? 'Out of stock' - : !selectedVariantId - ? 'Please select options' - : undefined; + const actionWithVariant = formAction.bind(null, selectedVariantId) return ( - - ); -} + +

+ {message} +

+ + ) +} \ No newline at end of file diff --git a/components/layout/footer.tsx b/components/layout/footer.tsx index 8627ca28b..23c5a0d00 100644 --- a/components/layout/footer.tsx +++ b/components/layout/footer.tsx @@ -58,9 +58,8 @@ export default async function Footer() {

Designed in California

- Crafted by{' '} - ▲ Vercel + Crafted by ▲ Vercel

diff --git a/components/layout/search/filter/index.tsx b/components/layout/search/filter/index.tsx index ac5002d68..7365d226d 100644 --- a/components/layout/search/filter/index.tsx +++ b/components/layout/search/filter/index.tsx @@ -19,7 +19,7 @@ export default function FilterList({ list, title }: { list: ListItem[]; title?: return ( <>