MED-103: add booking functionality

This commit is contained in:
Helena
2025-09-17 18:11:13 +03:00
parent 7c92b787ce
commit 22f7fa134b
44 changed files with 1923 additions and 479 deletions

View File

@@ -15,6 +15,7 @@ import {
import { getRegion } from "./regions";
import { sdk } from "@lib/config";
import { retrieveOrder } from "./orders";
import { completeTtoCart } from "../../../../../../lib/services/connected-online.service";
/**
* Retrieves a cart by its ID. If no ID is provided, it will use the cart ID from the cookies.
@@ -89,7 +90,10 @@ export async function getOrSetCart(countryCode: string) {
export async function updateCart(
{ id, ...data }: HttpTypes.StoreUpdateCart & { id?: string },
{ onSuccess, onError }: { onSuccess: () => void, onError: () => void } = { onSuccess: () => {}, onError: () => {} },
{ onSuccess, onError }: { onSuccess: () => void; onError: () => void } = {
onSuccess: () => {},
onError: () => {},
}
) {
const cartId = id || (await getCartId());
@@ -163,7 +167,12 @@ export async function addToCart({
})
.catch(medusaError);
return cart;
const newCart = await getOrSetCart(countryCode);
const addedItem = newCart.items?.filter(
(item) => !cart.items?.some((oldCartItem) => oldCartItem.id === item.id)
)?.[0];
return { newCart, addedItem };
}
export async function updateLineItem({
@@ -268,7 +277,10 @@ export async function initiatePaymentSession(
export async function applyPromotions(
codes: string[],
{ onSuccess, onError }: { onSuccess: () => void, onError: () => void } = { onSuccess: () => {}, onError: () => {} },
{ onSuccess, onError }: { onSuccess: () => void; onError: () => void } = {
onSuccess: () => {},
onError: () => {},
}
) {
const cartId = await getCartId();
@@ -410,7 +422,10 @@ export async function setAddresses(currentState: unknown, formData: FormData) {
* @param cartId - optional - The ID of the cart to place an order for.
* @returns The cart object if the order was successful, or null if not.
*/
export async function placeOrder(cartId?: string, options: { revalidateCacheTags: boolean } = { revalidateCacheTags: true }) {
export async function placeOrder(
cartId?: string,
options: { revalidateCacheTags: boolean } = { revalidateCacheTags: true }
) {
const id = cartId || (await getCartId());
if (!id) {

View File

@@ -20,7 +20,6 @@ export const listCategories = async (query?: Record<string, any>) => {
...query,
},
next,
cache: "force-cache",
}
)
.then(({ product_categories }) => product_categories);
@@ -56,7 +55,6 @@ export const getProductCategories = async ({
limit,
},
next,
//cache: "force-cache",
}
);
};