From 99a530d672000a92060eba0e08b93661e315057b Mon Sep 17 00:00:00 2001 From: Karli Date: Tue, 30 Sep 2025 16:21:08 +0300 Subject: [PATCH] feat(MED-98): use single in cart, add toggle for company benefits --- .../_components/cart/analysis-location.tsx | 108 ++++----- .../_components/cart/cart-form-content.tsx | 215 ++++++++++++++++++ .../(user)/_components/cart/cart-form.tsx | 47 ++++ .../(user)/_components/cart/discount-code.tsx | 90 ++++---- app/home/(user)/_components/cart/index.tsx | 202 +++++----------- app/home/(user)/_components/cart/types.ts | 8 + app/home/(user)/_lib/server/cart-actions.ts | 7 +- public/locales/en/cart.json | 3 + public/locales/et/cart.json | 3 + public/locales/ru/cart.json | 3 + 10 files changed, 420 insertions(+), 266 deletions(-) create mode 100644 app/home/(user)/_components/cart/cart-form-content.tsx create mode 100644 app/home/(user)/_components/cart/cart-form.tsx diff --git a/app/home/(user)/_components/cart/analysis-location.tsx b/app/home/(user)/_components/cart/analysis-location.tsx index 38189a5..7189fea 100644 --- a/app/home/(user)/_components/cart/analysis-location.tsx +++ b/app/home/(user)/_components/cart/analysis-location.tsx @@ -1,13 +1,10 @@ 'use client'; -import { zodResolver } from '@hookform/resolvers/zod'; import { StoreCart, StoreCartLineItem } from '@medusajs/types'; -import { useForm } from 'react-hook-form'; +import { useFormContext } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; import { toast } from 'sonner'; -import { z } from 'zod'; -import { Form } from '@kit/ui/form'; import { Select, SelectContent, @@ -22,10 +19,6 @@ import { Trans } from '@kit/ui/trans'; import { updateCartPartnerLocation } from '../../_lib/server/update-cart-partner-location'; import partnerLocations from './partner-locations.json'; -const AnalysisLocationSchema = z.object({ - locationId: z.string().min(1), -}); - export default function AnalysisLocation({ cart, synlabAnalyses, @@ -35,21 +28,15 @@ export default function AnalysisLocation({ }) { const { t } = useTranslation('cart'); - const form = useForm>({ - defaultValues: { - locationId: (cart.metadata?.partner_location_id as string) ?? '', - }, - resolver: zodResolver(AnalysisLocationSchema), - }); + const { watch, setValue } = useFormContext(); + const currentValue = watch('locationId'); const getLocation = (locationId: string) => partnerLocations.find(({ name }) => name === locationId); - const selectedLocation = getLocation(form.watch('locationId')); + const selectedLocation = getLocation(currentValue); - const onSubmit = async ({ - locationId, - }: z.infer) => { + const handleUpdateCartPartnerLocation = async (locationId: string) => { const promise = updateCartPartnerLocation({ cartId: cart.id, lineIds: synlabAnalyses.map(({ id }) => id), @@ -70,53 +57,48 @@ export default function AnalysisLocation({
+ +
+ {formatCurrency({ + value: cart.subtotal, + currencyCode: cart.currency_code, + locale: language, + })} +
+ {formatCurrency({ + value: cart.discount_total, + currencyCode: cart.currency_code, + locale: language, + })} +
+ {formatCurrency({ + value: benefitsAmount, + currencyCode: cart.currency_code, + locale: language, + })} +
+ {formatCurrency({ + value: montonioAmount, + currencyCode: cart.currency_code, + locale: language, + })} +
- -
- {formatCurrency({ - value: cart.subtotal, - currencyCode: cart.currency_code, - locale: language, - })} -
- {formatCurrency({ - value: cart.discount_total, - currencyCode: cart.currency_code, - locale: language, - })} -
- {formatCurrency({ - value: (companyBenefitsTotal > cart.total ? cart.total : companyBenefitsTotal), - currencyCode: cart.currency_code, - locale: language, - })} -
- {formatCurrency({ - value: montonioTotal < 0 ? 0 : montonioTotal, - currencyCode: cart.currency_code, - locale: language, - })} -