diff --git a/app/home/(user)/_components/cart/discount-code.tsx b/app/home/(user)/_components/cart/discount-code.tsx index 0a5cbaf..eea8ef4 100644 --- a/app/home/(user)/_components/cart/discount-code.tsx +++ b/app/home/(user)/_components/cart/discount-code.tsx @@ -1,6 +1,7 @@ "use client" -import { Badge, Heading, Text } from "@medusajs/ui" +import { Badge, Text } from "@medusajs/ui" +import { toast } from '@kit/ui/sonner'; import React, { useActionState } from "react"; import { applyPromotions, submitPromotionForm } from "@lib/data/cart" @@ -31,11 +32,19 @@ export default function DiscountCode({ cart }: { const removePromotionCode = async (code: string) => { const validPromotions = promotions.filter( - (promotion) => promotion.code !== code + (promotion) => promotion.code !== code, ) await applyPromotions( - validPromotions.filter((p) => p.code === undefined).map((p) => p.code!) + validPromotions.filter((p) => p.code === undefined).map((p) => p.code!), + { + onSuccess: () => { + toast.success(t('cart:discountCode.removeSuccess')); + }, + onError: () => { + toast.error(t('cart:discountCode.removeError')); + }, + } ) } @@ -45,7 +54,14 @@ export default function DiscountCode({ cart }: { .map((p) => p.code!) codes.push(code.toString()) - await applyPromotions(codes) + await applyPromotions(codes, { + onSuccess: () => { + toast.success(t('cart:discountCode.addSuccess')); + }, + onError: () => { + toast.error(t('cart:discountCode.addError')); + }, + }); form.reset() } @@ -64,7 +80,7 @@ export default function DiscountCode({ cart }: {
addPromotionCode(data.code))} - className="w-full mb-2 flex gap-x-2" + className="w-full mb-2 flex gap-x-2 sm:flex-row flex-col gap-y-2" > -

- -

- - {promotions.length > 0 && ( -
-
- - Promotion(s) applied: - + {promotions.length > 0 ? ( +
+
+

+ +

{promotions.map((promotion) => { return ( @@ -110,6 +122,7 @@ export default function DiscountCode({ cart }: { {promotion.code} {" "} @@ -151,7 +164,7 @@ export default function DiscountCode({ cart }: { > - Remove discount code from order + )} @@ -160,6 +173,10 @@ export default function DiscountCode({ cart }: { })}
+ ) : ( +

+ +

)}
) diff --git a/app/home/(user)/_components/cart/index.tsx b/app/home/(user)/_components/cart/index.tsx index 9f2b0fd..4ab083e 100644 --- a/app/home/(user)/_components/cart/index.tsx +++ b/app/home/(user)/_components/cart/index.tsx @@ -18,7 +18,7 @@ import { useTranslation } from "react-i18next"; import { handleNavigateToPayment } from "@/lib/services/medusaCart.service"; import AnalysisLocation from "./analysis-location"; -const IS_DISCOUNT_SHOWN = false as boolean; +const IS_DISCOUNT_SHOWN = true as boolean; export default function Cart({ cart, @@ -69,7 +69,7 @@ export default function Cart({ const hasCartItems = Array.isArray(cart.items) && cart.items.length > 0; const isLocationsShown = synlabAnalyses.length > 0; - + return (
@@ -77,28 +77,62 @@ export default function Cart({
{hasCartItems && ( -
-
-

- -

+ <> +
+
+

+ +

+
+
+

+ {formatCurrency({ + value: cart.subtotal, + currencyCode: cart.currency_code, + locale: language, + })} +

+
-
-

- {formatCurrency({ - value: cart.total, - currencyCode: cart.currency_code, - locale: language, - })} -

+
+
+

+ +

+
+
+

+ {formatCurrency({ + value: cart.discount_total, + currencyCode: cart.currency_code, + locale: language, + })} +

+
-
+
+
+

+ +

+
+
+

+ {formatCurrency({ + value: cart.total, + currencyCode: cart.currency_code, + locale: language, + })} +

+
+
+ )} -
+
{IS_DISCOUNT_SHOWN && (
@@ -113,7 +147,7 @@ export default function Cart({ {isLocationsShown && (
diff --git a/lib/services/medipost.service.ts b/lib/services/medipost.service.ts index 90bdce8..b6aec5d 100644 --- a/lib/services/medipost.service.ts +++ b/lib/services/medipost.service.ts @@ -10,6 +10,7 @@ import { getClientInstitution, getClientPerson, getConfidentiality, + getOrderEnteredPerson, getPais, getPatient, getProviderInstitution, @@ -553,14 +554,12 @@ export async function composeOrderXML({ ${getPais(USER, RECIPIENT, orderCreatedAt, orderId)} ${orderId} - ${getClientInstitution()} - ${getProviderInstitution()} - - ${getClientPerson(person)} + ${getClientPerson()} + ${getOrderEnteredPerson()} ${comment ?? ''} - ${getPatient(person)} + ${getPatient(person)} ${getConfidentiality()} ${specimenSection.join('')} ${analysisSection?.join('')} diff --git a/lib/services/medipostTest.service.ts b/lib/services/medipostTest.service.ts index 1a3b0d9..f4393f7 100644 --- a/lib/services/medipostTest.service.ts +++ b/lib/services/medipostTest.service.ts @@ -3,6 +3,7 @@ import { getClientInstitution, getClientPerson, + getOrderEnteredPerson, getPais, getPatient, getProviderInstitution, @@ -104,7 +105,8 @@ export async function composeOrderTestResponseXML({ ${orderId} ${getClientInstitution({ index: 1 })} ${getProviderInstitution({ index: 1 })} - ${getClientPerson(person)} + ${getClientPerson()} + ${getOrderEnteredPerson()} Siia tuleb tellija poolne märkus ${getPatient(person)} diff --git a/lib/templates/medipost-order.ts b/lib/templates/medipost-order.ts index 6568c22..10ce573 100644 --- a/lib/templates/medipost-order.ts +++ b/lib/templates/medipost-order.ts @@ -21,70 +21,48 @@ export const getPais = ( ${recipient} ${format(createdAt, DATE_TIME_FORMAT)} ${orderId} - argo@medreport.ee + info@medreport.ee `; }; export const getClientInstitution = ({ index }: { index?: number } = {}) => { - if (isProd) { - // return correct data - } return ` 16381793 MedReport OÜ - TSU + MRP +37258871517 `; }; export const getProviderInstitution = ({ index }: { index?: number } = {}) => { - if (isProd) { - // return correct data - } return ` 11107913 - Synlab HTI Tallinn - SLA + Synlab Eesti OÜ + HTI Synlab HTI Tallinn - +3723417123 + +37217123 `; }; -export const getClientPerson = ({ - idCode, - firstName, - lastName, - phone, -}: { - idCode: string, - firstName: string, - lastName: string, - phone: string, -}) => { - if (isProd) { - // return correct data - } +export const getClientPerson = () => { return ` 1.3.6.1.4.1.28284.6.2.4.9 - ${idCode} - ${lastName} - ${firstName} - ${phone ? `${phone.startsWith('+372') ? phone : `+372${phone}`}` : ''} + D07907 + Eduard + Tsvetkov + +37258131202 `; }; -// export const getOrderEnteredPerson = () => { -// if (isProd) { -// // return correct data -// } -// return ` -// 1.3.6.1.4.1.28284.6.2.4.9 -// D07907 -// Eduard -// Tsvetkov -// +37258131202 -// `; -// }; +export const getOrderEnteredPerson = () => { + return ` + 1.3.6.1.4.1.28284.6.2.4.9 + D07907 + Eduard + Tsvetkov + +37258131202 + `; +}; export const getPatient = ({ idCode, diff --git a/packages/features/medusa-storefront/src/lib/data/cart.ts b/packages/features/medusa-storefront/src/lib/data/cart.ts index 42b3700..0bb1cfd 100644 --- a/packages/features/medusa-storefront/src/lib/data/cart.ts +++ b/packages/features/medusa-storefront/src/lib/data/cart.ts @@ -87,7 +87,10 @@ export async function getOrSetCart(countryCode: string) { return cart; } -export async function updateCart({ id, ...data }: HttpTypes.StoreUpdateCart & { id?: string }) { +export async function updateCart( + { id, ...data }: HttpTypes.StoreUpdateCart & { id?: string }, + { onSuccess, onError }: { onSuccess: () => void, onError: () => void } = { onSuccess: () => {}, onError: () => {} }, +) { const cartId = id || (await getCartId()); if (!cartId) { @@ -109,9 +112,13 @@ export async function updateCart({ id, ...data }: HttpTypes.StoreUpdateCart & { const fulfillmentCacheTag = await getCacheTag("fulfillment"); revalidateTag(fulfillmentCacheTag); + onSuccess(); return cart; }) - .catch(medusaError); + .catch((e) => { + onError(); + return medusaError(e); + }); } export async function addToCart({ @@ -259,7 +266,10 @@ export async function initiatePaymentSession( .catch(medusaError); } -export async function applyPromotions(codes: string[]) { +export async function applyPromotions( + codes: string[], + { onSuccess, onError }: { onSuccess: () => void, onError: () => void } = { onSuccess: () => {}, onError: () => {} }, +) { const cartId = await getCartId(); if (!cartId) { @@ -278,8 +288,13 @@ export async function applyPromotions(codes: string[]) { const fulfillmentCacheTag = await getCacheTag("fulfillment"); revalidateTag(fulfillmentCacheTag); + + onSuccess(); }) - .catch(medusaError); + .catch((e) => { + onError(); + return medusaError(e); + }); } export async function applyGiftCard(code: string) { @@ -427,7 +442,7 @@ export async function placeOrder(cartId?: string, options: { revalidateCacheTags } else { throw new Error("Cart is not an order"); } - + return retrieveOrder(cartRes.order.id); } diff --git a/packages/features/medusa-storefront/src/lib/data/customer.ts b/packages/features/medusa-storefront/src/lib/data/customer.ts index 3b45071..bf56d6e 100644 --- a/packages/features/medusa-storefront/src/lib/data/customer.ts +++ b/packages/features/medusa-storefront/src/lib/data/customer.ts @@ -127,7 +127,7 @@ export async function login(_currentState: unknown, formData: FormData) { } } -export async function signout(countryCode: string) { +export async function signout(countryCode?: string, shouldRedirect = true) { await sdk.auth.logout() await removeAuthToken() @@ -140,7 +140,9 @@ export async function signout(countryCode: string) { const cartCacheTag = await getCacheTag("carts") revalidateTag(cartCacheTag) - redirect(`/${countryCode}/account`) + if (shouldRedirect) { + redirect(`/${countryCode!}/account`) + } } export async function transferCart() { diff --git a/packages/supabase/src/hooks/use-sign-out.ts b/packages/supabase/src/hooks/use-sign-out.ts index c827713..fbe65ee 100644 --- a/packages/supabase/src/hooks/use-sign-out.ts +++ b/packages/supabase/src/hooks/use-sign-out.ts @@ -1,12 +1,14 @@ import { useMutation } from '@tanstack/react-query'; import { useSupabase } from './use-supabase'; +import { signout } from '../../../features/medusa-storefront/src/lib/data/customer'; export function useSignOut() { const client = useSupabase(); return useMutation({ - mutationFn: () => { + mutationFn: async () => { + await signout(undefined, false); return client.auth.signOut(); }, }); diff --git a/public/locales/en/cart.json b/public/locales/en/cart.json index 1580536..84221a4 100644 --- a/public/locales/en/cart.json +++ b/public/locales/en/cart.json @@ -5,6 +5,7 @@ "emptyCartMessageDescription": "Add items to your cart to continue.", "subtotal": "Subtotal", "total": "Total", + "promotionsTotal": "Promotions total", "table": { "item": "Item", "quantity": "Quantity", @@ -24,10 +25,13 @@ "timeoutAction": "Continue" }, "discountCode": { + "title": "Gift card or promotion code", "label": "Add Promotion Code(s)", "apply": "Apply", "subtitle": "If you wish, you can add a promotion code", - "placeholder": "Enter promotion code" + "placeholder": "Enter promotion code", + "remove": "Remove promotion code", + "appliedCodes": "Promotion(s) applied:" }, "items": { "synlabAnalyses": { diff --git a/public/locales/et/cart.json b/public/locales/et/cart.json index efb1423..a7bcb19 100644 --- a/public/locales/et/cart.json +++ b/public/locales/et/cart.json @@ -4,6 +4,7 @@ "emptyCartMessage": "Sinu ostukorv on tühi", "emptyCartMessageDescription": "Lisa tooteid ostukorvi, et jätkata.", "subtotal": "Vahesumma", + "promotionsTotal": "Soodustuse summa", "total": "Summa", "table": { "item": "Toode", @@ -28,7 +29,13 @@ "label": "Lisa promo kood", "apply": "Rakenda", "subtitle": "Kui soovid, võid lisada promo koodi", - "placeholder": "Sisesta promo kood" + "placeholder": "Sisesta promo kood", + "remove": "Eemalda promo kood", + "appliedCodes": "Rakendatud sooduskoodid:", + "removeError": "Sooduskoodi eemaldamine ebaõnnestus", + "removeSuccess": "Sooduskood eemaldatud", + "addError": "Sooduskoodi rakendamine ebaõnnestus", + "addSuccess": "Sooduskood rakendatud" }, "items": { "synlabAnalyses": {