feat(MED-100): update cart checkout flow and views
This commit is contained in:
@@ -154,6 +154,8 @@ export async function addToCart({
|
||||
revalidateTag(fulfillmentCacheTag);
|
||||
})
|
||||
.catch(medusaError);
|
||||
|
||||
return cart;
|
||||
}
|
||||
|
||||
export async function updateLineItem({
|
||||
@@ -394,7 +396,7 @@ export async function placeOrder(cartId?: string) {
|
||||
const id = cartId || (await getCartId());
|
||||
|
||||
if (!id) {
|
||||
throw new Error("No existing cart found when placing an order");
|
||||
return;
|
||||
}
|
||||
|
||||
const headers = {
|
||||
@@ -411,17 +413,14 @@ export async function placeOrder(cartId?: string) {
|
||||
.catch(medusaError);
|
||||
|
||||
if (cartRes?.type === "order") {
|
||||
const countryCode =
|
||||
cartRes.order.shipping_address?.country_code?.toLowerCase();
|
||||
|
||||
const orderCacheTag = await getCacheTag("orders");
|
||||
revalidateTag(orderCacheTag);
|
||||
|
||||
removeCartId();
|
||||
redirect(`/${countryCode}/order/${cartRes?.order.id}/confirmed`);
|
||||
redirect(`/home/order/${cartRes?.order.id}/confirmed`);
|
||||
} else {
|
||||
throw new Error("Cart is not an order");
|
||||
}
|
||||
|
||||
return cartRes.cart;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,7 +14,7 @@ export const listProducts = async ({
|
||||
regionId,
|
||||
}: {
|
||||
pageParam?: number
|
||||
queryParams?: HttpTypes.FindParams & HttpTypes.StoreProductParams
|
||||
queryParams?: HttpTypes.FindParams & HttpTypes.StoreProductParams & { collection_id?: string }
|
||||
countryCode?: string
|
||||
regionId?: string
|
||||
}): Promise<{
|
||||
|
||||
@@ -57,7 +57,7 @@ export const getRegion = async (countryCode: string) => {
|
||||
|
||||
const region = countryCode
|
||||
? regionMap.get(countryCode)
|
||||
: regionMap.get("us")
|
||||
: regionMap.get("et")
|
||||
|
||||
return region
|
||||
} catch (e: any) {
|
||||
|
||||
@@ -3,24 +3,34 @@
|
||||
import { deleteLineItem } from "@lib/data/cart";
|
||||
import { Spinner, Trash } from "@medusajs/icons";
|
||||
import { clx } from "@medusajs/ui";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
|
||||
const DeleteButton = ({
|
||||
id,
|
||||
children,
|
||||
className,
|
||||
Icon,
|
||||
}: {
|
||||
id: string;
|
||||
children?: React.ReactNode;
|
||||
className?: string;
|
||||
Icon?: React.ReactNode;
|
||||
}) => {
|
||||
const [isDeleting, setIsDeleting] = useState(false);
|
||||
const router = useRouter();
|
||||
|
||||
const handleDelete = async (id: string) => {
|
||||
setIsDeleting(true);
|
||||
await deleteLineItem(id).catch((err) => {
|
||||
|
||||
try {
|
||||
await deleteLineItem(id);
|
||||
|
||||
router.refresh();
|
||||
} catch (err) {
|
||||
// TODO: display a toast notification with the error
|
||||
setIsDeleting(false);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -34,7 +44,7 @@ const DeleteButton = ({
|
||||
className="flex gap-x-1 text-ui-fg-subtle hover:text-ui-fg-base cursor-pointer"
|
||||
onClick={() => handleDelete(id)}
|
||||
>
|
||||
{isDeleting ? <Spinner className="animate-spin" /> : <Trash />}
|
||||
{isDeleting ? <Spinner className="animate-spin" /> : (Icon ?? <Trash />)}
|
||||
<span>{children}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user