@medusajs/draft-order 2.10.0-snapshot-20250904125819 → 2.10.0-snapshot-20250904131418

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.
@@ -9560,27 +9560,6 @@ const ID = () => {
9560
9560
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9561
9561
  ] });
9562
9562
  };
9563
- const CustomItems = () => {
9564
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9565
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9566
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9567
- ] });
9568
- };
9569
- const CustomItemsForm = () => {
9570
- const form = reactHookForm.useForm({
9571
- resolver: zod.zodResolver(schema$5)
9572
- });
9573
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9574
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9575
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9576
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9577
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9578
- ] }) })
9579
- ] }) });
9580
- };
9581
- const schema$5 = objectType({
9582
- email: stringType().email()
9583
- });
9584
9563
  const BillingAddress = () => {
9585
9564
  const { id } = reactRouterDom.useParams();
9586
9565
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9613,7 +9592,7 @@ const BillingAddressForm = ({ order }) => {
9613
9592
  postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9614
9593
  phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9615
9594
  },
9616
- resolver: zod.zodResolver(schema$4)
9595
+ resolver: zod.zodResolver(schema$5)
9617
9596
  });
9618
9597
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9619
9598
  const { handleSuccess } = useRouteModal();
@@ -9770,7 +9749,28 @@ const BillingAddressForm = ({ order }) => {
9770
9749
  }
9771
9750
  ) });
9772
9751
  };
9773
- const schema$4 = addressSchema;
9752
+ const schema$5 = addressSchema;
9753
+ const CustomItems = () => {
9754
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9755
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9756
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9757
+ ] });
9758
+ };
9759
+ const CustomItemsForm = () => {
9760
+ const form = reactHookForm.useForm({
9761
+ resolver: zod.zodResolver(schema$4)
9762
+ });
9763
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9764
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9765
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9766
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9767
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9768
+ ] }) })
9769
+ ] }) });
9770
+ };
9771
+ const schema$4 = objectType({
9772
+ email: stringType().email()
9773
+ });
9774
9774
  const Email = () => {
9775
9775
  const { id } = reactRouterDom.useParams();
9776
9776
  const { order, isPending, isError, error } = useOrder(id, {
@@ -10189,26 +10189,112 @@ function getHasUneditableRows(metadata) {
10189
10189
  (value) => !EDITABLE_TYPES.includes(typeof value)
10190
10190
  );
10191
10191
  }
10192
- const PROMOTION_QUERY_KEY = "promotions";
10193
- const promotionsQueryKeys = {
10194
- list: (query2) => [
10195
- PROMOTION_QUERY_KEY,
10196
- query2 ? query2 : void 0
10197
- ],
10198
- detail: (id, query2) => [
10199
- PROMOTION_QUERY_KEY,
10192
+ const SalesChannel = () => {
10193
+ const { id } = reactRouterDom.useParams();
10194
+ const { draft_order, isPending, isError, error } = useDraftOrder(
10200
10195
  id,
10201
- query2 ? query2 : void 0
10202
- ]
10196
+ {
10197
+ fields: "+sales_channel_id"
10198
+ },
10199
+ {
10200
+ enabled: !!id
10201
+ }
10202
+ );
10203
+ if (isError) {
10204
+ throw error;
10205
+ }
10206
+ const ISrEADY = !!draft_order && !isPending;
10207
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10208
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10209
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
10210
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
10211
+ ] }),
10212
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
10213
+ ] });
10203
10214
  };
10204
- const usePromotions = (query2, options) => {
10205
- const { data, ...rest } = reactQuery.useQuery({
10206
- queryKey: promotionsQueryKeys.list(query2),
10207
- queryFn: async () => sdk.admin.promotion.list(query2),
10208
- ...options
10215
+ const SalesChannelForm = ({ order }) => {
10216
+ const form = reactHookForm.useForm({
10217
+ defaultValues: {
10218
+ sales_channel_id: order.sales_channel_id || ""
10219
+ },
10220
+ resolver: zod.zodResolver(schema$2)
10209
10221
  });
10210
- return { ...data, ...rest };
10222
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10223
+ const { handleSuccess } = useRouteModal();
10224
+ const onSubmit = form.handleSubmit(async (data) => {
10225
+ await mutateAsync(
10226
+ {
10227
+ sales_channel_id: data.sales_channel_id
10228
+ },
10229
+ {
10230
+ onSuccess: () => {
10231
+ ui.toast.success("Sales channel updated");
10232
+ handleSuccess();
10233
+ },
10234
+ onError: (error) => {
10235
+ ui.toast.error(error.message);
10236
+ }
10237
+ }
10238
+ );
10239
+ });
10240
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10241
+ KeyboundForm,
10242
+ {
10243
+ className: "flex flex-1 flex-col overflow-hidden",
10244
+ onSubmit,
10245
+ children: [
10246
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
10247
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10248
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10249
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10250
+ ] }) })
10251
+ ]
10252
+ }
10253
+ ) });
10254
+ };
10255
+ const SalesChannelField = ({ control, order }) => {
10256
+ const salesChannels = useComboboxData({
10257
+ queryFn: async (params) => {
10258
+ return await sdk.admin.salesChannel.list(params);
10259
+ },
10260
+ queryKey: ["sales-channels"],
10261
+ getOptions: (data) => {
10262
+ return data.sales_channels.map((salesChannel) => ({
10263
+ label: salesChannel.name,
10264
+ value: salesChannel.id
10265
+ }));
10266
+ },
10267
+ defaultValue: order.sales_channel_id || void 0
10268
+ });
10269
+ return /* @__PURE__ */ jsxRuntime.jsx(
10270
+ Form$2.Field,
10271
+ {
10272
+ control,
10273
+ name: "sales_channel_id",
10274
+ render: ({ field }) => {
10275
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10276
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
10277
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10278
+ Combobox,
10279
+ {
10280
+ options: salesChannels.options,
10281
+ fetchNextPage: salesChannels.fetchNextPage,
10282
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
10283
+ searchValue: salesChannels.searchValue,
10284
+ onSearchValueChange: salesChannels.onSearchValueChange,
10285
+ placeholder: "Select sales channel",
10286
+ ...field
10287
+ }
10288
+ ) }),
10289
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10290
+ ] });
10291
+ }
10292
+ }
10293
+ );
10211
10294
  };
10295
+ const schema$2 = objectType({
10296
+ sales_channel_id: stringType().min(1)
10297
+ });
10212
10298
  const useCancelOrderEdit = ({ preview }) => {
10213
10299
  const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
10214
10300
  const onCancel = React.useCallback(async () => {
@@ -10255,97 +10341,92 @@ const useInitiateOrderEdit = ({
10255
10341
  run();
10256
10342
  }, [preview, navigate, mutateAsync]);
10257
10343
  };
10258
- const Promotions = () => {
10344
+ function convertNumber(value) {
10345
+ return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10346
+ }
10347
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
10348
+ const Shipping = () => {
10349
+ var _a;
10259
10350
  const { id } = reactRouterDom.useParams();
10351
+ const { order, isPending, isError, error } = useOrder(id, {
10352
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
10353
+ });
10260
10354
  const {
10261
10355
  order: preview,
10356
+ isPending: isPreviewPending,
10262
10357
  isError: isPreviewError,
10263
10358
  error: previewError
10264
- } = useOrderPreview(id, void 0);
10359
+ } = useOrderPreview(id);
10265
10360
  useInitiateOrderEdit({ preview });
10266
10361
  const { onCancel } = useCancelOrderEdit({ preview });
10362
+ if (isError) {
10363
+ throw error;
10364
+ }
10267
10365
  if (isPreviewError) {
10268
10366
  throw previewError;
10269
10367
  }
10270
- const isReady = !!preview;
10271
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
10272
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
10273
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
10274
- ] });
10368
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
10369
+ const isReady = preview && !isPreviewPending && order && !isPending;
10370
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
10371
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
10372
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
10373
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
10374
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
10375
+ ] }) }) }),
10376
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
10377
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10378
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
10379
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10380
+ ] }) });
10275
10381
  };
10276
- const PromotionForm = ({ preview }) => {
10277
- const { items, shipping_methods } = preview;
10382
+ const ShippingForm = ({ preview, order }) => {
10383
+ var _a;
10384
+ const { setIsOpen } = useStackedModal();
10278
10385
  const [isSubmitting, setIsSubmitting] = React.useState(false);
10279
- const [comboboxValue, setComboboxValue] = React.useState("");
10280
- const { handleSuccess } = useRouteModal();
10281
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10282
- const promoCodes = getPromotionCodes(items, shipping_methods);
10283
- const { promotions, isPending, isError, error } = usePromotions(
10386
+ const [data, setData] = React.useState(null);
10387
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
10388
+ const { shipping_options } = useShippingOptions(
10284
10389
  {
10285
- code: promoCodes
10390
+ id: appliedShippingOptionIds,
10391
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
10286
10392
  },
10287
10393
  {
10288
- enabled: !!promoCodes.length
10394
+ enabled: appliedShippingOptionIds.length > 0
10289
10395
  }
10290
10396
  );
10291
- const comboboxData = useComboboxData({
10292
- queryKey: ["promotions", "combobox", promoCodes],
10293
- queryFn: async (params) => {
10294
- return await sdk.admin.promotion.list({
10295
- ...params,
10296
- code: {
10297
- $nin: promoCodes
10298
- }
10299
- });
10300
- },
10301
- getOptions: (data) => {
10302
- return data.promotions.map((promotion) => ({
10303
- label: promotion.code,
10304
- value: promotion.code
10305
- }));
10306
- }
10307
- });
10308
- const add = async (value) => {
10309
- if (!value) {
10310
- return;
10311
- }
10312
- addPromotions(
10313
- {
10314
- promo_codes: [value]
10315
- },
10316
- {
10317
- onError: (e) => {
10318
- ui.toast.error(e.message);
10319
- comboboxData.onSearchValueChange("");
10320
- setComboboxValue("");
10321
- },
10322
- onSuccess: () => {
10323
- comboboxData.onSearchValueChange("");
10324
- setComboboxValue("");
10325
- }
10326
- }
10327
- );
10328
- };
10329
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10330
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
10331
- const onSubmit = async () => {
10332
- setIsSubmitting(true);
10333
- let requestSucceeded = false;
10334
- await requestOrderEdit(void 0, {
10335
- onError: (e) => {
10336
- ui.toast.error(e.message);
10337
- },
10338
- onSuccess: () => {
10339
- requestSucceeded = true;
10340
- }
10341
- });
10342
- if (!requestSucceeded) {
10343
- setIsSubmitting(false);
10344
- return;
10397
+ const uniqueShippingProfiles = React.useMemo(() => {
10398
+ const profiles = /* @__PURE__ */ new Map();
10399
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
10400
+ profiles.set(profile.id, profile);
10401
+ });
10402
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
10403
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
10404
+ });
10405
+ return Array.from(profiles.values());
10406
+ }, [order.items, shipping_options]);
10407
+ const { handleSuccess } = useRouteModal();
10408
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10409
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10410
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
10411
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
10412
+ const onSubmit = async () => {
10413
+ setIsSubmitting(true);
10414
+ let requestSucceeded = false;
10415
+ await requestOrderEdit(void 0, {
10416
+ onError: (e) => {
10417
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
10418
+ },
10419
+ onSuccess: () => {
10420
+ requestSucceeded = true;
10421
+ }
10422
+ });
10423
+ if (!requestSucceeded) {
10424
+ setIsSubmitting(false);
10425
+ return;
10345
10426
  }
10346
10427
  await confirmOrderEdit(void 0, {
10347
10428
  onError: (e) => {
10348
- ui.toast.error(e.message);
10429
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
10349
10430
  },
10350
10431
  onSuccess: () => {
10351
10432
  handleSuccess();
@@ -10355,276 +10436,24 @@ const PromotionForm = ({ preview }) => {
10355
10436
  }
10356
10437
  });
10357
10438
  };
10358
- if (isError) {
10359
- throw error;
10360
- }
10361
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
10362
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
10363
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
10364
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10365
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
10366
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
10367
- ] }),
10368
- /* @__PURE__ */ jsxRuntime.jsx(
10369
- Combobox,
10370
- {
10371
- id: "promotion-combobox",
10372
- "aria-describedby": "promotion-combobox-hint",
10373
- isFetchingNextPage: comboboxData.isFetchingNextPage,
10374
- fetchNextPage: comboboxData.fetchNextPage,
10375
- options: comboboxData.options,
10376
- onSearchValueChange: comboboxData.onSearchValueChange,
10377
- searchValue: comboboxData.searchValue,
10378
- disabled: comboboxData.disabled || isAddingPromotions,
10379
- onChange: add,
10380
- value: comboboxValue
10381
- }
10382
- )
10383
- ] }),
10384
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10385
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
10386
- PromotionItem,
10387
- {
10388
- promotion,
10389
- orderId: preview.id,
10390
- isLoading: isPending
10391
- },
10392
- promotion.id
10393
- )) })
10394
- ] }) }),
10395
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10396
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10397
- /* @__PURE__ */ jsxRuntime.jsx(
10398
- ui.Button,
10399
- {
10400
- size: "small",
10401
- type: "submit",
10402
- isLoading: isSubmitting || isAddingPromotions,
10403
- children: "Save"
10404
- }
10405
- )
10406
- ] }) })
10407
- ] });
10408
- };
10409
- const PromotionItem = ({
10410
- promotion,
10411
- orderId,
10412
- isLoading
10413
- }) => {
10414
- var _a;
10415
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
10416
- const onRemove = async () => {
10417
- removePromotions(
10418
- {
10419
- promo_codes: [promotion.code]
10420
- },
10421
- {
10422
- onError: (e) => {
10423
- ui.toast.error(e.message);
10439
+ const onKeydown = React.useCallback(
10440
+ (e) => {
10441
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10442
+ if (data || isSubmitting) {
10443
+ return;
10424
10444
  }
10445
+ onSubmit();
10425
10446
  }
10426
- );
10427
- };
10428
- const displayValue = getDisplayValue(promotion);
10429
- return /* @__PURE__ */ jsxRuntime.jsxs(
10430
- "div",
10431
- {
10432
- className: ui.clx(
10433
- "px-3 py-2 rounded-lg bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between",
10434
- {
10435
- "animate-pulse": isLoading
10436
- }
10437
- ),
10438
- children: [
10439
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10440
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
10441
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5 text-ui-fg-subtle", children: [
10442
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
10443
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
10444
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
10445
- ] }),
10446
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
10447
- ] })
10448
- ] }),
10449
- /* @__PURE__ */ jsxRuntime.jsx(
10450
- ui.IconButton,
10451
- {
10452
- size: "small",
10453
- type: "button",
10454
- variant: "transparent",
10455
- onClick: onRemove,
10456
- isLoading: isPending || isLoading,
10457
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
10458
- }
10459
- )
10460
- ]
10461
10447
  },
10462
- promotion.id
10448
+ [data, isSubmitting, onSubmit]
10463
10449
  );
10464
- };
10465
- function getDisplayValue(promotion) {
10466
- var _a, _b, _c, _d;
10467
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
10468
- if (!value) {
10469
- return null;
10470
- }
10471
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
10472
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
10473
- if (!currency) {
10474
- return null;
10475
- }
10476
- return getLocaleAmount(value, currency);
10477
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
10478
- return formatPercentage(value);
10479
- }
10480
- return null;
10481
- }
10482
- const formatter = new Intl.NumberFormat([], {
10483
- style: "percent",
10484
- minimumFractionDigits: 2
10485
- });
10486
- const formatPercentage = (value, isPercentageValue = false) => {
10487
- let val = value || 0;
10488
- if (!isPercentageValue) {
10489
- val = val / 100;
10490
- }
10491
- return formatter.format(val);
10492
- };
10493
- function getPromotionCodes(items, shippingMethods) {
10494
- const codes = /* @__PURE__ */ new Set();
10495
- for (const item of items) {
10496
- if (item.adjustments) {
10497
- for (const adjustment of item.adjustments) {
10498
- if (adjustment.code) {
10499
- codes.add(adjustment.code);
10500
- }
10501
- }
10502
- }
10503
- }
10504
- for (const shippingMethod of shippingMethods) {
10505
- if (shippingMethod.adjustments) {
10506
- for (const adjustment of shippingMethod.adjustments) {
10507
- if (adjustment.code) {
10508
- codes.add(adjustment.code);
10509
- }
10510
- }
10511
- }
10512
- }
10513
- return Array.from(codes);
10514
- }
10515
- function convertNumber(value) {
10516
- return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10517
- }
10518
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
10519
- const Shipping = () => {
10520
- var _a;
10521
- const { id } = reactRouterDom.useParams();
10522
- const { order, isPending, isError, error } = useOrder(id, {
10523
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
10524
- });
10525
- const {
10526
- order: preview,
10527
- isPending: isPreviewPending,
10528
- isError: isPreviewError,
10529
- error: previewError
10530
- } = useOrderPreview(id);
10531
- useInitiateOrderEdit({ preview });
10532
- const { onCancel } = useCancelOrderEdit({ preview });
10533
- if (isError) {
10534
- throw error;
10535
- }
10536
- if (isPreviewError) {
10537
- throw previewError;
10538
- }
10539
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
10540
- const isReady = preview && !isPreviewPending && order && !isPending;
10541
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
10542
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
10543
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
10544
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
10545
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
10546
- ] }) }) }),
10547
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
10548
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10549
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
10550
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10551
- ] }) });
10552
- };
10553
- const ShippingForm = ({ preview, order }) => {
10554
- var _a;
10555
- const { setIsOpen } = useStackedModal();
10556
- const [isSubmitting, setIsSubmitting] = React.useState(false);
10557
- const [data, setData] = React.useState(null);
10558
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
10559
- const { shipping_options } = useShippingOptions(
10560
- {
10561
- id: appliedShippingOptionIds,
10562
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
10563
- },
10564
- {
10565
- enabled: appliedShippingOptionIds.length > 0
10566
- }
10567
- );
10568
- const uniqueShippingProfiles = React.useMemo(() => {
10569
- const profiles = /* @__PURE__ */ new Map();
10570
- getUniqueShippingProfiles(order.items).forEach((profile) => {
10571
- profiles.set(profile.id, profile);
10572
- });
10573
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
10574
- profiles.set(option.shipping_profile_id, option.shipping_profile);
10575
- });
10576
- return Array.from(profiles.values());
10577
- }, [order.items, shipping_options]);
10578
- const { handleSuccess } = useRouteModal();
10579
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10580
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10581
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
10582
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
10583
- const onSubmit = async () => {
10584
- setIsSubmitting(true);
10585
- let requestSucceeded = false;
10586
- await requestOrderEdit(void 0, {
10587
- onError: (e) => {
10588
- ui.toast.error(`Failed to request order edit: ${e.message}`);
10589
- },
10590
- onSuccess: () => {
10591
- requestSucceeded = true;
10592
- }
10593
- });
10594
- if (!requestSucceeded) {
10595
- setIsSubmitting(false);
10596
- return;
10597
- }
10598
- await confirmOrderEdit(void 0, {
10599
- onError: (e) => {
10600
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
10601
- },
10602
- onSuccess: () => {
10603
- handleSuccess();
10604
- },
10605
- onSettled: () => {
10606
- setIsSubmitting(false);
10607
- }
10608
- });
10609
- };
10610
- const onKeydown = React.useCallback(
10611
- (e) => {
10612
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10613
- if (data || isSubmitting) {
10614
- return;
10615
- }
10616
- onSubmit();
10617
- }
10618
- },
10619
- [data, isSubmitting, onSubmit]
10620
- );
10621
- React.useEffect(() => {
10622
- document.addEventListener("keydown", onKeydown);
10623
- return () => {
10624
- document.removeEventListener("keydown", onKeydown);
10625
- };
10626
- }, [onKeydown]);
10627
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10450
+ React.useEffect(() => {
10451
+ document.addEventListener("keydown", onKeydown);
10452
+ return () => {
10453
+ document.removeEventListener("keydown", onKeydown);
10454
+ };
10455
+ }, [onKeydown]);
10456
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10628
10457
  /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
10629
10458
  /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
10630
10459
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
@@ -11322,972 +11151,1030 @@ const CustomAmountField = ({
11322
11151
  }
11323
11152
  );
11324
11153
  };
11325
- const SalesChannel = () => {
11154
+ const NumberInput = React.forwardRef(
11155
+ ({
11156
+ value,
11157
+ onChange,
11158
+ size = "base",
11159
+ min = 0,
11160
+ max = 100,
11161
+ step = 1,
11162
+ className,
11163
+ disabled,
11164
+ ...props
11165
+ }, ref) => {
11166
+ const handleChange = (event) => {
11167
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
11168
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
11169
+ onChange(newValue);
11170
+ }
11171
+ };
11172
+ const handleIncrement = () => {
11173
+ const newValue = value + step;
11174
+ if (max === void 0 || newValue <= max) {
11175
+ onChange(newValue);
11176
+ }
11177
+ };
11178
+ const handleDecrement = () => {
11179
+ const newValue = value - step;
11180
+ if (min === void 0 || newValue >= min) {
11181
+ onChange(newValue);
11182
+ }
11183
+ };
11184
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11185
+ "div",
11186
+ {
11187
+ className: ui.clx(
11188
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
11189
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
11190
+ {
11191
+ "h-7": size === "small",
11192
+ "h-8": size === "base"
11193
+ },
11194
+ className
11195
+ ),
11196
+ children: [
11197
+ /* @__PURE__ */ jsxRuntime.jsx(
11198
+ "input",
11199
+ {
11200
+ ref,
11201
+ type: "number",
11202
+ value,
11203
+ onChange: handleChange,
11204
+ min,
11205
+ max,
11206
+ step,
11207
+ className: ui.clx(
11208
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
11209
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
11210
+ "placeholder:text-ui-fg-muted"
11211
+ ),
11212
+ ...props
11213
+ }
11214
+ ),
11215
+ /* @__PURE__ */ jsxRuntime.jsxs(
11216
+ "button",
11217
+ {
11218
+ className: ui.clx(
11219
+ "flex items-center justify-center outline-none transition-fg",
11220
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
11221
+ "focus:bg-ui-bg-field-component-hover",
11222
+ "hover:bg-ui-bg-field-component-hover",
11223
+ {
11224
+ "size-7": size === "small",
11225
+ "size-8": size === "base"
11226
+ }
11227
+ ),
11228
+ type: "button",
11229
+ onClick: handleDecrement,
11230
+ disabled: min !== void 0 && value <= min || disabled,
11231
+ children: [
11232
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
11233
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
11234
+ ]
11235
+ }
11236
+ ),
11237
+ /* @__PURE__ */ jsxRuntime.jsxs(
11238
+ "button",
11239
+ {
11240
+ className: ui.clx(
11241
+ "flex items-center justify-center outline-none transition-fg",
11242
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
11243
+ "focus:bg-ui-bg-field-hover",
11244
+ "hover:bg-ui-bg-field-hover",
11245
+ {
11246
+ "size-7": size === "small",
11247
+ "size-8": size === "base"
11248
+ }
11249
+ ),
11250
+ type: "button",
11251
+ onClick: handleIncrement,
11252
+ disabled: max !== void 0 && value >= max || disabled,
11253
+ children: [
11254
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
11255
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
11256
+ ]
11257
+ }
11258
+ )
11259
+ ]
11260
+ }
11261
+ );
11262
+ }
11263
+ );
11264
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
11265
+ const productVariantsQueryKeys = {
11266
+ list: (query2) => [
11267
+ PRODUCT_VARIANTS_QUERY_KEY,
11268
+ query2 ? query2 : void 0
11269
+ ]
11270
+ };
11271
+ const useProductVariants = (query2, options) => {
11272
+ const { data, ...rest } = reactQuery.useQuery({
11273
+ queryKey: productVariantsQueryKeys.list(query2),
11274
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
11275
+ ...options
11276
+ });
11277
+ return { ...data, ...rest };
11278
+ };
11279
+ const STACKED_MODAL_ID = "items_stacked_modal";
11280
+ const Items = () => {
11326
11281
  const { id } = reactRouterDom.useParams();
11282
+ const {
11283
+ order: preview,
11284
+ isPending: isPreviewPending,
11285
+ isError: isPreviewError,
11286
+ error: previewError
11287
+ } = useOrderPreview(id, void 0, {
11288
+ placeholderData: reactQuery.keepPreviousData
11289
+ });
11290
+ useInitiateOrderEdit({ preview });
11327
11291
  const { draft_order, isPending, isError, error } = useDraftOrder(
11328
11292
  id,
11329
11293
  {
11330
- fields: "+sales_channel_id"
11294
+ fields: "currency_code"
11331
11295
  },
11332
11296
  {
11333
11297
  enabled: !!id
11334
11298
  }
11335
11299
  );
11300
+ const { onCancel } = useCancelOrderEdit({ preview });
11336
11301
  if (isError) {
11337
11302
  throw error;
11338
11303
  }
11339
- const ISrEADY = !!draft_order && !isPending;
11340
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11341
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11342
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11343
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11344
- ] }),
11345
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11346
- ] });
11304
+ if (isPreviewError) {
11305
+ throw previewError;
11306
+ }
11307
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
11308
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11309
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
11310
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11311
+ ] }) });
11347
11312
  };
11348
- const SalesChannelForm = ({ order }) => {
11349
- const form = reactHookForm.useForm({
11350
- defaultValues: {
11351
- sales_channel_id: order.sales_channel_id || ""
11352
- },
11353
- resolver: zod.zodResolver(schema$2)
11354
- });
11355
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11313
+ const ItemsForm = ({ preview, currencyCode }) => {
11314
+ var _a;
11315
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11316
+ const [modalContent, setModalContent] = React.useState(
11317
+ null
11318
+ );
11356
11319
  const { handleSuccess } = useRouteModal();
11357
- const onSubmit = form.handleSubmit(async (data) => {
11358
- await mutateAsync(
11359
- {
11360
- sales_channel_id: data.sales_channel_id
11320
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
11321
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11322
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11323
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
11324
+ const matches = React.useMemo(() => {
11325
+ return matchSorter.matchSorter(preview.items, query2, {
11326
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
11327
+ });
11328
+ }, [preview.items, query2]);
11329
+ const onSubmit = async () => {
11330
+ setIsSubmitting(true);
11331
+ let requestSucceeded = false;
11332
+ await requestOrderEdit(void 0, {
11333
+ onError: (e) => {
11334
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11361
11335
  },
11362
- {
11363
- onSuccess: () => {
11364
- ui.toast.success("Sales channel updated");
11365
- handleSuccess();
11366
- },
11367
- onError: (error) => {
11368
- ui.toast.error(error.message);
11369
- }
11336
+ onSuccess: () => {
11337
+ requestSucceeded = true;
11370
11338
  }
11371
- );
11372
- });
11373
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11374
- KeyboundForm,
11375
- {
11376
- className: "flex flex-1 flex-col overflow-hidden",
11377
- onSubmit,
11378
- children: [
11379
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11380
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11381
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11382
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11383
- ] }) })
11384
- ]
11339
+ });
11340
+ if (!requestSucceeded) {
11341
+ setIsSubmitting(false);
11342
+ return;
11385
11343
  }
11386
- ) });
11387
- };
11388
- const SalesChannelField = ({ control, order }) => {
11389
- const salesChannels = useComboboxData({
11390
- queryFn: async (params) => {
11391
- return await sdk.admin.salesChannel.list(params);
11392
- },
11393
- queryKey: ["sales-channels"],
11394
- getOptions: (data) => {
11395
- return data.sales_channels.map((salesChannel) => ({
11396
- label: salesChannel.name,
11397
- value: salesChannel.id
11398
- }));
11344
+ await confirmOrderEdit(void 0, {
11345
+ onError: (e) => {
11346
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11347
+ },
11348
+ onSuccess: () => {
11349
+ handleSuccess();
11350
+ },
11351
+ onSettled: () => {
11352
+ setIsSubmitting(false);
11353
+ }
11354
+ });
11355
+ };
11356
+ const onKeyDown = React.useCallback(
11357
+ (e) => {
11358
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11359
+ if (modalContent || isSubmitting) {
11360
+ return;
11361
+ }
11362
+ onSubmit();
11363
+ }
11399
11364
  },
11400
- defaultValue: order.sales_channel_id || void 0
11401
- });
11402
- return /* @__PURE__ */ jsxRuntime.jsx(
11403
- Form$2.Field,
11404
- {
11405
- control,
11406
- name: "sales_channel_id",
11407
- render: ({ field }) => {
11408
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11409
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11410
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11411
- Combobox,
11365
+ [modalContent, isSubmitting, onSubmit]
11366
+ );
11367
+ React.useEffect(() => {
11368
+ document.addEventListener("keydown", onKeyDown);
11369
+ return () => {
11370
+ document.removeEventListener("keydown", onKeyDown);
11371
+ };
11372
+ }, [onKeyDown]);
11373
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11374
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11375
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
11376
+ StackedFocusModal,
11377
+ {
11378
+ id: STACKED_MODAL_ID,
11379
+ onOpenChangeCallback: (open) => {
11380
+ if (!open) {
11381
+ setModalContent(null);
11382
+ }
11383
+ },
11384
+ children: [
11385
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11386
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11387
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
11388
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order." }) })
11389
+ ] }),
11390
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11391
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
11392
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
11393
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11394
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
11395
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
11396
+ ] }),
11397
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
11398
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
11399
+ ui.Input,
11400
+ {
11401
+ type: "search",
11402
+ placeholder: "Search items",
11403
+ value: searchValue,
11404
+ onChange: (e) => onSearchValueChange(e.target.value)
11405
+ }
11406
+ ) }),
11407
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11408
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
11409
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11410
+ /* @__PURE__ */ jsxRuntime.jsx(
11411
+ StackedModalTrigger,
11412
+ {
11413
+ type: "add-items",
11414
+ setModalContent
11415
+ }
11416
+ ),
11417
+ /* @__PURE__ */ jsxRuntime.jsx(
11418
+ StackedModalTrigger,
11419
+ {
11420
+ type: "add-custom-item",
11421
+ setModalContent
11422
+ }
11423
+ )
11424
+ ] })
11425
+ ] })
11426
+ ] })
11427
+ ] }),
11428
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11429
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_1fr_1fr_28px] gap-3 px-4 py-2 text-ui-fg-muted", children: [
11430
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
11431
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
11432
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
11433
+ /* @__PURE__ */ jsxRuntime.jsx("div", {})
11434
+ ] }) }),
11435
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
11436
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
11437
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
11438
+ ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
11439
+ Item,
11440
+ {
11441
+ item,
11442
+ preview,
11443
+ currencyCode
11444
+ },
11445
+ item.id
11446
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
11447
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
11448
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
11449
+ 'No items found for "',
11450
+ query2,
11451
+ '".'
11452
+ ] })
11453
+ ] }) })
11454
+ ] })
11455
+ ] }),
11456
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11457
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
11458
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
11459
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
11460
+ ui.Text,
11461
+ {
11462
+ size: "small",
11463
+ leading: "compact",
11464
+ className: "text-ui-fg-subtle",
11465
+ children: [
11466
+ itemCount,
11467
+ " ",
11468
+ itemCount === 1 ? "item" : "items"
11469
+ ]
11470
+ }
11471
+ ) }),
11472
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
11473
+ ] })
11474
+ ] }) }),
11475
+ modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
11476
+ CustomItemForm,
11412
11477
  {
11413
- options: salesChannels.options,
11414
- fetchNextPage: salesChannels.fetchNextPage,
11415
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11416
- searchValue: salesChannels.searchValue,
11417
- onSearchValueChange: salesChannels.onSearchValueChange,
11418
- placeholder: "Select sales channel",
11419
- ...field
11478
+ orderId: preview.id,
11479
+ currencyCode
11420
11480
  }
11421
- ) }),
11422
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11423
- ] });
11481
+ ) : null)
11482
+ ]
11424
11483
  }
11425
- }
11426
- );
11484
+ ) }),
11485
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
11486
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11487
+ /* @__PURE__ */ jsxRuntime.jsx(
11488
+ ui.Button,
11489
+ {
11490
+ size: "small",
11491
+ type: "button",
11492
+ onClick: onSubmit,
11493
+ isLoading: isSubmitting,
11494
+ children: "Save"
11495
+ }
11496
+ )
11497
+ ] }) })
11498
+ ] });
11427
11499
  };
11428
- const schema$2 = objectType({
11429
- sales_channel_id: stringType().min(1)
11430
- });
11431
- const ShippingAddress = () => {
11432
- const { id } = reactRouterDom.useParams();
11433
- const { order, isPending, isError, error } = useOrder(id, {
11434
- fields: "+shipping_address"
11435
- });
11436
- if (isError) {
11437
- throw error;
11500
+ const Item = ({ item, preview, currencyCode }) => {
11501
+ if (item.variant_id) {
11502
+ return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
11438
11503
  }
11439
- const isReady = !isPending && !!order;
11440
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11441
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11442
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11443
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11444
- ] }),
11445
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11446
- ] });
11504
+ return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
11447
11505
  };
11448
- const ShippingAddressForm = ({ order }) => {
11449
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11506
+ const VariantItem = ({ item, preview, currencyCode }) => {
11507
+ const [editing, setEditing] = React.useState(false);
11450
11508
  const form = reactHookForm.useForm({
11451
11509
  defaultValues: {
11452
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11453
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11454
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11455
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11456
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11457
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11458
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11459
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11460
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11461
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11510
+ quantity: item.quantity,
11511
+ unit_price: item.unit_price
11462
11512
  },
11463
- resolver: zod.zodResolver(schema$1)
11513
+ resolver: zod.zodResolver(variantItemSchema)
11464
11514
  });
11465
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11466
- const { handleSuccess } = useRouteModal();
11515
+ const actionId = React.useMemo(() => {
11516
+ var _a, _b;
11517
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
11518
+ }, [item]);
11519
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
11520
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
11521
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
11467
11522
  const onSubmit = form.handleSubmit(async (data) => {
11468
- await mutateAsync(
11469
- {
11470
- shipping_address: {
11471
- first_name: data.first_name,
11472
- last_name: data.last_name,
11473
- company: data.company,
11474
- address_1: data.address_1,
11475
- address_2: data.address_2,
11476
- city: data.city,
11477
- province: data.province,
11478
- country_code: data.country_code,
11479
- postal_code: data.postal_code,
11480
- phone: data.phone
11523
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
11524
+ setEditing(false);
11525
+ return;
11526
+ }
11527
+ if (!actionId) {
11528
+ await updateOriginalItem(
11529
+ {
11530
+ item_id: item.id,
11531
+ quantity: data.quantity,
11532
+ unit_price: convertNumber(data.unit_price)
11533
+ },
11534
+ {
11535
+ onSuccess: () => {
11536
+ setEditing(false);
11537
+ },
11538
+ onError: (e) => {
11539
+ ui.toast.error(e.message);
11540
+ }
11481
11541
  }
11542
+ );
11543
+ return;
11544
+ }
11545
+ await updateActionItem(
11546
+ {
11547
+ action_id: actionId,
11548
+ quantity: data.quantity,
11549
+ unit_price: convertNumber(data.unit_price)
11482
11550
  },
11483
11551
  {
11484
11552
  onSuccess: () => {
11485
- handleSuccess();
11553
+ setEditing(false);
11486
11554
  },
11487
- onError: (error) => {
11488
- ui.toast.error(error.message);
11555
+ onError: (e) => {
11556
+ ui.toast.error(e.message);
11489
11557
  }
11490
11558
  }
11491
11559
  );
11492
11560
  });
11493
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11494
- KeyboundForm,
11495
- {
11496
- className: "flex flex-1 flex-col overflow-hidden",
11497
- onSubmit,
11498
- children: [
11499
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
11500
- /* @__PURE__ */ jsxRuntime.jsx(
11501
- Form$2.Field,
11502
- {
11503
- control: form.control,
11504
- name: "country_code",
11505
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11506
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11507
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11508
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11509
- ] })
11510
- }
11511
- ),
11512
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11513
- /* @__PURE__ */ jsxRuntime.jsx(
11514
- Form$2.Field,
11515
- {
11516
- control: form.control,
11517
- name: "first_name",
11518
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11519
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11520
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11521
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11522
- ] })
11523
- }
11524
- ),
11525
- /* @__PURE__ */ jsxRuntime.jsx(
11526
- Form$2.Field,
11527
- {
11528
- control: form.control,
11529
- name: "last_name",
11530
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11531
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11532
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11533
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11534
- ] })
11535
- }
11536
- )
11537
- ] }),
11538
- /* @__PURE__ */ jsxRuntime.jsx(
11539
- Form$2.Field,
11540
- {
11541
- control: form.control,
11542
- name: "company",
11543
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11544
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11545
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11546
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11547
- ] })
11548
- }
11549
- ),
11550
- /* @__PURE__ */ jsxRuntime.jsx(
11551
- Form$2.Field,
11552
- {
11553
- control: form.control,
11554
- name: "address_1",
11555
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11556
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11557
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11558
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11559
- ] })
11560
- }
11561
- ),
11562
- /* @__PURE__ */ jsxRuntime.jsx(
11563
- Form$2.Field,
11564
- {
11565
- control: form.control,
11566
- name: "address_2",
11567
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11568
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11569
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11570
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11571
- ] })
11572
- }
11573
- ),
11574
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11575
- /* @__PURE__ */ jsxRuntime.jsx(
11576
- Form$2.Field,
11577
- {
11578
- control: form.control,
11579
- name: "postal_code",
11580
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11581
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11582
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11583
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11584
- ] })
11585
- }
11586
- ),
11587
- /* @__PURE__ */ jsxRuntime.jsx(
11588
- Form$2.Field,
11589
- {
11590
- control: form.control,
11591
- name: "city",
11592
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11593
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11594
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11595
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11596
- ] })
11597
- }
11598
- )
11599
- ] }),
11600
- /* @__PURE__ */ jsxRuntime.jsx(
11601
- Form$2.Field,
11602
- {
11603
- control: form.control,
11604
- name: "province",
11605
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11606
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11607
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11608
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11609
- ] })
11610
- }
11611
- ),
11612
- /* @__PURE__ */ jsxRuntime.jsx(
11613
- Form$2.Field,
11561
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
11562
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full", children: [
11563
+ /* @__PURE__ */ jsxRuntime.jsx(
11564
+ Thumbnail,
11565
+ {
11566
+ thumbnail: item.thumbnail,
11567
+ alt: item.product_title ?? void 0
11568
+ }
11569
+ ),
11570
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11571
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
11572
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
11573
+ /* @__PURE__ */ jsxRuntime.jsxs(
11574
+ ui.Text,
11614
11575
  {
11615
- control: form.control,
11616
- name: "phone",
11617
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11618
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11619
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11620
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11621
- ] })
11576
+ size: "small",
11577
+ leading: "compact",
11578
+ className: "text-ui-fg-subtle",
11579
+ children: [
11580
+ "(",
11581
+ item.variant_title,
11582
+ ")"
11583
+ ]
11622
11584
  }
11623
11585
  )
11624
- ] }) }),
11625
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11626
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11627
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11628
- ] }) })
11629
- ]
11630
- }
11631
- ) });
11632
- };
11633
- const schema$1 = addressSchema;
11634
- const TransferOwnership = () => {
11635
- const { id } = reactRouterDom.useParams();
11636
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11637
- fields: "id,customer_id,customer.*"
11638
- });
11639
- if (isError) {
11640
- throw error;
11641
- }
11642
- const isReady = !isPending && !!draft_order;
11643
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11644
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11645
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
11646
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
11586
+ ] }),
11587
+ /* @__PURE__ */ jsxRuntime.jsx(
11588
+ ui.Text,
11589
+ {
11590
+ size: "small",
11591
+ leading: "compact",
11592
+ className: "text-ui-fg-subtle",
11593
+ children: item.variant_sku
11594
+ }
11595
+ )
11596
+ ] })
11647
11597
  ] }),
11648
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
11649
- ] });
11650
- };
11651
- const TransferOwnershipForm = ({ order }) => {
11652
- var _a, _b;
11653
- const form = reactHookForm.useForm({
11654
- defaultValues: {
11655
- customer_id: order.customer_id || ""
11656
- },
11657
- resolver: zod.zodResolver(schema)
11658
- });
11659
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11660
- const { handleSuccess } = useRouteModal();
11661
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11662
- const currentCustomer = order.customer ? {
11663
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
11664
- value: order.customer.id
11665
- } : null;
11666
- const onSubmit = form.handleSubmit(async (data) => {
11667
- await mutateAsync(
11668
- { customer_id: data.customer_id },
11598
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(
11599
+ Form$2.Field,
11669
11600
  {
11670
- onSuccess: () => {
11671
- ui.toast.success("Customer updated");
11672
- handleSuccess();
11673
- },
11674
- onError: (error) => {
11675
- ui.toast.error(error.message);
11601
+ control: form.control,
11602
+ name: "quantity",
11603
+ render: ({ field }) => {
11604
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
11676
11605
  }
11677
11606
  }
11678
- );
11679
- });
11680
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11681
- KeyboundForm,
11682
- {
11683
- className: "flex flex-1 flex-col overflow-hidden",
11684
- onSubmit,
11685
- children: [
11686
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11687
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
11688
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
11689
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11690
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11691
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
11692
- ] }),
11693
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
11694
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
11695
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11696
- ] })
11697
- ] }),
11698
- /* @__PURE__ */ jsxRuntime.jsx(
11699
- CustomerField,
11607
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
11608
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(
11609
+ Form$2.Field,
11610
+ {
11611
+ control: form.control,
11612
+ name: "unit_price",
11613
+ render: ({ field: { onChange, ...field } }) => {
11614
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11615
+ ui.CurrencyInput,
11700
11616
  {
11701
- control: form.control,
11702
- currentCustomerId: order.customer_id
11617
+ ...field,
11618
+ symbol: getNativeSymbol(currencyCode),
11619
+ code: currencyCode,
11620
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
11703
11621
  }
11704
- )
11705
- ] }),
11706
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11707
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11708
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11709
- ] }) })
11710
- ]
11711
- }
11712
- ) });
11622
+ ) }) });
11623
+ }
11624
+ }
11625
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 flex items-center justify-end w-full", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
11626
+ /* @__PURE__ */ jsxRuntime.jsx(
11627
+ ui.IconButton,
11628
+ {
11629
+ type: "button",
11630
+ size: "small",
11631
+ onClick: editing ? onSubmit : () => {
11632
+ setEditing(true);
11633
+ },
11634
+ disabled: isPending,
11635
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
11636
+ }
11637
+ )
11638
+ ] }) }) });
11713
11639
  };
11714
- const CustomerField = ({ control, currentCustomerId }) => {
11715
- const customers = useComboboxData({
11716
- queryFn: async (params) => {
11717
- return await sdk.admin.customer.list({
11718
- ...params,
11719
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11720
- });
11640
+ const variantItemSchema = objectType({
11641
+ quantity: numberType(),
11642
+ unit_price: unionType([numberType(), stringType()])
11643
+ });
11644
+ const CustomItem = ({ item, preview, currencyCode }) => {
11645
+ const [editing, setEditing] = React.useState(false);
11646
+ const { quantity, unit_price, title } = item;
11647
+ const form = reactHookForm.useForm({
11648
+ defaultValues: {
11649
+ title,
11650
+ quantity,
11651
+ unit_price
11721
11652
  },
11722
- queryKey: ["customers"],
11723
- getOptions: (data) => {
11724
- return data.customers.map((customer) => {
11725
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11726
- return {
11727
- label: name ? `${name} (${customer.email})` : customer.email,
11728
- value: customer.id
11729
- };
11653
+ resolver: zod.zodResolver(customItemSchema)
11654
+ });
11655
+ React.useEffect(() => {
11656
+ form.reset({
11657
+ title,
11658
+ quantity,
11659
+ unit_price
11660
+ });
11661
+ }, [form, title, quantity, unit_price]);
11662
+ const actionId = React.useMemo(() => {
11663
+ var _a, _b;
11664
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
11665
+ }, [item]);
11666
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
11667
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
11668
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
11669
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
11670
+ const onSubmit = form.handleSubmit(async (data) => {
11671
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
11672
+ setEditing(false);
11673
+ return;
11674
+ }
11675
+ if (!actionId) {
11676
+ await updateOriginalItem(
11677
+ {
11678
+ item_id: item.id,
11679
+ quantity: data.quantity,
11680
+ unit_price: convertNumber(data.unit_price)
11681
+ },
11682
+ {
11683
+ onSuccess: () => {
11684
+ setEditing(false);
11685
+ },
11686
+ onError: (e) => {
11687
+ ui.toast.error(e.message);
11688
+ }
11689
+ }
11690
+ );
11691
+ return;
11692
+ }
11693
+ if (data.quantity === 0) {
11694
+ await removeActionItem(actionId, {
11695
+ onSuccess: () => {
11696
+ setEditing(false);
11697
+ },
11698
+ onError: (e) => {
11699
+ ui.toast.error(e.message);
11700
+ }
11730
11701
  });
11702
+ return;
11731
11703
  }
11704
+ await updateActionItem(
11705
+ {
11706
+ action_id: actionId,
11707
+ quantity: data.quantity,
11708
+ unit_price: convertNumber(data.unit_price)
11709
+ },
11710
+ {
11711
+ onSuccess: () => {
11712
+ setEditing(false);
11713
+ },
11714
+ onError: (e) => {
11715
+ ui.toast.error(e.message);
11716
+ }
11717
+ }
11718
+ );
11732
11719
  });
11733
- return /* @__PURE__ */ jsxRuntime.jsx(
11734
- Form$2.Field,
11735
- {
11736
- name: "customer_id",
11737
- control,
11738
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
11739
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11740
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
11741
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11742
- ] }),
11743
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11744
- Combobox,
11745
- {
11746
- options: customers.options,
11747
- fetchNextPage: customers.fetchNextPage,
11748
- isFetchingNextPage: customers.isFetchingNextPage,
11749
- searchValue: customers.searchValue,
11750
- onSearchValueChange: customers.onSearchValueChange,
11751
- placeholder: "Select customer",
11752
- ...field
11720
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
11721
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11722
+ /* @__PURE__ */ jsxRuntime.jsx(
11723
+ Thumbnail,
11724
+ {
11725
+ thumbnail: item.thumbnail,
11726
+ alt: item.title ?? void 0
11727
+ }
11728
+ ),
11729
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
11730
+ Form$2.Field,
11731
+ {
11732
+ control: form.control,
11733
+ name: "title",
11734
+ render: ({ field }) => {
11735
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
11753
11736
  }
11754
- ) }),
11755
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11756
- ] })
11757
- }
11758
- );
11737
+ }
11738
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
11739
+ ] }),
11740
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
11741
+ Form$2.Field,
11742
+ {
11743
+ control: form.control,
11744
+ name: "quantity",
11745
+ render: ({ field }) => {
11746
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
11747
+ }
11748
+ }
11749
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
11750
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
11751
+ Form$2.Field,
11752
+ {
11753
+ control: form.control,
11754
+ name: "unit_price",
11755
+ render: ({ field: { onChange, ...field } }) => {
11756
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11757
+ ui.CurrencyInput,
11758
+ {
11759
+ ...field,
11760
+ symbol: getNativeSymbol(currencyCode),
11761
+ code: currencyCode,
11762
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
11763
+ }
11764
+ ) }) });
11765
+ }
11766
+ }
11767
+ ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 flex items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
11768
+ /* @__PURE__ */ jsxRuntime.jsx(
11769
+ ui.IconButton,
11770
+ {
11771
+ type: "button",
11772
+ size: "small",
11773
+ onClick: editing ? onSubmit : () => {
11774
+ setEditing(true);
11775
+ },
11776
+ disabled: isPending,
11777
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
11778
+ }
11779
+ )
11780
+ ] }) }) });
11759
11781
  };
11760
- const Illustration = () => {
11761
- return /* @__PURE__ */ jsxRuntime.jsxs(
11762
- "svg",
11763
- {
11764
- width: "280",
11765
- height: "180",
11766
- viewBox: "0 0 280 180",
11767
- fill: "none",
11768
- xmlns: "http://www.w3.org/2000/svg",
11782
+ const StackedModalTrigger = ({
11783
+ type,
11784
+ setModalContent
11785
+ }) => {
11786
+ const { setIsOpen } = useStackedModal();
11787
+ const onClick = React.useCallback(() => {
11788
+ setModalContent(type);
11789
+ setIsOpen(STACKED_MODAL_ID, true);
11790
+ }, [setModalContent, setIsOpen, type]);
11791
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
11792
+ };
11793
+ const VARIANT_PREFIX = "items";
11794
+ const LIMIT = 50;
11795
+ const ExistingItemsForm = ({ orderId, items }) => {
11796
+ const { setIsOpen } = useStackedModal();
11797
+ const [rowSelection, setRowSelection] = React.useState(
11798
+ items.reduce((acc, item) => {
11799
+ acc[item.variant_id] = true;
11800
+ return acc;
11801
+ }, {})
11802
+ );
11803
+ React.useEffect(() => {
11804
+ setRowSelection(
11805
+ items.reduce((acc, item) => {
11806
+ if (item.variant_id) {
11807
+ acc[item.variant_id] = true;
11808
+ }
11809
+ return acc;
11810
+ }, {})
11811
+ );
11812
+ }, [items]);
11813
+ const { q, order, offset } = useQueryParams(
11814
+ ["q", "order", "offset"],
11815
+ VARIANT_PREFIX
11816
+ );
11817
+ const { variants, count, isPending, isError, error } = useProductVariants(
11818
+ {
11819
+ q,
11820
+ order,
11821
+ offset: offset ? parseInt(offset) : void 0,
11822
+ limit: LIMIT
11823
+ },
11824
+ {
11825
+ placeholderData: reactQuery.keepPreviousData
11826
+ }
11827
+ );
11828
+ const columns = useColumns();
11829
+ const { mutateAsync } = useDraftOrderAddItems(orderId);
11830
+ const onSubmit = async () => {
11831
+ const ids = Object.keys(rowSelection).filter(
11832
+ (id) => !items.find((i) => i.variant_id === id)
11833
+ );
11834
+ await mutateAsync(
11835
+ {
11836
+ items: ids.map((id) => ({
11837
+ variant_id: id,
11838
+ quantity: 1
11839
+ }))
11840
+ },
11841
+ {
11842
+ onSuccess: () => {
11843
+ setRowSelection({});
11844
+ setIsOpen(STACKED_MODAL_ID, false);
11845
+ },
11846
+ onError: (e) => {
11847
+ ui.toast.error(e.message);
11848
+ }
11849
+ }
11850
+ );
11851
+ };
11852
+ if (isError) {
11853
+ throw error;
11854
+ }
11855
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11856
+ StackedFocusModal.Content,
11857
+ {
11858
+ onOpenAutoFocus: (e) => {
11859
+ e.preventDefault();
11860
+ const searchInput = document.querySelector(
11861
+ "[data-modal-id='modal-search-input']"
11862
+ );
11863
+ if (searchInput) {
11864
+ searchInput.focus();
11865
+ }
11866
+ },
11769
11867
  children: [
11770
- /* @__PURE__ */ jsxRuntime.jsx(
11771
- "rect",
11772
- {
11773
- x: "0.00428286",
11774
- y: "-0.742904",
11775
- width: "33.5",
11776
- height: "65.5",
11777
- rx: "6.75",
11778
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
11779
- fill: "#D4D4D8",
11780
- stroke: "#52525B",
11781
- strokeWidth: "1.5"
11782
- }
11783
- ),
11784
- /* @__PURE__ */ jsxRuntime.jsx(
11785
- "rect",
11786
- {
11787
- x: "0.00428286",
11788
- y: "-0.742904",
11789
- width: "33.5",
11790
- height: "65.5",
11791
- rx: "6.75",
11792
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
11793
- fill: "white",
11794
- stroke: "#52525B",
11795
- strokeWidth: "1.5"
11796
- }
11797
- ),
11798
- /* @__PURE__ */ jsxRuntime.jsx(
11799
- "path",
11868
+ /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
11869
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
11870
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
11871
+ ] }),
11872
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
11873
+ DataTable,
11800
11874
  {
11801
- d: "M180.579 107.142L179.126 107.959",
11802
- stroke: "#52525B",
11803
- strokeWidth: "1.5",
11804
- strokeLinecap: "round",
11805
- strokeLinejoin: "round"
11875
+ data: variants,
11876
+ columns,
11877
+ isLoading: isPending,
11878
+ getRowId: (row) => row.id,
11879
+ rowCount: count,
11880
+ prefix: VARIANT_PREFIX,
11881
+ layout: "fill",
11882
+ rowSelection: {
11883
+ state: rowSelection,
11884
+ onRowSelectionChange: setRowSelection,
11885
+ enableRowSelection: (row) => {
11886
+ return !items.find((i) => i.variant_id === row.original.id);
11887
+ }
11888
+ },
11889
+ autoFocusSearch: true
11806
11890
  }
11807
- ),
11808
- /* @__PURE__ */ jsxRuntime.jsx(
11809
- "path",
11891
+ ) }),
11892
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
11893
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11894
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
11895
+ ] }) })
11896
+ ]
11897
+ }
11898
+ );
11899
+ };
11900
+ const columnHelper = ui.createDataTableColumnHelper();
11901
+ const useColumns = () => {
11902
+ return React.useMemo(() => {
11903
+ return [
11904
+ columnHelper.select(),
11905
+ columnHelper.accessor("product.title", {
11906
+ header: "Product",
11907
+ cell: ({ row }) => {
11908
+ var _a, _b, _c;
11909
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
11910
+ /* @__PURE__ */ jsxRuntime.jsx(
11911
+ Thumbnail,
11912
+ {
11913
+ thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
11914
+ alt: (_b = row.original.product) == null ? void 0 : _b.title
11915
+ }
11916
+ ),
11917
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
11918
+ ] });
11919
+ },
11920
+ enableSorting: true
11921
+ }),
11922
+ columnHelper.accessor("title", {
11923
+ header: "Variant",
11924
+ enableSorting: true
11925
+ }),
11926
+ columnHelper.accessor("sku", {
11927
+ header: "SKU",
11928
+ cell: ({ getValue }) => {
11929
+ return getValue() ?? "-";
11930
+ },
11931
+ enableSorting: true
11932
+ }),
11933
+ columnHelper.accessor("updated_at", {
11934
+ header: "Updated",
11935
+ cell: ({ getValue }) => {
11936
+ return /* @__PURE__ */ jsxRuntime.jsx(
11937
+ ui.Tooltip,
11938
+ {
11939
+ content: getFullDate({ date: getValue(), includeTime: true }),
11940
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
11941
+ }
11942
+ );
11943
+ },
11944
+ enableSorting: true,
11945
+ sortAscLabel: "Oldest first",
11946
+ sortDescLabel: "Newest first"
11947
+ }),
11948
+ columnHelper.accessor("created_at", {
11949
+ header: "Created",
11950
+ cell: ({ getValue }) => {
11951
+ return /* @__PURE__ */ jsxRuntime.jsx(
11952
+ ui.Tooltip,
11953
+ {
11954
+ content: getFullDate({ date: getValue(), includeTime: true }),
11955
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
11956
+ }
11957
+ );
11958
+ },
11959
+ enableSorting: true,
11960
+ sortAscLabel: "Oldest first",
11961
+ sortDescLabel: "Newest first"
11962
+ })
11963
+ ];
11964
+ }, []);
11965
+ };
11966
+ const CustomItemForm = ({ orderId, currencyCode }) => {
11967
+ const { setIsOpen } = useStackedModal();
11968
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
11969
+ const form = reactHookForm.useForm({
11970
+ defaultValues: {
11971
+ title: "",
11972
+ quantity: 1,
11973
+ unit_price: ""
11974
+ },
11975
+ resolver: zod.zodResolver(customItemSchema)
11976
+ });
11977
+ const onSubmit = form.handleSubmit(async (data) => {
11978
+ await addItems(
11979
+ {
11980
+ items: [
11810
11981
  {
11811
- opacity: "0.88",
11812
- d: "M182.305 109.546L180.257 109.534",
11813
- stroke: "#52525B",
11814
- strokeWidth: "1.5",
11815
- strokeLinecap: "round",
11816
- strokeLinejoin: "round"
11982
+ title: data.title,
11983
+ quantity: data.quantity,
11984
+ unit_price: convertNumber(data.unit_price)
11817
11985
  }
11818
- ),
11819
- /* @__PURE__ */ jsxRuntime.jsx(
11820
- "path",
11821
- {
11822
- opacity: "0.75",
11823
- d: "M180.551 111.93L179.108 111.096",
11824
- stroke: "#52525B",
11825
- strokeWidth: "1.5",
11826
- strokeLinecap: "round",
11827
- strokeLinejoin: "round"
11828
- }
11829
- ),
11830
- /* @__PURE__ */ jsxRuntime.jsx(
11831
- "path",
11832
- {
11833
- opacity: "0.63",
11834
- d: "M176.347 112.897L176.354 111.73",
11835
- stroke: "#52525B",
11836
- strokeWidth: "1.5",
11837
- strokeLinecap: "round",
11838
- strokeLinejoin: "round"
11839
- }
11840
- ),
11841
- /* @__PURE__ */ jsxRuntime.jsx(
11842
- "path",
11843
- {
11844
- opacity: "0.5",
11845
- d: "M172.153 111.881L173.606 111.064",
11846
- stroke: "#52525B",
11847
- strokeWidth: "1.5",
11848
- strokeLinecap: "round",
11849
- strokeLinejoin: "round"
11850
- }
11851
- ),
11852
- /* @__PURE__ */ jsxRuntime.jsx(
11853
- "path",
11854
- {
11855
- opacity: "0.38",
11856
- d: "M170.428 109.478L172.476 109.489",
11857
- stroke: "#52525B",
11858
- strokeWidth: "1.5",
11859
- strokeLinecap: "round",
11860
- strokeLinejoin: "round"
11861
- }
11862
- ),
11863
- /* @__PURE__ */ jsxRuntime.jsx(
11864
- "path",
11865
- {
11866
- opacity: "0.25",
11867
- d: "M172.181 107.094L173.624 107.928",
11868
- stroke: "#52525B",
11869
- strokeWidth: "1.5",
11870
- strokeLinecap: "round",
11871
- strokeLinejoin: "round"
11872
- }
11873
- ),
11874
- /* @__PURE__ */ jsxRuntime.jsx(
11875
- "path",
11876
- {
11877
- opacity: "0.13",
11878
- d: "M176.386 106.126L176.379 107.294",
11879
- stroke: "#52525B",
11880
- strokeWidth: "1.5",
11881
- strokeLinecap: "round",
11882
- strokeLinejoin: "round"
11883
- }
11884
- ),
11885
- /* @__PURE__ */ jsxRuntime.jsx(
11886
- "rect",
11887
- {
11888
- width: "12",
11889
- height: "3",
11890
- rx: "1.5",
11891
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
11892
- fill: "#D4D4D8"
11893
- }
11894
- ),
11895
- /* @__PURE__ */ jsxRuntime.jsx(
11896
- "rect",
11897
- {
11898
- x: "0.00428286",
11899
- y: "-0.742904",
11900
- width: "33.5",
11901
- height: "65.5",
11902
- rx: "6.75",
11903
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
11904
- fill: "#D4D4D8",
11905
- stroke: "#52525B",
11906
- strokeWidth: "1.5"
11907
- }
11908
- ),
11909
- /* @__PURE__ */ jsxRuntime.jsx(
11910
- "rect",
11911
- {
11912
- x: "0.00428286",
11913
- y: "-0.742904",
11914
- width: "33.5",
11915
- height: "65.5",
11916
- rx: "6.75",
11917
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
11918
- fill: "white",
11919
- stroke: "#52525B",
11920
- strokeWidth: "1.5"
11921
- }
11922
- ),
11923
- /* @__PURE__ */ jsxRuntime.jsx(
11924
- "rect",
11925
- {
11926
- width: "12",
11927
- height: "3",
11928
- rx: "1.5",
11929
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
11930
- fill: "#D4D4D8"
11931
- }
11932
- ),
11933
- /* @__PURE__ */ jsxRuntime.jsx(
11934
- "rect",
11935
- {
11936
- width: "17",
11937
- height: "3",
11938
- rx: "1.5",
11939
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
11940
- fill: "#D4D4D8"
11941
- }
11942
- ),
11943
- /* @__PURE__ */ jsxRuntime.jsx(
11944
- "rect",
11945
- {
11946
- width: "12",
11947
- height: "3",
11948
- rx: "1.5",
11949
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
11950
- fill: "#D4D4D8"
11951
- }
11952
- ),
11953
- /* @__PURE__ */ jsxRuntime.jsx(
11954
- "path",
11955
- {
11956
- 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",
11957
- fill: "#A1A1AA"
11958
- }
11959
- ),
11960
- /* @__PURE__ */ jsxRuntime.jsx(
11961
- "rect",
11962
- {
11963
- width: "17",
11964
- height: "3",
11965
- rx: "1.5",
11966
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
11967
- fill: "#A1A1AA"
11968
- }
11969
- ),
11970
- /* @__PURE__ */ jsxRuntime.jsx(
11971
- "rect",
11972
- {
11973
- width: "12",
11974
- height: "3",
11975
- rx: "1.5",
11976
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
11977
- fill: "#A1A1AA"
11978
- }
11979
- ),
11980
- /* @__PURE__ */ jsxRuntime.jsx(
11981
- "path",
11982
- {
11983
- 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",
11984
- fill: "#52525B"
11985
- }
11986
- ),
11987
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11988
- "path",
11989
- {
11990
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
11991
- stroke: "#A1A1AA",
11992
- strokeWidth: "1.5",
11993
- strokeLinecap: "round",
11994
- strokeLinejoin: "round"
11995
- }
11996
- ) }),
11997
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11998
- "path",
11999
- {
12000
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12001
- stroke: "#A1A1AA",
12002
- strokeWidth: "1.5",
12003
- strokeLinecap: "round",
12004
- strokeLinejoin: "round"
12005
- }
12006
- ) }),
12007
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12008
- "path",
12009
- {
12010
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12011
- stroke: "#A1A1AA",
12012
- strokeWidth: "1.5",
12013
- strokeLinecap: "round",
12014
- strokeLinejoin: "round"
12015
- }
12016
- ) }),
12017
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12018
- "path",
12019
- {
12020
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12021
- stroke: "#A1A1AA",
12022
- strokeWidth: "1.5",
12023
- strokeLinecap: "round",
12024
- strokeLinejoin: "round"
12025
- }
12026
- ) }),
12027
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12028
- "path",
12029
- {
12030
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12031
- stroke: "#A1A1AA",
12032
- strokeWidth: "1.5",
12033
- strokeLinecap: "round",
12034
- strokeLinejoin: "round"
12035
- }
12036
- ) }),
12037
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12038
- "path",
12039
- {
12040
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12041
- stroke: "#A1A1AA",
12042
- strokeWidth: "1.5",
12043
- strokeLinecap: "round",
12044
- strokeLinejoin: "round"
12045
- }
12046
- ) }),
12047
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12048
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12049
- "rect",
12050
- {
12051
- width: "12",
12052
- height: "12",
12053
- fill: "white",
12054
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12055
- }
12056
- ) }),
12057
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12058
- "rect",
12059
- {
12060
- width: "12",
12061
- height: "12",
12062
- fill: "white",
12063
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12064
- }
12065
- ) }),
12066
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12067
- "rect",
12068
- {
12069
- width: "12",
12070
- height: "12",
12071
- fill: "white",
12072
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12073
- }
12074
- ) }),
12075
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12076
- "rect",
12077
- {
12078
- width: "12",
12079
- height: "12",
12080
- fill: "white",
12081
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12082
- }
12083
- ) }),
12084
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12085
- "rect",
12086
- {
12087
- width: "12",
12088
- height: "12",
12089
- fill: "white",
12090
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12091
- }
12092
- ) }),
12093
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12094
- "rect",
12095
- {
12096
- width: "12",
12097
- height: "12",
12098
- fill: "white",
12099
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12100
- }
12101
- ) })
12102
- ] })
12103
- ]
12104
- }
12105
- );
12106
- };
12107
- const schema = objectType({
12108
- customer_id: stringType().min(1)
12109
- });
12110
- const NumberInput = React.forwardRef(
12111
- ({
12112
- value,
12113
- onChange,
12114
- size = "base",
12115
- min = 0,
12116
- max = 100,
12117
- step = 1,
12118
- className,
12119
- disabled,
12120
- ...props
12121
- }, ref) => {
12122
- const handleChange = (event) => {
12123
- const newValue = event.target.value === "" ? min : Number(event.target.value);
12124
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
12125
- onChange(newValue);
12126
- }
12127
- };
12128
- const handleIncrement = () => {
12129
- const newValue = value + step;
12130
- if (max === void 0 || newValue <= max) {
12131
- onChange(newValue);
12132
- }
12133
- };
12134
- const handleDecrement = () => {
12135
- const newValue = value - step;
12136
- if (min === void 0 || newValue >= min) {
12137
- onChange(newValue);
12138
- }
12139
- };
12140
- return /* @__PURE__ */ jsxRuntime.jsxs(
12141
- "div",
12142
- {
12143
- className: ui.clx(
12144
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
12145
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
12146
- {
12147
- "h-7": size === "small",
12148
- "h-8": size === "base"
12149
- },
12150
- className
12151
- ),
12152
- children: [
12153
- /* @__PURE__ */ jsxRuntime.jsx(
12154
- "input",
12155
- {
12156
- ref,
12157
- type: "number",
12158
- value,
12159
- onChange: handleChange,
12160
- min,
12161
- max,
12162
- step,
12163
- className: ui.clx(
12164
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
12165
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
12166
- "placeholder:text-ui-fg-muted"
12167
- ),
12168
- ...props
12169
- }
12170
- ),
12171
- /* @__PURE__ */ jsxRuntime.jsxs(
12172
- "button",
12173
- {
12174
- className: ui.clx(
12175
- "flex items-center justify-center outline-none transition-fg",
12176
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
12177
- "focus:bg-ui-bg-field-component-hover",
12178
- "hover:bg-ui-bg-field-component-hover",
12179
- {
12180
- "size-7": size === "small",
12181
- "size-8": size === "base"
12182
- }
12183
- ),
12184
- type: "button",
12185
- onClick: handleDecrement,
12186
- disabled: min !== void 0 && value <= min || disabled,
12187
- children: [
12188
- /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
12189
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
12190
- ]
12191
- }
12192
- ),
12193
- /* @__PURE__ */ jsxRuntime.jsxs(
12194
- "button",
12195
- {
12196
- className: ui.clx(
12197
- "flex items-center justify-center outline-none transition-fg",
12198
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
12199
- "focus:bg-ui-bg-field-hover",
12200
- "hover:bg-ui-bg-field-hover",
12201
- {
12202
- "size-7": size === "small",
12203
- "size-8": size === "base"
12204
- }
12205
- ),
12206
- type: "button",
12207
- onClick: handleIncrement,
12208
- disabled: max !== void 0 && value >= max || disabled,
12209
- children: [
12210
- /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
12211
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
12212
- ]
12213
- }
12214
- )
12215
11986
  ]
11987
+ },
11988
+ {
11989
+ onSuccess: () => {
11990
+ setIsOpen(STACKED_MODAL_ID, false);
11991
+ },
11992
+ onError: (e) => {
11993
+ ui.toast.error(e.message);
11994
+ }
12216
11995
  }
12217
11996
  );
12218
- }
12219
- );
12220
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
12221
- const productVariantsQueryKeys = {
11997
+ });
11998
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
11999
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12000
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
12001
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12002
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
12003
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
12004
+ ] }),
12005
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12006
+ /* @__PURE__ */ jsxRuntime.jsx(
12007
+ Form$2.Field,
12008
+ {
12009
+ control: form.control,
12010
+ name: "title",
12011
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12012
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12013
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
12014
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
12015
+ ] }),
12016
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12017
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12018
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12019
+ ] })
12020
+ ] }) })
12021
+ }
12022
+ ),
12023
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12024
+ /* @__PURE__ */ jsxRuntime.jsx(
12025
+ Form$2.Field,
12026
+ {
12027
+ control: form.control,
12028
+ name: "unit_price",
12029
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12030
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12031
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
12032
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
12033
+ ] }),
12034
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12035
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12036
+ ui.CurrencyInput,
12037
+ {
12038
+ symbol: getNativeSymbol(currencyCode),
12039
+ code: currencyCode,
12040
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
12041
+ ...field
12042
+ }
12043
+ ) }),
12044
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12045
+ ] })
12046
+ ] }) })
12047
+ }
12048
+ ),
12049
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12050
+ /* @__PURE__ */ jsxRuntime.jsx(
12051
+ Form$2.Field,
12052
+ {
12053
+ control: form.control,
12054
+ name: "quantity",
12055
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12056
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12057
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
12058
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
12059
+ ] }),
12060
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 w-full", children: [
12061
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field, className: "w-full" }) }) }),
12062
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12063
+ ] })
12064
+ ] }) })
12065
+ }
12066
+ )
12067
+ ] }) }) }),
12068
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
12069
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12070
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
12071
+ ] }) })
12072
+ ] }) }) });
12073
+ };
12074
+ const customItemSchema = objectType({
12075
+ title: stringType().min(1),
12076
+ quantity: numberType(),
12077
+ unit_price: unionType([numberType(), stringType()])
12078
+ });
12079
+ const PROMOTION_QUERY_KEY = "promotions";
12080
+ const promotionsQueryKeys = {
12222
12081
  list: (query2) => [
12223
- PRODUCT_VARIANTS_QUERY_KEY,
12082
+ PROMOTION_QUERY_KEY,
12083
+ query2 ? query2 : void 0
12084
+ ],
12085
+ detail: (id, query2) => [
12086
+ PROMOTION_QUERY_KEY,
12087
+ id,
12224
12088
  query2 ? query2 : void 0
12225
12089
  ]
12226
12090
  };
12227
- const useProductVariants = (query2, options) => {
12091
+ const usePromotions = (query2, options) => {
12228
12092
  const { data, ...rest } = reactQuery.useQuery({
12229
- queryKey: productVariantsQueryKeys.list(query2),
12230
- queryFn: async () => await sdk.admin.productVariant.list(query2),
12093
+ queryKey: promotionsQueryKeys.list(query2),
12094
+ queryFn: async () => sdk.admin.promotion.list(query2),
12231
12095
  ...options
12232
12096
  });
12233
12097
  return { ...data, ...rest };
12234
12098
  };
12235
- const STACKED_MODAL_ID = "items_stacked_modal";
12236
- const Items = () => {
12099
+ const Promotions = () => {
12237
12100
  const { id } = reactRouterDom.useParams();
12238
12101
  const {
12239
12102
  order: preview,
12240
- isPending: isPreviewPending,
12241
12103
  isError: isPreviewError,
12242
12104
  error: previewError
12243
- } = useOrderPreview(id, void 0, {
12244
- placeholderData: reactQuery.keepPreviousData
12245
- });
12105
+ } = useOrderPreview(id, void 0);
12246
12106
  useInitiateOrderEdit({ preview });
12247
- const { draft_order, isPending, isError, error } = useDraftOrder(
12248
- id,
12249
- {
12250
- fields: "currency_code"
12251
- },
12252
- {
12253
- enabled: !!id
12254
- }
12255
- );
12256
12107
  const { onCancel } = useCancelOrderEdit({ preview });
12257
- if (isError) {
12258
- throw error;
12259
- }
12260
12108
  if (isPreviewError) {
12261
12109
  throw previewError;
12262
12110
  }
12263
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
12264
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12265
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
12266
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12267
- ] }) });
12111
+ const isReady = !!preview;
12112
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
12113
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
12114
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
12115
+ ] });
12268
12116
  };
12269
- const ItemsForm = ({ preview, currencyCode }) => {
12270
- var _a;
12117
+ const PromotionForm = ({ preview }) => {
12118
+ const { items, shipping_methods } = preview;
12271
12119
  const [isSubmitting, setIsSubmitting] = React.useState(false);
12272
- const [modalContent, setModalContent] = React.useState(
12273
- null
12274
- );
12120
+ const [comboboxValue, setComboboxValue] = React.useState("");
12275
12121
  const { handleSuccess } = useRouteModal();
12276
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
12122
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
12123
+ const promoCodes = getPromotionCodes(items, shipping_methods);
12124
+ const { promotions, isPending, isError, error } = usePromotions(
12125
+ {
12126
+ code: promoCodes
12127
+ },
12128
+ {
12129
+ enabled: !!promoCodes.length
12130
+ }
12131
+ );
12132
+ const comboboxData = useComboboxData({
12133
+ queryKey: ["promotions", "combobox", promoCodes],
12134
+ queryFn: async (params) => {
12135
+ return await sdk.admin.promotion.list({
12136
+ ...params,
12137
+ code: {
12138
+ $nin: promoCodes
12139
+ }
12140
+ });
12141
+ },
12142
+ getOptions: (data) => {
12143
+ return data.promotions.map((promotion) => ({
12144
+ label: promotion.code,
12145
+ value: promotion.code
12146
+ }));
12147
+ }
12148
+ });
12149
+ const add = async (value) => {
12150
+ if (!value) {
12151
+ return;
12152
+ }
12153
+ addPromotions(
12154
+ {
12155
+ promo_codes: [value]
12156
+ },
12157
+ {
12158
+ onError: (e) => {
12159
+ ui.toast.error(e.message);
12160
+ comboboxData.onSearchValueChange("");
12161
+ setComboboxValue("");
12162
+ },
12163
+ onSuccess: () => {
12164
+ comboboxData.onSearchValueChange("");
12165
+ setComboboxValue("");
12166
+ }
12167
+ }
12168
+ );
12169
+ };
12277
12170
  const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12278
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12279
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
12280
- const matches = React.useMemo(() => {
12281
- return matchSorter.matchSorter(preview.items, query2, {
12282
- keys: ["product_title", "variant_title", "variant_sku", "title"]
12283
- });
12284
- }, [preview.items, query2]);
12171
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
12285
12172
  const onSubmit = async () => {
12286
12173
  setIsSubmitting(true);
12287
12174
  let requestSucceeded = false;
12288
12175
  await requestOrderEdit(void 0, {
12289
12176
  onError: (e) => {
12290
- ui.toast.error(`Failed to request order edit: ${e.message}`);
12177
+ ui.toast.error(e.message);
12291
12178
  },
12292
12179
  onSuccess: () => {
12293
12180
  requestSucceeded = true;
@@ -12299,7 +12186,7 @@ const ItemsForm = ({ preview, currencyCode }) => {
12299
12186
  }
12300
12187
  await confirmOrderEdit(void 0, {
12301
12188
  onError: (e) => {
12302
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
12189
+ ui.toast.error(e.message);
12303
12190
  },
12304
12191
  onSuccess: () => {
12305
12192
  handleSuccess();
@@ -12309,729 +12196,842 @@ const ItemsForm = ({ preview, currencyCode }) => {
12309
12196
  }
12310
12197
  });
12311
12198
  };
12312
- const onKeyDown = React.useCallback(
12313
- (e) => {
12314
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12315
- if (modalContent || isSubmitting) {
12316
- return;
12317
- }
12318
- onSubmit();
12319
- }
12320
- },
12321
- [modalContent, isSubmitting, onSubmit]
12322
- );
12323
- React.useEffect(() => {
12324
- document.addEventListener("keydown", onKeyDown);
12325
- return () => {
12326
- document.removeEventListener("keydown", onKeyDown);
12327
- };
12328
- }, [onKeyDown]);
12329
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
12330
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12331
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
12332
- StackedFocusModal,
12333
- {
12334
- id: STACKED_MODAL_ID,
12335
- onOpenChangeCallback: (open) => {
12336
- if (!open) {
12337
- setModalContent(null);
12199
+ if (isError) {
12200
+ throw error;
12201
+ }
12202
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
12203
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
12204
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
12205
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12206
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
12207
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
12208
+ ] }),
12209
+ /* @__PURE__ */ jsxRuntime.jsx(
12210
+ Combobox,
12211
+ {
12212
+ id: "promotion-combobox",
12213
+ "aria-describedby": "promotion-combobox-hint",
12214
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
12215
+ fetchNextPage: comboboxData.fetchNextPage,
12216
+ options: comboboxData.options,
12217
+ onSearchValueChange: comboboxData.onSearchValueChange,
12218
+ searchValue: comboboxData.searchValue,
12219
+ disabled: comboboxData.disabled || isAddingPromotions,
12220
+ onChange: add,
12221
+ value: comboboxValue
12338
12222
  }
12339
- },
12340
- children: [
12341
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
12342
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12343
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
12344
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order." }) })
12345
- ] }),
12346
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12347
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12348
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
12349
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12350
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
12351
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
12352
- ] }),
12353
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
12354
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
12355
- ui.Input,
12356
- {
12357
- type: "search",
12358
- placeholder: "Search items",
12359
- value: searchValue,
12360
- onChange: (e) => onSearchValueChange(e.target.value)
12361
- }
12362
- ) }),
12363
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
12364
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
12365
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
12366
- /* @__PURE__ */ jsxRuntime.jsx(
12367
- StackedModalTrigger,
12368
- {
12369
- type: "add-items",
12370
- setModalContent
12371
- }
12372
- ),
12373
- /* @__PURE__ */ jsxRuntime.jsx(
12374
- StackedModalTrigger,
12375
- {
12376
- type: "add-custom-item",
12377
- setModalContent
12378
- }
12379
- )
12380
- ] })
12381
- ] })
12382
- ] })
12383
- ] }),
12384
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12385
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_1fr_1fr_28px] gap-3 px-4 py-2 text-ui-fg-muted", children: [
12386
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12387
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
12388
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
12389
- /* @__PURE__ */ jsxRuntime.jsx("div", {})
12390
- ] }) }),
12391
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12392
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
12393
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
12394
- ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
12395
- Item,
12396
- {
12397
- item,
12398
- preview,
12399
- currencyCode
12400
- },
12401
- item.id
12402
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12403
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12404
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12405
- 'No items found for "',
12406
- query2,
12407
- '".'
12408
- ] })
12409
- ] }) })
12410
- ] })
12411
- ] }),
12412
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12413
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
12414
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
12415
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
12416
- ui.Text,
12417
- {
12418
- size: "small",
12419
- leading: "compact",
12420
- className: "text-ui-fg-subtle",
12421
- children: [
12422
- itemCount,
12423
- " ",
12424
- itemCount === 1 ? "item" : "items"
12425
- ]
12426
- }
12427
- ) }),
12428
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
12429
- ] })
12430
- ] }) }),
12431
- modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
12432
- CustomItemForm,
12433
- {
12434
- orderId: preview.id,
12435
- currencyCode
12436
- }
12437
- ) : null)
12438
- ]
12439
- }
12440
- ) }),
12441
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
12442
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12223
+ )
12224
+ ] }),
12225
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12226
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
12227
+ PromotionItem,
12228
+ {
12229
+ promotion,
12230
+ orderId: preview.id,
12231
+ isLoading: isPending
12232
+ },
12233
+ promotion.id
12234
+ )) })
12235
+ ] }) }),
12236
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12237
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12443
12238
  /* @__PURE__ */ jsxRuntime.jsx(
12444
12239
  ui.Button,
12445
12240
  {
12446
12241
  size: "small",
12447
- type: "button",
12448
- onClick: onSubmit,
12449
- isLoading: isSubmitting,
12242
+ type: "submit",
12243
+ isLoading: isSubmitting || isAddingPromotions,
12450
12244
  children: "Save"
12451
12245
  }
12452
12246
  )
12453
12247
  ] }) })
12454
12248
  ] });
12455
12249
  };
12456
- const Item = ({ item, preview, currencyCode }) => {
12457
- if (item.variant_id) {
12458
- return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
12459
- }
12460
- return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
12461
- };
12462
- const VariantItem = ({ item, preview, currencyCode }) => {
12463
- const [editing, setEditing] = React.useState(false);
12464
- const form = reactHookForm.useForm({
12465
- defaultValues: {
12466
- quantity: item.quantity,
12467
- unit_price: item.unit_price
12468
- },
12469
- resolver: zod.zodResolver(variantItemSchema)
12470
- });
12471
- const actionId = React.useMemo(() => {
12472
- var _a, _b;
12473
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
12474
- }, [item]);
12475
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
12476
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
12477
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
12478
- const onSubmit = form.handleSubmit(async (data) => {
12479
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
12480
- setEditing(false);
12481
- return;
12482
- }
12483
- if (!actionId) {
12484
- await updateOriginalItem(
12485
- {
12486
- item_id: item.id,
12487
- quantity: data.quantity,
12488
- unit_price: convertNumber(data.unit_price)
12489
- },
12490
- {
12491
- onSuccess: () => {
12492
- setEditing(false);
12493
- },
12494
- onError: (e) => {
12495
- ui.toast.error(e.message);
12496
- }
12497
- }
12498
- );
12499
- return;
12500
- }
12501
- await updateActionItem(
12250
+ const PromotionItem = ({
12251
+ promotion,
12252
+ orderId,
12253
+ isLoading
12254
+ }) => {
12255
+ var _a;
12256
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
12257
+ const onRemove = async () => {
12258
+ removePromotions(
12502
12259
  {
12503
- action_id: actionId,
12504
- quantity: data.quantity,
12505
- unit_price: convertNumber(data.unit_price)
12260
+ promo_codes: [promotion.code]
12506
12261
  },
12507
12262
  {
12508
- onSuccess: () => {
12509
- setEditing(false);
12510
- },
12511
12263
  onError: (e) => {
12512
12264
  ui.toast.error(e.message);
12513
12265
  }
12514
12266
  }
12515
12267
  );
12516
- });
12517
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
12518
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full", children: [
12519
- /* @__PURE__ */ jsxRuntime.jsx(
12520
- Thumbnail,
12268
+ };
12269
+ const displayValue = getDisplayValue(promotion);
12270
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12271
+ "div",
12272
+ {
12273
+ className: ui.clx(
12274
+ "px-3 py-2 rounded-lg bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between",
12521
12275
  {
12522
- thumbnail: item.thumbnail,
12523
- alt: item.product_title ?? void 0
12276
+ "animate-pulse": isLoading
12524
12277
  }
12525
12278
  ),
12526
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12527
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12528
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12529
- /* @__PURE__ */ jsxRuntime.jsxs(
12530
- ui.Text,
12531
- {
12532
- size: "small",
12533
- leading: "compact",
12534
- className: "text-ui-fg-subtle",
12535
- children: [
12536
- "(",
12537
- item.variant_title,
12538
- ")"
12539
- ]
12540
- }
12541
- )
12279
+ children: [
12280
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12281
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
12282
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5 text-ui-fg-subtle", children: [
12283
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
12284
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
12285
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
12286
+ ] }),
12287
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
12288
+ ] })
12542
12289
  ] }),
12543
12290
  /* @__PURE__ */ jsxRuntime.jsx(
12544
- ui.Text,
12291
+ ui.IconButton,
12545
12292
  {
12546
12293
  size: "small",
12547
- leading: "compact",
12548
- className: "text-ui-fg-subtle",
12549
- children: item.variant_sku
12294
+ type: "button",
12295
+ variant: "transparent",
12296
+ onClick: onRemove,
12297
+ isLoading: isPending || isLoading,
12298
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
12550
12299
  }
12551
12300
  )
12552
- ] })
12553
- ] }),
12554
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(
12555
- Form$2.Field,
12556
- {
12557
- control: form.control,
12558
- name: "quantity",
12559
- render: ({ field }) => {
12560
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
12561
- }
12562
- }
12563
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
12564
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(
12565
- Form$2.Field,
12566
- {
12567
- control: form.control,
12568
- name: "unit_price",
12569
- render: ({ field: { onChange, ...field } }) => {
12570
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12571
- ui.CurrencyInput,
12572
- {
12573
- ...field,
12574
- symbol: getNativeSymbol(currencyCode),
12575
- code: currencyCode,
12576
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
12577
- }
12578
- ) }) });
12579
- }
12580
- }
12581
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 flex items-center justify-end w-full", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
12582
- /* @__PURE__ */ jsxRuntime.jsx(
12583
- ui.IconButton,
12584
- {
12585
- type: "button",
12586
- size: "small",
12587
- onClick: editing ? onSubmit : () => {
12588
- setEditing(true);
12589
- },
12590
- disabled: isPending,
12591
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
12592
- }
12593
- )
12594
- ] }) }) });
12595
- };
12596
- const variantItemSchema = objectType({
12597
- quantity: numberType(),
12598
- unit_price: unionType([numberType(), stringType()])
12599
- });
12600
- const CustomItem = ({ item, preview, currencyCode }) => {
12601
- const [editing, setEditing] = React.useState(false);
12602
- const { quantity, unit_price, title } = item;
12603
- const form = reactHookForm.useForm({
12604
- defaultValues: {
12605
- title,
12606
- quantity,
12607
- unit_price
12301
+ ]
12608
12302
  },
12609
- resolver: zod.zodResolver(customItemSchema)
12610
- });
12611
- React.useEffect(() => {
12612
- form.reset({
12613
- title,
12614
- quantity,
12615
- unit_price
12616
- });
12617
- }, [form, title, quantity, unit_price]);
12618
- const actionId = React.useMemo(() => {
12619
- var _a, _b;
12620
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
12621
- }, [item]);
12622
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
12623
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
12624
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
12625
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
12626
- const onSubmit = form.handleSubmit(async (data) => {
12627
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
12628
- setEditing(false);
12629
- return;
12303
+ promotion.id
12304
+ );
12305
+ };
12306
+ function getDisplayValue(promotion) {
12307
+ var _a, _b, _c, _d;
12308
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
12309
+ if (!value) {
12310
+ return null;
12311
+ }
12312
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
12313
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
12314
+ if (!currency) {
12315
+ return null;
12630
12316
  }
12631
- if (!actionId) {
12632
- await updateOriginalItem(
12633
- {
12634
- item_id: item.id,
12635
- quantity: data.quantity,
12636
- unit_price: convertNumber(data.unit_price)
12637
- },
12638
- {
12639
- onSuccess: () => {
12640
- setEditing(false);
12641
- },
12642
- onError: (e) => {
12643
- ui.toast.error(e.message);
12644
- }
12317
+ return getLocaleAmount(value, currency);
12318
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
12319
+ return formatPercentage(value);
12320
+ }
12321
+ return null;
12322
+ }
12323
+ const formatter = new Intl.NumberFormat([], {
12324
+ style: "percent",
12325
+ minimumFractionDigits: 2
12326
+ });
12327
+ const formatPercentage = (value, isPercentageValue = false) => {
12328
+ let val = value || 0;
12329
+ if (!isPercentageValue) {
12330
+ val = val / 100;
12331
+ }
12332
+ return formatter.format(val);
12333
+ };
12334
+ function getPromotionCodes(items, shippingMethods) {
12335
+ const codes = /* @__PURE__ */ new Set();
12336
+ for (const item of items) {
12337
+ if (item.adjustments) {
12338
+ for (const adjustment of item.adjustments) {
12339
+ if (adjustment.code) {
12340
+ codes.add(adjustment.code);
12645
12341
  }
12646
- );
12647
- return;
12342
+ }
12648
12343
  }
12649
- if (data.quantity === 0) {
12650
- await removeActionItem(actionId, {
12651
- onSuccess: () => {
12652
- setEditing(false);
12653
- },
12654
- onError: (e) => {
12655
- ui.toast.error(e.message);
12344
+ }
12345
+ for (const shippingMethod of shippingMethods) {
12346
+ if (shippingMethod.adjustments) {
12347
+ for (const adjustment of shippingMethod.adjustments) {
12348
+ if (adjustment.code) {
12349
+ codes.add(adjustment.code);
12656
12350
  }
12657
- });
12658
- return;
12351
+ }
12659
12352
  }
12660
- await updateActionItem(
12661
- {
12662
- action_id: actionId,
12663
- quantity: data.quantity,
12664
- unit_price: convertNumber(data.unit_price)
12665
- },
12353
+ }
12354
+ return Array.from(codes);
12355
+ }
12356
+ const TransferOwnership = () => {
12357
+ const { id } = reactRouterDom.useParams();
12358
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12359
+ fields: "id,customer_id,customer.*"
12360
+ });
12361
+ if (isError) {
12362
+ throw error;
12363
+ }
12364
+ const isReady = !isPending && !!draft_order;
12365
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12366
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12367
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12368
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12369
+ ] }),
12370
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12371
+ ] });
12372
+ };
12373
+ const TransferOwnershipForm = ({ order }) => {
12374
+ var _a, _b;
12375
+ const form = reactHookForm.useForm({
12376
+ defaultValues: {
12377
+ customer_id: order.customer_id || ""
12378
+ },
12379
+ resolver: zod.zodResolver(schema$1)
12380
+ });
12381
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12382
+ const { handleSuccess } = useRouteModal();
12383
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12384
+ const currentCustomer = order.customer ? {
12385
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12386
+ value: order.customer.id
12387
+ } : null;
12388
+ const onSubmit = form.handleSubmit(async (data) => {
12389
+ await mutateAsync(
12390
+ { customer_id: data.customer_id },
12666
12391
  {
12667
12392
  onSuccess: () => {
12668
- setEditing(false);
12393
+ ui.toast.success("Customer updated");
12394
+ handleSuccess();
12669
12395
  },
12670
- onError: (e) => {
12671
- ui.toast.error(e.message);
12396
+ onError: (error) => {
12397
+ ui.toast.error(error.message);
12672
12398
  }
12673
12399
  }
12674
12400
  );
12675
12401
  });
12676
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
12677
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12678
- /* @__PURE__ */ jsxRuntime.jsx(
12679
- Thumbnail,
12680
- {
12681
- thumbnail: item.thumbnail,
12682
- alt: item.title ?? void 0
12683
- }
12684
- ),
12685
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
12686
- Form$2.Field,
12687
- {
12688
- control: form.control,
12689
- name: "title",
12690
- render: ({ field }) => {
12691
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
12692
- }
12693
- }
12694
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
12695
- ] }),
12696
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
12697
- Form$2.Field,
12698
- {
12699
- control: form.control,
12700
- name: "quantity",
12701
- render: ({ field }) => {
12702
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
12703
- }
12704
- }
12705
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
12706
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
12707
- Form$2.Field,
12708
- {
12709
- control: form.control,
12710
- name: "unit_price",
12711
- render: ({ field: { onChange, ...field } }) => {
12712
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12713
- ui.CurrencyInput,
12402
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12403
+ KeyboundForm,
12404
+ {
12405
+ className: "flex flex-1 flex-col overflow-hidden",
12406
+ onSubmit,
12407
+ children: [
12408
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12409
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12410
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12411
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12412
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12413
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12414
+ ] }),
12415
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12416
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12417
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12418
+ ] })
12419
+ ] }),
12420
+ /* @__PURE__ */ jsxRuntime.jsx(
12421
+ CustomerField,
12714
12422
  {
12715
- ...field,
12716
- symbol: getNativeSymbol(currencyCode),
12717
- code: currencyCode,
12718
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
12423
+ control: form.control,
12424
+ currentCustomerId: order.customer_id
12719
12425
  }
12720
- ) }) });
12721
- }
12722
- }
12723
- ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 flex items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
12724
- /* @__PURE__ */ jsxRuntime.jsx(
12725
- ui.IconButton,
12726
- {
12727
- type: "button",
12728
- size: "small",
12729
- onClick: editing ? onSubmit : () => {
12730
- setEditing(true);
12731
- },
12732
- disabled: isPending,
12733
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
12734
- }
12735
- )
12736
- ] }) }) });
12737
- };
12738
- const StackedModalTrigger = ({
12739
- type,
12740
- setModalContent
12741
- }) => {
12742
- const { setIsOpen } = useStackedModal();
12743
- const onClick = React.useCallback(() => {
12744
- setModalContent(type);
12745
- setIsOpen(STACKED_MODAL_ID, true);
12746
- }, [setModalContent, setIsOpen, type]);
12747
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
12426
+ )
12427
+ ] }),
12428
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12429
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12430
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12431
+ ] }) })
12432
+ ]
12433
+ }
12434
+ ) });
12748
12435
  };
12749
- const VARIANT_PREFIX = "items";
12750
- const LIMIT = 50;
12751
- const ExistingItemsForm = ({ orderId, items }) => {
12752
- const { setIsOpen } = useStackedModal();
12753
- const [rowSelection, setRowSelection] = React.useState(
12754
- items.reduce((acc, item) => {
12755
- acc[item.variant_id] = true;
12756
- return acc;
12757
- }, {})
12758
- );
12759
- React.useEffect(() => {
12760
- setRowSelection(
12761
- items.reduce((acc, item) => {
12762
- if (item.variant_id) {
12763
- acc[item.variant_id] = true;
12764
- }
12765
- return acc;
12766
- }, {})
12767
- );
12768
- }, [items]);
12769
- const { q, order, offset } = useQueryParams(
12770
- ["q", "order", "offset"],
12771
- VARIANT_PREFIX
12772
- );
12773
- const { variants, count, isPending, isError, error } = useProductVariants(
12774
- {
12775
- q,
12776
- order,
12777
- offset: offset ? parseInt(offset) : void 0,
12778
- limit: LIMIT
12436
+ const CustomerField = ({ control, currentCustomerId }) => {
12437
+ const customers = useComboboxData({
12438
+ queryFn: async (params) => {
12439
+ return await sdk.admin.customer.list({
12440
+ ...params,
12441
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12442
+ });
12779
12443
  },
12780
- {
12781
- placeholderData: reactQuery.keepPreviousData
12444
+ queryKey: ["customers"],
12445
+ getOptions: (data) => {
12446
+ return data.customers.map((customer) => {
12447
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12448
+ return {
12449
+ label: name ? `${name} (${customer.email})` : customer.email,
12450
+ value: customer.id
12451
+ };
12452
+ });
12782
12453
  }
12783
- );
12784
- const columns = useColumns();
12785
- const { mutateAsync } = useDraftOrderAddItems(orderId);
12786
- const onSubmit = async () => {
12787
- const ids = Object.keys(rowSelection).filter(
12788
- (id) => !items.find((i) => i.variant_id === id)
12789
- );
12790
- await mutateAsync(
12791
- {
12792
- items: ids.map((id) => ({
12793
- variant_id: id,
12794
- quantity: 1
12795
- }))
12796
- },
12797
- {
12798
- onSuccess: () => {
12799
- setRowSelection({});
12800
- setIsOpen(STACKED_MODAL_ID, false);
12801
- },
12802
- onError: (e) => {
12803
- ui.toast.error(e.message);
12804
- }
12805
- }
12806
- );
12807
- };
12808
- if (isError) {
12809
- throw error;
12810
- }
12454
+ });
12455
+ return /* @__PURE__ */ jsxRuntime.jsx(
12456
+ Form$2.Field,
12457
+ {
12458
+ name: "customer_id",
12459
+ control,
12460
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12461
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12462
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12463
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12464
+ ] }),
12465
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12466
+ Combobox,
12467
+ {
12468
+ options: customers.options,
12469
+ fetchNextPage: customers.fetchNextPage,
12470
+ isFetchingNextPage: customers.isFetchingNextPage,
12471
+ searchValue: customers.searchValue,
12472
+ onSearchValueChange: customers.onSearchValueChange,
12473
+ placeholder: "Select customer",
12474
+ ...field
12475
+ }
12476
+ ) }),
12477
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12478
+ ] })
12479
+ }
12480
+ );
12481
+ };
12482
+ const Illustration = () => {
12811
12483
  return /* @__PURE__ */ jsxRuntime.jsxs(
12812
- StackedFocusModal.Content,
12484
+ "svg",
12813
12485
  {
12814
- onOpenAutoFocus: (e) => {
12815
- e.preventDefault();
12816
- const searchInput = document.querySelector(
12817
- "[data-modal-id='modal-search-input']"
12818
- );
12819
- if (searchInput) {
12820
- searchInput.focus();
12821
- }
12822
- },
12486
+ width: "280",
12487
+ height: "180",
12488
+ viewBox: "0 0 280 180",
12489
+ fill: "none",
12490
+ xmlns: "http://www.w3.org/2000/svg",
12823
12491
  children: [
12824
- /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
12825
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
12826
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
12827
- ] }),
12828
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
12829
- DataTable,
12492
+ /* @__PURE__ */ jsxRuntime.jsx(
12493
+ "rect",
12494
+ {
12495
+ x: "0.00428286",
12496
+ y: "-0.742904",
12497
+ width: "33.5",
12498
+ height: "65.5",
12499
+ rx: "6.75",
12500
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12501
+ fill: "#D4D4D8",
12502
+ stroke: "#52525B",
12503
+ strokeWidth: "1.5"
12504
+ }
12505
+ ),
12506
+ /* @__PURE__ */ jsxRuntime.jsx(
12507
+ "rect",
12508
+ {
12509
+ x: "0.00428286",
12510
+ y: "-0.742904",
12511
+ width: "33.5",
12512
+ height: "65.5",
12513
+ rx: "6.75",
12514
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12515
+ fill: "white",
12516
+ stroke: "#52525B",
12517
+ strokeWidth: "1.5"
12518
+ }
12519
+ ),
12520
+ /* @__PURE__ */ jsxRuntime.jsx(
12521
+ "path",
12522
+ {
12523
+ d: "M180.579 107.142L179.126 107.959",
12524
+ stroke: "#52525B",
12525
+ strokeWidth: "1.5",
12526
+ strokeLinecap: "round",
12527
+ strokeLinejoin: "round"
12528
+ }
12529
+ ),
12530
+ /* @__PURE__ */ jsxRuntime.jsx(
12531
+ "path",
12532
+ {
12533
+ opacity: "0.88",
12534
+ d: "M182.305 109.546L180.257 109.534",
12535
+ stroke: "#52525B",
12536
+ strokeWidth: "1.5",
12537
+ strokeLinecap: "round",
12538
+ strokeLinejoin: "round"
12539
+ }
12540
+ ),
12541
+ /* @__PURE__ */ jsxRuntime.jsx(
12542
+ "path",
12543
+ {
12544
+ opacity: "0.75",
12545
+ d: "M180.551 111.93L179.108 111.096",
12546
+ stroke: "#52525B",
12547
+ strokeWidth: "1.5",
12548
+ strokeLinecap: "round",
12549
+ strokeLinejoin: "round"
12550
+ }
12551
+ ),
12552
+ /* @__PURE__ */ jsxRuntime.jsx(
12553
+ "path",
12554
+ {
12555
+ opacity: "0.63",
12556
+ d: "M176.347 112.897L176.354 111.73",
12557
+ stroke: "#52525B",
12558
+ strokeWidth: "1.5",
12559
+ strokeLinecap: "round",
12560
+ strokeLinejoin: "round"
12561
+ }
12562
+ ),
12563
+ /* @__PURE__ */ jsxRuntime.jsx(
12564
+ "path",
12565
+ {
12566
+ opacity: "0.5",
12567
+ d: "M172.153 111.881L173.606 111.064",
12568
+ stroke: "#52525B",
12569
+ strokeWidth: "1.5",
12570
+ strokeLinecap: "round",
12571
+ strokeLinejoin: "round"
12572
+ }
12573
+ ),
12574
+ /* @__PURE__ */ jsxRuntime.jsx(
12575
+ "path",
12576
+ {
12577
+ opacity: "0.38",
12578
+ d: "M170.428 109.478L172.476 109.489",
12579
+ stroke: "#52525B",
12580
+ strokeWidth: "1.5",
12581
+ strokeLinecap: "round",
12582
+ strokeLinejoin: "round"
12583
+ }
12584
+ ),
12585
+ /* @__PURE__ */ jsxRuntime.jsx(
12586
+ "path",
12587
+ {
12588
+ opacity: "0.25",
12589
+ d: "M172.181 107.094L173.624 107.928",
12590
+ stroke: "#52525B",
12591
+ strokeWidth: "1.5",
12592
+ strokeLinecap: "round",
12593
+ strokeLinejoin: "round"
12594
+ }
12595
+ ),
12596
+ /* @__PURE__ */ jsxRuntime.jsx(
12597
+ "path",
12598
+ {
12599
+ opacity: "0.13",
12600
+ d: "M176.386 106.126L176.379 107.294",
12601
+ stroke: "#52525B",
12602
+ strokeWidth: "1.5",
12603
+ strokeLinecap: "round",
12604
+ strokeLinejoin: "round"
12605
+ }
12606
+ ),
12607
+ /* @__PURE__ */ jsxRuntime.jsx(
12608
+ "rect",
12609
+ {
12610
+ width: "12",
12611
+ height: "3",
12612
+ rx: "1.5",
12613
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12614
+ fill: "#D4D4D8"
12615
+ }
12616
+ ),
12617
+ /* @__PURE__ */ jsxRuntime.jsx(
12618
+ "rect",
12619
+ {
12620
+ x: "0.00428286",
12621
+ y: "-0.742904",
12622
+ width: "33.5",
12623
+ height: "65.5",
12624
+ rx: "6.75",
12625
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12626
+ fill: "#D4D4D8",
12627
+ stroke: "#52525B",
12628
+ strokeWidth: "1.5"
12629
+ }
12630
+ ),
12631
+ /* @__PURE__ */ jsxRuntime.jsx(
12632
+ "rect",
12633
+ {
12634
+ x: "0.00428286",
12635
+ y: "-0.742904",
12636
+ width: "33.5",
12637
+ height: "65.5",
12638
+ rx: "6.75",
12639
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12640
+ fill: "white",
12641
+ stroke: "#52525B",
12642
+ strokeWidth: "1.5"
12643
+ }
12644
+ ),
12645
+ /* @__PURE__ */ jsxRuntime.jsx(
12646
+ "rect",
12647
+ {
12648
+ width: "12",
12649
+ height: "3",
12650
+ rx: "1.5",
12651
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12652
+ fill: "#D4D4D8"
12653
+ }
12654
+ ),
12655
+ /* @__PURE__ */ jsxRuntime.jsx(
12656
+ "rect",
12657
+ {
12658
+ width: "17",
12659
+ height: "3",
12660
+ rx: "1.5",
12661
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12662
+ fill: "#D4D4D8"
12663
+ }
12664
+ ),
12665
+ /* @__PURE__ */ jsxRuntime.jsx(
12666
+ "rect",
12667
+ {
12668
+ width: "12",
12669
+ height: "3",
12670
+ rx: "1.5",
12671
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12672
+ fill: "#D4D4D8"
12673
+ }
12674
+ ),
12675
+ /* @__PURE__ */ jsxRuntime.jsx(
12676
+ "path",
12677
+ {
12678
+ 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",
12679
+ fill: "#A1A1AA"
12680
+ }
12681
+ ),
12682
+ /* @__PURE__ */ jsxRuntime.jsx(
12683
+ "rect",
12684
+ {
12685
+ width: "17",
12686
+ height: "3",
12687
+ rx: "1.5",
12688
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12689
+ fill: "#A1A1AA"
12690
+ }
12691
+ ),
12692
+ /* @__PURE__ */ jsxRuntime.jsx(
12693
+ "rect",
12694
+ {
12695
+ width: "12",
12696
+ height: "3",
12697
+ rx: "1.5",
12698
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12699
+ fill: "#A1A1AA"
12700
+ }
12701
+ ),
12702
+ /* @__PURE__ */ jsxRuntime.jsx(
12703
+ "path",
12830
12704
  {
12831
- data: variants,
12832
- columns,
12833
- isLoading: isPending,
12834
- getRowId: (row) => row.id,
12835
- rowCount: count,
12836
- prefix: VARIANT_PREFIX,
12837
- layout: "fill",
12838
- rowSelection: {
12839
- state: rowSelection,
12840
- onRowSelectionChange: setRowSelection,
12841
- enableRowSelection: (row) => {
12842
- return !items.find((i) => i.variant_id === row.original.id);
12843
- }
12844
- },
12845
- autoFocusSearch: true
12705
+ 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",
12706
+ fill: "#52525B"
12707
+ }
12708
+ ),
12709
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12710
+ "path",
12711
+ {
12712
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12713
+ stroke: "#A1A1AA",
12714
+ strokeWidth: "1.5",
12715
+ strokeLinecap: "round",
12716
+ strokeLinejoin: "round"
12846
12717
  }
12847
12718
  ) }),
12848
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
12849
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12850
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
12851
- ] }) })
12852
- ]
12853
- }
12854
- );
12855
- };
12856
- const columnHelper = ui.createDataTableColumnHelper();
12857
- const useColumns = () => {
12858
- return React.useMemo(() => {
12859
- return [
12860
- columnHelper.select(),
12861
- columnHelper.accessor("product.title", {
12862
- header: "Product",
12863
- cell: ({ row }) => {
12864
- var _a, _b, _c;
12865
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
12866
- /* @__PURE__ */ jsxRuntime.jsx(
12867
- Thumbnail,
12868
- {
12869
- thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
12870
- alt: (_b = row.original.product) == null ? void 0 : _b.title
12871
- }
12872
- ),
12873
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
12874
- ] });
12875
- },
12876
- enableSorting: true
12877
- }),
12878
- columnHelper.accessor("title", {
12879
- header: "Variant",
12880
- enableSorting: true
12881
- }),
12882
- columnHelper.accessor("sku", {
12883
- header: "SKU",
12884
- cell: ({ getValue }) => {
12885
- return getValue() ?? "-";
12886
- },
12887
- enableSorting: true
12888
- }),
12889
- columnHelper.accessor("updated_at", {
12890
- header: "Updated",
12891
- cell: ({ getValue }) => {
12892
- return /* @__PURE__ */ jsxRuntime.jsx(
12893
- ui.Tooltip,
12719
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12720
+ "path",
12721
+ {
12722
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12723
+ stroke: "#A1A1AA",
12724
+ strokeWidth: "1.5",
12725
+ strokeLinecap: "round",
12726
+ strokeLinejoin: "round"
12727
+ }
12728
+ ) }),
12729
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12730
+ "path",
12731
+ {
12732
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12733
+ stroke: "#A1A1AA",
12734
+ strokeWidth: "1.5",
12735
+ strokeLinecap: "round",
12736
+ strokeLinejoin: "round"
12737
+ }
12738
+ ) }),
12739
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12740
+ "path",
12741
+ {
12742
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12743
+ stroke: "#A1A1AA",
12744
+ strokeWidth: "1.5",
12745
+ strokeLinecap: "round",
12746
+ strokeLinejoin: "round"
12747
+ }
12748
+ ) }),
12749
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12750
+ "path",
12751
+ {
12752
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12753
+ stroke: "#A1A1AA",
12754
+ strokeWidth: "1.5",
12755
+ strokeLinecap: "round",
12756
+ strokeLinejoin: "round"
12757
+ }
12758
+ ) }),
12759
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12760
+ "path",
12761
+ {
12762
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12763
+ stroke: "#A1A1AA",
12764
+ strokeWidth: "1.5",
12765
+ strokeLinecap: "round",
12766
+ strokeLinejoin: "round"
12767
+ }
12768
+ ) }),
12769
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12770
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12771
+ "rect",
12894
12772
  {
12895
- content: getFullDate({ date: getValue(), includeTime: true }),
12896
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
12773
+ width: "12",
12774
+ height: "12",
12775
+ fill: "white",
12776
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12897
12777
  }
12898
- );
12899
- },
12900
- enableSorting: true,
12901
- sortAscLabel: "Oldest first",
12902
- sortDescLabel: "Newest first"
12903
- }),
12904
- columnHelper.accessor("created_at", {
12905
- header: "Created",
12906
- cell: ({ getValue }) => {
12907
- return /* @__PURE__ */ jsxRuntime.jsx(
12908
- ui.Tooltip,
12778
+ ) }),
12779
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12780
+ "rect",
12909
12781
  {
12910
- content: getFullDate({ date: getValue(), includeTime: true }),
12911
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
12782
+ width: "12",
12783
+ height: "12",
12784
+ fill: "white",
12785
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12912
12786
  }
12913
- );
12914
- },
12915
- enableSorting: true,
12916
- sortAscLabel: "Oldest first",
12917
- sortDescLabel: "Newest first"
12918
- })
12919
- ];
12920
- }, []);
12787
+ ) }),
12788
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12789
+ "rect",
12790
+ {
12791
+ width: "12",
12792
+ height: "12",
12793
+ fill: "white",
12794
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12795
+ }
12796
+ ) }),
12797
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12798
+ "rect",
12799
+ {
12800
+ width: "12",
12801
+ height: "12",
12802
+ fill: "white",
12803
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12804
+ }
12805
+ ) }),
12806
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12807
+ "rect",
12808
+ {
12809
+ width: "12",
12810
+ height: "12",
12811
+ fill: "white",
12812
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12813
+ }
12814
+ ) }),
12815
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12816
+ "rect",
12817
+ {
12818
+ width: "12",
12819
+ height: "12",
12820
+ fill: "white",
12821
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12822
+ }
12823
+ ) })
12824
+ ] })
12825
+ ]
12826
+ }
12827
+ );
12921
12828
  };
12922
- const CustomItemForm = ({ orderId, currencyCode }) => {
12923
- const { setIsOpen } = useStackedModal();
12924
- const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
12829
+ const schema$1 = objectType({
12830
+ customer_id: stringType().min(1)
12831
+ });
12832
+ const ShippingAddress = () => {
12833
+ const { id } = reactRouterDom.useParams();
12834
+ const { order, isPending, isError, error } = useOrder(id, {
12835
+ fields: "+shipping_address"
12836
+ });
12837
+ if (isError) {
12838
+ throw error;
12839
+ }
12840
+ const isReady = !isPending && !!order;
12841
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12842
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12843
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12844
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12845
+ ] }),
12846
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12847
+ ] });
12848
+ };
12849
+ const ShippingAddressForm = ({ order }) => {
12850
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12925
12851
  const form = reactHookForm.useForm({
12926
12852
  defaultValues: {
12927
- title: "",
12928
- quantity: 1,
12929
- unit_price: ""
12853
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12854
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12855
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12856
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12857
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12858
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12859
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12860
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12861
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12862
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12930
12863
  },
12931
- resolver: zod.zodResolver(customItemSchema)
12864
+ resolver: zod.zodResolver(schema)
12932
12865
  });
12866
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12867
+ const { handleSuccess } = useRouteModal();
12933
12868
  const onSubmit = form.handleSubmit(async (data) => {
12934
- await addItems(
12869
+ await mutateAsync(
12935
12870
  {
12936
- items: [
12937
- {
12938
- title: data.title,
12939
- quantity: data.quantity,
12940
- unit_price: convertNumber(data.unit_price)
12941
- }
12942
- ]
12871
+ shipping_address: {
12872
+ first_name: data.first_name,
12873
+ last_name: data.last_name,
12874
+ company: data.company,
12875
+ address_1: data.address_1,
12876
+ address_2: data.address_2,
12877
+ city: data.city,
12878
+ province: data.province,
12879
+ country_code: data.country_code,
12880
+ postal_code: data.postal_code,
12881
+ phone: data.phone
12882
+ }
12943
12883
  },
12944
12884
  {
12945
12885
  onSuccess: () => {
12946
- setIsOpen(STACKED_MODAL_ID, false);
12886
+ handleSuccess();
12947
12887
  },
12948
- onError: (e) => {
12949
- ui.toast.error(e.message);
12888
+ onError: (error) => {
12889
+ ui.toast.error(error.message);
12950
12890
  }
12951
12891
  }
12952
12892
  );
12953
12893
  });
12954
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
12955
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12956
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
12957
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12958
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
12959
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
12960
- ] }),
12961
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12962
- /* @__PURE__ */ jsxRuntime.jsx(
12963
- Form$2.Field,
12964
- {
12965
- control: form.control,
12966
- name: "title",
12967
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12968
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12969
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
12970
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
12971
- ] }),
12972
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12973
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12974
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12975
- ] })
12976
- ] }) })
12977
- }
12978
- ),
12979
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12980
- /* @__PURE__ */ jsxRuntime.jsx(
12981
- Form$2.Field,
12982
- {
12983
- control: form.control,
12984
- name: "unit_price",
12985
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12986
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12987
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
12988
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
12989
- ] }),
12990
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12991
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12992
- ui.CurrencyInput,
12993
- {
12994
- symbol: getNativeSymbol(currencyCode),
12995
- code: currencyCode,
12996
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
12997
- ...field
12998
- }
12999
- ) }),
13000
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13001
- ] })
13002
- ] }) })
13003
- }
13004
- ),
13005
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
13006
- /* @__PURE__ */ jsxRuntime.jsx(
13007
- Form$2.Field,
13008
- {
13009
- control: form.control,
13010
- name: "quantity",
13011
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13012
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
13013
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
13014
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
13015
- ] }),
13016
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 w-full", children: [
13017
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field, className: "w-full" }) }) }),
13018
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13019
- ] })
13020
- ] }) })
13021
- }
13022
- )
13023
- ] }) }) }),
13024
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
13025
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
13026
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
13027
- ] }) })
13028
- ] }) }) });
12894
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12895
+ KeyboundForm,
12896
+ {
12897
+ className: "flex flex-1 flex-col overflow-hidden",
12898
+ onSubmit,
12899
+ children: [
12900
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12901
+ /* @__PURE__ */ jsxRuntime.jsx(
12902
+ Form$2.Field,
12903
+ {
12904
+ control: form.control,
12905
+ name: "country_code",
12906
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12907
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12908
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12909
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12910
+ ] })
12911
+ }
12912
+ ),
12913
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12914
+ /* @__PURE__ */ jsxRuntime.jsx(
12915
+ Form$2.Field,
12916
+ {
12917
+ control: form.control,
12918
+ name: "first_name",
12919
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12920
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12921
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12922
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12923
+ ] })
12924
+ }
12925
+ ),
12926
+ /* @__PURE__ */ jsxRuntime.jsx(
12927
+ Form$2.Field,
12928
+ {
12929
+ control: form.control,
12930
+ name: "last_name",
12931
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12932
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12933
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12934
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12935
+ ] })
12936
+ }
12937
+ )
12938
+ ] }),
12939
+ /* @__PURE__ */ jsxRuntime.jsx(
12940
+ Form$2.Field,
12941
+ {
12942
+ control: form.control,
12943
+ name: "company",
12944
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12945
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12946
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12947
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12948
+ ] })
12949
+ }
12950
+ ),
12951
+ /* @__PURE__ */ jsxRuntime.jsx(
12952
+ Form$2.Field,
12953
+ {
12954
+ control: form.control,
12955
+ name: "address_1",
12956
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12957
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12958
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12959
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12960
+ ] })
12961
+ }
12962
+ ),
12963
+ /* @__PURE__ */ jsxRuntime.jsx(
12964
+ Form$2.Field,
12965
+ {
12966
+ control: form.control,
12967
+ name: "address_2",
12968
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12969
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12970
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12971
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12972
+ ] })
12973
+ }
12974
+ ),
12975
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12976
+ /* @__PURE__ */ jsxRuntime.jsx(
12977
+ Form$2.Field,
12978
+ {
12979
+ control: form.control,
12980
+ name: "postal_code",
12981
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12982
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12983
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12984
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12985
+ ] })
12986
+ }
12987
+ ),
12988
+ /* @__PURE__ */ jsxRuntime.jsx(
12989
+ Form$2.Field,
12990
+ {
12991
+ control: form.control,
12992
+ name: "city",
12993
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12994
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12995
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12996
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12997
+ ] })
12998
+ }
12999
+ )
13000
+ ] }),
13001
+ /* @__PURE__ */ jsxRuntime.jsx(
13002
+ Form$2.Field,
13003
+ {
13004
+ control: form.control,
13005
+ name: "province",
13006
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13007
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13008
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13009
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13010
+ ] })
13011
+ }
13012
+ ),
13013
+ /* @__PURE__ */ jsxRuntime.jsx(
13014
+ Form$2.Field,
13015
+ {
13016
+ control: form.control,
13017
+ name: "phone",
13018
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13019
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13020
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13021
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13022
+ ] })
13023
+ }
13024
+ )
13025
+ ] }) }),
13026
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13027
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13028
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13029
+ ] }) })
13030
+ ]
13031
+ }
13032
+ ) });
13029
13033
  };
13030
- const customItemSchema = objectType({
13031
- title: stringType().min(1),
13032
- quantity: numberType(),
13033
- unit_price: unionType([numberType(), stringType()])
13034
- });
13034
+ const schema = addressSchema;
13035
13035
  const widgetModule = { widgets: [] };
13036
13036
  const routeModule = {
13037
13037
  routes: [
@@ -13052,14 +13052,14 @@ const routeModule = {
13052
13052
  handle,
13053
13053
  loader,
13054
13054
  children: [
13055
- {
13056
- Component: CustomItems,
13057
- path: "/draft-orders/:id/custom-items"
13058
- },
13059
13055
  {
13060
13056
  Component: BillingAddress,
13061
13057
  path: "/draft-orders/:id/billing-address"
13062
13058
  },
13059
+ {
13060
+ Component: CustomItems,
13061
+ path: "/draft-orders/:id/custom-items"
13062
+ },
13063
13063
  {
13064
13064
  Component: Email,
13065
13065
  path: "/draft-orders/:id/email"
@@ -13069,28 +13069,28 @@ const routeModule = {
13069
13069
  path: "/draft-orders/:id/metadata"
13070
13070
  },
13071
13071
  {
13072
- Component: Promotions,
13073
- path: "/draft-orders/:id/promotions"
13072
+ Component: SalesChannel,
13073
+ path: "/draft-orders/:id/sales-channel"
13074
13074
  },
13075
13075
  {
13076
13076
  Component: Shipping,
13077
13077
  path: "/draft-orders/:id/shipping"
13078
13078
  },
13079
13079
  {
13080
- Component: SalesChannel,
13081
- path: "/draft-orders/:id/sales-channel"
13080
+ Component: Items,
13081
+ path: "/draft-orders/:id/items"
13082
13082
  },
13083
13083
  {
13084
- Component: ShippingAddress,
13085
- path: "/draft-orders/:id/shipping-address"
13084
+ Component: Promotions,
13085
+ path: "/draft-orders/:id/promotions"
13086
13086
  },
13087
13087
  {
13088
13088
  Component: TransferOwnership,
13089
13089
  path: "/draft-orders/:id/transfer-ownership"
13090
13090
  },
13091
13091
  {
13092
- Component: Items,
13093
- path: "/draft-orders/:id/items"
13092
+ Component: ShippingAddress,
13093
+ path: "/draft-orders/:id/shipping-address"
13094
13094
  }
13095
13095
  ]
13096
13096
  }