feat(MED-131): update location in action so cart is always reloaded properly
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
import { toast } from 'sonner';
|
||||
import { useForm } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
import { updateLineItem } from "@lib/data/cart"
|
||||
import { StoreCart, StoreCartLineItem } from "@medusajs/types"
|
||||
import { Form } from "@kit/ui/form";
|
||||
import { Trans } from '@kit/ui/trans';
|
||||
@@ -18,6 +17,7 @@ import {
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@kit/ui/select';
|
||||
import { updateCartPartnerLocation } from '../../_lib/server/update-cart-partner-location';
|
||||
|
||||
const AnalysisLocationSchema = z.object({
|
||||
locationId: z.string().min(1),
|
||||
@@ -40,16 +40,12 @@ export default function AnalysisLocation({ cart, analysisPackages }: { cart: Sto
|
||||
});
|
||||
|
||||
const onSubmit = async ({ locationId }: z.infer<typeof AnalysisLocationSchema>) => {
|
||||
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,
|
||||
},
|
||||
});
|
||||
}));
|
||||
const promise = updateCartPartnerLocation({
|
||||
cartId: cart.id,
|
||||
lineIds: analysisPackages.map(({ id }) => id),
|
||||
partnerLocationId: locationId,
|
||||
partnerLocationName: MOCK_LOCATIONS.find((location) => location.id === locationId)?.name ?? '',
|
||||
});
|
||||
|
||||
toast.promise(promise, {
|
||||
success: t(`cart:items.analysisLocation.success`),
|
||||
|
||||
Reference in New Issue
Block a user