Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

3 changes: 1 addition & 2 deletions core/app/[locale]/(default)/cart/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { getCartId } from '~/lib/cart';
import { getPreferredCurrencyCode } from '~/lib/currency';
import { exists } from '~/lib/utils';

import { redirectToCheckout } from './_actions/redirect-to-checkout';
import { updateCouponCode } from './_actions/update-coupon-code';
import { updateGiftCertificate } from './_actions/update-gift-certificate';
import { updateLineItem } from './_actions/update-line-item';
Expand Down Expand Up @@ -251,7 +250,7 @@ export default async function Cart({ params }: Props) {
},
].filter(exists),
}}
checkoutAction={redirectToCheckout}
checkoutAction="/checkout"
checkoutLabel={t('proceedToCheckout')}
couponCode={{
action: updateCouponCode,
Expand Down
7 changes: 7 additions & 0 deletions core/app/[locale]/(default)/checkout/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BigCommerceAuthError } from '@bigcommerce/catalyst-client';
import { unstable_rethrow as rethrow } from 'next/navigation';
import { NextRequest, NextResponse } from 'next/server';
import { getTranslations } from 'next-intl/server';

import { getSessionCustomerAccessToken } from '~/auth';
import { getChannelIdFromLocale } from '~/channels.config';
Expand All @@ -10,6 +11,7 @@ import { redirect } from '~/i18n/routing';
import { getVisitIdCookie, getVisitorIdCookie } from '~/lib/analytics/bigcommerce';
import { getCartId } from '~/lib/cart';
import { getConsentCookie } from '~/lib/consent-manager/cookies/server';
import { serverToast } from '~/lib/server-toast';

const CheckoutRedirectMutation = graphql(`
mutation CheckoutRedirectMutation(
Expand Down Expand Up @@ -55,8 +57,11 @@ export async function GET(req: NextRequest, { params }: { params: Promise<{ loca
const cartId = req.nextUrl.searchParams.get('cartId') ?? (await getCartId());
const customerAccessToken = await getSessionCustomerAccessToken();
const channelId = getChannelIdFromLocale(locale);
const t = await getTranslations('Cart.Errors');

if (!cartId) {
await serverToast.error(t('cartNotFound'));

return redirect({ href: '/cart', locale });
}

Expand Down Expand Up @@ -86,6 +91,8 @@ export async function GET(req: NextRequest, { params }: { params: Promise<{ loca
data.cart.createCartRedirectUrls.errors.length > 0 ||
!data.cart.createCartRedirectUrls.redirectUrls
) {
await serverToast.error(t('somethingWentWrong'));

return redirect({ href: '/cart', locale });
}

Expand Down
2 changes: 1 addition & 1 deletion core/lib/server-toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function setToastCookie(data: ServerToastData) {
sameSite: 'strict',
path: '/',
partitioned: true,
maxAge: 0,
maxAge: 1,
});
}

Expand Down
8 changes: 4 additions & 4 deletions core/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
"couponCode": "Coupon code",
"removeCouponCode": "Remove coupon code",
"invalidCouponCode": "Please enter a valid coupon code",
"cartNotFound": "No cartId cookie found."
"cartNotFound": "An error occurred when retrieving your cart"
},
"Shipping": {
"shipping": "Shipping",
Expand All @@ -324,7 +324,7 @@
"shippingOptions": "Shipping options",
"updateShipping": "Update shipping",
"addShipping": "Add shipping",
"cartNotFound": "No cartId cookie found.",
"cartNotFound": "An error occurred when retrieving your cart",
"noShippingOptions": "There are no shipping options available for your address"
}
},
Expand All @@ -336,15 +336,15 @@
"to": "To",
"message": "Message",
"invalidGiftCertificate": "Please enter a valid gift certificate code",
"cartNotFound": "No cartId cookie found."
"cartNotFound": "An error occurred when retrieving your cart"
},
"Empty": {
"title": "Your cart is empty.",
"subtitle": "Add some products to get started.",
"cta": "Continue shopping"
},
"Errors": {
"cartNotFound": "No cartId cookie found.",
"cartNotFound": "An error occurred when retrieving your cart",
"lineItemNotFound": "Line item not found.",
"failedToUpdateQuantity": "Failed to update quantity.",
"somethingWentWrong": "Something went wrong. Please try again later."
Expand Down
17 changes: 13 additions & 4 deletions core/vibes/soul/sections/cart/client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export interface CartProps<LineItem extends CartLineItem> {
summaryTitle?: string;
emptyState?: CartEmptyState;
lineItemAction: Action<CartState<LineItem>, FormData>;
checkoutAction: Action<SubmissionResult | null, FormData>;
checkoutAction: Action<SubmissionResult | null, FormData> | string;
checkoutLabel?: string;
deleteLineItemLabel?: string;
decrementLineItemLabel?: string;
Expand Down Expand Up @@ -628,10 +628,19 @@ function CheckoutButton({
isCartUpdatePending,
...props
}: {
action: Action<SubmissionResult | null, FormData>;
action: Action<SubmissionResult | null, FormData> | string;
isCartUpdatePending: boolean;
} & ComponentPropsWithoutRef<typeof Button>) {
const [lastResult, formAction] = useActionState(action, null);
const [lastResult, formAction] = useActionState(
async (state: SubmissionResult | null, formData: FormData) => {
if (typeof action !== 'function') {
return null;
}

return action(state, formData);
},
null,
);

const [form] = useForm({ lastResult });

Expand All @@ -644,7 +653,7 @@ function CheckoutButton({
}, [form.errors]);

return (
<form action={formAction}>
<form action={typeof action === 'string' ? action : formAction}>
<SubmitButton {...props} isCartUpdatePending={isCartUpdatePending} />
</form>
);
Expand Down