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