feat(MED-100): update cart checkout flow and views
This commit is contained in:
@@ -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