@medusajs/draft-order 2.10.4-preview-20251005090149 → 2.10.4-preview-20251005120155

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.
@@ -9573,196 +9573,6 @@ const ID = () => {
9573
9573
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9574
9574
  ] });
9575
9575
  };
9576
- const BillingAddress = () => {
9577
- const { id } = reactRouterDom.useParams();
9578
- const { order, isPending, isError, error } = useOrder(id, {
9579
- fields: "+billing_address"
9580
- });
9581
- if (isError) {
9582
- throw error;
9583
- }
9584
- const isReady = !isPending && !!order;
9585
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9586
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9587
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
9588
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9589
- ] }),
9590
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9591
- ] });
9592
- };
9593
- const BillingAddressForm = ({ order }) => {
9594
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9595
- const form = reactHookForm.useForm({
9596
- defaultValues: {
9597
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9598
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9599
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9600
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9601
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9602
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9603
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9604
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9605
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9606
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9607
- },
9608
- resolver: zod.zodResolver(schema$5)
9609
- });
9610
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9611
- const { handleSuccess } = useRouteModal();
9612
- const onSubmit = form.handleSubmit(async (data) => {
9613
- await mutateAsync(
9614
- { billing_address: data },
9615
- {
9616
- onSuccess: () => {
9617
- handleSuccess();
9618
- },
9619
- onError: (error) => {
9620
- ui.toast.error(error.message);
9621
- }
9622
- }
9623
- );
9624
- });
9625
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9626
- KeyboundForm,
9627
- {
9628
- className: "flex flex-1 flex-col overflow-hidden",
9629
- onSubmit,
9630
- children: [
9631
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
9632
- /* @__PURE__ */ jsxRuntime.jsx(
9633
- Form$2.Field,
9634
- {
9635
- control: form.control,
9636
- name: "country_code",
9637
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9638
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
9639
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
9640
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9641
- ] })
9642
- }
9643
- ),
9644
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9645
- /* @__PURE__ */ jsxRuntime.jsx(
9646
- Form$2.Field,
9647
- {
9648
- control: form.control,
9649
- name: "first_name",
9650
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9651
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
9652
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9653
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9654
- ] })
9655
- }
9656
- ),
9657
- /* @__PURE__ */ jsxRuntime.jsx(
9658
- Form$2.Field,
9659
- {
9660
- control: form.control,
9661
- name: "last_name",
9662
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9663
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
9664
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9665
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9666
- ] })
9667
- }
9668
- )
9669
- ] }),
9670
- /* @__PURE__ */ jsxRuntime.jsx(
9671
- Form$2.Field,
9672
- {
9673
- control: form.control,
9674
- name: "company",
9675
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9676
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
9677
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9678
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9679
- ] })
9680
- }
9681
- ),
9682
- /* @__PURE__ */ jsxRuntime.jsx(
9683
- Form$2.Field,
9684
- {
9685
- control: form.control,
9686
- name: "address_1",
9687
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9688
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
9689
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9690
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9691
- ] })
9692
- }
9693
- ),
9694
- /* @__PURE__ */ jsxRuntime.jsx(
9695
- Form$2.Field,
9696
- {
9697
- control: form.control,
9698
- name: "address_2",
9699
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9700
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9701
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9702
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9703
- ] })
9704
- }
9705
- ),
9706
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9707
- /* @__PURE__ */ jsxRuntime.jsx(
9708
- Form$2.Field,
9709
- {
9710
- control: form.control,
9711
- name: "postal_code",
9712
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9713
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
9714
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9715
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9716
- ] })
9717
- }
9718
- ),
9719
- /* @__PURE__ */ jsxRuntime.jsx(
9720
- Form$2.Field,
9721
- {
9722
- control: form.control,
9723
- name: "city",
9724
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9725
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
9726
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9727
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9728
- ] })
9729
- }
9730
- )
9731
- ] }),
9732
- /* @__PURE__ */ jsxRuntime.jsx(
9733
- Form$2.Field,
9734
- {
9735
- control: form.control,
9736
- name: "province",
9737
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9738
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9739
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9740
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9741
- ] })
9742
- }
9743
- ),
9744
- /* @__PURE__ */ jsxRuntime.jsx(
9745
- Form$2.Field,
9746
- {
9747
- control: form.control,
9748
- name: "phone",
9749
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9750
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
9751
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9752
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9753
- ] })
9754
- }
9755
- )
9756
- ] }) }),
9757
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9758
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9759
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9760
- ] }) })
9761
- ]
9762
- }
9763
- ) });
9764
- };
9765
- const schema$5 = addressSchema;
9766
9576
  const CustomItems = () => {
9767
9577
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9768
9578
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
@@ -9771,7 +9581,7 @@ const CustomItems = () => {
9771
9581
  };
9772
9582
  const CustomItemsForm = () => {
9773
9583
  const form = reactHookForm.useForm({
9774
- resolver: zod.zodResolver(schema$4)
9584
+ resolver: zod.zodResolver(schema$5)
9775
9585
  });
9776
9586
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9777
9587
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
@@ -9781,7 +9591,7 @@ const CustomItemsForm = () => {
9781
9591
  ] }) })
9782
9592
  ] }) });
9783
9593
  };
9784
- const schema$4 = objectType({
9594
+ const schema$5 = objectType({
9785
9595
  email: stringType().email()
9786
9596
  });
9787
9597
  const Email = () => {
@@ -9806,7 +9616,7 @@ const EmailForm = ({ order }) => {
9806
9616
  defaultValues: {
9807
9617
  email: order.email ?? ""
9808
9618
  },
9809
- resolver: zod.zodResolver(schema$3)
9619
+ resolver: zod.zodResolver(schema$4)
9810
9620
  });
9811
9621
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9812
9622
  const { handleSuccess } = useRouteModal();
@@ -9849,7 +9659,7 @@ const EmailForm = ({ order }) => {
9849
9659
  }
9850
9660
  ) });
9851
9661
  };
9852
- const schema$3 = objectType({
9662
+ const schema$4 = objectType({
9853
9663
  email: stringType().email()
9854
9664
  });
9855
9665
  const NumberInput = React.forwardRef(
@@ -10826,67 +10636,417 @@ const customItemSchema = objectType({
10826
10636
  quantity: numberType(),
10827
10637
  unit_price: unionType([numberType(), stringType()])
10828
10638
  });
10829
- const PROMOTION_QUERY_KEY = "promotions";
10830
- const promotionsQueryKeys = {
10831
- list: (query2) => [
10832
- PROMOTION_QUERY_KEY,
10833
- query2 ? query2 : void 0
10834
- ],
10835
- detail: (id, query2) => [
10836
- PROMOTION_QUERY_KEY,
10837
- id,
10838
- query2 ? query2 : void 0
10839
- ]
10840
- };
10841
- const usePromotions = (query2, options) => {
10842
- const { data, ...rest } = reactQuery.useQuery({
10843
- queryKey: promotionsQueryKeys.list(query2),
10844
- queryFn: async () => sdk.admin.promotion.list(query2),
10845
- ...options
10846
- });
10847
- return { ...data, ...rest };
10848
- };
10849
- const Promotions = () => {
10850
- const { id } = reactRouterDom.useParams();
10851
- const {
10852
- order: preview,
10853
- isError: isPreviewError,
10854
- error: previewError
10855
- } = useOrderPreview(id, void 0);
10856
- useInitiateOrderEdit({ preview });
10857
- const { onCancel } = useCancelOrderEdit({ preview });
10858
- if (isPreviewError) {
10859
- throw previewError;
10860
- }
10861
- const isReady = !!preview;
10862
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
10863
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
10864
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
10865
- ] });
10866
- };
10867
- const PromotionForm = ({ preview }) => {
10868
- const { items, shipping_methods } = preview;
10869
- const [isSubmitting, setIsSubmitting] = React.useState(false);
10870
- const [comboboxValue, setComboboxValue] = React.useState("");
10871
- const { handleSuccess } = useRouteModal();
10872
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10873
- const promoIds = getPromotionIds(items, shipping_methods);
10874
- const { promotions, isPending, isError, error } = usePromotions(
10875
- {
10876
- id: promoIds
10877
- },
10878
- {
10879
- enabled: !!promoIds.length
10880
- }
10881
- );
10882
- const comboboxData = useComboboxData({
10883
- queryKey: ["promotions", "combobox", promoIds],
10884
- queryFn: async (params) => {
10885
- return await sdk.admin.promotion.list({
10886
- ...params,
10887
- id: {
10888
- $nin: promoIds
10889
- }
10639
+ const InlineTip = React.forwardRef(
10640
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
10641
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10642
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10643
+ "div",
10644
+ {
10645
+ ref,
10646
+ className: ui.clx(
10647
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10648
+ className
10649
+ ),
10650
+ ...props,
10651
+ children: [
10652
+ /* @__PURE__ */ jsxRuntime.jsx(
10653
+ "div",
10654
+ {
10655
+ role: "presentation",
10656
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10657
+ "bg-ui-tag-orange-icon": variant === "warning"
10658
+ })
10659
+ }
10660
+ ),
10661
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
10662
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10663
+ labelValue,
10664
+ ":"
10665
+ ] }),
10666
+ " ",
10667
+ children
10668
+ ] })
10669
+ ]
10670
+ }
10671
+ );
10672
+ }
10673
+ );
10674
+ InlineTip.displayName = "InlineTip";
10675
+ const MetadataFieldSchema = objectType({
10676
+ key: stringType(),
10677
+ disabled: booleanType().optional(),
10678
+ value: anyType()
10679
+ });
10680
+ const MetadataSchema = objectType({
10681
+ metadata: arrayType(MetadataFieldSchema)
10682
+ });
10683
+ const Metadata = () => {
10684
+ const { id } = reactRouterDom.useParams();
10685
+ const { order, isPending, isError, error } = useOrder(id, {
10686
+ fields: "metadata"
10687
+ });
10688
+ if (isError) {
10689
+ throw error;
10690
+ }
10691
+ const isReady = !isPending && !!order;
10692
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10693
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10694
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
10695
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10696
+ ] }),
10697
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10698
+ ] });
10699
+ };
10700
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10701
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10702
+ const MetadataForm = ({ orderId, metadata }) => {
10703
+ const { handleSuccess } = useRouteModal();
10704
+ const hasUneditableRows = getHasUneditableRows(metadata);
10705
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10706
+ const form = reactHookForm.useForm({
10707
+ defaultValues: {
10708
+ metadata: getDefaultValues(metadata)
10709
+ },
10710
+ resolver: zod.zodResolver(MetadataSchema)
10711
+ });
10712
+ const handleSubmit = form.handleSubmit(async (data) => {
10713
+ const parsedData = parseValues(data);
10714
+ await mutateAsync(
10715
+ {
10716
+ metadata: parsedData
10717
+ },
10718
+ {
10719
+ onSuccess: () => {
10720
+ ui.toast.success("Metadata updated");
10721
+ handleSuccess();
10722
+ },
10723
+ onError: (error) => {
10724
+ ui.toast.error(error.message);
10725
+ }
10726
+ }
10727
+ );
10728
+ });
10729
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
10730
+ control: form.control,
10731
+ name: "metadata"
10732
+ });
10733
+ function deleteRow(index) {
10734
+ remove(index);
10735
+ if (fields.length === 1) {
10736
+ insert(0, {
10737
+ key: "",
10738
+ value: "",
10739
+ disabled: false
10740
+ });
10741
+ }
10742
+ }
10743
+ function insertRow(index, position) {
10744
+ insert(index + (position === "above" ? 0 : 1), {
10745
+ key: "",
10746
+ value: "",
10747
+ disabled: false
10748
+ });
10749
+ }
10750
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10751
+ KeyboundForm,
10752
+ {
10753
+ onSubmit: handleSubmit,
10754
+ className: "flex flex-1 flex-col overflow-hidden",
10755
+ children: [
10756
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10757
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10758
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10759
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10760
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
10761
+ ] }),
10762
+ fields.map((field, index) => {
10763
+ const isDisabled = field.disabled || false;
10764
+ let placeholder = "-";
10765
+ if (typeof field.value === "object") {
10766
+ placeholder = "{ ... }";
10767
+ }
10768
+ if (Array.isArray(field.value)) {
10769
+ placeholder = "[ ... ]";
10770
+ }
10771
+ return /* @__PURE__ */ jsxRuntime.jsx(
10772
+ ConditionalTooltip,
10773
+ {
10774
+ showTooltip: isDisabled,
10775
+ content: "This row is disabled because it contains non-primitive data.",
10776
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
10777
+ /* @__PURE__ */ jsxRuntime.jsxs(
10778
+ "div",
10779
+ {
10780
+ className: ui.clx("grid grid-cols-2 divide-x", {
10781
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
10782
+ }),
10783
+ children: [
10784
+ /* @__PURE__ */ jsxRuntime.jsx(
10785
+ Form$2.Field,
10786
+ {
10787
+ control: form.control,
10788
+ name: `metadata.${index}.key`,
10789
+ render: ({ field: field2 }) => {
10790
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10791
+ GridInput,
10792
+ {
10793
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10794
+ ...field2,
10795
+ disabled: isDisabled,
10796
+ placeholder: "Key"
10797
+ }
10798
+ ) }) });
10799
+ }
10800
+ }
10801
+ ),
10802
+ /* @__PURE__ */ jsxRuntime.jsx(
10803
+ Form$2.Field,
10804
+ {
10805
+ control: form.control,
10806
+ name: `metadata.${index}.value`,
10807
+ render: ({ field: { value, ...field2 } }) => {
10808
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10809
+ GridInput,
10810
+ {
10811
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
10812
+ ...field2,
10813
+ value: isDisabled ? placeholder : value,
10814
+ disabled: isDisabled,
10815
+ placeholder: "Value"
10816
+ }
10817
+ ) }) });
10818
+ }
10819
+ }
10820
+ )
10821
+ ]
10822
+ }
10823
+ ),
10824
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10825
+ /* @__PURE__ */ jsxRuntime.jsx(
10826
+ ui.DropdownMenu.Trigger,
10827
+ {
10828
+ className: ui.clx(
10829
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10830
+ {
10831
+ hidden: isDisabled
10832
+ }
10833
+ ),
10834
+ disabled: isDisabled,
10835
+ asChild: true,
10836
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
10837
+ }
10838
+ ),
10839
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10840
+ /* @__PURE__ */ jsxRuntime.jsxs(
10841
+ ui.DropdownMenu.Item,
10842
+ {
10843
+ className: "gap-x-2",
10844
+ onClick: () => insertRow(index, "above"),
10845
+ children: [
10846
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
10847
+ "Insert row above"
10848
+ ]
10849
+ }
10850
+ ),
10851
+ /* @__PURE__ */ jsxRuntime.jsxs(
10852
+ ui.DropdownMenu.Item,
10853
+ {
10854
+ className: "gap-x-2",
10855
+ onClick: () => insertRow(index, "below"),
10856
+ children: [
10857
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
10858
+ "Insert row below"
10859
+ ]
10860
+ }
10861
+ ),
10862
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
10863
+ /* @__PURE__ */ jsxRuntime.jsxs(
10864
+ ui.DropdownMenu.Item,
10865
+ {
10866
+ className: "gap-x-2",
10867
+ onClick: () => deleteRow(index),
10868
+ children: [
10869
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
10870
+ "Delete row"
10871
+ ]
10872
+ }
10873
+ )
10874
+ ] })
10875
+ ] })
10876
+ ] })
10877
+ },
10878
+ field.id
10879
+ );
10880
+ })
10881
+ ] }),
10882
+ hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
10883
+ ] }),
10884
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10885
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10886
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10887
+ ] }) })
10888
+ ]
10889
+ }
10890
+ ) });
10891
+ };
10892
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
10893
+ return /* @__PURE__ */ jsxRuntime.jsx(
10894
+ "input",
10895
+ {
10896
+ ref,
10897
+ ...props,
10898
+ autoComplete: "off",
10899
+ className: ui.clx(
10900
+ "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
10901
+ className
10902
+ )
10903
+ }
10904
+ );
10905
+ });
10906
+ GridInput.displayName = "MetadataForm.GridInput";
10907
+ const PlaceholderInner = () => {
10908
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10909
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10910
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10911
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
10912
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
10913
+ ] }) })
10914
+ ] });
10915
+ };
10916
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
10917
+ function getDefaultValues(metadata) {
10918
+ if (!metadata || !Object.keys(metadata).length) {
10919
+ return [
10920
+ {
10921
+ key: "",
10922
+ value: "",
10923
+ disabled: false
10924
+ }
10925
+ ];
10926
+ }
10927
+ return Object.entries(metadata).map(([key, value]) => {
10928
+ if (!EDITABLE_TYPES.includes(typeof value)) {
10929
+ return {
10930
+ key,
10931
+ value,
10932
+ disabled: true
10933
+ };
10934
+ }
10935
+ let stringValue = value;
10936
+ if (typeof value !== "string") {
10937
+ stringValue = JSON.stringify(value);
10938
+ }
10939
+ return {
10940
+ key,
10941
+ value: stringValue,
10942
+ original_key: key
10943
+ };
10944
+ });
10945
+ }
10946
+ function parseValues(values) {
10947
+ const metadata = values.metadata;
10948
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10949
+ if (isEmpty) {
10950
+ return null;
10951
+ }
10952
+ const update = {};
10953
+ metadata.forEach((field) => {
10954
+ let key = field.key;
10955
+ let value = field.value;
10956
+ const disabled = field.disabled;
10957
+ if (!key || !value) {
10958
+ return;
10959
+ }
10960
+ if (disabled) {
10961
+ update[key] = value;
10962
+ return;
10963
+ }
10964
+ key = key.trim();
10965
+ value = value.trim();
10966
+ if (value === "true") {
10967
+ update[key] = true;
10968
+ } else if (value === "false") {
10969
+ update[key] = false;
10970
+ } else {
10971
+ const parsedNumber = parseFloat(value);
10972
+ if (!isNaN(parsedNumber)) {
10973
+ update[key] = parsedNumber;
10974
+ } else {
10975
+ update[key] = value;
10976
+ }
10977
+ }
10978
+ });
10979
+ return update;
10980
+ }
10981
+ function getHasUneditableRows(metadata) {
10982
+ if (!metadata) {
10983
+ return false;
10984
+ }
10985
+ return Object.values(metadata).some(
10986
+ (value) => !EDITABLE_TYPES.includes(typeof value)
10987
+ );
10988
+ }
10989
+ const PROMOTION_QUERY_KEY = "promotions";
10990
+ const promotionsQueryKeys = {
10991
+ list: (query2) => [
10992
+ PROMOTION_QUERY_KEY,
10993
+ query2 ? query2 : void 0
10994
+ ],
10995
+ detail: (id, query2) => [
10996
+ PROMOTION_QUERY_KEY,
10997
+ id,
10998
+ query2 ? query2 : void 0
10999
+ ]
11000
+ };
11001
+ const usePromotions = (query2, options) => {
11002
+ const { data, ...rest } = reactQuery.useQuery({
11003
+ queryKey: promotionsQueryKeys.list(query2),
11004
+ queryFn: async () => sdk.admin.promotion.list(query2),
11005
+ ...options
11006
+ });
11007
+ return { ...data, ...rest };
11008
+ };
11009
+ const Promotions = () => {
11010
+ const { id } = reactRouterDom.useParams();
11011
+ const {
11012
+ order: preview,
11013
+ isError: isPreviewError,
11014
+ error: previewError
11015
+ } = useOrderPreview(id, void 0);
11016
+ useInitiateOrderEdit({ preview });
11017
+ const { onCancel } = useCancelOrderEdit({ preview });
11018
+ if (isPreviewError) {
11019
+ throw previewError;
11020
+ }
11021
+ const isReady = !!preview;
11022
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11023
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11024
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11025
+ ] });
11026
+ };
11027
+ const PromotionForm = ({ preview }) => {
11028
+ const { items, shipping_methods } = preview;
11029
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11030
+ const [comboboxValue, setComboboxValue] = React.useState("");
11031
+ const { handleSuccess } = useRouteModal();
11032
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11033
+ const promoIds = getPromotionIds(items, shipping_methods);
11034
+ const { promotions, isPending, isError, error } = usePromotions(
11035
+ {
11036
+ id: promoIds
11037
+ },
11038
+ {
11039
+ enabled: !!promoIds.length
11040
+ }
11041
+ );
11042
+ const comboboxData = useComboboxData({
11043
+ queryKey: ["promotions", "combobox", promoIds],
11044
+ queryFn: async (params) => {
11045
+ return await sdk.admin.promotion.list({
11046
+ ...params,
11047
+ id: {
11048
+ $nin: promoIds
11049
+ }
10890
11050
  });
10891
11051
  },
10892
11052
  getOptions: (data) => {
@@ -11103,112 +11263,6 @@ function getPromotionIds(items, shippingMethods) {
11103
11263
  }
11104
11264
  return Array.from(promotionIds);
11105
11265
  }
11106
- const SalesChannel = () => {
11107
- const { id } = reactRouterDom.useParams();
11108
- const { draft_order, isPending, isError, error } = useDraftOrder(
11109
- id,
11110
- {
11111
- fields: "+sales_channel_id"
11112
- },
11113
- {
11114
- enabled: !!id
11115
- }
11116
- );
11117
- if (isError) {
11118
- throw error;
11119
- }
11120
- const ISrEADY = !!draft_order && !isPending;
11121
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11122
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11123
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11124
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11125
- ] }),
11126
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11127
- ] });
11128
- };
11129
- const SalesChannelForm = ({ order }) => {
11130
- const form = reactHookForm.useForm({
11131
- defaultValues: {
11132
- sales_channel_id: order.sales_channel_id || ""
11133
- },
11134
- resolver: zod.zodResolver(schema$2)
11135
- });
11136
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11137
- const { handleSuccess } = useRouteModal();
11138
- const onSubmit = form.handleSubmit(async (data) => {
11139
- await mutateAsync(
11140
- {
11141
- sales_channel_id: data.sales_channel_id
11142
- },
11143
- {
11144
- onSuccess: () => {
11145
- ui.toast.success("Sales channel updated");
11146
- handleSuccess();
11147
- },
11148
- onError: (error) => {
11149
- ui.toast.error(error.message);
11150
- }
11151
- }
11152
- );
11153
- });
11154
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11155
- KeyboundForm,
11156
- {
11157
- className: "flex flex-1 flex-col overflow-hidden",
11158
- onSubmit,
11159
- children: [
11160
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11161
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11162
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11163
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11164
- ] }) })
11165
- ]
11166
- }
11167
- ) });
11168
- };
11169
- const SalesChannelField = ({ control, order }) => {
11170
- const salesChannels = useComboboxData({
11171
- queryFn: async (params) => {
11172
- return await sdk.admin.salesChannel.list(params);
11173
- },
11174
- queryKey: ["sales-channels"],
11175
- getOptions: (data) => {
11176
- return data.sales_channels.map((salesChannel) => ({
11177
- label: salesChannel.name,
11178
- value: salesChannel.id
11179
- }));
11180
- },
11181
- defaultValue: order.sales_channel_id || void 0
11182
- });
11183
- return /* @__PURE__ */ jsxRuntime.jsx(
11184
- Form$2.Field,
11185
- {
11186
- control,
11187
- name: "sales_channel_id",
11188
- render: ({ field }) => {
11189
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11190
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11191
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11192
- Combobox,
11193
- {
11194
- options: salesChannels.options,
11195
- fetchNextPage: salesChannels.fetchNextPage,
11196
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11197
- searchValue: salesChannels.searchValue,
11198
- onSearchValueChange: salesChannels.onSearchValueChange,
11199
- placeholder: "Select sales channel",
11200
- ...field
11201
- }
11202
- ) }),
11203
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11204
- ] });
11205
- }
11206
- }
11207
- );
11208
- };
11209
- const schema$2 = objectType({
11210
- sales_channel_id: stringType().min(1)
11211
- });
11212
11266
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11213
11267
  const Shipping = () => {
11214
11268
  var _a;
@@ -12048,7 +12102,7 @@ const ShippingAddressForm = ({ order }) => {
12048
12102
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12049
12103
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12050
12104
  },
12051
- resolver: zod.zodResolver(schema$1)
12105
+ resolver: zod.zodResolver(schema$3)
12052
12106
  });
12053
12107
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12054
12108
  const { handleSuccess } = useRouteModal();
@@ -12218,7 +12272,7 @@ const ShippingAddressForm = ({ order }) => {
12218
12272
  }
12219
12273
  ) });
12220
12274
  };
12221
- const schema$1 = addressSchema;
12275
+ const schema$3 = addressSchema;
12222
12276
  const TransferOwnership = () => {
12223
12277
  const { id } = reactRouterDom.useParams();
12224
12278
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12242,7 +12296,7 @@ const TransferOwnershipForm = ({ order }) => {
12242
12296
  defaultValues: {
12243
12297
  customer_id: order.customer_id || ""
12244
12298
  },
12245
- resolver: zod.zodResolver(schema)
12299
+ resolver: zod.zodResolver(schema$2)
12246
12300
  });
12247
12301
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12248
12302
  const { handleSuccess } = useRouteModal();
@@ -12692,57 +12746,13 @@ const Illustration = () => {
12692
12746
  }
12693
12747
  );
12694
12748
  };
12695
- const schema = objectType({
12749
+ const schema$2 = objectType({
12696
12750
  customer_id: stringType().min(1)
12697
12751
  });
12698
- const InlineTip = React.forwardRef(
12699
- ({ variant = "tip", label, className, children, ...props }, ref) => {
12700
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
12701
- return /* @__PURE__ */ jsxRuntime.jsxs(
12702
- "div",
12703
- {
12704
- ref,
12705
- className: ui.clx(
12706
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
12707
- className
12708
- ),
12709
- ...props,
12710
- children: [
12711
- /* @__PURE__ */ jsxRuntime.jsx(
12712
- "div",
12713
- {
12714
- role: "presentation",
12715
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
12716
- "bg-ui-tag-orange-icon": variant === "warning"
12717
- })
12718
- }
12719
- ),
12720
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
12721
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
12722
- labelValue,
12723
- ":"
12724
- ] }),
12725
- " ",
12726
- children
12727
- ] })
12728
- ]
12729
- }
12730
- );
12731
- }
12732
- );
12733
- InlineTip.displayName = "InlineTip";
12734
- const MetadataFieldSchema = objectType({
12735
- key: stringType(),
12736
- disabled: booleanType().optional(),
12737
- value: anyType()
12738
- });
12739
- const MetadataSchema = objectType({
12740
- metadata: arrayType(MetadataFieldSchema)
12741
- });
12742
- const Metadata = () => {
12752
+ const BillingAddress = () => {
12743
12753
  const { id } = reactRouterDom.useParams();
12744
12754
  const { order, isPending, isError, error } = useOrder(id, {
12745
- fields: "metadata"
12755
+ fields: "+billing_address"
12746
12756
  });
12747
12757
  if (isError) {
12748
12758
  throw error;
@@ -12750,33 +12760,36 @@ const Metadata = () => {
12750
12760
  const isReady = !isPending && !!order;
12751
12761
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12752
12762
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12753
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
12754
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
12763
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
12764
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12755
12765
  ] }),
12756
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
12766
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
12757
12767
  ] });
12758
12768
  };
12759
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
12760
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
12761
- const MetadataForm = ({ orderId, metadata }) => {
12762
- const { handleSuccess } = useRouteModal();
12763
- const hasUneditableRows = getHasUneditableRows(metadata);
12764
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
12769
+ const BillingAddressForm = ({ order }) => {
12770
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12765
12771
  const form = reactHookForm.useForm({
12766
12772
  defaultValues: {
12767
- metadata: getDefaultValues(metadata)
12773
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12774
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12775
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12776
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12777
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12778
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12779
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12780
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12781
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12782
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12768
12783
  },
12769
- resolver: zod.zodResolver(MetadataSchema)
12784
+ resolver: zod.zodResolver(schema$1)
12770
12785
  });
12771
- const handleSubmit = form.handleSubmit(async (data) => {
12772
- const parsedData = parseValues(data);
12786
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12787
+ const { handleSuccess } = useRouteModal();
12788
+ const onSubmit = form.handleSubmit(async (data) => {
12773
12789
  await mutateAsync(
12774
- {
12775
- metadata: parsedData
12776
- },
12790
+ { billing_address: data },
12777
12791
  {
12778
12792
  onSuccess: () => {
12779
- ui.toast.success("Metadata updated");
12780
12793
  handleSuccess();
12781
12794
  },
12782
12795
  onError: (error) => {
@@ -12785,266 +12798,253 @@ const MetadataForm = ({ orderId, metadata }) => {
12785
12798
  }
12786
12799
  );
12787
12800
  });
12788
- const { fields, insert, remove } = reactHookForm.useFieldArray({
12789
- control: form.control,
12790
- name: "metadata"
12791
- });
12792
- function deleteRow(index) {
12793
- remove(index);
12794
- if (fields.length === 1) {
12795
- insert(0, {
12796
- key: "",
12797
- value: "",
12798
- disabled: false
12799
- });
12800
- }
12801
- }
12802
- function insertRow(index, position) {
12803
- insert(index + (position === "above" ? 0 : 1), {
12804
- key: "",
12805
- value: "",
12806
- disabled: false
12807
- });
12808
- }
12809
12801
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12810
12802
  KeyboundForm,
12811
12803
  {
12812
- onSubmit: handleSubmit,
12813
12804
  className: "flex flex-1 flex-col overflow-hidden",
12805
+ onSubmit,
12814
12806
  children: [
12815
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
12816
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
12817
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
12818
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
12819
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
12820
- ] }),
12821
- fields.map((field, index) => {
12822
- const isDisabled = field.disabled || false;
12823
- let placeholder = "-";
12824
- if (typeof field.value === "object") {
12825
- placeholder = "{ ... }";
12807
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12808
+ /* @__PURE__ */ jsxRuntime.jsx(
12809
+ Form$2.Field,
12810
+ {
12811
+ control: form.control,
12812
+ name: "country_code",
12813
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12814
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12815
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12816
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12817
+ ] })
12818
+ }
12819
+ ),
12820
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12821
+ /* @__PURE__ */ jsxRuntime.jsx(
12822
+ Form$2.Field,
12823
+ {
12824
+ control: form.control,
12825
+ name: "first_name",
12826
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12827
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12828
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12829
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12830
+ ] })
12826
12831
  }
12827
- if (Array.isArray(field.value)) {
12828
- placeholder = "[ ... ]";
12832
+ ),
12833
+ /* @__PURE__ */ jsxRuntime.jsx(
12834
+ Form$2.Field,
12835
+ {
12836
+ control: form.control,
12837
+ name: "last_name",
12838
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12839
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12840
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12841
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12842
+ ] })
12829
12843
  }
12830
- return /* @__PURE__ */ jsxRuntime.jsx(
12831
- ConditionalTooltip,
12832
- {
12833
- showTooltip: isDisabled,
12834
- content: "This row is disabled because it contains non-primitive data.",
12835
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
12836
- /* @__PURE__ */ jsxRuntime.jsxs(
12837
- "div",
12838
- {
12839
- className: ui.clx("grid grid-cols-2 divide-x", {
12840
- "overflow-hidden rounded-b-lg": index === fields.length - 1
12841
- }),
12842
- children: [
12843
- /* @__PURE__ */ jsxRuntime.jsx(
12844
- Form$2.Field,
12845
- {
12846
- control: form.control,
12847
- name: `metadata.${index}.key`,
12848
- render: ({ field: field2 }) => {
12849
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12850
- GridInput,
12851
- {
12852
- "aria-labelledby": METADATA_KEY_LABEL_ID,
12853
- ...field2,
12854
- disabled: isDisabled,
12855
- placeholder: "Key"
12856
- }
12857
- ) }) });
12858
- }
12859
- }
12860
- ),
12861
- /* @__PURE__ */ jsxRuntime.jsx(
12862
- Form$2.Field,
12863
- {
12864
- control: form.control,
12865
- name: `metadata.${index}.value`,
12866
- render: ({ field: { value, ...field2 } }) => {
12867
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12868
- GridInput,
12869
- {
12870
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
12871
- ...field2,
12872
- value: isDisabled ? placeholder : value,
12873
- disabled: isDisabled,
12874
- placeholder: "Value"
12875
- }
12876
- ) }) });
12877
- }
12878
- }
12879
- )
12880
- ]
12881
- }
12882
- ),
12883
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
12884
- /* @__PURE__ */ jsxRuntime.jsx(
12885
- ui.DropdownMenu.Trigger,
12886
- {
12887
- className: ui.clx(
12888
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
12889
- {
12890
- hidden: isDisabled
12891
- }
12892
- ),
12893
- disabled: isDisabled,
12894
- asChild: true,
12895
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
12896
- }
12897
- ),
12898
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
12899
- /* @__PURE__ */ jsxRuntime.jsxs(
12900
- ui.DropdownMenu.Item,
12901
- {
12902
- className: "gap-x-2",
12903
- onClick: () => insertRow(index, "above"),
12904
- children: [
12905
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
12906
- "Insert row above"
12907
- ]
12908
- }
12909
- ),
12910
- /* @__PURE__ */ jsxRuntime.jsxs(
12911
- ui.DropdownMenu.Item,
12912
- {
12913
- className: "gap-x-2",
12914
- onClick: () => insertRow(index, "below"),
12915
- children: [
12916
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
12917
- "Insert row below"
12918
- ]
12919
- }
12920
- ),
12921
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
12922
- /* @__PURE__ */ jsxRuntime.jsxs(
12923
- ui.DropdownMenu.Item,
12924
- {
12925
- className: "gap-x-2",
12926
- onClick: () => deleteRow(index),
12927
- children: [
12928
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
12929
- "Delete row"
12930
- ]
12931
- }
12932
- )
12933
- ] })
12934
- ] })
12935
- ] })
12936
- },
12937
- field.id
12938
- );
12939
- })
12844
+ )
12845
+ ] }),
12846
+ /* @__PURE__ */ jsxRuntime.jsx(
12847
+ Form$2.Field,
12848
+ {
12849
+ control: form.control,
12850
+ name: "company",
12851
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12852
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12853
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12854
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12855
+ ] })
12856
+ }
12857
+ ),
12858
+ /* @__PURE__ */ jsxRuntime.jsx(
12859
+ Form$2.Field,
12860
+ {
12861
+ control: form.control,
12862
+ name: "address_1",
12863
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12864
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12865
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12866
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12867
+ ] })
12868
+ }
12869
+ ),
12870
+ /* @__PURE__ */ jsxRuntime.jsx(
12871
+ Form$2.Field,
12872
+ {
12873
+ control: form.control,
12874
+ name: "address_2",
12875
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12876
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12877
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12878
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12879
+ ] })
12880
+ }
12881
+ ),
12882
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12883
+ /* @__PURE__ */ jsxRuntime.jsx(
12884
+ Form$2.Field,
12885
+ {
12886
+ control: form.control,
12887
+ name: "postal_code",
12888
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12889
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12890
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12891
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12892
+ ] })
12893
+ }
12894
+ ),
12895
+ /* @__PURE__ */ jsxRuntime.jsx(
12896
+ Form$2.Field,
12897
+ {
12898
+ control: form.control,
12899
+ name: "city",
12900
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12901
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12902
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12903
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12904
+ ] })
12905
+ }
12906
+ )
12940
12907
  ] }),
12941
- hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
12942
- ] }),
12943
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12944
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12908
+ /* @__PURE__ */ jsxRuntime.jsx(
12909
+ Form$2.Field,
12910
+ {
12911
+ control: form.control,
12912
+ name: "province",
12913
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12914
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12915
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12916
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12917
+ ] })
12918
+ }
12919
+ ),
12920
+ /* @__PURE__ */ jsxRuntime.jsx(
12921
+ Form$2.Field,
12922
+ {
12923
+ control: form.control,
12924
+ name: "phone",
12925
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12926
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12927
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12928
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12929
+ ] })
12930
+ }
12931
+ )
12932
+ ] }) }),
12933
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12934
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12945
12935
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12946
12936
  ] }) })
12947
12937
  ]
12948
12938
  }
12949
12939
  ) });
12950
12940
  };
12951
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
12952
- return /* @__PURE__ */ jsxRuntime.jsx(
12953
- "input",
12941
+ const schema$1 = addressSchema;
12942
+ const SalesChannel = () => {
12943
+ const { id } = reactRouterDom.useParams();
12944
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12945
+ id,
12954
12946
  {
12955
- ref,
12956
- ...props,
12957
- autoComplete: "off",
12958
- className: ui.clx(
12959
- "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
12960
- className
12961
- )
12947
+ fields: "+sales_channel_id"
12948
+ },
12949
+ {
12950
+ enabled: !!id
12962
12951
  }
12963
12952
  );
12964
- });
12965
- GridInput.displayName = "MetadataForm.GridInput";
12966
- const PlaceholderInner = () => {
12967
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
12968
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
12969
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12970
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
12971
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
12972
- ] }) })
12953
+ if (isError) {
12954
+ throw error;
12955
+ }
12956
+ const ISrEADY = !!draft_order && !isPending;
12957
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12958
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12959
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12960
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12961
+ ] }),
12962
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12973
12963
  ] });
12974
12964
  };
12975
- const EDITABLE_TYPES = ["string", "number", "boolean"];
12976
- function getDefaultValues(metadata) {
12977
- if (!metadata || !Object.keys(metadata).length) {
12978
- return [
12965
+ const SalesChannelForm = ({ order }) => {
12966
+ const form = reactHookForm.useForm({
12967
+ defaultValues: {
12968
+ sales_channel_id: order.sales_channel_id || ""
12969
+ },
12970
+ resolver: zod.zodResolver(schema)
12971
+ });
12972
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12973
+ const { handleSuccess } = useRouteModal();
12974
+ const onSubmit = form.handleSubmit(async (data) => {
12975
+ await mutateAsync(
12979
12976
  {
12980
- key: "",
12981
- value: "",
12982
- disabled: false
12977
+ sales_channel_id: data.sales_channel_id
12978
+ },
12979
+ {
12980
+ onSuccess: () => {
12981
+ ui.toast.success("Sales channel updated");
12982
+ handleSuccess();
12983
+ },
12984
+ onError: (error) => {
12985
+ ui.toast.error(error.message);
12986
+ }
12983
12987
  }
12984
- ];
12985
- }
12986
- return Object.entries(metadata).map(([key, value]) => {
12987
- if (!EDITABLE_TYPES.includes(typeof value)) {
12988
- return {
12989
- key,
12990
- value,
12991
- disabled: true
12992
- };
12993
- }
12994
- let stringValue = value;
12995
- if (typeof value !== "string") {
12996
- stringValue = JSON.stringify(value);
12997
- }
12998
- return {
12999
- key,
13000
- value: stringValue,
13001
- original_key: key
13002
- };
12988
+ );
13003
12989
  });
13004
- }
13005
- function parseValues(values) {
13006
- const metadata = values.metadata;
13007
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
13008
- if (isEmpty) {
13009
- return null;
13010
- }
13011
- const update = {};
13012
- metadata.forEach((field) => {
13013
- let key = field.key;
13014
- let value = field.value;
13015
- const disabled = field.disabled;
13016
- if (!key || !value) {
13017
- return;
13018
- }
13019
- if (disabled) {
13020
- update[key] = value;
13021
- return;
12990
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12991
+ KeyboundForm,
12992
+ {
12993
+ className: "flex flex-1 flex-col overflow-hidden",
12994
+ onSubmit,
12995
+ children: [
12996
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
12997
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12998
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12999
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13000
+ ] }) })
13001
+ ]
13022
13002
  }
13023
- key = key.trim();
13024
- value = value.trim();
13025
- if (value === "true") {
13026
- update[key] = true;
13027
- } else if (value === "false") {
13028
- update[key] = false;
13029
- } else {
13030
- const parsedNumber = parseFloat(value);
13031
- if (!isNaN(parsedNumber)) {
13032
- update[key] = parsedNumber;
13033
- } else {
13034
- update[key] = value;
13003
+ ) });
13004
+ };
13005
+ const SalesChannelField = ({ control, order }) => {
13006
+ const salesChannels = useComboboxData({
13007
+ queryFn: async (params) => {
13008
+ return await sdk.admin.salesChannel.list(params);
13009
+ },
13010
+ queryKey: ["sales-channels"],
13011
+ getOptions: (data) => {
13012
+ return data.sales_channels.map((salesChannel) => ({
13013
+ label: salesChannel.name,
13014
+ value: salesChannel.id
13015
+ }));
13016
+ },
13017
+ defaultValue: order.sales_channel_id || void 0
13018
+ });
13019
+ return /* @__PURE__ */ jsxRuntime.jsx(
13020
+ Form$2.Field,
13021
+ {
13022
+ control,
13023
+ name: "sales_channel_id",
13024
+ render: ({ field }) => {
13025
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13026
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
13027
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13028
+ Combobox,
13029
+ {
13030
+ options: salesChannels.options,
13031
+ fetchNextPage: salesChannels.fetchNextPage,
13032
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
13033
+ searchValue: salesChannels.searchValue,
13034
+ onSearchValueChange: salesChannels.onSearchValueChange,
13035
+ placeholder: "Select sales channel",
13036
+ ...field
13037
+ }
13038
+ ) }),
13039
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13040
+ ] });
13035
13041
  }
13036
13042
  }
13037
- });
13038
- return update;
13039
- }
13040
- function getHasUneditableRows(metadata) {
13041
- if (!metadata) {
13042
- return false;
13043
- }
13044
- return Object.values(metadata).some(
13045
- (value) => !EDITABLE_TYPES.includes(typeof value)
13046
13043
  );
13047
- }
13044
+ };
13045
+ const schema = objectType({
13046
+ sales_channel_id: stringType().min(1)
13047
+ });
13048
13048
  const widgetModule = { widgets: [] };
13049
13049
  const routeModule = {
13050
13050
  routes: [
@@ -13065,10 +13065,6 @@ const routeModule = {
13065
13065
  handle,
13066
13066
  loader,
13067
13067
  children: [
13068
- {
13069
- Component: BillingAddress,
13070
- path: "/draft-orders/:id/billing-address"
13071
- },
13072
13068
  {
13073
13069
  Component: CustomItems,
13074
13070
  path: "/draft-orders/:id/custom-items"
@@ -13082,12 +13078,12 @@ const routeModule = {
13082
13078
  path: "/draft-orders/:id/items"
13083
13079
  },
13084
13080
  {
13085
- Component: Promotions,
13086
- path: "/draft-orders/:id/promotions"
13081
+ Component: Metadata,
13082
+ path: "/draft-orders/:id/metadata"
13087
13083
  },
13088
13084
  {
13089
- Component: SalesChannel,
13090
- path: "/draft-orders/:id/sales-channel"
13085
+ Component: Promotions,
13086
+ path: "/draft-orders/:id/promotions"
13091
13087
  },
13092
13088
  {
13093
13089
  Component: Shipping,
@@ -13102,8 +13098,12 @@ const routeModule = {
13102
13098
  path: "/draft-orders/:id/transfer-ownership"
13103
13099
  },
13104
13100
  {
13105
- Component: Metadata,
13106
- path: "/draft-orders/:id/metadata"
13101
+ Component: BillingAddress,
13102
+ path: "/draft-orders/:id/billing-address"
13103
+ },
13104
+ {
13105
+ Component: SalesChannel,
13106
+ path: "/draft-orders/:id/sales-channel"
13107
13107
  }
13108
13108
  ]
13109
13109
  }