MED-103: add booking functionality
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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",
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user