wip: Saving work

This commit is contained in:
Sol Irvine 2023-08-31 20:06:14 -07:00
parent c044d494a4
commit b7d78faaf0
19 changed files with 40 additions and 24 deletions

View File

@ -23,7 +23,7 @@ export default async function Page({ params }: { params: { locale?: SupportedLoc
let cart;
if (cartId) {
cart = await getCart(cartId);
cart = await getCart({ cartId, language: params?.locale?.toUpperCase() });
}
const awardsPage = await getPage({ handle: 'awards', language: params?.locale?.toUpperCase() });

View File

@ -25,7 +25,7 @@ export default async function Page({ params }: { params: { locale?: SupportedLoc
let cart;
if (cartId) {
cart = await getCart(cartId);
cart = await getCart({ cartId, language: params?.locale?.toUpperCase() });
}
return (

View File

@ -25,7 +25,7 @@ export default async function Page({ params }: { params: { locale?: SupportedLoc
let cart;
if (cartId) {
cart = await getCart(cartId);
cart = await getCart({ cartId, language: params?.locale?.toUpperCase() });
}
return (

View File

@ -25,7 +25,7 @@ export default async function Page({ params }: { params: { locale?: SupportedLoc
let cart;
if (cartId) {
cart = await getCart(cartId);
cart = await getCart({ cartId, language: params?.locale?.toUpperCase() });
}
return (

View File

@ -29,7 +29,7 @@ export default async function DisclosuresPage({
let cart;
if (cartId) {
cart = await getCart(cartId);
cart = await getCart({ cartId, language: locale?.toUpperCase() });
}
return (

View File

@ -45,7 +45,9 @@ export default async function HomePage({
let cart;
if (cartId) {
cart = await getCart(cartId);
console.debug({ cartId });
cart = await getCart({ cartId, language: locale?.toUpperCase() });
console.debug({ cart });
}
return (

View File

@ -29,7 +29,7 @@ export default async function PrivacyPage({
let cart;
if (cartId) {
cart = await getCart(cartId);
cart = await getCart({ cartId, language: locale?.toUpperCase() });
}
return (

View File

@ -28,7 +28,7 @@ export default async function ProductLayout({
let cart;
if (cartId) {
cart = await getCart(cartId);
cart = await getCart({ cartId, language: locale?.toUpperCase() });
}
return (

View File

@ -30,8 +30,6 @@ export async function generateMetadata({
language: params?.locale?.toUpperCase()
});
console.debug({ product });
if (!product) return notFound();
const { url, width, height, altText: alt } = product.featuredImage || {};

View File

@ -29,7 +29,7 @@ export default async function ProductPage({
let cart;
if (cartId) {
cart = await getCart(cartId);
cart = await getCart({ cartId, language: locale?.toUpperCase() });
}
return (

View File

@ -39,7 +39,7 @@ export default async function Page({ params }: { params: { locale?: SupportedLoc
let cart;
if (cartId) {
cart = await getCart(cartId);
cart = await getCart({ cartId, language: params?.locale?.toUpperCase() });
}
const page = await getPage({ handle: 'shop-list', language: params?.locale?.toUpperCase() });

View File

@ -28,7 +28,7 @@ export default async function BlogLayout({
let cart;
if (cartId) {
cart = await getCart(cartId);
cart = await getCart({ cartId, language: locale?.toUpperCase() });
}
return (

View File

@ -28,7 +28,7 @@ export default async function StoriesPage({
let cart;
if (cartId) {
cart = await getCart(cartId);
cart = await getCart({ cartId, language: locale?.toUpperCase() });
}
return (

View File

@ -27,7 +27,7 @@ export default async function TermsPage({
let cart;
if (cartId) {
cart = await getCart(cartId);
cart = await getCart({ cartId, language: locale?.toUpperCase() });
}
return (

View File

@ -1,14 +1,21 @@
'use server';
import { SupportedLocale } from 'components/layout/navbar/language-control';
import { addToCart, createCart, getCart, removeFromCart, updateCart } from 'lib/shopify';
import { cookies } from 'next/headers';
export const addItem = async (variantId: string | undefined): Promise<String | undefined> => {
export const addItem = async ({
variantId,
locale
}: {
variantId: string | undefined;
locale?: string;
}): Promise<String | undefined> => {
let cartId = cookies().get('cartId')?.value;
let cart;
if (cartId) {
cart = await getCart(cartId);
cart = await getCart({ cartId, language: locale?.toUpperCase() });
}
if (!cartId || !cart) {
@ -30,16 +37,18 @@ export const addItem = async (variantId: string | undefined): Promise<String | u
export const addItems = async ({
variantId,
quantity = 1
quantity = 1,
locale
}: {
variantId: string | undefined;
quantity: number;
locale?: SupportedLocale;
}): Promise<String | undefined> => {
let cartId = cookies().get('cartId')?.value;
let cart;
if (cartId) {
cart = await getCart(cartId);
cart = await getCart({ cartId, language: locale?.toUpperCase() });
}
if (!cartId || !cart) {

View File

@ -2,9 +2,10 @@
import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/24/outline';
import clsx from 'clsx';
import { SupportedLocale } from 'components/layout/navbar/language-control';
import LoadingDots from 'components/loading-dots';
import { ProductVariant } from 'lib/shopify/types';
import { useTranslations } from 'next-intl';
import { useLocale, useTranslations } from 'next-intl';
import { useRouter, useSearchParams } from 'next/navigation';
import { useState, useTransition } from 'react';
import { addItems } from './actions';
@ -20,6 +21,7 @@ export function AddManyToCart({
}) {
const router = useRouter();
const searchParams = useSearchParams();
const locale = useLocale();
const t = useTranslations('Index');
const [currentQuantity, setCurrentQuantity] = useState<number>(quantity);
@ -83,7 +85,8 @@ export function AddManyToCart({
startTransition(async () => {
const error = await addItems({
variantId: selectedVariantId,
quantity: currentQuantity
quantity: currentQuantity,
locale: locale as SupportedLocale
});
if (error) {

View File

@ -1,13 +1,14 @@
import { SupportedLocale } from 'components/layout/navbar/language-control';
import { getCart } from 'lib/shopify';
import { cookies } from 'next/headers';
import CartModal from './modal';
export default async function Cart() {
export default async function Cart({ locale }: { locale?: SupportedLocale }) {
const cartId = cookies().get('cartId')?.value;
let cart;
if (cartId) {
cart = await getCart(cartId);
cart = await getCart({ cartId, language: locale?.toUpperCase() });
}
return <CartModal cart={cart} />;

View File

@ -1,7 +1,8 @@
import cartFragment from '../fragments/cart';
export const getCartQuery = /* GraphQL */ `
query getCart($cartId: ID!) {
query getCart($cartId: ID!, $country: CountryCode, $language: LanguageCode)
@inContext(country: $country, language: $language) {
cart(id: $cartId) {
...cart
}

View File

@ -176,6 +176,8 @@ export type ShopifyCartOperation = {
};
variables: {
cartId: string;
language?: string;
country?: string;
};
};