feat(MED-100): partner location metadata stored on order line instead of order
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
import { toast } from 'sonner';
|
||||
import { useForm } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
import { updateCart } from "@lib/data/cart"
|
||||
import { StoreCart } from "@medusajs/types"
|
||||
import { updateLineItem } from "@lib/data/cart"
|
||||
import { StoreCart, StoreCartLineItem } from "@medusajs/types"
|
||||
import { Form } from "@kit/ui/form";
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
import { useTranslation } from "react-i18next";
|
||||
@@ -29,7 +29,7 @@ const MOCK_LOCATIONS: { id: string, name: string }[] = [
|
||||
{ id: "synlab-parnu-1", name: "SYNLAB - Pärnu" },
|
||||
]
|
||||
|
||||
export default function AnalysisLocation({ cart }: { cart: StoreCart }) {
|
||||
export default function AnalysisLocation({ cart, analysisPackages }: { cart: StoreCart, analysisPackages: StoreCartLineItem[] }) {
|
||||
const { t } = useTranslation('cart');
|
||||
|
||||
const form = useForm<z.infer<typeof AnalysisLocationSchema>>({
|
||||
@@ -40,12 +40,16 @@ export default function AnalysisLocation({ cart }: { cart: StoreCart }) {
|
||||
});
|
||||
|
||||
const onSubmit = async ({ locationId }: z.infer<typeof AnalysisLocationSchema>) => {
|
||||
const promise = updateCart({
|
||||
metadata: {
|
||||
partner_location_name: MOCK_LOCATIONS.find(({ id }) => id === locationId)?.name ?? '',
|
||||
partner_location_id: locationId,
|
||||
},
|
||||
});
|
||||
const promise = Promise.all(analysisPackages.map(async ({ id, quantity }) => {
|
||||
await updateLineItem({
|
||||
lineId: id,
|
||||
quantity,
|
||||
metadata: {
|
||||
partner_location_name: MOCK_LOCATIONS.find((location) => location.id === locationId)?.name ?? '',
|
||||
partner_location_id: locationId,
|
||||
},
|
||||
});
|
||||
}));
|
||||
|
||||
toast.promise(promise, {
|
||||
success: t(`cart:items.analysisLocation.success`),
|
||||
|
||||
@@ -121,7 +121,7 @@ export default function Cart({
|
||||
</h5>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<AnalysisLocation cart={{ ...cart }} />
|
||||
<AnalysisLocation cart={{ ...cart }} analysisPackages={analysisPackages} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
@@ -22,7 +22,7 @@ export default function OrderItem({ item, currencyCode }: {
|
||||
className="txt-medium-plus text-ui-fg-base"
|
||||
data-testid="product-name"
|
||||
>
|
||||
{item.product_title}
|
||||
{item.product_title}{` (${item.metadata?.partner_location_name ?? "-"})`}
|
||||
</span>
|
||||
<LineItemOptions variant={item.variant} data-testid="product-variant" />
|
||||
</TableCell>
|
||||
|
||||
Reference in New Issue
Block a user