@medusajs/draft-order 2.10.4-preview-20250920090150 → 2.10.4-preview-20250920150155

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9567,6 +9567,27 @@ const ID = () => {
9567
9567
  /* @__PURE__ */ jsx(Outlet, {})
9568
9568
  ] });
9569
9569
  };
9570
+ const CustomItems = () => {
9571
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9572
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9573
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
9574
+ ] });
9575
+ };
9576
+ const CustomItemsForm = () => {
9577
+ const form = useForm({
9578
+ resolver: zodResolver(schema$5)
9579
+ });
9580
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9581
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9582
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9583
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9584
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9585
+ ] }) })
9586
+ ] }) });
9587
+ };
9588
+ const schema$5 = objectType({
9589
+ email: stringType().email()
9590
+ });
9570
9591
  const BillingAddress = () => {
9571
9592
  const { id } = useParams();
9572
9593
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9599,7 +9620,7 @@ const BillingAddressForm = ({ order }) => {
9599
9620
  postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9600
9621
  phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9601
9622
  },
9602
- resolver: zodResolver(schema$5)
9623
+ resolver: zodResolver(schema$4)
9603
9624
  });
9604
9625
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9605
9626
  const { handleSuccess } = useRouteModal();
@@ -9756,28 +9777,7 @@ const BillingAddressForm = ({ order }) => {
9756
9777
  }
9757
9778
  ) });
9758
9779
  };
9759
- const schema$5 = addressSchema;
9760
- const CustomItems = () => {
9761
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9762
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9763
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9764
- ] });
9765
- };
9766
- const CustomItemsForm = () => {
9767
- const form = useForm({
9768
- resolver: zodResolver(schema$4)
9769
- });
9770
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9771
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9772
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9773
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9774
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9775
- ] }) })
9776
- ] }) });
9777
- };
9778
- const schema$4 = objectType({
9779
- email: stringType().email()
9780
- });
9780
+ const schema$4 = addressSchema;
9781
9781
  const Email = () => {
9782
9782
  const { id } = useParams();
9783
9783
  const { order, isPending, isError, error } = useOrder(id, {
@@ -11170,166 +11170,323 @@ function getHasUneditableRows(metadata) {
11170
11170
  (value) => !EDITABLE_TYPES.includes(typeof value)
11171
11171
  );
11172
11172
  }
11173
- const SalesChannel = () => {
11174
- const { id } = useParams();
11175
- const { draft_order, isPending, isError, error } = useDraftOrder(
11173
+ const PROMOTION_QUERY_KEY = "promotions";
11174
+ const promotionsQueryKeys = {
11175
+ list: (query2) => [
11176
+ PROMOTION_QUERY_KEY,
11177
+ query2 ? query2 : void 0
11178
+ ],
11179
+ detail: (id, query2) => [
11180
+ PROMOTION_QUERY_KEY,
11176
11181
  id,
11182
+ query2 ? query2 : void 0
11183
+ ]
11184
+ };
11185
+ const usePromotions = (query2, options) => {
11186
+ const { data, ...rest } = useQuery({
11187
+ queryKey: promotionsQueryKeys.list(query2),
11188
+ queryFn: async () => sdk.admin.promotion.list(query2),
11189
+ ...options
11190
+ });
11191
+ return { ...data, ...rest };
11192
+ };
11193
+ const Promotions = () => {
11194
+ const { id } = useParams();
11195
+ const {
11196
+ order: preview,
11197
+ isError: isPreviewError,
11198
+ error: previewError
11199
+ } = useOrderPreview(id, void 0);
11200
+ useInitiateOrderEdit({ preview });
11201
+ const { onCancel } = useCancelOrderEdit({ preview });
11202
+ if (isPreviewError) {
11203
+ throw previewError;
11204
+ }
11205
+ const isReady = !!preview;
11206
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11207
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11208
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11209
+ ] });
11210
+ };
11211
+ const PromotionForm = ({ preview }) => {
11212
+ const { items, shipping_methods } = preview;
11213
+ const [isSubmitting, setIsSubmitting] = useState(false);
11214
+ const [comboboxValue, setComboboxValue] = useState("");
11215
+ const { handleSuccess } = useRouteModal();
11216
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11217
+ const promoIds = getPromotionIds(items, shipping_methods);
11218
+ const { promotions, isPending, isError, error } = usePromotions(
11177
11219
  {
11178
- fields: "+sales_channel_id"
11220
+ id: promoIds
11179
11221
  },
11180
11222
  {
11181
- enabled: !!id
11223
+ enabled: !!promoIds.length
11182
11224
  }
11183
11225
  );
11184
- if (isError) {
11185
- throw error;
11186
- }
11187
- const ISrEADY = !!draft_order && !isPending;
11188
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11189
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11190
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11191
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11192
- ] }),
11193
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11194
- ] });
11195
- };
11196
- const SalesChannelForm = ({ order }) => {
11197
- const form = useForm({
11198
- defaultValues: {
11199
- sales_channel_id: order.sales_channel_id || ""
11226
+ const comboboxData = useComboboxData({
11227
+ queryKey: ["promotions", "combobox", promoIds],
11228
+ queryFn: async (params) => {
11229
+ return await sdk.admin.promotion.list({
11230
+ ...params,
11231
+ id: {
11232
+ $nin: promoIds
11233
+ }
11234
+ });
11200
11235
  },
11201
- resolver: zodResolver(schema$2)
11236
+ getOptions: (data) => {
11237
+ return data.promotions.map((promotion) => ({
11238
+ label: promotion.code,
11239
+ value: promotion.code
11240
+ }));
11241
+ }
11202
11242
  });
11203
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11204
- const { handleSuccess } = useRouteModal();
11205
- const onSubmit = form.handleSubmit(async (data) => {
11206
- await mutateAsync(
11243
+ const add = async (value) => {
11244
+ if (!value) {
11245
+ return;
11246
+ }
11247
+ addPromotions(
11207
11248
  {
11208
- sales_channel_id: data.sales_channel_id
11249
+ promo_codes: [value]
11209
11250
  },
11210
11251
  {
11211
- onSuccess: () => {
11212
- toast.success("Sales channel updated");
11213
- handleSuccess();
11252
+ onError: (e) => {
11253
+ toast.error(e.message);
11254
+ comboboxData.onSearchValueChange("");
11255
+ setComboboxValue("");
11214
11256
  },
11215
- onError: (error) => {
11216
- toast.error(error.message);
11257
+ onSuccess: () => {
11258
+ comboboxData.onSearchValueChange("");
11259
+ setComboboxValue("");
11217
11260
  }
11218
11261
  }
11219
11262
  );
11220
- });
11221
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11222
- KeyboundForm,
11223
- {
11224
- className: "flex flex-1 flex-col overflow-hidden",
11225
- onSubmit,
11226
- children: [
11227
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11228
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11229
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11230
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11231
- ] }) })
11232
- ]
11233
- }
11234
- ) });
11235
- };
11236
- const SalesChannelField = ({ control, order }) => {
11237
- const salesChannels = useComboboxData({
11238
- queryFn: async (params) => {
11239
- return await sdk.admin.salesChannel.list(params);
11240
- },
11241
- queryKey: ["sales-channels"],
11242
- getOptions: (data) => {
11243
- return data.sales_channels.map((salesChannel) => ({
11244
- label: salesChannel.name,
11245
- value: salesChannel.id
11246
- }));
11247
- },
11248
- defaultValue: order.sales_channel_id || void 0
11249
- });
11250
- return /* @__PURE__ */ jsx(
11251
- Form$2.Field,
11252
- {
11253
- control,
11254
- name: "sales_channel_id",
11255
- render: ({ field }) => {
11256
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11257
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11258
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11259
- Combobox,
11260
- {
11261
- options: salesChannels.options,
11262
- fetchNextPage: salesChannels.fetchNextPage,
11263
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11264
- searchValue: salesChannels.searchValue,
11265
- onSearchValueChange: salesChannels.onSearchValueChange,
11266
- placeholder: "Select sales channel",
11267
- ...field
11268
- }
11269
- ) }),
11270
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11271
- ] });
11263
+ };
11264
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11265
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11266
+ const onSubmit = async () => {
11267
+ setIsSubmitting(true);
11268
+ let requestSucceeded = false;
11269
+ await requestOrderEdit(void 0, {
11270
+ onError: (e) => {
11271
+ toast.error(e.message);
11272
+ },
11273
+ onSuccess: () => {
11274
+ requestSucceeded = true;
11272
11275
  }
11276
+ });
11277
+ if (!requestSucceeded) {
11278
+ setIsSubmitting(false);
11279
+ return;
11273
11280
  }
11274
- );
11275
- };
11276
- const schema$2 = objectType({
11277
- sales_channel_id: stringType().min(1)
11278
- });
11279
- const ShippingAddress = () => {
11280
- const { id } = useParams();
11281
- const { order, isPending, isError, error } = useOrder(id, {
11282
- fields: "+shipping_address"
11283
- });
11281
+ await confirmOrderEdit(void 0, {
11282
+ onError: (e) => {
11283
+ toast.error(e.message);
11284
+ },
11285
+ onSuccess: () => {
11286
+ handleSuccess();
11287
+ },
11288
+ onSettled: () => {
11289
+ setIsSubmitting(false);
11290
+ }
11291
+ });
11292
+ };
11284
11293
  if (isError) {
11285
11294
  throw error;
11286
11295
  }
11287
- const isReady = !isPending && !!order;
11288
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11289
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11290
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11291
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11292
- ] }),
11293
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11294
- ] });
11295
- };
11296
- const ShippingAddressForm = ({ order }) => {
11297
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11298
- const form = useForm({
11299
- defaultValues: {
11300
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11301
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11302
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11303
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11304
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11305
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11306
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11307
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11308
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11309
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11296
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11297
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11298
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11299
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11300
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11301
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11302
+ ] }),
11303
+ /* @__PURE__ */ jsx(
11304
+ Combobox,
11305
+ {
11306
+ id: "promotion-combobox",
11307
+ "aria-describedby": "promotion-combobox-hint",
11308
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11309
+ fetchNextPage: comboboxData.fetchNextPage,
11310
+ options: comboboxData.options,
11311
+ onSearchValueChange: comboboxData.onSearchValueChange,
11312
+ searchValue: comboboxData.searchValue,
11313
+ disabled: comboboxData.disabled || isAddingPromotions,
11314
+ onChange: add,
11315
+ value: comboboxValue
11316
+ }
11317
+ )
11318
+ ] }),
11319
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11320
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11321
+ PromotionItem,
11322
+ {
11323
+ promotion,
11324
+ orderId: preview.id,
11325
+ isLoading: isPending
11326
+ },
11327
+ promotion.id
11328
+ )) })
11329
+ ] }) }),
11330
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11331
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11332
+ /* @__PURE__ */ jsx(
11333
+ Button,
11334
+ {
11335
+ size: "small",
11336
+ type: "submit",
11337
+ isLoading: isSubmitting || isAddingPromotions,
11338
+ children: "Save"
11339
+ }
11340
+ )
11341
+ ] }) })
11342
+ ] });
11343
+ };
11344
+ const PromotionItem = ({
11345
+ promotion,
11346
+ orderId,
11347
+ isLoading
11348
+ }) => {
11349
+ var _a;
11350
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11351
+ const onRemove = async () => {
11352
+ removePromotions(
11353
+ {
11354
+ promo_codes: [promotion.code]
11355
+ },
11356
+ {
11357
+ onError: (e) => {
11358
+ toast.error(e.message);
11359
+ }
11360
+ }
11361
+ );
11362
+ };
11363
+ const displayValue = getDisplayValue(promotion);
11364
+ return /* @__PURE__ */ jsxs(
11365
+ "div",
11366
+ {
11367
+ className: clx(
11368
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11369
+ {
11370
+ "animate-pulse": isLoading
11371
+ }
11372
+ ),
11373
+ children: [
11374
+ /* @__PURE__ */ jsxs("div", { children: [
11375
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11376
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11377
+ displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11378
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11379
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11380
+ ] }),
11381
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11382
+ ] })
11383
+ ] }),
11384
+ /* @__PURE__ */ jsx(
11385
+ IconButton,
11386
+ {
11387
+ size: "small",
11388
+ type: "button",
11389
+ variant: "transparent",
11390
+ onClick: onRemove,
11391
+ isLoading: isPending || isLoading,
11392
+ children: /* @__PURE__ */ jsx(XMark, {})
11393
+ }
11394
+ )
11395
+ ]
11310
11396
  },
11311
- resolver: zodResolver(schema$1)
11397
+ promotion.id
11398
+ );
11399
+ };
11400
+ function getDisplayValue(promotion) {
11401
+ var _a, _b, _c, _d;
11402
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11403
+ if (!value) {
11404
+ return null;
11405
+ }
11406
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11407
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11408
+ if (!currency) {
11409
+ return null;
11410
+ }
11411
+ return getLocaleAmount(value, currency);
11412
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11413
+ return formatPercentage(value);
11414
+ }
11415
+ return null;
11416
+ }
11417
+ const formatter = new Intl.NumberFormat([], {
11418
+ style: "percent",
11419
+ minimumFractionDigits: 2
11420
+ });
11421
+ const formatPercentage = (value, isPercentageValue = false) => {
11422
+ let val = value || 0;
11423
+ if (!isPercentageValue) {
11424
+ val = val / 100;
11425
+ }
11426
+ return formatter.format(val);
11427
+ };
11428
+ function getPromotionIds(items, shippingMethods) {
11429
+ const promotionIds = /* @__PURE__ */ new Set();
11430
+ for (const item of items) {
11431
+ if (item.adjustments) {
11432
+ for (const adjustment of item.adjustments) {
11433
+ if (adjustment.promotion_id) {
11434
+ promotionIds.add(adjustment.promotion_id);
11435
+ }
11436
+ }
11437
+ }
11438
+ }
11439
+ for (const shippingMethod of shippingMethods) {
11440
+ if (shippingMethod.adjustments) {
11441
+ for (const adjustment of shippingMethod.adjustments) {
11442
+ if (adjustment.promotion_id) {
11443
+ promotionIds.add(adjustment.promotion_id);
11444
+ }
11445
+ }
11446
+ }
11447
+ }
11448
+ return Array.from(promotionIds);
11449
+ }
11450
+ const SalesChannel = () => {
11451
+ const { id } = useParams();
11452
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11453
+ id,
11454
+ {
11455
+ fields: "+sales_channel_id"
11456
+ },
11457
+ {
11458
+ enabled: !!id
11459
+ }
11460
+ );
11461
+ if (isError) {
11462
+ throw error;
11463
+ }
11464
+ const ISrEADY = !!draft_order && !isPending;
11465
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11466
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11467
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11468
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11469
+ ] }),
11470
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11471
+ ] });
11472
+ };
11473
+ const SalesChannelForm = ({ order }) => {
11474
+ const form = useForm({
11475
+ defaultValues: {
11476
+ sales_channel_id: order.sales_channel_id || ""
11477
+ },
11478
+ resolver: zodResolver(schema$2)
11312
11479
  });
11313
11480
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11314
11481
  const { handleSuccess } = useRouteModal();
11315
11482
  const onSubmit = form.handleSubmit(async (data) => {
11316
11483
  await mutateAsync(
11317
11484
  {
11318
- shipping_address: {
11319
- first_name: data.first_name,
11320
- last_name: data.last_name,
11321
- company: data.company,
11322
- address_1: data.address_1,
11323
- address_2: data.address_2,
11324
- city: data.city,
11325
- province: data.province,
11326
- country_code: data.country_code,
11327
- postal_code: data.postal_code,
11328
- phone: data.phone
11329
- }
11485
+ sales_channel_id: data.sales_channel_id
11330
11486
  },
11331
11487
  {
11332
11488
  onSuccess: () => {
11489
+ toast.success("Sales channel updated");
11333
11490
  handleSuccess();
11334
11491
  },
11335
11492
  onError: (error) => {
@@ -11344,719 +11501,160 @@ const ShippingAddressForm = ({ order }) => {
11344
11501
  className: "flex flex-1 flex-col overflow-hidden",
11345
11502
  onSubmit,
11346
11503
  children: [
11347
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
11348
- /* @__PURE__ */ jsx(
11349
- Form$2.Field,
11504
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11505
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11506
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11507
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11508
+ ] }) })
11509
+ ]
11510
+ }
11511
+ ) });
11512
+ };
11513
+ const SalesChannelField = ({ control, order }) => {
11514
+ const salesChannels = useComboboxData({
11515
+ queryFn: async (params) => {
11516
+ return await sdk.admin.salesChannel.list(params);
11517
+ },
11518
+ queryKey: ["sales-channels"],
11519
+ getOptions: (data) => {
11520
+ return data.sales_channels.map((salesChannel) => ({
11521
+ label: salesChannel.name,
11522
+ value: salesChannel.id
11523
+ }));
11524
+ },
11525
+ defaultValue: order.sales_channel_id || void 0
11526
+ });
11527
+ return /* @__PURE__ */ jsx(
11528
+ Form$2.Field,
11529
+ {
11530
+ control,
11531
+ name: "sales_channel_id",
11532
+ render: ({ field }) => {
11533
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11534
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11535
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11536
+ Combobox,
11350
11537
  {
11351
- control: form.control,
11352
- name: "country_code",
11353
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11354
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11355
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11356
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11357
- ] })
11538
+ options: salesChannels.options,
11539
+ fetchNextPage: salesChannels.fetchNextPage,
11540
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11541
+ searchValue: salesChannels.searchValue,
11542
+ onSearchValueChange: salesChannels.onSearchValueChange,
11543
+ placeholder: "Select sales channel",
11544
+ ...field
11358
11545
  }
11359
- ),
11360
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11361
- /* @__PURE__ */ jsx(
11362
- Form$2.Field,
11363
- {
11364
- control: form.control,
11365
- name: "first_name",
11366
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11367
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11368
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11369
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11370
- ] })
11371
- }
11372
- ),
11373
- /* @__PURE__ */ jsx(
11374
- Form$2.Field,
11375
- {
11376
- control: form.control,
11377
- name: "last_name",
11378
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11379
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11380
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11381
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11382
- ] })
11383
- }
11384
- )
11385
- ] }),
11386
- /* @__PURE__ */ jsx(
11387
- Form$2.Field,
11388
- {
11389
- control: form.control,
11390
- name: "company",
11391
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11392
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11393
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11394
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11395
- ] })
11396
- }
11397
- ),
11398
- /* @__PURE__ */ jsx(
11399
- Form$2.Field,
11400
- {
11401
- control: form.control,
11402
- name: "address_1",
11403
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11404
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11405
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11406
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11407
- ] })
11408
- }
11409
- ),
11410
- /* @__PURE__ */ jsx(
11411
- Form$2.Field,
11412
- {
11413
- control: form.control,
11414
- name: "address_2",
11415
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11416
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11417
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11418
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11419
- ] })
11420
- }
11421
- ),
11422
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11423
- /* @__PURE__ */ jsx(
11424
- Form$2.Field,
11425
- {
11426
- control: form.control,
11427
- name: "postal_code",
11428
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11429
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11430
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11431
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11432
- ] })
11433
- }
11434
- ),
11435
- /* @__PURE__ */ jsx(
11436
- Form$2.Field,
11437
- {
11438
- control: form.control,
11439
- name: "city",
11440
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11441
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11442
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11443
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11444
- ] })
11445
- }
11446
- )
11447
- ] }),
11448
- /* @__PURE__ */ jsx(
11449
- Form$2.Field,
11450
- {
11451
- control: form.control,
11452
- name: "province",
11453
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11454
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11455
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11456
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11457
- ] })
11458
- }
11459
- ),
11460
- /* @__PURE__ */ jsx(
11461
- Form$2.Field,
11462
- {
11463
- control: form.control,
11464
- name: "phone",
11465
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11466
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11467
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11468
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11469
- ] })
11470
- }
11471
- )
11472
- ] }) }),
11473
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11474
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11475
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11476
- ] }) })
11477
- ]
11546
+ ) }),
11547
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11548
+ ] });
11549
+ }
11478
11550
  }
11479
- ) });
11551
+ );
11480
11552
  };
11481
- const schema$1 = addressSchema;
11482
- const TransferOwnership = () => {
11553
+ const schema$2 = objectType({
11554
+ sales_channel_id: stringType().min(1)
11555
+ });
11556
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11557
+ const Shipping = () => {
11558
+ var _a;
11483
11559
  const { id } = useParams();
11484
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11485
- fields: "id,customer_id,customer.*"
11560
+ const { order, isPending, isError, error } = useOrder(id, {
11561
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11486
11562
  });
11563
+ const {
11564
+ order: preview,
11565
+ isPending: isPreviewPending,
11566
+ isError: isPreviewError,
11567
+ error: previewError
11568
+ } = useOrderPreview(id);
11569
+ useInitiateOrderEdit({ preview });
11570
+ const { onCancel } = useCancelOrderEdit({ preview });
11487
11571
  if (isError) {
11488
11572
  throw error;
11489
11573
  }
11490
- const isReady = !isPending && !!draft_order;
11491
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11492
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11493
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
11494
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
11495
- ] }),
11496
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
11497
- ] });
11574
+ if (isPreviewError) {
11575
+ throw previewError;
11576
+ }
11577
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11578
+ const isReady = preview && !isPreviewPending && order && !isPending;
11579
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11580
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11581
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11582
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11583
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11584
+ ] }) }) }),
11585
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11586
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11587
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11588
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11589
+ ] }) });
11498
11590
  };
11499
- const TransferOwnershipForm = ({ order }) => {
11500
- var _a, _b;
11501
- const form = useForm({
11502
- defaultValues: {
11503
- customer_id: order.customer_id || ""
11591
+ const ShippingForm = ({ preview, order }) => {
11592
+ var _a;
11593
+ const { setIsOpen } = useStackedModal();
11594
+ const [isSubmitting, setIsSubmitting] = useState(false);
11595
+ const [data, setData] = useState(null);
11596
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11597
+ const { shipping_options } = useShippingOptions(
11598
+ {
11599
+ id: appliedShippingOptionIds,
11600
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11504
11601
  },
11505
- resolver: zodResolver(schema)
11506
- });
11507
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11602
+ {
11603
+ enabled: appliedShippingOptionIds.length > 0
11604
+ }
11605
+ );
11606
+ const uniqueShippingProfiles = useMemo(() => {
11607
+ const profiles = /* @__PURE__ */ new Map();
11608
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11609
+ profiles.set(profile.id, profile);
11610
+ });
11611
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11612
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11613
+ });
11614
+ return Array.from(profiles.values());
11615
+ }, [order.items, shipping_options]);
11508
11616
  const { handleSuccess } = useRouteModal();
11509
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11510
- const currentCustomer = order.customer ? {
11511
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
11512
- value: order.customer.id
11513
- } : null;
11514
- const onSubmit = form.handleSubmit(async (data) => {
11515
- await mutateAsync(
11516
- { customer_id: data.customer_id },
11517
- {
11518
- onSuccess: () => {
11519
- toast.success("Customer updated");
11520
- handleSuccess();
11521
- },
11522
- onError: (error) => {
11523
- toast.error(error.message);
11617
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11618
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11619
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11620
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11621
+ const onSubmit = async () => {
11622
+ setIsSubmitting(true);
11623
+ let requestSucceeded = false;
11624
+ await requestOrderEdit(void 0, {
11625
+ onError: (e) => {
11626
+ toast.error(`Failed to request order edit: ${e.message}`);
11627
+ },
11628
+ onSuccess: () => {
11629
+ requestSucceeded = true;
11630
+ }
11631
+ });
11632
+ if (!requestSucceeded) {
11633
+ setIsSubmitting(false);
11634
+ return;
11635
+ }
11636
+ await confirmOrderEdit(void 0, {
11637
+ onError: (e) => {
11638
+ toast.error(`Failed to confirm order edit: ${e.message}`);
11639
+ },
11640
+ onSuccess: () => {
11641
+ handleSuccess();
11642
+ },
11643
+ onSettled: () => {
11644
+ setIsSubmitting(false);
11645
+ }
11646
+ });
11647
+ };
11648
+ const onKeydown = useCallback(
11649
+ (e) => {
11650
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11651
+ if (data || isSubmitting) {
11652
+ return;
11524
11653
  }
11654
+ onSubmit();
11525
11655
  }
11526
- );
11527
- });
11528
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11529
- KeyboundForm,
11530
- {
11531
- className: "flex flex-1 flex-col overflow-hidden",
11532
- onSubmit,
11533
- children: [
11534
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11535
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
11536
- currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
11537
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11538
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11539
- /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
11540
- ] }),
11541
- /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
11542
- /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
11543
- /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11544
- ] })
11545
- ] }),
11546
- /* @__PURE__ */ jsx(
11547
- CustomerField,
11548
- {
11549
- control: form.control,
11550
- currentCustomerId: order.customer_id
11551
- }
11552
- )
11553
- ] }),
11554
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11555
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11556
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11557
- ] }) })
11558
- ]
11559
- }
11560
- ) });
11561
- };
11562
- const CustomerField = ({ control, currentCustomerId }) => {
11563
- const customers = useComboboxData({
11564
- queryFn: async (params) => {
11565
- return await sdk.admin.customer.list({
11566
- ...params,
11567
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11568
- });
11569
11656
  },
11570
- queryKey: ["customers"],
11571
- getOptions: (data) => {
11572
- return data.customers.map((customer) => {
11573
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11574
- return {
11575
- label: name ? `${name} (${customer.email})` : customer.email,
11576
- value: customer.id
11577
- };
11578
- });
11579
- }
11580
- });
11581
- return /* @__PURE__ */ jsx(
11582
- Form$2.Field,
11583
- {
11584
- name: "customer_id",
11585
- control,
11586
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
11587
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11588
- /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
11589
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11590
- ] }),
11591
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11592
- Combobox,
11593
- {
11594
- options: customers.options,
11595
- fetchNextPage: customers.fetchNextPage,
11596
- isFetchingNextPage: customers.isFetchingNextPage,
11597
- searchValue: customers.searchValue,
11598
- onSearchValueChange: customers.onSearchValueChange,
11599
- placeholder: "Select customer",
11600
- ...field
11601
- }
11602
- ) }),
11603
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11604
- ] })
11605
- }
11606
- );
11607
- };
11608
- const Illustration = () => {
11609
- return /* @__PURE__ */ jsxs(
11610
- "svg",
11611
- {
11612
- width: "280",
11613
- height: "180",
11614
- viewBox: "0 0 280 180",
11615
- fill: "none",
11616
- xmlns: "http://www.w3.org/2000/svg",
11617
- children: [
11618
- /* @__PURE__ */ jsx(
11619
- "rect",
11620
- {
11621
- x: "0.00428286",
11622
- y: "-0.742904",
11623
- width: "33.5",
11624
- height: "65.5",
11625
- rx: "6.75",
11626
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
11627
- fill: "#D4D4D8",
11628
- stroke: "#52525B",
11629
- strokeWidth: "1.5"
11630
- }
11631
- ),
11632
- /* @__PURE__ */ jsx(
11633
- "rect",
11634
- {
11635
- x: "0.00428286",
11636
- y: "-0.742904",
11637
- width: "33.5",
11638
- height: "65.5",
11639
- rx: "6.75",
11640
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
11641
- fill: "white",
11642
- stroke: "#52525B",
11643
- strokeWidth: "1.5"
11644
- }
11645
- ),
11646
- /* @__PURE__ */ jsx(
11647
- "path",
11648
- {
11649
- d: "M180.579 107.142L179.126 107.959",
11650
- stroke: "#52525B",
11651
- strokeWidth: "1.5",
11652
- strokeLinecap: "round",
11653
- strokeLinejoin: "round"
11654
- }
11655
- ),
11656
- /* @__PURE__ */ jsx(
11657
- "path",
11658
- {
11659
- opacity: "0.88",
11660
- d: "M182.305 109.546L180.257 109.534",
11661
- stroke: "#52525B",
11662
- strokeWidth: "1.5",
11663
- strokeLinecap: "round",
11664
- strokeLinejoin: "round"
11665
- }
11666
- ),
11667
- /* @__PURE__ */ jsx(
11668
- "path",
11669
- {
11670
- opacity: "0.75",
11671
- d: "M180.551 111.93L179.108 111.096",
11672
- stroke: "#52525B",
11673
- strokeWidth: "1.5",
11674
- strokeLinecap: "round",
11675
- strokeLinejoin: "round"
11676
- }
11677
- ),
11678
- /* @__PURE__ */ jsx(
11679
- "path",
11680
- {
11681
- opacity: "0.63",
11682
- d: "M176.347 112.897L176.354 111.73",
11683
- stroke: "#52525B",
11684
- strokeWidth: "1.5",
11685
- strokeLinecap: "round",
11686
- strokeLinejoin: "round"
11687
- }
11688
- ),
11689
- /* @__PURE__ */ jsx(
11690
- "path",
11691
- {
11692
- opacity: "0.5",
11693
- d: "M172.153 111.881L173.606 111.064",
11694
- stroke: "#52525B",
11695
- strokeWidth: "1.5",
11696
- strokeLinecap: "round",
11697
- strokeLinejoin: "round"
11698
- }
11699
- ),
11700
- /* @__PURE__ */ jsx(
11701
- "path",
11702
- {
11703
- opacity: "0.38",
11704
- d: "M170.428 109.478L172.476 109.489",
11705
- stroke: "#52525B",
11706
- strokeWidth: "1.5",
11707
- strokeLinecap: "round",
11708
- strokeLinejoin: "round"
11709
- }
11710
- ),
11711
- /* @__PURE__ */ jsx(
11712
- "path",
11713
- {
11714
- opacity: "0.25",
11715
- d: "M172.181 107.094L173.624 107.928",
11716
- stroke: "#52525B",
11717
- strokeWidth: "1.5",
11718
- strokeLinecap: "round",
11719
- strokeLinejoin: "round"
11720
- }
11721
- ),
11722
- /* @__PURE__ */ jsx(
11723
- "path",
11724
- {
11725
- opacity: "0.13",
11726
- d: "M176.386 106.126L176.379 107.294",
11727
- stroke: "#52525B",
11728
- strokeWidth: "1.5",
11729
- strokeLinecap: "round",
11730
- strokeLinejoin: "round"
11731
- }
11732
- ),
11733
- /* @__PURE__ */ jsx(
11734
- "rect",
11735
- {
11736
- width: "12",
11737
- height: "3",
11738
- rx: "1.5",
11739
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
11740
- fill: "#D4D4D8"
11741
- }
11742
- ),
11743
- /* @__PURE__ */ jsx(
11744
- "rect",
11745
- {
11746
- x: "0.00428286",
11747
- y: "-0.742904",
11748
- width: "33.5",
11749
- height: "65.5",
11750
- rx: "6.75",
11751
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
11752
- fill: "#D4D4D8",
11753
- stroke: "#52525B",
11754
- strokeWidth: "1.5"
11755
- }
11756
- ),
11757
- /* @__PURE__ */ jsx(
11758
- "rect",
11759
- {
11760
- x: "0.00428286",
11761
- y: "-0.742904",
11762
- width: "33.5",
11763
- height: "65.5",
11764
- rx: "6.75",
11765
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
11766
- fill: "white",
11767
- stroke: "#52525B",
11768
- strokeWidth: "1.5"
11769
- }
11770
- ),
11771
- /* @__PURE__ */ jsx(
11772
- "rect",
11773
- {
11774
- width: "12",
11775
- height: "3",
11776
- rx: "1.5",
11777
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
11778
- fill: "#D4D4D8"
11779
- }
11780
- ),
11781
- /* @__PURE__ */ jsx(
11782
- "rect",
11783
- {
11784
- width: "17",
11785
- height: "3",
11786
- rx: "1.5",
11787
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
11788
- fill: "#D4D4D8"
11789
- }
11790
- ),
11791
- /* @__PURE__ */ jsx(
11792
- "rect",
11793
- {
11794
- width: "12",
11795
- height: "3",
11796
- rx: "1.5",
11797
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
11798
- fill: "#D4D4D8"
11799
- }
11800
- ),
11801
- /* @__PURE__ */ jsx(
11802
- "path",
11803
- {
11804
- d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
11805
- fill: "#A1A1AA"
11806
- }
11807
- ),
11808
- /* @__PURE__ */ jsx(
11809
- "rect",
11810
- {
11811
- width: "17",
11812
- height: "3",
11813
- rx: "1.5",
11814
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
11815
- fill: "#A1A1AA"
11816
- }
11817
- ),
11818
- /* @__PURE__ */ jsx(
11819
- "rect",
11820
- {
11821
- width: "12",
11822
- height: "3",
11823
- rx: "1.5",
11824
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
11825
- fill: "#A1A1AA"
11826
- }
11827
- ),
11828
- /* @__PURE__ */ jsx(
11829
- "path",
11830
- {
11831
- d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
11832
- fill: "#52525B"
11833
- }
11834
- ),
11835
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
11836
- "path",
11837
- {
11838
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
11839
- stroke: "#A1A1AA",
11840
- strokeWidth: "1.5",
11841
- strokeLinecap: "round",
11842
- strokeLinejoin: "round"
11843
- }
11844
- ) }),
11845
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
11846
- "path",
11847
- {
11848
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
11849
- stroke: "#A1A1AA",
11850
- strokeWidth: "1.5",
11851
- strokeLinecap: "round",
11852
- strokeLinejoin: "round"
11853
- }
11854
- ) }),
11855
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
11856
- "path",
11857
- {
11858
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
11859
- stroke: "#A1A1AA",
11860
- strokeWidth: "1.5",
11861
- strokeLinecap: "round",
11862
- strokeLinejoin: "round"
11863
- }
11864
- ) }),
11865
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
11866
- "path",
11867
- {
11868
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
11869
- stroke: "#A1A1AA",
11870
- strokeWidth: "1.5",
11871
- strokeLinecap: "round",
11872
- strokeLinejoin: "round"
11873
- }
11874
- ) }),
11875
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
11876
- "path",
11877
- {
11878
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
11879
- stroke: "#A1A1AA",
11880
- strokeWidth: "1.5",
11881
- strokeLinecap: "round",
11882
- strokeLinejoin: "round"
11883
- }
11884
- ) }),
11885
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
11886
- "path",
11887
- {
11888
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
11889
- stroke: "#A1A1AA",
11890
- strokeWidth: "1.5",
11891
- strokeLinecap: "round",
11892
- strokeLinejoin: "round"
11893
- }
11894
- ) }),
11895
- /* @__PURE__ */ jsxs("defs", { children: [
11896
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
11897
- "rect",
11898
- {
11899
- width: "12",
11900
- height: "12",
11901
- fill: "white",
11902
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
11903
- }
11904
- ) }),
11905
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
11906
- "rect",
11907
- {
11908
- width: "12",
11909
- height: "12",
11910
- fill: "white",
11911
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
11912
- }
11913
- ) }),
11914
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
11915
- "rect",
11916
- {
11917
- width: "12",
11918
- height: "12",
11919
- fill: "white",
11920
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
11921
- }
11922
- ) }),
11923
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
11924
- "rect",
11925
- {
11926
- width: "12",
11927
- height: "12",
11928
- fill: "white",
11929
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
11930
- }
11931
- ) }),
11932
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
11933
- "rect",
11934
- {
11935
- width: "12",
11936
- height: "12",
11937
- fill: "white",
11938
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
11939
- }
11940
- ) }),
11941
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
11942
- "rect",
11943
- {
11944
- width: "12",
11945
- height: "12",
11946
- fill: "white",
11947
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
11948
- }
11949
- ) })
11950
- ] })
11951
- ]
11952
- }
11953
- );
11954
- };
11955
- const schema = objectType({
11956
- customer_id: stringType().min(1)
11957
- });
11958
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11959
- const Shipping = () => {
11960
- var _a;
11961
- const { id } = useParams();
11962
- const { order, isPending, isError, error } = useOrder(id, {
11963
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11964
- });
11965
- const {
11966
- order: preview,
11967
- isPending: isPreviewPending,
11968
- isError: isPreviewError,
11969
- error: previewError
11970
- } = useOrderPreview(id);
11971
- useInitiateOrderEdit({ preview });
11972
- const { onCancel } = useCancelOrderEdit({ preview });
11973
- if (isError) {
11974
- throw error;
11975
- }
11976
- if (isPreviewError) {
11977
- throw previewError;
11978
- }
11979
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11980
- const isReady = preview && !isPreviewPending && order && !isPending;
11981
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11982
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11983
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11984
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11985
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11986
- ] }) }) }),
11987
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11988
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11989
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11990
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11991
- ] }) });
11992
- };
11993
- const ShippingForm = ({ preview, order }) => {
11994
- var _a;
11995
- const { setIsOpen } = useStackedModal();
11996
- const [isSubmitting, setIsSubmitting] = useState(false);
11997
- const [data, setData] = useState(null);
11998
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11999
- const { shipping_options } = useShippingOptions(
12000
- {
12001
- id: appliedShippingOptionIds,
12002
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
12003
- },
12004
- {
12005
- enabled: appliedShippingOptionIds.length > 0
12006
- }
12007
- );
12008
- const uniqueShippingProfiles = useMemo(() => {
12009
- const profiles = /* @__PURE__ */ new Map();
12010
- getUniqueShippingProfiles(order.items).forEach((profile) => {
12011
- profiles.set(profile.id, profile);
12012
- });
12013
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
12014
- profiles.set(option.shipping_profile_id, option.shipping_profile);
12015
- });
12016
- return Array.from(profiles.values());
12017
- }, [order.items, shipping_options]);
12018
- const { handleSuccess } = useRouteModal();
12019
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12020
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12021
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
12022
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
12023
- const onSubmit = async () => {
12024
- setIsSubmitting(true);
12025
- let requestSucceeded = false;
12026
- await requestOrderEdit(void 0, {
12027
- onError: (e) => {
12028
- toast.error(`Failed to request order edit: ${e.message}`);
12029
- },
12030
- onSuccess: () => {
12031
- requestSucceeded = true;
12032
- }
12033
- });
12034
- if (!requestSucceeded) {
12035
- setIsSubmitting(false);
12036
- return;
12037
- }
12038
- await confirmOrderEdit(void 0, {
12039
- onError: (e) => {
12040
- toast.error(`Failed to confirm order edit: ${e.message}`);
12041
- },
12042
- onSuccess: () => {
12043
- handleSuccess();
12044
- },
12045
- onSettled: () => {
12046
- setIsSubmitting(false);
12047
- }
12048
- });
12049
- };
12050
- const onKeydown = useCallback(
12051
- (e) => {
12052
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12053
- if (data || isSubmitting) {
12054
- return;
12055
- }
12056
- onSubmit();
12057
- }
12058
- },
12059
- [data, isSubmitting, onSubmit]
11657
+ [data, isSubmitting, onSubmit]
12060
11658
  );
12061
11659
  useEffect(() => {
12062
11660
  document.addEventListener("keydown", onKeydown);
@@ -12748,297 +12346,699 @@ const CustomAmountField = ({
12748
12346
  /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12749
12347
  /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12750
12348
  ] }),
12751
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12752
- CurrencyInput,
12349
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12350
+ CurrencyInput,
12351
+ {
12352
+ ...field,
12353
+ onValueChange: (value) => onChange(value),
12354
+ symbol: getNativeSymbol(currencyCode),
12355
+ code: currencyCode
12356
+ }
12357
+ ) })
12358
+ ] });
12359
+ }
12360
+ }
12361
+ );
12362
+ };
12363
+ const ShippingAddress = () => {
12364
+ const { id } = useParams();
12365
+ const { order, isPending, isError, error } = useOrder(id, {
12366
+ fields: "+shipping_address"
12367
+ });
12368
+ if (isError) {
12369
+ throw error;
12370
+ }
12371
+ const isReady = !isPending && !!order;
12372
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12373
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12374
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12375
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12376
+ ] }),
12377
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12378
+ ] });
12379
+ };
12380
+ const ShippingAddressForm = ({ order }) => {
12381
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12382
+ const form = useForm({
12383
+ defaultValues: {
12384
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12385
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12386
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12387
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12388
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12389
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12390
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12391
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12392
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12393
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12394
+ },
12395
+ resolver: zodResolver(schema$1)
12396
+ });
12397
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12398
+ const { handleSuccess } = useRouteModal();
12399
+ const onSubmit = form.handleSubmit(async (data) => {
12400
+ await mutateAsync(
12401
+ {
12402
+ shipping_address: {
12403
+ first_name: data.first_name,
12404
+ last_name: data.last_name,
12405
+ company: data.company,
12406
+ address_1: data.address_1,
12407
+ address_2: data.address_2,
12408
+ city: data.city,
12409
+ province: data.province,
12410
+ country_code: data.country_code,
12411
+ postal_code: data.postal_code,
12412
+ phone: data.phone
12413
+ }
12414
+ },
12415
+ {
12416
+ onSuccess: () => {
12417
+ handleSuccess();
12418
+ },
12419
+ onError: (error) => {
12420
+ toast.error(error.message);
12421
+ }
12422
+ }
12423
+ );
12424
+ });
12425
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12426
+ KeyboundForm,
12427
+ {
12428
+ className: "flex flex-1 flex-col overflow-hidden",
12429
+ onSubmit,
12430
+ children: [
12431
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12432
+ /* @__PURE__ */ jsx(
12433
+ Form$2.Field,
12434
+ {
12435
+ control: form.control,
12436
+ name: "country_code",
12437
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12438
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12439
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12440
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12441
+ ] })
12442
+ }
12443
+ ),
12444
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12445
+ /* @__PURE__ */ jsx(
12446
+ Form$2.Field,
12447
+ {
12448
+ control: form.control,
12449
+ name: "first_name",
12450
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12451
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12452
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12453
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12454
+ ] })
12455
+ }
12456
+ ),
12457
+ /* @__PURE__ */ jsx(
12458
+ Form$2.Field,
12459
+ {
12460
+ control: form.control,
12461
+ name: "last_name",
12462
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12463
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12464
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12465
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12466
+ ] })
12467
+ }
12468
+ )
12469
+ ] }),
12470
+ /* @__PURE__ */ jsx(
12471
+ Form$2.Field,
12472
+ {
12473
+ control: form.control,
12474
+ name: "company",
12475
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12476
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12477
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12478
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12479
+ ] })
12480
+ }
12481
+ ),
12482
+ /* @__PURE__ */ jsx(
12483
+ Form$2.Field,
12484
+ {
12485
+ control: form.control,
12486
+ name: "address_1",
12487
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12488
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12489
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12490
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12491
+ ] })
12492
+ }
12493
+ ),
12494
+ /* @__PURE__ */ jsx(
12495
+ Form$2.Field,
12496
+ {
12497
+ control: form.control,
12498
+ name: "address_2",
12499
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12500
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12501
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12502
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12503
+ ] })
12504
+ }
12505
+ ),
12506
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12507
+ /* @__PURE__ */ jsx(
12508
+ Form$2.Field,
12509
+ {
12510
+ control: form.control,
12511
+ name: "postal_code",
12512
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12513
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12514
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12515
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12516
+ ] })
12517
+ }
12518
+ ),
12519
+ /* @__PURE__ */ jsx(
12520
+ Form$2.Field,
12521
+ {
12522
+ control: form.control,
12523
+ name: "city",
12524
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12525
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12526
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12527
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12528
+ ] })
12529
+ }
12530
+ )
12531
+ ] }),
12532
+ /* @__PURE__ */ jsx(
12533
+ Form$2.Field,
12753
12534
  {
12754
- ...field,
12755
- onValueChange: (value) => onChange(value),
12756
- symbol: getNativeSymbol(currencyCode),
12757
- code: currencyCode
12535
+ control: form.control,
12536
+ name: "province",
12537
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12538
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12539
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12540
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12541
+ ] })
12758
12542
  }
12759
- ) })
12760
- ] });
12761
- }
12543
+ ),
12544
+ /* @__PURE__ */ jsx(
12545
+ Form$2.Field,
12546
+ {
12547
+ control: form.control,
12548
+ name: "phone",
12549
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12550
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12551
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12552
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12553
+ ] })
12554
+ }
12555
+ )
12556
+ ] }) }),
12557
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12558
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12559
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12560
+ ] }) })
12561
+ ]
12762
12562
  }
12763
- );
12764
- };
12765
- const PROMOTION_QUERY_KEY = "promotions";
12766
- const promotionsQueryKeys = {
12767
- list: (query2) => [
12768
- PROMOTION_QUERY_KEY,
12769
- query2 ? query2 : void 0
12770
- ],
12771
- detail: (id, query2) => [
12772
- PROMOTION_QUERY_KEY,
12773
- id,
12774
- query2 ? query2 : void 0
12775
- ]
12776
- };
12777
- const usePromotions = (query2, options) => {
12778
- const { data, ...rest } = useQuery({
12779
- queryKey: promotionsQueryKeys.list(query2),
12780
- queryFn: async () => sdk.admin.promotion.list(query2),
12781
- ...options
12782
- });
12783
- return { ...data, ...rest };
12563
+ ) });
12784
12564
  };
12785
- const Promotions = () => {
12565
+ const schema$1 = addressSchema;
12566
+ const TransferOwnership = () => {
12786
12567
  const { id } = useParams();
12787
- const {
12788
- order: preview,
12789
- isError: isPreviewError,
12790
- error: previewError
12791
- } = useOrderPreview(id, void 0);
12792
- useInitiateOrderEdit({ preview });
12793
- const { onCancel } = useCancelOrderEdit({ preview });
12794
- if (isPreviewError) {
12795
- throw previewError;
12568
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12569
+ fields: "id,customer_id,customer.*"
12570
+ });
12571
+ if (isError) {
12572
+ throw error;
12796
12573
  }
12797
- const isReady = !!preview;
12798
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
12799
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
12800
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
12574
+ const isReady = !isPending && !!draft_order;
12575
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12576
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12577
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12578
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12579
+ ] }),
12580
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12801
12581
  ] });
12802
12582
  };
12803
- const PromotionForm = ({ preview }) => {
12804
- const { items, shipping_methods } = preview;
12805
- const [isSubmitting, setIsSubmitting] = useState(false);
12806
- const [comboboxValue, setComboboxValue] = useState("");
12807
- const { handleSuccess } = useRouteModal();
12808
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
12809
- const promoIds = getPromotionIds(items, shipping_methods);
12810
- const { promotions, isPending, isError, error } = usePromotions(
12811
- {
12812
- id: promoIds
12583
+ const TransferOwnershipForm = ({ order }) => {
12584
+ var _a, _b;
12585
+ const form = useForm({
12586
+ defaultValues: {
12587
+ customer_id: order.customer_id || ""
12813
12588
  },
12589
+ resolver: zodResolver(schema)
12590
+ });
12591
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12592
+ const { handleSuccess } = useRouteModal();
12593
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12594
+ const currentCustomer = order.customer ? {
12595
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12596
+ value: order.customer.id
12597
+ } : null;
12598
+ const onSubmit = form.handleSubmit(async (data) => {
12599
+ await mutateAsync(
12600
+ { customer_id: data.customer_id },
12601
+ {
12602
+ onSuccess: () => {
12603
+ toast.success("Customer updated");
12604
+ handleSuccess();
12605
+ },
12606
+ onError: (error) => {
12607
+ toast.error(error.message);
12608
+ }
12609
+ }
12610
+ );
12611
+ });
12612
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12613
+ KeyboundForm,
12814
12614
  {
12815
- enabled: !!promoIds.length
12615
+ className: "flex flex-1 flex-col overflow-hidden",
12616
+ onSubmit,
12617
+ children: [
12618
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12619
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12620
+ currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12621
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12622
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12623
+ /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12624
+ ] }),
12625
+ /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12626
+ /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12627
+ /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12628
+ ] })
12629
+ ] }),
12630
+ /* @__PURE__ */ jsx(
12631
+ CustomerField,
12632
+ {
12633
+ control: form.control,
12634
+ currentCustomerId: order.customer_id
12635
+ }
12636
+ )
12637
+ ] }),
12638
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12639
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12640
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12641
+ ] }) })
12642
+ ]
12816
12643
  }
12817
- );
12818
- const comboboxData = useComboboxData({
12819
- queryKey: ["promotions", "combobox", promoIds],
12644
+ ) });
12645
+ };
12646
+ const CustomerField = ({ control, currentCustomerId }) => {
12647
+ const customers = useComboboxData({
12820
12648
  queryFn: async (params) => {
12821
- return await sdk.admin.promotion.list({
12649
+ return await sdk.admin.customer.list({
12822
12650
  ...params,
12823
- id: {
12824
- $nin: promoIds
12825
- }
12651
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12826
12652
  });
12827
12653
  },
12654
+ queryKey: ["customers"],
12828
12655
  getOptions: (data) => {
12829
- return data.promotions.map((promotion) => ({
12830
- label: promotion.code,
12831
- value: promotion.code
12832
- }));
12656
+ return data.customers.map((customer) => {
12657
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12658
+ return {
12659
+ label: name ? `${name} (${customer.email})` : customer.email,
12660
+ value: customer.id
12661
+ };
12662
+ });
12833
12663
  }
12834
12664
  });
12835
- const add = async (value) => {
12836
- if (!value) {
12837
- return;
12838
- }
12839
- addPromotions(
12840
- {
12841
- promo_codes: [value]
12842
- },
12843
- {
12844
- onError: (e) => {
12845
- toast.error(e.message);
12846
- comboboxData.onSearchValueChange("");
12847
- setComboboxValue("");
12848
- },
12849
- onSuccess: () => {
12850
- comboboxData.onSearchValueChange("");
12851
- setComboboxValue("");
12852
- }
12853
- }
12854
- );
12855
- };
12856
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12857
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
12858
- const onSubmit = async () => {
12859
- setIsSubmitting(true);
12860
- let requestSucceeded = false;
12861
- await requestOrderEdit(void 0, {
12862
- onError: (e) => {
12863
- toast.error(e.message);
12864
- },
12865
- onSuccess: () => {
12866
- requestSucceeded = true;
12867
- }
12868
- });
12869
- if (!requestSucceeded) {
12870
- setIsSubmitting(false);
12871
- return;
12872
- }
12873
- await confirmOrderEdit(void 0, {
12874
- onError: (e) => {
12875
- toast.error(e.message);
12876
- },
12877
- onSuccess: () => {
12878
- handleSuccess();
12879
- },
12880
- onSettled: () => {
12881
- setIsSubmitting(false);
12882
- }
12883
- });
12884
- };
12885
- if (isError) {
12886
- throw error;
12887
- }
12888
- return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
12889
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
12890
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
12665
+ return /* @__PURE__ */ jsx(
12666
+ Form$2.Field,
12667
+ {
12668
+ name: "customer_id",
12669
+ control,
12670
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
12891
12671
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12892
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
12893
- /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
12672
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
12673
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12894
12674
  ] }),
12675
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12676
+ Combobox,
12677
+ {
12678
+ options: customers.options,
12679
+ fetchNextPage: customers.fetchNextPage,
12680
+ isFetchingNextPage: customers.isFetchingNextPage,
12681
+ searchValue: customers.searchValue,
12682
+ onSearchValueChange: customers.onSearchValueChange,
12683
+ placeholder: "Select customer",
12684
+ ...field
12685
+ }
12686
+ ) }),
12687
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12688
+ ] })
12689
+ }
12690
+ );
12691
+ };
12692
+ const Illustration = () => {
12693
+ return /* @__PURE__ */ jsxs(
12694
+ "svg",
12695
+ {
12696
+ width: "280",
12697
+ height: "180",
12698
+ viewBox: "0 0 280 180",
12699
+ fill: "none",
12700
+ xmlns: "http://www.w3.org/2000/svg",
12701
+ children: [
12895
12702
  /* @__PURE__ */ jsx(
12896
- Combobox,
12703
+ "rect",
12704
+ {
12705
+ x: "0.00428286",
12706
+ y: "-0.742904",
12707
+ width: "33.5",
12708
+ height: "65.5",
12709
+ rx: "6.75",
12710
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12711
+ fill: "#D4D4D8",
12712
+ stroke: "#52525B",
12713
+ strokeWidth: "1.5"
12714
+ }
12715
+ ),
12716
+ /* @__PURE__ */ jsx(
12717
+ "rect",
12718
+ {
12719
+ x: "0.00428286",
12720
+ y: "-0.742904",
12721
+ width: "33.5",
12722
+ height: "65.5",
12723
+ rx: "6.75",
12724
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12725
+ fill: "white",
12726
+ stroke: "#52525B",
12727
+ strokeWidth: "1.5"
12728
+ }
12729
+ ),
12730
+ /* @__PURE__ */ jsx(
12731
+ "path",
12732
+ {
12733
+ d: "M180.579 107.142L179.126 107.959",
12734
+ stroke: "#52525B",
12735
+ strokeWidth: "1.5",
12736
+ strokeLinecap: "round",
12737
+ strokeLinejoin: "round"
12738
+ }
12739
+ ),
12740
+ /* @__PURE__ */ jsx(
12741
+ "path",
12742
+ {
12743
+ opacity: "0.88",
12744
+ d: "M182.305 109.546L180.257 109.534",
12745
+ stroke: "#52525B",
12746
+ strokeWidth: "1.5",
12747
+ strokeLinecap: "round",
12748
+ strokeLinejoin: "round"
12749
+ }
12750
+ ),
12751
+ /* @__PURE__ */ jsx(
12752
+ "path",
12753
+ {
12754
+ opacity: "0.75",
12755
+ d: "M180.551 111.93L179.108 111.096",
12756
+ stroke: "#52525B",
12757
+ strokeWidth: "1.5",
12758
+ strokeLinecap: "round",
12759
+ strokeLinejoin: "round"
12760
+ }
12761
+ ),
12762
+ /* @__PURE__ */ jsx(
12763
+ "path",
12764
+ {
12765
+ opacity: "0.63",
12766
+ d: "M176.347 112.897L176.354 111.73",
12767
+ stroke: "#52525B",
12768
+ strokeWidth: "1.5",
12769
+ strokeLinecap: "round",
12770
+ strokeLinejoin: "round"
12771
+ }
12772
+ ),
12773
+ /* @__PURE__ */ jsx(
12774
+ "path",
12775
+ {
12776
+ opacity: "0.5",
12777
+ d: "M172.153 111.881L173.606 111.064",
12778
+ stroke: "#52525B",
12779
+ strokeWidth: "1.5",
12780
+ strokeLinecap: "round",
12781
+ strokeLinejoin: "round"
12782
+ }
12783
+ ),
12784
+ /* @__PURE__ */ jsx(
12785
+ "path",
12786
+ {
12787
+ opacity: "0.38",
12788
+ d: "M170.428 109.478L172.476 109.489",
12789
+ stroke: "#52525B",
12790
+ strokeWidth: "1.5",
12791
+ strokeLinecap: "round",
12792
+ strokeLinejoin: "round"
12793
+ }
12794
+ ),
12795
+ /* @__PURE__ */ jsx(
12796
+ "path",
12797
+ {
12798
+ opacity: "0.25",
12799
+ d: "M172.181 107.094L173.624 107.928",
12800
+ stroke: "#52525B",
12801
+ strokeWidth: "1.5",
12802
+ strokeLinecap: "round",
12803
+ strokeLinejoin: "round"
12804
+ }
12805
+ ),
12806
+ /* @__PURE__ */ jsx(
12807
+ "path",
12808
+ {
12809
+ opacity: "0.13",
12810
+ d: "M176.386 106.126L176.379 107.294",
12811
+ stroke: "#52525B",
12812
+ strokeWidth: "1.5",
12813
+ strokeLinecap: "round",
12814
+ strokeLinejoin: "round"
12815
+ }
12816
+ ),
12817
+ /* @__PURE__ */ jsx(
12818
+ "rect",
12819
+ {
12820
+ width: "12",
12821
+ height: "3",
12822
+ rx: "1.5",
12823
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12824
+ fill: "#D4D4D8"
12825
+ }
12826
+ ),
12827
+ /* @__PURE__ */ jsx(
12828
+ "rect",
12829
+ {
12830
+ x: "0.00428286",
12831
+ y: "-0.742904",
12832
+ width: "33.5",
12833
+ height: "65.5",
12834
+ rx: "6.75",
12835
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12836
+ fill: "#D4D4D8",
12837
+ stroke: "#52525B",
12838
+ strokeWidth: "1.5"
12839
+ }
12840
+ ),
12841
+ /* @__PURE__ */ jsx(
12842
+ "rect",
12843
+ {
12844
+ x: "0.00428286",
12845
+ y: "-0.742904",
12846
+ width: "33.5",
12847
+ height: "65.5",
12848
+ rx: "6.75",
12849
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12850
+ fill: "white",
12851
+ stroke: "#52525B",
12852
+ strokeWidth: "1.5"
12853
+ }
12854
+ ),
12855
+ /* @__PURE__ */ jsx(
12856
+ "rect",
12857
+ {
12858
+ width: "12",
12859
+ height: "3",
12860
+ rx: "1.5",
12861
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12862
+ fill: "#D4D4D8"
12863
+ }
12864
+ ),
12865
+ /* @__PURE__ */ jsx(
12866
+ "rect",
12867
+ {
12868
+ width: "17",
12869
+ height: "3",
12870
+ rx: "1.5",
12871
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12872
+ fill: "#D4D4D8"
12873
+ }
12874
+ ),
12875
+ /* @__PURE__ */ jsx(
12876
+ "rect",
12877
+ {
12878
+ width: "12",
12879
+ height: "3",
12880
+ rx: "1.5",
12881
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12882
+ fill: "#D4D4D8"
12883
+ }
12884
+ ),
12885
+ /* @__PURE__ */ jsx(
12886
+ "path",
12887
+ {
12888
+ d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
12889
+ fill: "#A1A1AA"
12890
+ }
12891
+ ),
12892
+ /* @__PURE__ */ jsx(
12893
+ "rect",
12894
+ {
12895
+ width: "17",
12896
+ height: "3",
12897
+ rx: "1.5",
12898
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12899
+ fill: "#A1A1AA"
12900
+ }
12901
+ ),
12902
+ /* @__PURE__ */ jsx(
12903
+ "rect",
12904
+ {
12905
+ width: "12",
12906
+ height: "3",
12907
+ rx: "1.5",
12908
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12909
+ fill: "#A1A1AA"
12910
+ }
12911
+ ),
12912
+ /* @__PURE__ */ jsx(
12913
+ "path",
12914
+ {
12915
+ d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12916
+ fill: "#52525B"
12917
+ }
12918
+ ),
12919
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
12920
+ "path",
12921
+ {
12922
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12923
+ stroke: "#A1A1AA",
12924
+ strokeWidth: "1.5",
12925
+ strokeLinecap: "round",
12926
+ strokeLinejoin: "round"
12927
+ }
12928
+ ) }),
12929
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
12930
+ "path",
12931
+ {
12932
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12933
+ stroke: "#A1A1AA",
12934
+ strokeWidth: "1.5",
12935
+ strokeLinecap: "round",
12936
+ strokeLinejoin: "round"
12937
+ }
12938
+ ) }),
12939
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
12940
+ "path",
12897
12941
  {
12898
- id: "promotion-combobox",
12899
- "aria-describedby": "promotion-combobox-hint",
12900
- isFetchingNextPage: comboboxData.isFetchingNextPage,
12901
- fetchNextPage: comboboxData.fetchNextPage,
12902
- options: comboboxData.options,
12903
- onSearchValueChange: comboboxData.onSearchValueChange,
12904
- searchValue: comboboxData.searchValue,
12905
- disabled: comboboxData.disabled || isAddingPromotions,
12906
- onChange: add,
12907
- value: comboboxValue
12942
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12943
+ stroke: "#A1A1AA",
12944
+ strokeWidth: "1.5",
12945
+ strokeLinecap: "round",
12946
+ strokeLinejoin: "round"
12908
12947
  }
12909
- )
12910
- ] }),
12911
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12912
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
12913
- PromotionItem,
12914
- {
12915
- promotion,
12916
- orderId: preview.id,
12917
- isLoading: isPending
12918
- },
12919
- promotion.id
12920
- )) })
12921
- ] }) }),
12922
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12923
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12924
- /* @__PURE__ */ jsx(
12925
- Button,
12926
- {
12927
- size: "small",
12928
- type: "submit",
12929
- isLoading: isSubmitting || isAddingPromotions,
12930
- children: "Save"
12931
- }
12932
- )
12933
- ] }) })
12934
- ] });
12935
- };
12936
- const PromotionItem = ({
12937
- promotion,
12938
- orderId,
12939
- isLoading
12940
- }) => {
12941
- var _a;
12942
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
12943
- const onRemove = async () => {
12944
- removePromotions(
12945
- {
12946
- promo_codes: [promotion.code]
12947
- },
12948
- {
12949
- onError: (e) => {
12950
- toast.error(e.message);
12951
- }
12952
- }
12953
- );
12954
- };
12955
- const displayValue = getDisplayValue(promotion);
12956
- return /* @__PURE__ */ jsxs(
12957
- "div",
12958
- {
12959
- className: clx(
12960
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
12961
- {
12962
- "animate-pulse": isLoading
12963
- }
12964
- ),
12965
- children: [
12966
- /* @__PURE__ */ jsxs("div", { children: [
12967
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
12968
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
12969
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
12970
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
12971
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
12972
- ] }),
12973
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
12974
- ] })
12975
- ] }),
12976
- /* @__PURE__ */ jsx(
12977
- IconButton,
12948
+ ) }),
12949
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
12950
+ "path",
12978
12951
  {
12979
- size: "small",
12980
- type: "button",
12981
- variant: "transparent",
12982
- onClick: onRemove,
12983
- isLoading: isPending || isLoading,
12984
- children: /* @__PURE__ */ jsx(XMark, {})
12952
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12953
+ stroke: "#A1A1AA",
12954
+ strokeWidth: "1.5",
12955
+ strokeLinecap: "round",
12956
+ strokeLinejoin: "round"
12985
12957
  }
12986
- )
12958
+ ) }),
12959
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12960
+ "path",
12961
+ {
12962
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12963
+ stroke: "#A1A1AA",
12964
+ strokeWidth: "1.5",
12965
+ strokeLinecap: "round",
12966
+ strokeLinejoin: "round"
12967
+ }
12968
+ ) }),
12969
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12970
+ "path",
12971
+ {
12972
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12973
+ stroke: "#A1A1AA",
12974
+ strokeWidth: "1.5",
12975
+ strokeLinecap: "round",
12976
+ strokeLinejoin: "round"
12977
+ }
12978
+ ) }),
12979
+ /* @__PURE__ */ jsxs("defs", { children: [
12980
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12981
+ "rect",
12982
+ {
12983
+ width: "12",
12984
+ height: "12",
12985
+ fill: "white",
12986
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12987
+ }
12988
+ ) }),
12989
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12990
+ "rect",
12991
+ {
12992
+ width: "12",
12993
+ height: "12",
12994
+ fill: "white",
12995
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12996
+ }
12997
+ ) }),
12998
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12999
+ "rect",
13000
+ {
13001
+ width: "12",
13002
+ height: "12",
13003
+ fill: "white",
13004
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
13005
+ }
13006
+ ) }),
13007
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
13008
+ "rect",
13009
+ {
13010
+ width: "12",
13011
+ height: "12",
13012
+ fill: "white",
13013
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
13014
+ }
13015
+ ) }),
13016
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
13017
+ "rect",
13018
+ {
13019
+ width: "12",
13020
+ height: "12",
13021
+ fill: "white",
13022
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13023
+ }
13024
+ ) }),
13025
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
13026
+ "rect",
13027
+ {
13028
+ width: "12",
13029
+ height: "12",
13030
+ fill: "white",
13031
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13032
+ }
13033
+ ) })
13034
+ ] })
12987
13035
  ]
12988
- },
12989
- promotion.id
13036
+ }
12990
13037
  );
12991
13038
  };
12992
- function getDisplayValue(promotion) {
12993
- var _a, _b, _c, _d;
12994
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
12995
- if (!value) {
12996
- return null;
12997
- }
12998
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
12999
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
13000
- if (!currency) {
13001
- return null;
13002
- }
13003
- return getLocaleAmount(value, currency);
13004
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
13005
- return formatPercentage(value);
13006
- }
13007
- return null;
13008
- }
13009
- const formatter = new Intl.NumberFormat([], {
13010
- style: "percent",
13011
- minimumFractionDigits: 2
13039
+ const schema = objectType({
13040
+ customer_id: stringType().min(1)
13012
13041
  });
13013
- const formatPercentage = (value, isPercentageValue = false) => {
13014
- let val = value || 0;
13015
- if (!isPercentageValue) {
13016
- val = val / 100;
13017
- }
13018
- return formatter.format(val);
13019
- };
13020
- function getPromotionIds(items, shippingMethods) {
13021
- const promotionIds = /* @__PURE__ */ new Set();
13022
- for (const item of items) {
13023
- if (item.adjustments) {
13024
- for (const adjustment of item.adjustments) {
13025
- if (adjustment.promotion_id) {
13026
- promotionIds.add(adjustment.promotion_id);
13027
- }
13028
- }
13029
- }
13030
- }
13031
- for (const shippingMethod of shippingMethods) {
13032
- if (shippingMethod.adjustments) {
13033
- for (const adjustment of shippingMethod.adjustments) {
13034
- if (adjustment.promotion_id) {
13035
- promotionIds.add(adjustment.promotion_id);
13036
- }
13037
- }
13038
- }
13039
- }
13040
- return Array.from(promotionIds);
13041
- }
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
13044
13044
  routes: [
@@ -13059,14 +13059,14 @@ const routeModule = {
13059
13059
  handle,
13060
13060
  loader,
13061
13061
  children: [
13062
- {
13063
- Component: BillingAddress,
13064
- path: "/draft-orders/:id/billing-address"
13065
- },
13066
13062
  {
13067
13063
  Component: CustomItems,
13068
13064
  path: "/draft-orders/:id/custom-items"
13069
13065
  },
13066
+ {
13067
+ Component: BillingAddress,
13068
+ path: "/draft-orders/:id/billing-address"
13069
+ },
13070
13070
  {
13071
13071
  Component: Email,
13072
13072
  path: "/draft-orders/:id/email"
@@ -13079,10 +13079,18 @@ const routeModule = {
13079
13079
  Component: Metadata,
13080
13080
  path: "/draft-orders/:id/metadata"
13081
13081
  },
13082
+ {
13083
+ Component: Promotions,
13084
+ path: "/draft-orders/:id/promotions"
13085
+ },
13082
13086
  {
13083
13087
  Component: SalesChannel,
13084
13088
  path: "/draft-orders/:id/sales-channel"
13085
13089
  },
13090
+ {
13091
+ Component: Shipping,
13092
+ path: "/draft-orders/:id/shipping"
13093
+ },
13086
13094
  {
13087
13095
  Component: ShippingAddress,
13088
13096
  path: "/draft-orders/:id/shipping-address"
@@ -13090,14 +13098,6 @@ const routeModule = {
13090
13098
  {
13091
13099
  Component: TransferOwnership,
13092
13100
  path: "/draft-orders/:id/transfer-ownership"
13093
- },
13094
- {
13095
- Component: Shipping,
13096
- path: "/draft-orders/:id/shipping"
13097
- },
13098
- {
13099
- Component: Promotions,
13100
- path: "/draft-orders/:id/promotions"
13101
13101
  }
13102
13102
  ]
13103
13103
  }