Merge pull request #51 from MR-medreport/MED-105-v3
feat(MED-101): disable cart timer, create audit log on "remove item from cart"
This commit is contained in:
@@ -32,11 +32,12 @@ export default async function CartPage() {
|
|||||||
|
|
||||||
const otherItemsSorted = otherItems.sort((a, b) => (a.updated_at ?? "") > (b.updated_at ?? "") ? -1 : 1);
|
const otherItemsSorted = otherItems.sort((a, b) => (a.updated_at ?? "") > (b.updated_at ?? "") ? -1 : 1);
|
||||||
const item = otherItemsSorted[0];
|
const item = otherItemsSorted[0];
|
||||||
|
const hasItemsWithTimer = false as boolean;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageBody>
|
<PageBody>
|
||||||
<PageHeader title={<Trans i18nKey="cart:title" />}>
|
<PageHeader title={<Trans i18nKey="cart:title" />}>
|
||||||
{item && item.updated_at && <CartTimer cartItem={item} />}
|
{hasItemsWithTimer && item && item.updated_at && <CartTimer cartItem={item} />}
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
<Cart cart={cart} analysisPackages={analysisPackages} otherItems={otherItems} />
|
<Cart cart={cart} analysisPackages={analysisPackages} otherItems={otherItems} />
|
||||||
</PageBody>
|
</PageBody>
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import { useState } from "react";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
import { deleteLineItem } from "@lib/data/cart";
|
|
||||||
import { Spinner } from "@medusajs/icons";
|
import { Spinner } from "@medusajs/icons";
|
||||||
|
import { handleDeleteCartItem } from "~/lib/services/medusaCart.service";
|
||||||
|
|
||||||
const CartItemDelete = ({
|
const CartItemDelete = ({
|
||||||
id,
|
id,
|
||||||
@@ -22,7 +22,7 @@ const CartItemDelete = ({
|
|||||||
setIsDeleting(true);
|
setIsDeleting(true);
|
||||||
|
|
||||||
const promise = async () => {
|
const promise = async () => {
|
||||||
await deleteLineItem(id);
|
await handleDeleteCartItem({ lineId: id });
|
||||||
};
|
};
|
||||||
|
|
||||||
toast.promise(promise, {
|
toast.promise(promise, {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { z } from 'zod';
|
|||||||
import { loadCurrentUserAccount } from '@/app/home/(user)/_lib/server/load-user-account';
|
import { loadCurrentUserAccount } from '@/app/home/(user)/_lib/server/load-user-account';
|
||||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||||
import { addToCart, deleteLineItem, retrieveCart } from '@lib/data/cart';
|
import { addToCart, deleteLineItem, retrieveCart } from '@lib/data/cart';
|
||||||
|
import { getCartId } from '@lib/data/cookies';
|
||||||
import { StoreCartLineItem, StoreProductVariant } from '@medusajs/types';
|
import { StoreCartLineItem, StoreProductVariant } from '@medusajs/types';
|
||||||
import { MontonioOrderHandlerService } from '@/packages/billing/montonio/src';
|
import { MontonioOrderHandlerService } from '@/packages/billing/montonio/src';
|
||||||
import { requireUserInServerComponent } from '../server/require-user-in-server-component';
|
import { requireUserInServerComponent } from '../server/require-user-in-server-component';
|
||||||
@@ -64,6 +65,36 @@ export async function handleAddToCart({
|
|||||||
return cart;
|
return cart;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function handleDeleteCartItem({
|
||||||
|
lineId,
|
||||||
|
}: {
|
||||||
|
lineId: string;
|
||||||
|
}) {
|
||||||
|
await deleteLineItem(lineId);
|
||||||
|
|
||||||
|
const supabase = getSupabaseServerClient();
|
||||||
|
const cartId = await getCartId();
|
||||||
|
const user = await requireUserInServerComponent();
|
||||||
|
const account = await loadCurrentUserAccount()
|
||||||
|
if (!account) {
|
||||||
|
throw new Error('Account not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
const { error } = await supabase
|
||||||
|
.schema('audit')
|
||||||
|
.from('cart_entries')
|
||||||
|
.insert({
|
||||||
|
variant_id: lineId,
|
||||||
|
operation: 'REMOVE_FROM_CART',
|
||||||
|
account_id: account.id,
|
||||||
|
cart_id: cartId!,
|
||||||
|
changed_by: user.id,
|
||||||
|
});
|
||||||
|
if (error) {
|
||||||
|
throw new Error('Error logging cart entry: ' + error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function handleNavigateToPayment({ language, paymentSessionId }: { language: string, paymentSessionId: string }) {
|
export async function handleNavigateToPayment({ language, paymentSessionId }: { language: string, paymentSessionId: string }) {
|
||||||
const supabase = getSupabaseServerClient();
|
const supabase = getSupabaseServerClient();
|
||||||
const user = await requireUserInServerComponent();
|
const user = await requireUserInServerComponent();
|
||||||
|
|||||||
Reference in New Issue
Block a user