@medusajs/draft-order 2.10.4-preview-20251011030926 → 2.10.4-preview-20251011060147

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,13 +9591,57 @@ 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
- const Email = () => {
9597
+ const InlineTip = React.forwardRef(
9598
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
9599
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9600
+ return /* @__PURE__ */ jsxRuntime.jsxs(
9601
+ "div",
9602
+ {
9603
+ ref,
9604
+ className: ui.clx(
9605
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9606
+ className
9607
+ ),
9608
+ ...props,
9609
+ children: [
9610
+ /* @__PURE__ */ jsxRuntime.jsx(
9611
+ "div",
9612
+ {
9613
+ role: "presentation",
9614
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9615
+ "bg-ui-tag-orange-icon": variant === "warning"
9616
+ })
9617
+ }
9618
+ ),
9619
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
9620
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9621
+ labelValue,
9622
+ ":"
9623
+ ] }),
9624
+ " ",
9625
+ children
9626
+ ] })
9627
+ ]
9628
+ }
9629
+ );
9630
+ }
9631
+ );
9632
+ InlineTip.displayName = "InlineTip";
9633
+ const MetadataFieldSchema = objectType({
9634
+ key: stringType(),
9635
+ disabled: booleanType().optional(),
9636
+ value: anyType()
9637
+ });
9638
+ const MetadataSchema = objectType({
9639
+ metadata: arrayType(MetadataFieldSchema)
9640
+ });
9641
+ const Metadata = () => {
9788
9642
  const { id } = reactRouterDom.useParams();
9789
9643
  const { order, isPending, isError, error } = useOrder(id, {
9790
- fields: "+email"
9644
+ fields: "metadata"
9791
9645
  });
9792
9646
  if (isError) {
9793
9647
  throw error;
@@ -9795,26 +9649,33 @@ const Email = () => {
9795
9649
  const isReady = !isPending && !!order;
9796
9650
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9797
9651
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9798
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9799
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9652
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
9653
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9800
9654
  ] }),
9801
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9655
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9802
9656
  ] });
9803
9657
  };
9804
- const EmailForm = ({ order }) => {
9658
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9659
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9660
+ const MetadataForm = ({ orderId, metadata }) => {
9661
+ const { handleSuccess } = useRouteModal();
9662
+ const hasUneditableRows = getHasUneditableRows(metadata);
9663
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9805
9664
  const form = reactHookForm.useForm({
9806
9665
  defaultValues: {
9807
- email: order.email ?? ""
9666
+ metadata: getDefaultValues(metadata)
9808
9667
  },
9809
- resolver: zod.zodResolver(schema$3)
9668
+ resolver: zod.zodResolver(MetadataSchema)
9810
9669
  });
9811
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9812
- const { handleSuccess } = useRouteModal();
9813
- const onSubmit = form.handleSubmit(async (data) => {
9670
+ const handleSubmit = form.handleSubmit(async (data) => {
9671
+ const parsedData = parseValues(data);
9814
9672
  await mutateAsync(
9815
- { email: data.email },
9673
+ {
9674
+ metadata: parsedData
9675
+ },
9816
9676
  {
9817
9677
  onSuccess: () => {
9678
+ ui.toast.success("Metadata updated");
9818
9679
  handleSuccess();
9819
9680
  },
9820
9681
  onError: (error) => {
@@ -9823,156 +9684,282 @@ const EmailForm = ({ order }) => {
9823
9684
  }
9824
9685
  );
9825
9686
  });
9687
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
9688
+ control: form.control,
9689
+ name: "metadata"
9690
+ });
9691
+ function deleteRow(index) {
9692
+ remove(index);
9693
+ if (fields.length === 1) {
9694
+ insert(0, {
9695
+ key: "",
9696
+ value: "",
9697
+ disabled: false
9698
+ });
9699
+ }
9700
+ }
9701
+ function insertRow(index, position) {
9702
+ insert(index + (position === "above" ? 0 : 1), {
9703
+ key: "",
9704
+ value: "",
9705
+ disabled: false
9706
+ });
9707
+ }
9826
9708
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9827
9709
  KeyboundForm,
9828
9710
  {
9711
+ onSubmit: handleSubmit,
9829
9712
  className: "flex flex-1 flex-col overflow-hidden",
9830
- onSubmit,
9831
9713
  children: [
9832
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9833
- Form$2.Field,
9834
- {
9835
- control: form.control,
9836
- name: "email",
9837
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9838
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9839
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9840
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9841
- ] })
9842
- }
9843
- ) }),
9844
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9845
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9714
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9715
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9716
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9717
+ /* @__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" }) }),
9718
+ /* @__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" }) })
9719
+ ] }),
9720
+ fields.map((field, index) => {
9721
+ const isDisabled = field.disabled || false;
9722
+ let placeholder = "-";
9723
+ if (typeof field.value === "object") {
9724
+ placeholder = "{ ... }";
9725
+ }
9726
+ if (Array.isArray(field.value)) {
9727
+ placeholder = "[ ... ]";
9728
+ }
9729
+ return /* @__PURE__ */ jsxRuntime.jsx(
9730
+ ConditionalTooltip,
9731
+ {
9732
+ showTooltip: isDisabled,
9733
+ content: "This row is disabled because it contains non-primitive data.",
9734
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
9735
+ /* @__PURE__ */ jsxRuntime.jsxs(
9736
+ "div",
9737
+ {
9738
+ className: ui.clx("grid grid-cols-2 divide-x", {
9739
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
9740
+ }),
9741
+ children: [
9742
+ /* @__PURE__ */ jsxRuntime.jsx(
9743
+ Form$2.Field,
9744
+ {
9745
+ control: form.control,
9746
+ name: `metadata.${index}.key`,
9747
+ render: ({ field: field2 }) => {
9748
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9749
+ GridInput,
9750
+ {
9751
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
9752
+ ...field2,
9753
+ disabled: isDisabled,
9754
+ placeholder: "Key"
9755
+ }
9756
+ ) }) });
9757
+ }
9758
+ }
9759
+ ),
9760
+ /* @__PURE__ */ jsxRuntime.jsx(
9761
+ Form$2.Field,
9762
+ {
9763
+ control: form.control,
9764
+ name: `metadata.${index}.value`,
9765
+ render: ({ field: { value, ...field2 } }) => {
9766
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9767
+ GridInput,
9768
+ {
9769
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
9770
+ ...field2,
9771
+ value: isDisabled ? placeholder : value,
9772
+ disabled: isDisabled,
9773
+ placeholder: "Value"
9774
+ }
9775
+ ) }) });
9776
+ }
9777
+ }
9778
+ )
9779
+ ]
9780
+ }
9781
+ ),
9782
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
9783
+ /* @__PURE__ */ jsxRuntime.jsx(
9784
+ ui.DropdownMenu.Trigger,
9785
+ {
9786
+ className: ui.clx(
9787
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
9788
+ {
9789
+ hidden: isDisabled
9790
+ }
9791
+ ),
9792
+ disabled: isDisabled,
9793
+ asChild: true,
9794
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
9795
+ }
9796
+ ),
9797
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
9798
+ /* @__PURE__ */ jsxRuntime.jsxs(
9799
+ ui.DropdownMenu.Item,
9800
+ {
9801
+ className: "gap-x-2",
9802
+ onClick: () => insertRow(index, "above"),
9803
+ children: [
9804
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
9805
+ "Insert row above"
9806
+ ]
9807
+ }
9808
+ ),
9809
+ /* @__PURE__ */ jsxRuntime.jsxs(
9810
+ ui.DropdownMenu.Item,
9811
+ {
9812
+ className: "gap-x-2",
9813
+ onClick: () => insertRow(index, "below"),
9814
+ children: [
9815
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
9816
+ "Insert row below"
9817
+ ]
9818
+ }
9819
+ ),
9820
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
9821
+ /* @__PURE__ */ jsxRuntime.jsxs(
9822
+ ui.DropdownMenu.Item,
9823
+ {
9824
+ className: "gap-x-2",
9825
+ onClick: () => deleteRow(index),
9826
+ children: [
9827
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
9828
+ "Delete row"
9829
+ ]
9830
+ }
9831
+ )
9832
+ ] })
9833
+ ] })
9834
+ ] })
9835
+ },
9836
+ field.id
9837
+ );
9838
+ })
9839
+ ] }),
9840
+ 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." })
9841
+ ] }),
9842
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9843
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
9846
9844
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9847
9845
  ] }) })
9848
9846
  ]
9849
9847
  }
9850
9848
  ) });
9851
9849
  };
9852
- const schema$3 = objectType({
9853
- email: stringType().email()
9850
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
9851
+ return /* @__PURE__ */ jsxRuntime.jsx(
9852
+ "input",
9853
+ {
9854
+ ref,
9855
+ ...props,
9856
+ autoComplete: "off",
9857
+ className: ui.clx(
9858
+ "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",
9859
+ className
9860
+ )
9861
+ }
9862
+ );
9854
9863
  });
9855
- const NumberInput = React.forwardRef(
9856
- ({
9857
- value,
9858
- onChange,
9859
- size = "base",
9860
- min = 0,
9861
- max = 100,
9862
- step = 1,
9863
- className,
9864
- disabled,
9865
- ...props
9866
- }, ref) => {
9867
- const handleChange = (event) => {
9868
- const newValue = event.target.value === "" ? min : Number(event.target.value);
9869
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9870
- onChange(newValue);
9871
- }
9872
- };
9873
- const handleIncrement = () => {
9874
- const newValue = value + step;
9875
- if (max === void 0 || newValue <= max) {
9876
- onChange(newValue);
9877
- }
9878
- };
9879
- const handleDecrement = () => {
9880
- const newValue = value - step;
9881
- if (min === void 0 || newValue >= min) {
9882
- onChange(newValue);
9864
+ GridInput.displayName = "MetadataForm.GridInput";
9865
+ const PlaceholderInner = () => {
9866
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
9867
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
9868
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9869
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
9870
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
9871
+ ] }) })
9872
+ ] });
9873
+ };
9874
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
9875
+ function getDefaultValues(metadata) {
9876
+ if (!metadata || !Object.keys(metadata).length) {
9877
+ return [
9878
+ {
9879
+ key: "",
9880
+ value: "",
9881
+ disabled: false
9883
9882
  }
9883
+ ];
9884
+ }
9885
+ return Object.entries(metadata).map(([key, value]) => {
9886
+ if (!EDITABLE_TYPES.includes(typeof value)) {
9887
+ return {
9888
+ key,
9889
+ value,
9890
+ disabled: true
9891
+ };
9892
+ }
9893
+ let stringValue = value;
9894
+ if (typeof value !== "string") {
9895
+ stringValue = JSON.stringify(value);
9896
+ }
9897
+ return {
9898
+ key,
9899
+ value: stringValue,
9900
+ original_key: key
9884
9901
  };
9885
- return /* @__PURE__ */ jsxRuntime.jsxs(
9886
- "div",
9887
- {
9888
- className: ui.clx(
9889
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9890
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9891
- {
9892
- "h-7": size === "small",
9893
- "h-8": size === "base"
9894
- },
9895
- className
9896
- ),
9897
- children: [
9898
- /* @__PURE__ */ jsxRuntime.jsx(
9899
- "input",
9900
- {
9901
- ref,
9902
- type: "number",
9903
- value,
9904
- onChange: handleChange,
9905
- min,
9906
- max,
9907
- step,
9908
- className: ui.clx(
9909
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9910
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9911
- "placeholder:text-ui-fg-muted"
9912
- ),
9913
- ...props
9914
- }
9915
- ),
9916
- /* @__PURE__ */ jsxRuntime.jsxs(
9917
- "button",
9918
- {
9919
- className: ui.clx(
9920
- "flex items-center justify-center outline-none transition-fg",
9921
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9922
- "focus:bg-ui-bg-field-component-hover",
9923
- "hover:bg-ui-bg-field-component-hover",
9924
- {
9925
- "size-7": size === "small",
9926
- "size-8": size === "base"
9927
- }
9928
- ),
9929
- type: "button",
9930
- onClick: handleDecrement,
9931
- disabled: min !== void 0 && value <= min || disabled,
9932
- children: [
9933
- /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
9934
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9935
- ]
9936
- }
9937
- ),
9938
- /* @__PURE__ */ jsxRuntime.jsxs(
9939
- "button",
9940
- {
9941
- className: ui.clx(
9942
- "flex items-center justify-center outline-none transition-fg",
9943
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9944
- "focus:bg-ui-bg-field-hover",
9945
- "hover:bg-ui-bg-field-hover",
9946
- {
9947
- "size-7": size === "small",
9948
- "size-8": size === "base"
9949
- }
9950
- ),
9951
- type: "button",
9952
- onClick: handleIncrement,
9953
- disabled: max !== void 0 && value >= max || disabled,
9954
- children: [
9955
- /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
9956
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9957
- ]
9958
- }
9959
- )
9960
- ]
9902
+ });
9903
+ }
9904
+ function parseValues(values) {
9905
+ const metadata = values.metadata;
9906
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
9907
+ if (isEmpty) {
9908
+ return null;
9909
+ }
9910
+ const update = {};
9911
+ metadata.forEach((field) => {
9912
+ let key = field.key;
9913
+ let value = field.value;
9914
+ const disabled = field.disabled;
9915
+ if (!key || !value) {
9916
+ return;
9917
+ }
9918
+ if (disabled) {
9919
+ update[key] = value;
9920
+ return;
9921
+ }
9922
+ key = key.trim();
9923
+ value = value.trim();
9924
+ if (value === "true") {
9925
+ update[key] = true;
9926
+ } else if (value === "false") {
9927
+ update[key] = false;
9928
+ } else {
9929
+ const parsedNumber = parseFloat(value);
9930
+ if (!isNaN(parsedNumber)) {
9931
+ update[key] = parsedNumber;
9932
+ } else {
9933
+ update[key] = value;
9961
9934
  }
9962
- );
9935
+ }
9936
+ });
9937
+ return update;
9938
+ }
9939
+ function getHasUneditableRows(metadata) {
9940
+ if (!metadata) {
9941
+ return false;
9963
9942
  }
9964
- );
9965
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9966
- const productVariantsQueryKeys = {
9943
+ return Object.values(metadata).some(
9944
+ (value) => !EDITABLE_TYPES.includes(typeof value)
9945
+ );
9946
+ }
9947
+ const PROMOTION_QUERY_KEY = "promotions";
9948
+ const promotionsQueryKeys = {
9967
9949
  list: (query2) => [
9968
- PRODUCT_VARIANTS_QUERY_KEY,
9950
+ PROMOTION_QUERY_KEY,
9951
+ query2 ? query2 : void 0
9952
+ ],
9953
+ detail: (id, query2) => [
9954
+ PROMOTION_QUERY_KEY,
9955
+ id,
9969
9956
  query2 ? query2 : void 0
9970
9957
  ]
9971
9958
  };
9972
- const useProductVariants = (query2, options) => {
9959
+ const usePromotions = (query2, options) => {
9973
9960
  const { data, ...rest } = reactQuery.useQuery({
9974
- queryKey: productVariantsQueryKeys.list(query2),
9975
- queryFn: async () => await sdk.admin.productVariant.list(query2),
9961
+ queryKey: promotionsQueryKeys.list(query2),
9962
+ queryFn: async () => sdk.admin.promotion.list(query2),
9976
9963
  ...options
9977
9964
  });
9978
9965
  return { ...data, ...rest };
@@ -10023,65 +10010,85 @@ const useInitiateOrderEdit = ({
10023
10010
  run();
10024
10011
  }, [preview, navigate, mutateAsync]);
10025
10012
  };
10026
- function convertNumber(value) {
10027
- return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10028
- }
10029
- const STACKED_MODAL_ID = "items_stacked_modal";
10030
- const Items = () => {
10013
+ const Promotions = () => {
10031
10014
  const { id } = reactRouterDom.useParams();
10032
10015
  const {
10033
10016
  order: preview,
10034
- isPending: isPreviewPending,
10035
10017
  isError: isPreviewError,
10036
10018
  error: previewError
10037
- } = useOrderPreview(id, void 0, {
10038
- placeholderData: reactQuery.keepPreviousData
10039
- });
10019
+ } = useOrderPreview(id, void 0);
10040
10020
  useInitiateOrderEdit({ preview });
10041
- const { draft_order, isPending, isError, error } = useDraftOrder(
10042
- id,
10043
- {
10044
- fields: "currency_code"
10045
- },
10046
- {
10047
- enabled: !!id
10048
- }
10049
- );
10050
10021
  const { onCancel } = useCancelOrderEdit({ preview });
10051
- if (isError) {
10052
- throw error;
10053
- }
10054
10022
  if (isPreviewError) {
10055
10023
  throw previewError;
10056
10024
  }
10057
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10058
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10059
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10060
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10061
- ] }) });
10025
+ const isReady = !!preview;
10026
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
10027
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
10028
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
10029
+ ] });
10062
10030
  };
10063
- const ItemsForm = ({ preview, currencyCode }) => {
10064
- var _a;
10031
+ const PromotionForm = ({ preview }) => {
10032
+ const { items, shipping_methods } = preview;
10065
10033
  const [isSubmitting, setIsSubmitting] = React.useState(false);
10066
- const [modalContent, setModalContent] = React.useState(
10067
- null
10068
- );
10034
+ const [comboboxValue, setComboboxValue] = React.useState("");
10069
10035
  const { handleSuccess } = useRouteModal();
10070
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10036
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10037
+ const promoIds = getPromotionIds(items, shipping_methods);
10038
+ const { promotions, isPending, isError, error } = usePromotions(
10039
+ {
10040
+ id: promoIds
10041
+ },
10042
+ {
10043
+ enabled: !!promoIds.length
10044
+ }
10045
+ );
10046
+ const comboboxData = useComboboxData({
10047
+ queryKey: ["promotions", "combobox", promoIds],
10048
+ queryFn: async (params) => {
10049
+ return await sdk.admin.promotion.list({
10050
+ ...params,
10051
+ id: {
10052
+ $nin: promoIds
10053
+ }
10054
+ });
10055
+ },
10056
+ getOptions: (data) => {
10057
+ return data.promotions.map((promotion) => ({
10058
+ label: promotion.code,
10059
+ value: promotion.code
10060
+ }));
10061
+ }
10062
+ });
10063
+ const add = async (value) => {
10064
+ if (!value) {
10065
+ return;
10066
+ }
10067
+ addPromotions(
10068
+ {
10069
+ promo_codes: [value]
10070
+ },
10071
+ {
10072
+ onError: (e) => {
10073
+ ui.toast.error(e.message);
10074
+ comboboxData.onSearchValueChange("");
10075
+ setComboboxValue("");
10076
+ },
10077
+ onSuccess: () => {
10078
+ comboboxData.onSearchValueChange("");
10079
+ setComboboxValue("");
10080
+ }
10081
+ }
10082
+ );
10083
+ };
10071
10084
  const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10072
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10073
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10074
- const matches = React.useMemo(() => {
10075
- return matchSorter.matchSorter(preview.items, query2, {
10076
- keys: ["product_title", "variant_title", "variant_sku", "title"]
10077
- });
10078
- }, [preview.items, query2]);
10085
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
10079
10086
  const onSubmit = async () => {
10080
10087
  setIsSubmitting(true);
10081
10088
  let requestSucceeded = false;
10082
10089
  await requestOrderEdit(void 0, {
10083
10090
  onError: (e) => {
10084
- ui.toast.error(`Failed to request order edit: ${e.message}`);
10091
+ ui.toast.error(e.message);
10085
10092
  },
10086
10093
  onSuccess: () => {
10087
10094
  requestSucceeded = true;
@@ -10093,7 +10100,7 @@ const ItemsForm = ({ preview, currencyCode }) => {
10093
10100
  }
10094
10101
  await confirmOrderEdit(void 0, {
10095
10102
  onError: (e) => {
10096
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
10103
+ ui.toast.error(e.message);
10097
10104
  },
10098
10105
  onSuccess: () => {
10099
10106
  handleSuccess();
@@ -10103,1589 +10110,399 @@ const ItemsForm = ({ preview, currencyCode }) => {
10103
10110
  }
10104
10111
  });
10105
10112
  };
10106
- const onKeyDown = React.useCallback(
10107
- (e) => {
10108
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10109
- if (modalContent || isSubmitting) {
10110
- return;
10111
- }
10112
- onSubmit();
10113
- }
10114
- },
10115
- [modalContent, isSubmitting, onSubmit]
10116
- );
10117
- React.useEffect(() => {
10118
- document.addEventListener("keydown", onKeyDown);
10119
- return () => {
10120
- document.removeEventListener("keydown", onKeyDown);
10121
- };
10122
- }, [onKeyDown]);
10123
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10124
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
10125
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
10126
- StackedFocusModal,
10127
- {
10128
- id: STACKED_MODAL_ID,
10129
- onOpenChangeCallback: (open) => {
10130
- if (!open) {
10131
- setModalContent(null);
10113
+ if (isError) {
10114
+ throw error;
10115
+ }
10116
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
10117
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
10118
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
10119
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10120
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
10121
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
10122
+ ] }),
10123
+ /* @__PURE__ */ jsxRuntime.jsx(
10124
+ Combobox,
10125
+ {
10126
+ id: "promotion-combobox",
10127
+ "aria-describedby": "promotion-combobox-hint",
10128
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
10129
+ fetchNextPage: comboboxData.fetchNextPage,
10130
+ options: comboboxData.options,
10131
+ onSearchValueChange: comboboxData.onSearchValueChange,
10132
+ searchValue: comboboxData.searchValue,
10133
+ disabled: comboboxData.disabled || isAddingPromotions,
10134
+ onChange: add,
10135
+ value: comboboxValue
10132
10136
  }
10137
+ )
10138
+ ] }),
10139
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10140
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
10141
+ PromotionItem,
10142
+ {
10143
+ promotion,
10144
+ orderId: preview.id,
10145
+ isLoading: isPending
10133
10146
  },
10134
- children: [
10135
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
10136
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10137
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
10138
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order" }) })
10139
- ] }),
10140
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10141
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
10142
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10143
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10144
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10145
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10146
- ] }),
10147
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
10148
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10149
- ui.Input,
10150
- {
10151
- type: "search",
10152
- placeholder: "Search items",
10153
- value: searchValue,
10154
- onChange: (e) => onSearchValueChange(e.target.value)
10155
- }
10156
- ) }),
10157
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10158
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
10159
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10160
- /* @__PURE__ */ jsxRuntime.jsx(
10161
- StackedModalTrigger$1,
10162
- {
10163
- type: "add-items",
10164
- setModalContent
10165
- }
10166
- ),
10167
- /* @__PURE__ */ jsxRuntime.jsx(
10168
- StackedModalTrigger$1,
10169
- {
10170
- type: "add-custom-item",
10171
- setModalContent
10172
- }
10173
- )
10174
- ] })
10175
- ] })
10176
- ] })
10177
- ] }),
10178
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10179
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
10180
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
10181
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10182
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
10183
- /* @__PURE__ */ jsxRuntime.jsx("div", {})
10184
- ] }) }),
10185
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
10186
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10187
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10188
- ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
10189
- Item,
10190
- {
10191
- item,
10192
- preview,
10193
- currencyCode
10194
- },
10195
- item.id
10196
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
10197
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10198
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
10199
- 'No items found for "',
10200
- query2,
10201
- '".'
10202
- ] })
10203
- ] }) })
10204
- ] })
10205
- ] }),
10206
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10207
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10208
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10209
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
10210
- ui.Text,
10211
- {
10212
- size: "small",
10213
- leading: "compact",
10214
- className: "text-ui-fg-subtle",
10215
- children: [
10216
- itemCount,
10217
- " ",
10218
- itemCount === 1 ? "item" : "items"
10219
- ]
10220
- }
10221
- ) }),
10222
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
10223
- ] })
10224
- ] }) }),
10225
- modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
10226
- CustomItemForm,
10227
- {
10228
- orderId: preview.id,
10229
- currencyCode
10230
- }
10231
- ) : null)
10232
- ]
10233
- }
10234
- ) }),
10235
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10236
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10147
+ promotion.id
10148
+ )) })
10149
+ ] }) }),
10150
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10151
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10237
10152
  /* @__PURE__ */ jsxRuntime.jsx(
10238
10153
  ui.Button,
10239
10154
  {
10240
10155
  size: "small",
10241
- type: "button",
10242
- onClick: onSubmit,
10243
- isLoading: isSubmitting,
10156
+ type: "submit",
10157
+ isLoading: isSubmitting || isAddingPromotions,
10244
10158
  children: "Save"
10245
10159
  }
10246
10160
  )
10247
10161
  ] }) })
10248
10162
  ] });
10249
10163
  };
10250
- const Item = ({ item, preview, currencyCode }) => {
10251
- if (item.variant_id) {
10252
- return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
10253
- }
10254
- return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
10255
- };
10256
- const VariantItem = ({ item, preview, currencyCode }) => {
10257
- const [editing, setEditing] = React.useState(false);
10258
- const form = reactHookForm.useForm({
10259
- defaultValues: {
10260
- quantity: item.quantity,
10261
- unit_price: item.unit_price
10262
- },
10263
- resolver: zod.zodResolver(variantItemSchema)
10264
- });
10265
- const actionId = React.useMemo(() => {
10266
- var _a, _b;
10267
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10268
- }, [item]);
10269
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10270
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10271
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10272
- const onSubmit = form.handleSubmit(async (data) => {
10273
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10274
- setEditing(false);
10275
- return;
10276
- }
10277
- if (!actionId) {
10278
- await updateOriginalItem(
10279
- {
10280
- item_id: item.id,
10281
- quantity: data.quantity,
10282
- unit_price: convertNumber(data.unit_price)
10283
- },
10284
- {
10285
- onSuccess: () => {
10286
- setEditing(false);
10287
- },
10288
- onError: (e) => {
10289
- ui.toast.error(e.message);
10290
- }
10291
- }
10292
- );
10293
- return;
10294
- }
10295
- await updateActionItem(
10164
+ const PromotionItem = ({
10165
+ promotion,
10166
+ orderId,
10167
+ isLoading
10168
+ }) => {
10169
+ var _a;
10170
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
10171
+ const onRemove = async () => {
10172
+ removePromotions(
10296
10173
  {
10297
- action_id: actionId,
10298
- quantity: data.quantity,
10299
- unit_price: convertNumber(data.unit_price)
10174
+ promo_codes: [promotion.code]
10300
10175
  },
10301
10176
  {
10302
- onSuccess: () => {
10303
- setEditing(false);
10304
- },
10305
10177
  onError: (e) => {
10306
10178
  ui.toast.error(e.message);
10307
10179
  }
10308
10180
  }
10309
10181
  );
10310
- });
10311
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10312
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10313
- /* @__PURE__ */ jsxRuntime.jsx(
10314
- Thumbnail,
10182
+ };
10183
+ const displayValue = getDisplayValue(promotion);
10184
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10185
+ "div",
10186
+ {
10187
+ className: ui.clx(
10188
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
10315
10189
  {
10316
- thumbnail: item.thumbnail,
10317
- alt: item.product_title ?? void 0
10190
+ "animate-pulse": isLoading
10318
10191
  }
10319
10192
  ),
10320
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10321
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10322
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10323
- /* @__PURE__ */ jsxRuntime.jsxs(
10324
- ui.Text,
10325
- {
10326
- size: "small",
10327
- leading: "compact",
10328
- className: "text-ui-fg-subtle",
10329
- children: [
10330
- "(",
10331
- item.variant_title,
10332
- ")"
10333
- ]
10334
- }
10335
- )
10193
+ children: [
10194
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10195
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
10196
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
10197
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
10198
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
10199
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
10200
+ ] }),
10201
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
10202
+ ] })
10336
10203
  ] }),
10337
10204
  /* @__PURE__ */ jsxRuntime.jsx(
10338
- ui.Text,
10205
+ ui.IconButton,
10339
10206
  {
10340
10207
  size: "small",
10341
- leading: "compact",
10342
- className: "text-ui-fg-subtle",
10343
- children: item.variant_sku
10208
+ type: "button",
10209
+ variant: "transparent",
10210
+ onClick: onRemove,
10211
+ isLoading: isPending || isLoading,
10212
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
10344
10213
  }
10345
10214
  )
10346
- ] })
10347
- ] }),
10348
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10349
- Form$2.Field,
10350
- {
10351
- control: form.control,
10352
- name: "quantity",
10353
- render: ({ field }) => {
10354
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10215
+ ]
10216
+ },
10217
+ promotion.id
10218
+ );
10219
+ };
10220
+ function getDisplayValue(promotion) {
10221
+ var _a, _b, _c, _d;
10222
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
10223
+ if (!value) {
10224
+ return null;
10225
+ }
10226
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
10227
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
10228
+ if (!currency) {
10229
+ return null;
10230
+ }
10231
+ return getLocaleAmount(value, currency);
10232
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
10233
+ return formatPercentage(value);
10234
+ }
10235
+ return null;
10236
+ }
10237
+ const formatter = new Intl.NumberFormat([], {
10238
+ style: "percent",
10239
+ minimumFractionDigits: 2
10240
+ });
10241
+ const formatPercentage = (value, isPercentageValue = false) => {
10242
+ let val = value || 0;
10243
+ if (!isPercentageValue) {
10244
+ val = val / 100;
10245
+ }
10246
+ return formatter.format(val);
10247
+ };
10248
+ function getPromotionIds(items, shippingMethods) {
10249
+ const promotionIds = /* @__PURE__ */ new Set();
10250
+ for (const item of items) {
10251
+ if (item.adjustments) {
10252
+ for (const adjustment of item.adjustments) {
10253
+ if (adjustment.promotion_id) {
10254
+ promotionIds.add(adjustment.promotion_id);
10355
10255
  }
10356
10256
  }
10357
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10358
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10359
- Form$2.Field,
10360
- {
10361
- control: form.control,
10362
- name: "unit_price",
10363
- render: ({ field: { onChange, ...field } }) => {
10364
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10365
- ui.CurrencyInput,
10366
- {
10367
- ...field,
10368
- symbol: getNativeSymbol(currencyCode),
10369
- code: currencyCode,
10370
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10371
- }
10372
- ) }) });
10257
+ }
10258
+ }
10259
+ for (const shippingMethod of shippingMethods) {
10260
+ if (shippingMethod.adjustments) {
10261
+ for (const adjustment of shippingMethod.adjustments) {
10262
+ if (adjustment.promotion_id) {
10263
+ promotionIds.add(adjustment.promotion_id);
10373
10264
  }
10374
10265
  }
10375
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10376
- /* @__PURE__ */ jsxRuntime.jsx(
10377
- ui.IconButton,
10378
- {
10379
- type: "button",
10380
- size: "small",
10381
- onClick: editing ? onSubmit : () => {
10382
- setEditing(true);
10383
- },
10384
- disabled: isPending,
10385
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10386
- }
10387
- )
10388
- ] }) }) });
10266
+ }
10267
+ }
10268
+ return Array.from(promotionIds);
10269
+ }
10270
+ const SalesChannel = () => {
10271
+ const { id } = reactRouterDom.useParams();
10272
+ const { draft_order, isPending, isError, error } = useDraftOrder(
10273
+ id,
10274
+ {
10275
+ fields: "+sales_channel_id"
10276
+ },
10277
+ {
10278
+ enabled: !!id
10279
+ }
10280
+ );
10281
+ if (isError) {
10282
+ throw error;
10283
+ }
10284
+ const ISrEADY = !!draft_order && !isPending;
10285
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10286
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10287
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
10288
+ /* @__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" }) })
10289
+ ] }),
10290
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
10291
+ ] });
10389
10292
  };
10390
- const variantItemSchema = objectType({
10391
- quantity: numberType(),
10392
- unit_price: unionType([numberType(), stringType()])
10393
- });
10394
- const CustomItem = ({ item, preview, currencyCode }) => {
10395
- const [editing, setEditing] = React.useState(false);
10396
- const { quantity, unit_price, title } = item;
10293
+ const SalesChannelForm = ({ order }) => {
10397
10294
  const form = reactHookForm.useForm({
10398
10295
  defaultValues: {
10399
- title,
10400
- quantity,
10401
- unit_price
10296
+ sales_channel_id: order.sales_channel_id || ""
10402
10297
  },
10403
- resolver: zod.zodResolver(customItemSchema)
10298
+ resolver: zod.zodResolver(schema$4)
10404
10299
  });
10405
- React.useEffect(() => {
10406
- form.reset({
10407
- title,
10408
- quantity,
10409
- unit_price
10410
- });
10411
- }, [form, title, quantity, unit_price]);
10412
- const actionId = React.useMemo(() => {
10413
- var _a, _b;
10414
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10415
- }, [item]);
10416
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10417
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10418
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10419
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10300
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10301
+ const { handleSuccess } = useRouteModal();
10420
10302
  const onSubmit = form.handleSubmit(async (data) => {
10421
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10422
- setEditing(false);
10423
- return;
10424
- }
10425
- if (!actionId) {
10426
- await updateOriginalItem(
10427
- {
10428
- item_id: item.id,
10429
- quantity: data.quantity,
10430
- unit_price: convertNumber(data.unit_price)
10431
- },
10432
- {
10433
- onSuccess: () => {
10434
- setEditing(false);
10435
- },
10436
- onError: (e) => {
10437
- ui.toast.error(e.message);
10438
- }
10439
- }
10440
- );
10441
- return;
10442
- }
10443
- if (data.quantity === 0) {
10444
- await removeActionItem(actionId, {
10445
- onSuccess: () => {
10446
- setEditing(false);
10447
- },
10448
- onError: (e) => {
10449
- ui.toast.error(e.message);
10450
- }
10451
- });
10452
- return;
10453
- }
10454
- await updateActionItem(
10303
+ await mutateAsync(
10455
10304
  {
10456
- action_id: actionId,
10457
- quantity: data.quantity,
10458
- unit_price: convertNumber(data.unit_price)
10305
+ sales_channel_id: data.sales_channel_id
10459
10306
  },
10460
10307
  {
10461
10308
  onSuccess: () => {
10462
- setEditing(false);
10309
+ ui.toast.success("Sales channel updated");
10310
+ handleSuccess();
10463
10311
  },
10464
- onError: (e) => {
10465
- ui.toast.error(e.message);
10312
+ onError: (error) => {
10313
+ ui.toast.error(error.message);
10466
10314
  }
10467
10315
  }
10468
10316
  );
10469
10317
  });
10470
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10471
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
10472
- /* @__PURE__ */ jsxRuntime.jsx(
10473
- Thumbnail,
10474
- {
10475
- thumbnail: item.thumbnail,
10476
- alt: item.title ?? void 0
10477
- }
10478
- ),
10479
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10480
- Form$2.Field,
10481
- {
10482
- control: form.control,
10483
- name: "title",
10484
- render: ({ field }) => {
10485
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
10486
- }
10487
- }
10488
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
10489
- ] }),
10490
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10491
- Form$2.Field,
10492
- {
10493
- control: form.control,
10494
- name: "quantity",
10495
- render: ({ field }) => {
10496
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10497
- }
10498
- }
10499
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
10500
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10501
- Form$2.Field,
10502
- {
10503
- control: form.control,
10504
- name: "unit_price",
10505
- render: ({ field: { onChange, ...field } }) => {
10506
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10507
- ui.CurrencyInput,
10508
- {
10509
- ...field,
10510
- symbol: getNativeSymbol(currencyCode),
10511
- code: currencyCode,
10512
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10513
- }
10514
- ) }) });
10515
- }
10516
- }
10517
- ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10518
- /* @__PURE__ */ jsxRuntime.jsx(
10519
- ui.IconButton,
10520
- {
10521
- type: "button",
10522
- size: "small",
10523
- onClick: editing ? onSubmit : () => {
10524
- setEditing(true);
10525
- },
10526
- disabled: isPending,
10527
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10318
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10319
+ KeyboundForm,
10320
+ {
10321
+ className: "flex flex-1 flex-col overflow-hidden",
10322
+ onSubmit,
10323
+ children: [
10324
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
10325
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10326
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10327
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10328
+ ] }) })
10329
+ ]
10330
+ }
10331
+ ) });
10332
+ };
10333
+ const SalesChannelField = ({ control, order }) => {
10334
+ const salesChannels = useComboboxData({
10335
+ queryFn: async (params) => {
10336
+ return await sdk.admin.salesChannel.list(params);
10337
+ },
10338
+ queryKey: ["sales-channels"],
10339
+ getOptions: (data) => {
10340
+ return data.sales_channels.map((salesChannel) => ({
10341
+ label: salesChannel.name,
10342
+ value: salesChannel.id
10343
+ }));
10344
+ },
10345
+ defaultValue: order.sales_channel_id || void 0
10346
+ });
10347
+ return /* @__PURE__ */ jsxRuntime.jsx(
10348
+ Form$2.Field,
10349
+ {
10350
+ control,
10351
+ name: "sales_channel_id",
10352
+ render: ({ field }) => {
10353
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10354
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
10355
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10356
+ Combobox,
10357
+ {
10358
+ options: salesChannels.options,
10359
+ fetchNextPage: salesChannels.fetchNextPage,
10360
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
10361
+ searchValue: salesChannels.searchValue,
10362
+ onSearchValueChange: salesChannels.onSearchValueChange,
10363
+ placeholder: "Select sales channel",
10364
+ ...field
10365
+ }
10366
+ ) }),
10367
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10368
+ ] });
10528
10369
  }
10529
- )
10530
- ] }) }) });
10370
+ }
10371
+ );
10531
10372
  };
10532
- const StackedModalTrigger$1 = ({
10533
- type,
10534
- setModalContent
10535
- }) => {
10536
- const { setIsOpen } = useStackedModal();
10537
- const onClick = React.useCallback(() => {
10538
- setModalContent(type);
10539
- setIsOpen(STACKED_MODAL_ID, true);
10540
- }, [setModalContent, setIsOpen, type]);
10541
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
10373
+ const schema$4 = objectType({
10374
+ sales_channel_id: stringType().min(1)
10375
+ });
10376
+ function convertNumber(value) {
10377
+ return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10378
+ }
10379
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
10380
+ const Shipping = () => {
10381
+ var _a;
10382
+ const { id } = reactRouterDom.useParams();
10383
+ const { order, isPending, isError, error } = useOrder(id, {
10384
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
10385
+ });
10386
+ const {
10387
+ order: preview,
10388
+ isPending: isPreviewPending,
10389
+ isError: isPreviewError,
10390
+ error: previewError
10391
+ } = useOrderPreview(id);
10392
+ useInitiateOrderEdit({ preview });
10393
+ const { onCancel } = useCancelOrderEdit({ preview });
10394
+ if (isError) {
10395
+ throw error;
10396
+ }
10397
+ if (isPreviewError) {
10398
+ throw previewError;
10399
+ }
10400
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
10401
+ const isReady = preview && !isPreviewPending && order && !isPending;
10402
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
10403
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
10404
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
10405
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
10406
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
10407
+ ] }) }) }),
10408
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
10409
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10410
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
10411
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10412
+ ] }) });
10542
10413
  };
10543
- const VARIANT_PREFIX = "items";
10544
- const LIMIT = 50;
10545
- const ExistingItemsForm = ({ orderId, items }) => {
10414
+ const ShippingForm = ({ preview, order }) => {
10415
+ var _a;
10546
10416
  const { setIsOpen } = useStackedModal();
10547
- const [rowSelection, setRowSelection] = React.useState(
10548
- items.reduce((acc, item) => {
10549
- acc[item.variant_id] = true;
10550
- return acc;
10551
- }, {})
10552
- );
10553
- React.useEffect(() => {
10554
- setRowSelection(
10555
- items.reduce((acc, item) => {
10556
- if (item.variant_id) {
10557
- acc[item.variant_id] = true;
10558
- }
10559
- return acc;
10560
- }, {})
10561
- );
10562
- }, [items]);
10563
- const { q, order, offset } = useQueryParams(
10564
- ["q", "order", "offset"],
10565
- VARIANT_PREFIX
10566
- );
10567
- const { variants, count, isPending, isError, error } = useProductVariants(
10417
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
10418
+ const [data, setData] = React.useState(null);
10419
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
10420
+ const { shipping_options } = useShippingOptions(
10568
10421
  {
10569
- q,
10570
- order,
10571
- offset: offset ? parseInt(offset) : void 0,
10572
- limit: LIMIT
10422
+ id: appliedShippingOptionIds,
10423
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
10573
10424
  },
10574
10425
  {
10575
- placeholderData: reactQuery.keepPreviousData
10426
+ enabled: appliedShippingOptionIds.length > 0
10576
10427
  }
10577
10428
  );
10578
- const columns = useColumns();
10579
- const { mutateAsync } = useDraftOrderAddItems(orderId);
10429
+ const uniqueShippingProfiles = React.useMemo(() => {
10430
+ const profiles = /* @__PURE__ */ new Map();
10431
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
10432
+ profiles.set(profile.id, profile);
10433
+ });
10434
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
10435
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
10436
+ });
10437
+ return Array.from(profiles.values());
10438
+ }, [order.items, shipping_options]);
10439
+ const { handleSuccess } = useRouteModal();
10440
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10441
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10442
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
10443
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
10580
10444
  const onSubmit = async () => {
10581
- const ids = Object.keys(rowSelection).filter(
10582
- (id) => !items.find((i) => i.variant_id === id)
10583
- );
10584
- await mutateAsync(
10585
- {
10586
- items: ids.map((id) => ({
10587
- variant_id: id,
10588
- quantity: 1
10589
- }))
10445
+ setIsSubmitting(true);
10446
+ let requestSucceeded = false;
10447
+ await requestOrderEdit(void 0, {
10448
+ onError: (e) => {
10449
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
10590
10450
  },
10591
- {
10592
- onSuccess: () => {
10593
- setRowSelection({});
10594
- setIsOpen(STACKED_MODAL_ID, false);
10595
- },
10596
- onError: (e) => {
10597
- ui.toast.error(e.message);
10598
- }
10451
+ onSuccess: () => {
10452
+ requestSucceeded = true;
10599
10453
  }
10600
- );
10454
+ });
10455
+ if (!requestSucceeded) {
10456
+ setIsSubmitting(false);
10457
+ return;
10458
+ }
10459
+ await confirmOrderEdit(void 0, {
10460
+ onError: (e) => {
10461
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
10462
+ },
10463
+ onSuccess: () => {
10464
+ handleSuccess();
10465
+ },
10466
+ onSettled: () => {
10467
+ setIsSubmitting(false);
10468
+ }
10469
+ });
10601
10470
  };
10602
- if (isError) {
10603
- throw error;
10604
- }
10605
- return /* @__PURE__ */ jsxRuntime.jsxs(
10606
- StackedFocusModal.Content,
10607
- {
10608
- onOpenAutoFocus: (e) => {
10609
- e.preventDefault();
10610
- const searchInput = document.querySelector(
10611
- "[data-modal-id='modal-search-input']"
10612
- );
10613
- if (searchInput) {
10614
- searchInput.focus();
10471
+ const onKeydown = React.useCallback(
10472
+ (e) => {
10473
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10474
+ if (data || isSubmitting) {
10475
+ return;
10615
10476
  }
10616
- },
10617
- children: [
10618
- /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
10619
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10620
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
10621
- ] }),
10622
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
10623
- DataTable,
10624
- {
10625
- data: variants,
10626
- columns,
10627
- isLoading: isPending,
10628
- getRowId: (row) => row.id,
10629
- rowCount: count,
10630
- prefix: VARIANT_PREFIX,
10631
- layout: "fill",
10632
- rowSelection: {
10633
- state: rowSelection,
10634
- onRowSelectionChange: setRowSelection,
10635
- enableRowSelection: (row) => {
10636
- return !items.find((i) => i.variant_id === row.original.id);
10637
- }
10638
- },
10639
- autoFocusSearch: true
10640
- }
10641
- ) }),
10642
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10643
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10644
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
10645
- ] }) })
10646
- ]
10647
- }
10477
+ onSubmit();
10478
+ }
10479
+ },
10480
+ [data, isSubmitting, onSubmit]
10648
10481
  );
10649
- };
10650
- const columnHelper = ui.createDataTableColumnHelper();
10651
- const useColumns = () => {
10652
- return React.useMemo(() => {
10653
- return [
10654
- columnHelper.select(),
10655
- columnHelper.accessor("product.title", {
10656
- header: "Product",
10657
- cell: ({ row }) => {
10658
- var _a, _b, _c;
10659
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
10482
+ React.useEffect(() => {
10483
+ document.addEventListener("keydown", onKeydown);
10484
+ return () => {
10485
+ document.removeEventListener("keydown", onKeydown);
10486
+ };
10487
+ }, [onKeydown]);
10488
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10489
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
10490
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
10491
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
10492
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10493
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
10494
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
10495
+ ] }),
10496
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10497
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
10498
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
10660
10499
  /* @__PURE__ */ jsxRuntime.jsx(
10661
- Thumbnail,
10500
+ ui.Text,
10662
10501
  {
10663
- thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
10664
- alt: (_b = row.original.product) == null ? void 0 : _b.title
10665
- }
10666
- ),
10667
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
10668
- ] });
10669
- },
10670
- enableSorting: true
10671
- }),
10672
- columnHelper.accessor("title", {
10673
- header: "Variant",
10674
- enableSorting: true
10675
- }),
10676
- columnHelper.accessor("sku", {
10677
- header: "SKU",
10678
- cell: ({ getValue }) => {
10679
- return getValue() ?? "-";
10680
- },
10681
- enableSorting: true
10682
- }),
10683
- columnHelper.accessor("updated_at", {
10684
- header: "Updated",
10685
- cell: ({ getValue }) => {
10686
- return /* @__PURE__ */ jsxRuntime.jsx(
10687
- ui.Tooltip,
10688
- {
10689
- content: getFullDate({ date: getValue(), includeTime: true }),
10690
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
10691
- }
10692
- );
10693
- },
10694
- enableSorting: true,
10695
- sortAscLabel: "Oldest first",
10696
- sortDescLabel: "Newest first"
10697
- }),
10698
- columnHelper.accessor("created_at", {
10699
- header: "Created",
10700
- cell: ({ getValue }) => {
10701
- return /* @__PURE__ */ jsxRuntime.jsx(
10702
- ui.Tooltip,
10703
- {
10704
- content: getFullDate({ date: getValue(), includeTime: true }),
10705
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
10706
- }
10707
- );
10708
- },
10709
- enableSorting: true,
10710
- sortAscLabel: "Oldest first",
10711
- sortDescLabel: "Newest first"
10712
- })
10713
- ];
10714
- }, []);
10715
- };
10716
- const CustomItemForm = ({ orderId, currencyCode }) => {
10717
- const { setIsOpen } = useStackedModal();
10718
- const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
10719
- const form = reactHookForm.useForm({
10720
- defaultValues: {
10721
- title: "",
10722
- quantity: 1,
10723
- unit_price: ""
10724
- },
10725
- resolver: zod.zodResolver(customItemSchema)
10726
- });
10727
- const onSubmit = form.handleSubmit(async (data) => {
10728
- await addItems(
10729
- {
10730
- items: [
10731
- {
10732
- title: data.title,
10733
- quantity: data.quantity,
10734
- unit_price: convertNumber(data.unit_price)
10735
- }
10736
- ]
10737
- },
10738
- {
10739
- onSuccess: () => {
10740
- setIsOpen(STACKED_MODAL_ID, false);
10741
- },
10742
- onError: (e) => {
10743
- ui.toast.error(e.message);
10744
- }
10745
- }
10746
- );
10747
- });
10748
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
10749
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
10750
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
10751
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10752
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
10753
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
10754
- ] }),
10755
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10756
- /* @__PURE__ */ jsxRuntime.jsx(
10757
- Form$2.Field,
10758
- {
10759
- control: form.control,
10760
- name: "title",
10761
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10762
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10763
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
10764
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
10765
- ] }),
10766
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10767
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10768
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10769
- ] })
10770
- ] }) })
10771
- }
10772
- ),
10773
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10774
- /* @__PURE__ */ jsxRuntime.jsx(
10775
- Form$2.Field,
10776
- {
10777
- control: form.control,
10778
- name: "unit_price",
10779
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10780
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10781
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
10782
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
10783
- ] }),
10784
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10785
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10786
- ui.CurrencyInput,
10787
- {
10788
- symbol: getNativeSymbol(currencyCode),
10789
- code: currencyCode,
10790
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
10791
- ...field
10792
- }
10793
- ) }),
10794
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10795
- ] })
10796
- ] }) })
10797
- }
10798
- ),
10799
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10800
- /* @__PURE__ */ jsxRuntime.jsx(
10801
- Form$2.Field,
10802
- {
10803
- control: form.control,
10804
- name: "quantity",
10805
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10806
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10807
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
10808
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
10809
- ] }),
10810
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex-1", children: [
10811
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field, className: "w-full" }) }) }),
10812
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10813
- ] })
10814
- ] }) })
10815
- }
10816
- )
10817
- ] }) }) }),
10818
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10819
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10820
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
10821
- ] }) })
10822
- ] }) }) });
10823
- };
10824
- const customItemSchema = objectType({
10825
- title: stringType().min(1),
10826
- quantity: numberType(),
10827
- unit_price: unionType([numberType(), stringType()])
10828
- });
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
- }
10890
- });
10891
- },
10892
- getOptions: (data) => {
10893
- return data.promotions.map((promotion) => ({
10894
- label: promotion.code,
10895
- value: promotion.code
10896
- }));
10897
- }
10898
- });
10899
- const add = async (value) => {
10900
- if (!value) {
10901
- return;
10902
- }
10903
- addPromotions(
10904
- {
10905
- promo_codes: [value]
10906
- },
10907
- {
10908
- onError: (e) => {
10909
- ui.toast.error(e.message);
10910
- comboboxData.onSearchValueChange("");
10911
- setComboboxValue("");
10912
- },
10913
- onSuccess: () => {
10914
- comboboxData.onSearchValueChange("");
10915
- setComboboxValue("");
10916
- }
10917
- }
10918
- );
10919
- };
10920
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10921
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
10922
- const onSubmit = async () => {
10923
- setIsSubmitting(true);
10924
- let requestSucceeded = false;
10925
- await requestOrderEdit(void 0, {
10926
- onError: (e) => {
10927
- ui.toast.error(e.message);
10928
- },
10929
- onSuccess: () => {
10930
- requestSucceeded = true;
10931
- }
10932
- });
10933
- if (!requestSucceeded) {
10934
- setIsSubmitting(false);
10935
- return;
10936
- }
10937
- await confirmOrderEdit(void 0, {
10938
- onError: (e) => {
10939
- ui.toast.error(e.message);
10940
- },
10941
- onSuccess: () => {
10942
- handleSuccess();
10943
- },
10944
- onSettled: () => {
10945
- setIsSubmitting(false);
10946
- }
10947
- });
10948
- };
10949
- if (isError) {
10950
- throw error;
10951
- }
10952
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
10953
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
10954
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
10955
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10956
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
10957
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
10958
- ] }),
10959
- /* @__PURE__ */ jsxRuntime.jsx(
10960
- Combobox,
10961
- {
10962
- id: "promotion-combobox",
10963
- "aria-describedby": "promotion-combobox-hint",
10964
- isFetchingNextPage: comboboxData.isFetchingNextPage,
10965
- fetchNextPage: comboboxData.fetchNextPage,
10966
- options: comboboxData.options,
10967
- onSearchValueChange: comboboxData.onSearchValueChange,
10968
- searchValue: comboboxData.searchValue,
10969
- disabled: comboboxData.disabled || isAddingPromotions,
10970
- onChange: add,
10971
- value: comboboxValue
10972
- }
10973
- )
10974
- ] }),
10975
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10976
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
10977
- PromotionItem,
10978
- {
10979
- promotion,
10980
- orderId: preview.id,
10981
- isLoading: isPending
10982
- },
10983
- promotion.id
10984
- )) })
10985
- ] }) }),
10986
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10987
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10988
- /* @__PURE__ */ jsxRuntime.jsx(
10989
- ui.Button,
10990
- {
10991
- size: "small",
10992
- type: "submit",
10993
- isLoading: isSubmitting || isAddingPromotions,
10994
- children: "Save"
10995
- }
10996
- )
10997
- ] }) })
10998
- ] });
10999
- };
11000
- const PromotionItem = ({
11001
- promotion,
11002
- orderId,
11003
- isLoading
11004
- }) => {
11005
- var _a;
11006
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11007
- const onRemove = async () => {
11008
- removePromotions(
11009
- {
11010
- promo_codes: [promotion.code]
11011
- },
11012
- {
11013
- onError: (e) => {
11014
- ui.toast.error(e.message);
11015
- }
11016
- }
11017
- );
11018
- };
11019
- const displayValue = getDisplayValue(promotion);
11020
- return /* @__PURE__ */ jsxRuntime.jsxs(
11021
- "div",
11022
- {
11023
- className: ui.clx(
11024
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11025
- {
11026
- "animate-pulse": isLoading
11027
- }
11028
- ),
11029
- children: [
11030
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11031
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11032
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11033
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11034
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11035
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11036
- ] }),
11037
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11038
- ] })
11039
- ] }),
11040
- /* @__PURE__ */ jsxRuntime.jsx(
11041
- ui.IconButton,
11042
- {
11043
- size: "small",
11044
- type: "button",
11045
- variant: "transparent",
11046
- onClick: onRemove,
11047
- isLoading: isPending || isLoading,
11048
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11049
- }
11050
- )
11051
- ]
11052
- },
11053
- promotion.id
11054
- );
11055
- };
11056
- function getDisplayValue(promotion) {
11057
- var _a, _b, _c, _d;
11058
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11059
- if (!value) {
11060
- return null;
11061
- }
11062
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11063
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11064
- if (!currency) {
11065
- return null;
11066
- }
11067
- return getLocaleAmount(value, currency);
11068
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11069
- return formatPercentage(value);
11070
- }
11071
- return null;
11072
- }
11073
- const formatter = new Intl.NumberFormat([], {
11074
- style: "percent",
11075
- minimumFractionDigits: 2
11076
- });
11077
- const formatPercentage = (value, isPercentageValue = false) => {
11078
- let val = value || 0;
11079
- if (!isPercentageValue) {
11080
- val = val / 100;
11081
- }
11082
- return formatter.format(val);
11083
- };
11084
- function getPromotionIds(items, shippingMethods) {
11085
- const promotionIds = /* @__PURE__ */ new Set();
11086
- for (const item of items) {
11087
- if (item.adjustments) {
11088
- for (const adjustment of item.adjustments) {
11089
- if (adjustment.promotion_id) {
11090
- promotionIds.add(adjustment.promotion_id);
11091
- }
11092
- }
11093
- }
11094
- }
11095
- for (const shippingMethod of shippingMethods) {
11096
- if (shippingMethod.adjustments) {
11097
- for (const adjustment of shippingMethod.adjustments) {
11098
- if (adjustment.promotion_id) {
11099
- promotionIds.add(adjustment.promotion_id);
11100
- }
11101
- }
11102
- }
11103
- }
11104
- return Array.from(promotionIds);
11105
- }
11106
- const InlineTip = React.forwardRef(
11107
- ({ variant = "tip", label, className, children, ...props }, ref) => {
11108
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
11109
- return /* @__PURE__ */ jsxRuntime.jsxs(
11110
- "div",
11111
- {
11112
- ref,
11113
- className: ui.clx(
11114
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
11115
- className
11116
- ),
11117
- ...props,
11118
- children: [
11119
- /* @__PURE__ */ jsxRuntime.jsx(
11120
- "div",
11121
- {
11122
- role: "presentation",
11123
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
11124
- "bg-ui-tag-orange-icon": variant === "warning"
11125
- })
11126
- }
11127
- ),
11128
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
11129
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
11130
- labelValue,
11131
- ":"
11132
- ] }),
11133
- " ",
11134
- children
11135
- ] })
11136
- ]
11137
- }
11138
- );
11139
- }
11140
- );
11141
- InlineTip.displayName = "InlineTip";
11142
- const MetadataFieldSchema = objectType({
11143
- key: stringType(),
11144
- disabled: booleanType().optional(),
11145
- value: anyType()
11146
- });
11147
- const MetadataSchema = objectType({
11148
- metadata: arrayType(MetadataFieldSchema)
11149
- });
11150
- const Metadata = () => {
11151
- const { id } = reactRouterDom.useParams();
11152
- const { order, isPending, isError, error } = useOrder(id, {
11153
- fields: "metadata"
11154
- });
11155
- if (isError) {
11156
- throw error;
11157
- }
11158
- const isReady = !isPending && !!order;
11159
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11160
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11161
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
11162
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
11163
- ] }),
11164
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11165
- ] });
11166
- };
11167
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
11168
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
11169
- const MetadataForm = ({ orderId, metadata }) => {
11170
- const { handleSuccess } = useRouteModal();
11171
- const hasUneditableRows = getHasUneditableRows(metadata);
11172
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
11173
- const form = reactHookForm.useForm({
11174
- defaultValues: {
11175
- metadata: getDefaultValues(metadata)
11176
- },
11177
- resolver: zod.zodResolver(MetadataSchema)
11178
- });
11179
- const handleSubmit = form.handleSubmit(async (data) => {
11180
- const parsedData = parseValues(data);
11181
- await mutateAsync(
11182
- {
11183
- metadata: parsedData
11184
- },
11185
- {
11186
- onSuccess: () => {
11187
- ui.toast.success("Metadata updated");
11188
- handleSuccess();
11189
- },
11190
- onError: (error) => {
11191
- ui.toast.error(error.message);
11192
- }
11193
- }
11194
- );
11195
- });
11196
- const { fields, insert, remove } = reactHookForm.useFieldArray({
11197
- control: form.control,
11198
- name: "metadata"
11199
- });
11200
- function deleteRow(index) {
11201
- remove(index);
11202
- if (fields.length === 1) {
11203
- insert(0, {
11204
- key: "",
11205
- value: "",
11206
- disabled: false
11207
- });
11208
- }
11209
- }
11210
- function insertRow(index, position) {
11211
- insert(index + (position === "above" ? 0 : 1), {
11212
- key: "",
11213
- value: "",
11214
- disabled: false
11215
- });
11216
- }
11217
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11218
- KeyboundForm,
11219
- {
11220
- onSubmit: handleSubmit,
11221
- className: "flex flex-1 flex-col overflow-hidden",
11222
- children: [
11223
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
11224
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
11225
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
11226
- /* @__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" }) }),
11227
- /* @__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" }) })
11228
- ] }),
11229
- fields.map((field, index) => {
11230
- const isDisabled = field.disabled || false;
11231
- let placeholder = "-";
11232
- if (typeof field.value === "object") {
11233
- placeholder = "{ ... }";
11234
- }
11235
- if (Array.isArray(field.value)) {
11236
- placeholder = "[ ... ]";
11237
- }
11238
- return /* @__PURE__ */ jsxRuntime.jsx(
11239
- ConditionalTooltip,
11240
- {
11241
- showTooltip: isDisabled,
11242
- content: "This row is disabled because it contains non-primitive data.",
11243
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
11244
- /* @__PURE__ */ jsxRuntime.jsxs(
11245
- "div",
11246
- {
11247
- className: ui.clx("grid grid-cols-2 divide-x", {
11248
- "overflow-hidden rounded-b-lg": index === fields.length - 1
11249
- }),
11250
- children: [
11251
- /* @__PURE__ */ jsxRuntime.jsx(
11252
- Form$2.Field,
11253
- {
11254
- control: form.control,
11255
- name: `metadata.${index}.key`,
11256
- render: ({ field: field2 }) => {
11257
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11258
- GridInput,
11259
- {
11260
- "aria-labelledby": METADATA_KEY_LABEL_ID,
11261
- ...field2,
11262
- disabled: isDisabled,
11263
- placeholder: "Key"
11264
- }
11265
- ) }) });
11266
- }
11267
- }
11268
- ),
11269
- /* @__PURE__ */ jsxRuntime.jsx(
11270
- Form$2.Field,
11271
- {
11272
- control: form.control,
11273
- name: `metadata.${index}.value`,
11274
- render: ({ field: { value, ...field2 } }) => {
11275
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11276
- GridInput,
11277
- {
11278
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
11279
- ...field2,
11280
- value: isDisabled ? placeholder : value,
11281
- disabled: isDisabled,
11282
- placeholder: "Value"
11283
- }
11284
- ) }) });
11285
- }
11286
- }
11287
- )
11288
- ]
11289
- }
11290
- ),
11291
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11292
- /* @__PURE__ */ jsxRuntime.jsx(
11293
- ui.DropdownMenu.Trigger,
11294
- {
11295
- className: ui.clx(
11296
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11297
- {
11298
- hidden: isDisabled
11299
- }
11300
- ),
11301
- disabled: isDisabled,
11302
- asChild: true,
11303
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11304
- }
11305
- ),
11306
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11307
- /* @__PURE__ */ jsxRuntime.jsxs(
11308
- ui.DropdownMenu.Item,
11309
- {
11310
- className: "gap-x-2",
11311
- onClick: () => insertRow(index, "above"),
11312
- children: [
11313
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11314
- "Insert row above"
11315
- ]
11316
- }
11317
- ),
11318
- /* @__PURE__ */ jsxRuntime.jsxs(
11319
- ui.DropdownMenu.Item,
11320
- {
11321
- className: "gap-x-2",
11322
- onClick: () => insertRow(index, "below"),
11323
- children: [
11324
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11325
- "Insert row below"
11326
- ]
11327
- }
11328
- ),
11329
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11330
- /* @__PURE__ */ jsxRuntime.jsxs(
11331
- ui.DropdownMenu.Item,
11332
- {
11333
- className: "gap-x-2",
11334
- onClick: () => deleteRow(index),
11335
- children: [
11336
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11337
- "Delete row"
11338
- ]
11339
- }
11340
- )
11341
- ] })
11342
- ] })
11343
- ] })
11344
- },
11345
- field.id
11346
- );
11347
- })
11348
- ] }),
11349
- 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." })
11350
- ] }),
11351
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11352
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11353
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11354
- ] }) })
11355
- ]
11356
- }
11357
- ) });
11358
- };
11359
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11360
- return /* @__PURE__ */ jsxRuntime.jsx(
11361
- "input",
11362
- {
11363
- ref,
11364
- ...props,
11365
- autoComplete: "off",
11366
- className: ui.clx(
11367
- "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",
11368
- className
11369
- )
11370
- }
11371
- );
11372
- });
11373
- GridInput.displayName = "MetadataForm.GridInput";
11374
- const PlaceholderInner = () => {
11375
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11376
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11377
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11378
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11379
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11380
- ] }) })
11381
- ] });
11382
- };
11383
- const EDITABLE_TYPES = ["string", "number", "boolean"];
11384
- function getDefaultValues(metadata) {
11385
- if (!metadata || !Object.keys(metadata).length) {
11386
- return [
11387
- {
11388
- key: "",
11389
- value: "",
11390
- disabled: false
11391
- }
11392
- ];
11393
- }
11394
- return Object.entries(metadata).map(([key, value]) => {
11395
- if (!EDITABLE_TYPES.includes(typeof value)) {
11396
- return {
11397
- key,
11398
- value,
11399
- disabled: true
11400
- };
11401
- }
11402
- let stringValue = value;
11403
- if (typeof value !== "string") {
11404
- stringValue = JSON.stringify(value);
11405
- }
11406
- return {
11407
- key,
11408
- value: stringValue,
11409
- original_key: key
11410
- };
11411
- });
11412
- }
11413
- function parseValues(values) {
11414
- const metadata = values.metadata;
11415
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11416
- if (isEmpty) {
11417
- return null;
11418
- }
11419
- const update = {};
11420
- metadata.forEach((field) => {
11421
- let key = field.key;
11422
- let value = field.value;
11423
- const disabled = field.disabled;
11424
- if (!key || !value) {
11425
- return;
11426
- }
11427
- if (disabled) {
11428
- update[key] = value;
11429
- return;
11430
- }
11431
- key = key.trim();
11432
- value = value.trim();
11433
- if (value === "true") {
11434
- update[key] = true;
11435
- } else if (value === "false") {
11436
- update[key] = false;
11437
- } else {
11438
- const parsedNumber = parseFloat(value);
11439
- if (!isNaN(parsedNumber)) {
11440
- update[key] = parsedNumber;
11441
- } else {
11442
- update[key] = value;
11443
- }
11444
- }
11445
- });
11446
- return update;
11447
- }
11448
- function getHasUneditableRows(metadata) {
11449
- if (!metadata) {
11450
- return false;
11451
- }
11452
- return Object.values(metadata).some(
11453
- (value) => !EDITABLE_TYPES.includes(typeof value)
11454
- );
11455
- }
11456
- const SalesChannel = () => {
11457
- const { id } = reactRouterDom.useParams();
11458
- const { draft_order, isPending, isError, error } = useDraftOrder(
11459
- id,
11460
- {
11461
- fields: "+sales_channel_id"
11462
- },
11463
- {
11464
- enabled: !!id
11465
- }
11466
- );
11467
- if (isError) {
11468
- throw error;
11469
- }
11470
- const ISrEADY = !!draft_order && !isPending;
11471
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11472
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11473
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11474
- /* @__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" }) })
11475
- ] }),
11476
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11477
- ] });
11478
- };
11479
- const SalesChannelForm = ({ order }) => {
11480
- const form = reactHookForm.useForm({
11481
- defaultValues: {
11482
- sales_channel_id: order.sales_channel_id || ""
11483
- },
11484
- resolver: zod.zodResolver(schema$2)
11485
- });
11486
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11487
- const { handleSuccess } = useRouteModal();
11488
- const onSubmit = form.handleSubmit(async (data) => {
11489
- await mutateAsync(
11490
- {
11491
- sales_channel_id: data.sales_channel_id
11492
- },
11493
- {
11494
- onSuccess: () => {
11495
- ui.toast.success("Sales channel updated");
11496
- handleSuccess();
11497
- },
11498
- onError: (error) => {
11499
- ui.toast.error(error.message);
11500
- }
11501
- }
11502
- );
11503
- });
11504
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11505
- KeyboundForm,
11506
- {
11507
- className: "flex flex-1 flex-col overflow-hidden",
11508
- onSubmit,
11509
- children: [
11510
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11511
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11512
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11513
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11514
- ] }) })
11515
- ]
11516
- }
11517
- ) });
11518
- };
11519
- const SalesChannelField = ({ control, order }) => {
11520
- const salesChannels = useComboboxData({
11521
- queryFn: async (params) => {
11522
- return await sdk.admin.salesChannel.list(params);
11523
- },
11524
- queryKey: ["sales-channels"],
11525
- getOptions: (data) => {
11526
- return data.sales_channels.map((salesChannel) => ({
11527
- label: salesChannel.name,
11528
- value: salesChannel.id
11529
- }));
11530
- },
11531
- defaultValue: order.sales_channel_id || void 0
11532
- });
11533
- return /* @__PURE__ */ jsxRuntime.jsx(
11534
- Form$2.Field,
11535
- {
11536
- control,
11537
- name: "sales_channel_id",
11538
- render: ({ field }) => {
11539
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11540
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11541
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11542
- Combobox,
11543
- {
11544
- options: salesChannels.options,
11545
- fetchNextPage: salesChannels.fetchNextPage,
11546
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11547
- searchValue: salesChannels.searchValue,
11548
- onSearchValueChange: salesChannels.onSearchValueChange,
11549
- placeholder: "Select sales channel",
11550
- ...field
11551
- }
11552
- ) }),
11553
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11554
- ] });
11555
- }
11556
- }
11557
- );
11558
- };
11559
- const schema$2 = objectType({
11560
- sales_channel_id: stringType().min(1)
11561
- });
11562
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11563
- const Shipping = () => {
11564
- var _a;
11565
- const { id } = reactRouterDom.useParams();
11566
- const { order, isPending, isError, error } = useOrder(id, {
11567
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11568
- });
11569
- const {
11570
- order: preview,
11571
- isPending: isPreviewPending,
11572
- isError: isPreviewError,
11573
- error: previewError
11574
- } = useOrderPreview(id);
11575
- useInitiateOrderEdit({ preview });
11576
- const { onCancel } = useCancelOrderEdit({ preview });
11577
- if (isError) {
11578
- throw error;
11579
- }
11580
- if (isPreviewError) {
11581
- throw previewError;
11582
- }
11583
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11584
- const isReady = preview && !isPreviewPending && order && !isPending;
11585
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11586
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11587
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11588
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11589
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11590
- ] }) }) }),
11591
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11592
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11593
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11594
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11595
- ] }) });
11596
- };
11597
- const ShippingForm = ({ preview, order }) => {
11598
- var _a;
11599
- const { setIsOpen } = useStackedModal();
11600
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11601
- const [data, setData] = React.useState(null);
11602
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11603
- const { shipping_options } = useShippingOptions(
11604
- {
11605
- id: appliedShippingOptionIds,
11606
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11607
- },
11608
- {
11609
- enabled: appliedShippingOptionIds.length > 0
11610
- }
11611
- );
11612
- const uniqueShippingProfiles = React.useMemo(() => {
11613
- const profiles = /* @__PURE__ */ new Map();
11614
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11615
- profiles.set(profile.id, profile);
11616
- });
11617
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11618
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11619
- });
11620
- return Array.from(profiles.values());
11621
- }, [order.items, shipping_options]);
11622
- const { handleSuccess } = useRouteModal();
11623
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11624
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11625
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11626
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11627
- const onSubmit = async () => {
11628
- setIsSubmitting(true);
11629
- let requestSucceeded = false;
11630
- await requestOrderEdit(void 0, {
11631
- onError: (e) => {
11632
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11633
- },
11634
- onSuccess: () => {
11635
- requestSucceeded = true;
11636
- }
11637
- });
11638
- if (!requestSucceeded) {
11639
- setIsSubmitting(false);
11640
- return;
11641
- }
11642
- await confirmOrderEdit(void 0, {
11643
- onError: (e) => {
11644
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11645
- },
11646
- onSuccess: () => {
11647
- handleSuccess();
11648
- },
11649
- onSettled: () => {
11650
- setIsSubmitting(false);
11651
- }
11652
- });
11653
- };
11654
- const onKeydown = React.useCallback(
11655
- (e) => {
11656
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11657
- if (data || isSubmitting) {
11658
- return;
11659
- }
11660
- onSubmit();
11661
- }
11662
- },
11663
- [data, isSubmitting, onSubmit]
11664
- );
11665
- React.useEffect(() => {
11666
- document.addEventListener("keydown", onKeydown);
11667
- return () => {
11668
- document.removeEventListener("keydown", onKeydown);
11669
- };
11670
- }, [onKeydown]);
11671
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11672
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11673
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11674
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11675
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11676
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11677
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11678
- ] }),
11679
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11680
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11681
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11682
- /* @__PURE__ */ jsxRuntime.jsx(
11683
- ui.Text,
11684
- {
11685
- size: "xsmall",
11686
- weight: "plus",
11687
- className: "text-ui-fg-muted",
11688
- children: "Shipping profile"
10502
+ size: "xsmall",
10503
+ weight: "plus",
10504
+ className: "text-ui-fg-muted",
10505
+ children: "Shipping profile"
11689
10506
  }
11690
10507
  ),
11691
10508
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -11866,7 +10683,7 @@ const ShippingForm = ({ preview, order }) => {
11866
10683
  ]
11867
10684
  }
11868
10685
  ) : /* @__PURE__ */ jsxRuntime.jsx(
11869
- StackedModalTrigger,
10686
+ StackedModalTrigger$1,
11870
10687
  {
11871
10688
  shippingProfileId: profile.id,
11872
10689
  shippingOption,
@@ -11977,7 +10794,7 @@ const ShippingForm = ({ preview, order }) => {
11977
10794
  ] }) })
11978
10795
  ] });
11979
10796
  };
11980
- const StackedModalTrigger = ({
10797
+ const StackedModalTrigger$1 = ({
11981
10798
  shippingProfileId,
11982
10799
  shippingOption,
11983
10800
  shippingMethod,
@@ -12398,7 +11215,7 @@ const ShippingAddressForm = ({ order }) => {
12398
11215
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12399
11216
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12400
11217
  },
12401
- resolver: zod.zodResolver(schema$1)
11218
+ resolver: zod.zodResolver(schema$3)
12402
11219
  });
12403
11220
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12404
11221
  const { handleSuccess } = useRouteModal();
@@ -12568,7 +11385,7 @@ const ShippingAddressForm = ({ order }) => {
12568
11385
  }
12569
11386
  ) });
12570
11387
  };
12571
- const schema$1 = addressSchema;
11388
+ const schema$3 = addressSchema;
12572
11389
  const TransferOwnership = () => {
12573
11390
  const { id } = reactRouterDom.useParams();
12574
11391
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12592,7 +11409,7 @@ const TransferOwnershipForm = ({ order }) => {
12592
11409
  defaultValues: {
12593
11410
  customer_id: order.customer_id || ""
12594
11411
  },
12595
- resolver: zod.zodResolver(schema)
11412
+ resolver: zod.zodResolver(schema$2)
12596
11413
  });
12597
11414
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12598
11415
  const { handleSuccess } = useRouteModal();
@@ -12891,159 +11708,1342 @@ const Illustration = () => {
12891
11708
  /* @__PURE__ */ jsxRuntime.jsx(
12892
11709
  "path",
12893
11710
  {
12894
- 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",
12895
- fill: "#A1A1AA"
12896
- }
11711
+ 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",
11712
+ fill: "#A1A1AA"
11713
+ }
11714
+ ),
11715
+ /* @__PURE__ */ jsxRuntime.jsx(
11716
+ "rect",
11717
+ {
11718
+ width: "17",
11719
+ height: "3",
11720
+ rx: "1.5",
11721
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
11722
+ fill: "#A1A1AA"
11723
+ }
11724
+ ),
11725
+ /* @__PURE__ */ jsxRuntime.jsx(
11726
+ "rect",
11727
+ {
11728
+ width: "12",
11729
+ height: "3",
11730
+ rx: "1.5",
11731
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
11732
+ fill: "#A1A1AA"
11733
+ }
11734
+ ),
11735
+ /* @__PURE__ */ jsxRuntime.jsx(
11736
+ "path",
11737
+ {
11738
+ 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",
11739
+ fill: "#52525B"
11740
+ }
11741
+ ),
11742
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11743
+ "path",
11744
+ {
11745
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
11746
+ stroke: "#A1A1AA",
11747
+ strokeWidth: "1.5",
11748
+ strokeLinecap: "round",
11749
+ strokeLinejoin: "round"
11750
+ }
11751
+ ) }),
11752
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11753
+ "path",
11754
+ {
11755
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
11756
+ stroke: "#A1A1AA",
11757
+ strokeWidth: "1.5",
11758
+ strokeLinecap: "round",
11759
+ strokeLinejoin: "round"
11760
+ }
11761
+ ) }),
11762
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11763
+ "path",
11764
+ {
11765
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
11766
+ stroke: "#A1A1AA",
11767
+ strokeWidth: "1.5",
11768
+ strokeLinecap: "round",
11769
+ strokeLinejoin: "round"
11770
+ }
11771
+ ) }),
11772
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11773
+ "path",
11774
+ {
11775
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
11776
+ stroke: "#A1A1AA",
11777
+ strokeWidth: "1.5",
11778
+ strokeLinecap: "round",
11779
+ strokeLinejoin: "round"
11780
+ }
11781
+ ) }),
11782
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11783
+ "path",
11784
+ {
11785
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
11786
+ stroke: "#A1A1AA",
11787
+ strokeWidth: "1.5",
11788
+ strokeLinecap: "round",
11789
+ strokeLinejoin: "round"
11790
+ }
11791
+ ) }),
11792
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11793
+ "path",
11794
+ {
11795
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
11796
+ stroke: "#A1A1AA",
11797
+ strokeWidth: "1.5",
11798
+ strokeLinecap: "round",
11799
+ strokeLinejoin: "round"
11800
+ }
11801
+ ) }),
11802
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
11803
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11804
+ "rect",
11805
+ {
11806
+ width: "12",
11807
+ height: "12",
11808
+ fill: "white",
11809
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
11810
+ }
11811
+ ) }),
11812
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11813
+ "rect",
11814
+ {
11815
+ width: "12",
11816
+ height: "12",
11817
+ fill: "white",
11818
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
11819
+ }
11820
+ ) }),
11821
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11822
+ "rect",
11823
+ {
11824
+ width: "12",
11825
+ height: "12",
11826
+ fill: "white",
11827
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
11828
+ }
11829
+ ) }),
11830
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11831
+ "rect",
11832
+ {
11833
+ width: "12",
11834
+ height: "12",
11835
+ fill: "white",
11836
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
11837
+ }
11838
+ ) }),
11839
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11840
+ "rect",
11841
+ {
11842
+ width: "12",
11843
+ height: "12",
11844
+ fill: "white",
11845
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
11846
+ }
11847
+ ) }),
11848
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11849
+ "rect",
11850
+ {
11851
+ width: "12",
11852
+ height: "12",
11853
+ fill: "white",
11854
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
11855
+ }
11856
+ ) })
11857
+ ] })
11858
+ ]
11859
+ }
11860
+ );
11861
+ };
11862
+ const schema$2 = objectType({
11863
+ customer_id: stringType().min(1)
11864
+ });
11865
+ const BillingAddress = () => {
11866
+ const { id } = reactRouterDom.useParams();
11867
+ const { order, isPending, isError, error } = useOrder(id, {
11868
+ fields: "+billing_address"
11869
+ });
11870
+ if (isError) {
11871
+ throw error;
11872
+ }
11873
+ const isReady = !isPending && !!order;
11874
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11875
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11876
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
11877
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
11878
+ ] }),
11879
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
11880
+ ] });
11881
+ };
11882
+ const BillingAddressForm = ({ order }) => {
11883
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11884
+ const form = reactHookForm.useForm({
11885
+ defaultValues: {
11886
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
11887
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
11888
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
11889
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
11890
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
11891
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
11892
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
11893
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
11894
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
11895
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
11896
+ },
11897
+ resolver: zod.zodResolver(schema$1)
11898
+ });
11899
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11900
+ const { handleSuccess } = useRouteModal();
11901
+ const onSubmit = form.handleSubmit(async (data) => {
11902
+ await mutateAsync(
11903
+ { billing_address: data },
11904
+ {
11905
+ onSuccess: () => {
11906
+ handleSuccess();
11907
+ },
11908
+ onError: (error) => {
11909
+ ui.toast.error(error.message);
11910
+ }
11911
+ }
11912
+ );
11913
+ });
11914
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11915
+ KeyboundForm,
11916
+ {
11917
+ className: "flex flex-1 flex-col overflow-hidden",
11918
+ onSubmit,
11919
+ children: [
11920
+ /* @__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: [
11921
+ /* @__PURE__ */ jsxRuntime.jsx(
11922
+ Form$2.Field,
11923
+ {
11924
+ control: form.control,
11925
+ name: "country_code",
11926
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11927
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11928
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11929
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11930
+ ] })
11931
+ }
11932
+ ),
11933
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11934
+ /* @__PURE__ */ jsxRuntime.jsx(
11935
+ Form$2.Field,
11936
+ {
11937
+ control: form.control,
11938
+ name: "first_name",
11939
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11940
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11941
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11942
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11943
+ ] })
11944
+ }
11945
+ ),
11946
+ /* @__PURE__ */ jsxRuntime.jsx(
11947
+ Form$2.Field,
11948
+ {
11949
+ control: form.control,
11950
+ name: "last_name",
11951
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11952
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11953
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11954
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11955
+ ] })
11956
+ }
11957
+ )
11958
+ ] }),
11959
+ /* @__PURE__ */ jsxRuntime.jsx(
11960
+ Form$2.Field,
11961
+ {
11962
+ control: form.control,
11963
+ name: "company",
11964
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11965
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11966
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11967
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11968
+ ] })
11969
+ }
11970
+ ),
11971
+ /* @__PURE__ */ jsxRuntime.jsx(
11972
+ Form$2.Field,
11973
+ {
11974
+ control: form.control,
11975
+ name: "address_1",
11976
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11977
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11978
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11979
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11980
+ ] })
11981
+ }
11982
+ ),
11983
+ /* @__PURE__ */ jsxRuntime.jsx(
11984
+ Form$2.Field,
11985
+ {
11986
+ control: form.control,
11987
+ name: "address_2",
11988
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11989
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11990
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11991
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11992
+ ] })
11993
+ }
11994
+ ),
11995
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11996
+ /* @__PURE__ */ jsxRuntime.jsx(
11997
+ Form$2.Field,
11998
+ {
11999
+ control: form.control,
12000
+ name: "postal_code",
12001
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12002
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12003
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12004
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12005
+ ] })
12006
+ }
12007
+ ),
12008
+ /* @__PURE__ */ jsxRuntime.jsx(
12009
+ Form$2.Field,
12010
+ {
12011
+ control: form.control,
12012
+ name: "city",
12013
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12014
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12015
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12016
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12017
+ ] })
12018
+ }
12019
+ )
12020
+ ] }),
12021
+ /* @__PURE__ */ jsxRuntime.jsx(
12022
+ Form$2.Field,
12023
+ {
12024
+ control: form.control,
12025
+ name: "province",
12026
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12027
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12028
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12029
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12030
+ ] })
12031
+ }
12032
+ ),
12033
+ /* @__PURE__ */ jsxRuntime.jsx(
12034
+ Form$2.Field,
12035
+ {
12036
+ control: form.control,
12037
+ name: "phone",
12038
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12039
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12040
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12041
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12042
+ ] })
12043
+ }
12044
+ )
12045
+ ] }) }),
12046
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12047
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12048
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12049
+ ] }) })
12050
+ ]
12051
+ }
12052
+ ) });
12053
+ };
12054
+ const schema$1 = addressSchema;
12055
+ const NumberInput = React.forwardRef(
12056
+ ({
12057
+ value,
12058
+ onChange,
12059
+ size = "base",
12060
+ min = 0,
12061
+ max = 100,
12062
+ step = 1,
12063
+ className,
12064
+ disabled,
12065
+ ...props
12066
+ }, ref) => {
12067
+ const handleChange = (event) => {
12068
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
12069
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
12070
+ onChange(newValue);
12071
+ }
12072
+ };
12073
+ const handleIncrement = () => {
12074
+ const newValue = value + step;
12075
+ if (max === void 0 || newValue <= max) {
12076
+ onChange(newValue);
12077
+ }
12078
+ };
12079
+ const handleDecrement = () => {
12080
+ const newValue = value - step;
12081
+ if (min === void 0 || newValue >= min) {
12082
+ onChange(newValue);
12083
+ }
12084
+ };
12085
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12086
+ "div",
12087
+ {
12088
+ className: ui.clx(
12089
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
12090
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
12091
+ {
12092
+ "h-7": size === "small",
12093
+ "h-8": size === "base"
12094
+ },
12095
+ className
12897
12096
  ),
12898
- /* @__PURE__ */ jsxRuntime.jsx(
12899
- "rect",
12900
- {
12901
- width: "17",
12902
- height: "3",
12903
- rx: "1.5",
12904
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12905
- fill: "#A1A1AA"
12097
+ children: [
12098
+ /* @__PURE__ */ jsxRuntime.jsx(
12099
+ "input",
12100
+ {
12101
+ ref,
12102
+ type: "number",
12103
+ value,
12104
+ onChange: handleChange,
12105
+ min,
12106
+ max,
12107
+ step,
12108
+ className: ui.clx(
12109
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
12110
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
12111
+ "placeholder:text-ui-fg-muted"
12112
+ ),
12113
+ ...props
12114
+ }
12115
+ ),
12116
+ /* @__PURE__ */ jsxRuntime.jsxs(
12117
+ "button",
12118
+ {
12119
+ className: ui.clx(
12120
+ "flex items-center justify-center outline-none transition-fg",
12121
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
12122
+ "focus:bg-ui-bg-field-component-hover",
12123
+ "hover:bg-ui-bg-field-component-hover",
12124
+ {
12125
+ "size-7": size === "small",
12126
+ "size-8": size === "base"
12127
+ }
12128
+ ),
12129
+ type: "button",
12130
+ onClick: handleDecrement,
12131
+ disabled: min !== void 0 && value <= min || disabled,
12132
+ children: [
12133
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
12134
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
12135
+ ]
12136
+ }
12137
+ ),
12138
+ /* @__PURE__ */ jsxRuntime.jsxs(
12139
+ "button",
12140
+ {
12141
+ className: ui.clx(
12142
+ "flex items-center justify-center outline-none transition-fg",
12143
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
12144
+ "focus:bg-ui-bg-field-hover",
12145
+ "hover:bg-ui-bg-field-hover",
12146
+ {
12147
+ "size-7": size === "small",
12148
+ "size-8": size === "base"
12149
+ }
12150
+ ),
12151
+ type: "button",
12152
+ onClick: handleIncrement,
12153
+ disabled: max !== void 0 && value >= max || disabled,
12154
+ children: [
12155
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
12156
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
12157
+ ]
12158
+ }
12159
+ )
12160
+ ]
12161
+ }
12162
+ );
12163
+ }
12164
+ );
12165
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
12166
+ const productVariantsQueryKeys = {
12167
+ list: (query2) => [
12168
+ PRODUCT_VARIANTS_QUERY_KEY,
12169
+ query2 ? query2 : void 0
12170
+ ]
12171
+ };
12172
+ const useProductVariants = (query2, options) => {
12173
+ const { data, ...rest } = reactQuery.useQuery({
12174
+ queryKey: productVariantsQueryKeys.list(query2),
12175
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
12176
+ ...options
12177
+ });
12178
+ return { ...data, ...rest };
12179
+ };
12180
+ const STACKED_MODAL_ID = "items_stacked_modal";
12181
+ const Items = () => {
12182
+ const { id } = reactRouterDom.useParams();
12183
+ const {
12184
+ order: preview,
12185
+ isPending: isPreviewPending,
12186
+ isError: isPreviewError,
12187
+ error: previewError
12188
+ } = useOrderPreview(id, void 0, {
12189
+ placeholderData: reactQuery.keepPreviousData
12190
+ });
12191
+ useInitiateOrderEdit({ preview });
12192
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12193
+ id,
12194
+ {
12195
+ fields: "currency_code"
12196
+ },
12197
+ {
12198
+ enabled: !!id
12199
+ }
12200
+ );
12201
+ const { onCancel } = useCancelOrderEdit({ preview });
12202
+ if (isError) {
12203
+ throw error;
12204
+ }
12205
+ if (isPreviewError) {
12206
+ throw previewError;
12207
+ }
12208
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
12209
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12210
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
12211
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12212
+ ] }) });
12213
+ };
12214
+ const ItemsForm = ({ preview, currencyCode }) => {
12215
+ var _a;
12216
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
12217
+ const [modalContent, setModalContent] = React.useState(
12218
+ null
12219
+ );
12220
+ const { handleSuccess } = useRouteModal();
12221
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
12222
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12223
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12224
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
12225
+ const matches = React.useMemo(() => {
12226
+ return matchSorter.matchSorter(preview.items, query2, {
12227
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
12228
+ });
12229
+ }, [preview.items, query2]);
12230
+ const onSubmit = async () => {
12231
+ setIsSubmitting(true);
12232
+ let requestSucceeded = false;
12233
+ await requestOrderEdit(void 0, {
12234
+ onError: (e) => {
12235
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
12236
+ },
12237
+ onSuccess: () => {
12238
+ requestSucceeded = true;
12239
+ }
12240
+ });
12241
+ if (!requestSucceeded) {
12242
+ setIsSubmitting(false);
12243
+ return;
12244
+ }
12245
+ await confirmOrderEdit(void 0, {
12246
+ onError: (e) => {
12247
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
12248
+ },
12249
+ onSuccess: () => {
12250
+ handleSuccess();
12251
+ },
12252
+ onSettled: () => {
12253
+ setIsSubmitting(false);
12254
+ }
12255
+ });
12256
+ };
12257
+ const onKeyDown = React.useCallback(
12258
+ (e) => {
12259
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12260
+ if (modalContent || isSubmitting) {
12261
+ return;
12262
+ }
12263
+ onSubmit();
12264
+ }
12265
+ },
12266
+ [modalContent, isSubmitting, onSubmit]
12267
+ );
12268
+ React.useEffect(() => {
12269
+ document.addEventListener("keydown", onKeyDown);
12270
+ return () => {
12271
+ document.removeEventListener("keydown", onKeyDown);
12272
+ };
12273
+ }, [onKeyDown]);
12274
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
12275
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12276
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
12277
+ StackedFocusModal,
12278
+ {
12279
+ id: STACKED_MODAL_ID,
12280
+ onOpenChangeCallback: (open) => {
12281
+ if (!open) {
12282
+ setModalContent(null);
12906
12283
  }
12907
- ),
12908
- /* @__PURE__ */ jsxRuntime.jsx(
12909
- "rect",
12910
- {
12911
- width: "12",
12912
- height: "3",
12913
- rx: "1.5",
12914
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12915
- fill: "#A1A1AA"
12284
+ },
12285
+ children: [
12286
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
12287
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12288
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
12289
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order" }) })
12290
+ ] }),
12291
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12292
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12293
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
12294
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12295
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
12296
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
12297
+ ] }),
12298
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
12299
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
12300
+ ui.Input,
12301
+ {
12302
+ type: "search",
12303
+ placeholder: "Search items",
12304
+ value: searchValue,
12305
+ onChange: (e) => onSearchValueChange(e.target.value)
12306
+ }
12307
+ ) }),
12308
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
12309
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
12310
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
12311
+ /* @__PURE__ */ jsxRuntime.jsx(
12312
+ StackedModalTrigger,
12313
+ {
12314
+ type: "add-items",
12315
+ setModalContent
12316
+ }
12317
+ ),
12318
+ /* @__PURE__ */ jsxRuntime.jsx(
12319
+ StackedModalTrigger,
12320
+ {
12321
+ type: "add-custom-item",
12322
+ setModalContent
12323
+ }
12324
+ )
12325
+ ] })
12326
+ ] })
12327
+ ] })
12328
+ ] }),
12329
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12330
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
12331
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12332
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
12333
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
12334
+ /* @__PURE__ */ jsxRuntime.jsx("div", {})
12335
+ ] }) }),
12336
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
12337
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
12338
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
12339
+ ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
12340
+ Item,
12341
+ {
12342
+ item,
12343
+ preview,
12344
+ currencyCode
12345
+ },
12346
+ item.id
12347
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
12348
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12349
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12350
+ 'No items found for "',
12351
+ query2,
12352
+ '".'
12353
+ ] })
12354
+ ] }) })
12355
+ ] })
12356
+ ] }),
12357
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12358
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
12359
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
12360
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
12361
+ ui.Text,
12362
+ {
12363
+ size: "small",
12364
+ leading: "compact",
12365
+ className: "text-ui-fg-subtle",
12366
+ children: [
12367
+ itemCount,
12368
+ " ",
12369
+ itemCount === 1 ? "item" : "items"
12370
+ ]
12371
+ }
12372
+ ) }),
12373
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
12374
+ ] })
12375
+ ] }) }),
12376
+ modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
12377
+ CustomItemForm,
12378
+ {
12379
+ orderId: preview.id,
12380
+ currencyCode
12381
+ }
12382
+ ) : null)
12383
+ ]
12384
+ }
12385
+ ) }),
12386
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12387
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12388
+ /* @__PURE__ */ jsxRuntime.jsx(
12389
+ ui.Button,
12390
+ {
12391
+ size: "small",
12392
+ type: "button",
12393
+ onClick: onSubmit,
12394
+ isLoading: isSubmitting,
12395
+ children: "Save"
12396
+ }
12397
+ )
12398
+ ] }) })
12399
+ ] });
12400
+ };
12401
+ const Item = ({ item, preview, currencyCode }) => {
12402
+ if (item.variant_id) {
12403
+ return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
12404
+ }
12405
+ return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
12406
+ };
12407
+ const VariantItem = ({ item, preview, currencyCode }) => {
12408
+ const [editing, setEditing] = React.useState(false);
12409
+ const form = reactHookForm.useForm({
12410
+ defaultValues: {
12411
+ quantity: item.quantity,
12412
+ unit_price: item.unit_price
12413
+ },
12414
+ resolver: zod.zodResolver(variantItemSchema)
12415
+ });
12416
+ const actionId = React.useMemo(() => {
12417
+ var _a, _b;
12418
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
12419
+ }, [item]);
12420
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
12421
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
12422
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
12423
+ const onSubmit = form.handleSubmit(async (data) => {
12424
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
12425
+ setEditing(false);
12426
+ return;
12427
+ }
12428
+ if (!actionId) {
12429
+ await updateOriginalItem(
12430
+ {
12431
+ item_id: item.id,
12432
+ quantity: data.quantity,
12433
+ unit_price: convertNumber(data.unit_price)
12434
+ },
12435
+ {
12436
+ onSuccess: () => {
12437
+ setEditing(false);
12438
+ },
12439
+ onError: (e) => {
12440
+ ui.toast.error(e.message);
12916
12441
  }
12917
- ),
12442
+ }
12443
+ );
12444
+ return;
12445
+ }
12446
+ await updateActionItem(
12447
+ {
12448
+ action_id: actionId,
12449
+ quantity: data.quantity,
12450
+ unit_price: convertNumber(data.unit_price)
12451
+ },
12452
+ {
12453
+ onSuccess: () => {
12454
+ setEditing(false);
12455
+ },
12456
+ onError: (e) => {
12457
+ ui.toast.error(e.message);
12458
+ }
12459
+ }
12460
+ );
12461
+ });
12462
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
12463
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
12464
+ /* @__PURE__ */ jsxRuntime.jsx(
12465
+ Thumbnail,
12466
+ {
12467
+ thumbnail: item.thumbnail,
12468
+ alt: item.product_title ?? void 0
12469
+ }
12470
+ ),
12471
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12472
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12473
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12474
+ /* @__PURE__ */ jsxRuntime.jsxs(
12475
+ ui.Text,
12476
+ {
12477
+ size: "small",
12478
+ leading: "compact",
12479
+ className: "text-ui-fg-subtle",
12480
+ children: [
12481
+ "(",
12482
+ item.variant_title,
12483
+ ")"
12484
+ ]
12485
+ }
12486
+ )
12487
+ ] }),
12918
12488
  /* @__PURE__ */ jsxRuntime.jsx(
12919
- "path",
12920
- {
12921
- 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",
12922
- fill: "#52525B"
12923
- }
12924
- ),
12925
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12926
- "path",
12489
+ ui.Text,
12927
12490
  {
12928
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12929
- stroke: "#A1A1AA",
12930
- strokeWidth: "1.5",
12931
- strokeLinecap: "round",
12932
- strokeLinejoin: "round"
12491
+ size: "small",
12492
+ leading: "compact",
12493
+ className: "text-ui-fg-subtle",
12494
+ children: item.variant_sku
12933
12495
  }
12934
- ) }),
12935
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12936
- "path",
12937
- {
12938
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12939
- stroke: "#A1A1AA",
12940
- strokeWidth: "1.5",
12941
- strokeLinecap: "round",
12942
- strokeLinejoin: "round"
12496
+ )
12497
+ ] })
12498
+ ] }),
12499
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
12500
+ Form$2.Field,
12501
+ {
12502
+ control: form.control,
12503
+ name: "quantity",
12504
+ render: ({ field }) => {
12505
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
12506
+ }
12507
+ }
12508
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
12509
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
12510
+ Form$2.Field,
12511
+ {
12512
+ control: form.control,
12513
+ name: "unit_price",
12514
+ render: ({ field: { onChange, ...field } }) => {
12515
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12516
+ ui.CurrencyInput,
12517
+ {
12518
+ ...field,
12519
+ symbol: getNativeSymbol(currencyCode),
12520
+ code: currencyCode,
12521
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
12522
+ }
12523
+ ) }) });
12524
+ }
12525
+ }
12526
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
12527
+ /* @__PURE__ */ jsxRuntime.jsx(
12528
+ ui.IconButton,
12529
+ {
12530
+ type: "button",
12531
+ size: "small",
12532
+ onClick: editing ? onSubmit : () => {
12533
+ setEditing(true);
12534
+ },
12535
+ disabled: isPending,
12536
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
12537
+ }
12538
+ )
12539
+ ] }) }) });
12540
+ };
12541
+ const variantItemSchema = objectType({
12542
+ quantity: numberType(),
12543
+ unit_price: unionType([numberType(), stringType()])
12544
+ });
12545
+ const CustomItem = ({ item, preview, currencyCode }) => {
12546
+ const [editing, setEditing] = React.useState(false);
12547
+ const { quantity, unit_price, title } = item;
12548
+ const form = reactHookForm.useForm({
12549
+ defaultValues: {
12550
+ title,
12551
+ quantity,
12552
+ unit_price
12553
+ },
12554
+ resolver: zod.zodResolver(customItemSchema)
12555
+ });
12556
+ React.useEffect(() => {
12557
+ form.reset({
12558
+ title,
12559
+ quantity,
12560
+ unit_price
12561
+ });
12562
+ }, [form, title, quantity, unit_price]);
12563
+ const actionId = React.useMemo(() => {
12564
+ var _a, _b;
12565
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
12566
+ }, [item]);
12567
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
12568
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
12569
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
12570
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
12571
+ const onSubmit = form.handleSubmit(async (data) => {
12572
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
12573
+ setEditing(false);
12574
+ return;
12575
+ }
12576
+ if (!actionId) {
12577
+ await updateOriginalItem(
12578
+ {
12579
+ item_id: item.id,
12580
+ quantity: data.quantity,
12581
+ unit_price: convertNumber(data.unit_price)
12582
+ },
12583
+ {
12584
+ onSuccess: () => {
12585
+ setEditing(false);
12586
+ },
12587
+ onError: (e) => {
12588
+ ui.toast.error(e.message);
12943
12589
  }
12944
- ) }),
12945
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12946
- "path",
12947
- {
12948
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12949
- stroke: "#A1A1AA",
12950
- strokeWidth: "1.5",
12951
- strokeLinecap: "round",
12952
- strokeLinejoin: "round"
12590
+ }
12591
+ );
12592
+ return;
12593
+ }
12594
+ if (data.quantity === 0) {
12595
+ await removeActionItem(actionId, {
12596
+ onSuccess: () => {
12597
+ setEditing(false);
12598
+ },
12599
+ onError: (e) => {
12600
+ ui.toast.error(e.message);
12601
+ }
12602
+ });
12603
+ return;
12604
+ }
12605
+ await updateActionItem(
12606
+ {
12607
+ action_id: actionId,
12608
+ quantity: data.quantity,
12609
+ unit_price: convertNumber(data.unit_price)
12610
+ },
12611
+ {
12612
+ onSuccess: () => {
12613
+ setEditing(false);
12614
+ },
12615
+ onError: (e) => {
12616
+ ui.toast.error(e.message);
12617
+ }
12618
+ }
12619
+ );
12620
+ });
12621
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
12622
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12623
+ /* @__PURE__ */ jsxRuntime.jsx(
12624
+ Thumbnail,
12625
+ {
12626
+ thumbnail: item.thumbnail,
12627
+ alt: item.title ?? void 0
12628
+ }
12629
+ ),
12630
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
12631
+ Form$2.Field,
12632
+ {
12633
+ control: form.control,
12634
+ name: "title",
12635
+ render: ({ field }) => {
12636
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
12953
12637
  }
12954
- ) }),
12955
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12956
- "path",
12638
+ }
12639
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
12640
+ ] }),
12641
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
12642
+ Form$2.Field,
12643
+ {
12644
+ control: form.control,
12645
+ name: "quantity",
12646
+ render: ({ field }) => {
12647
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
12648
+ }
12649
+ }
12650
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
12651
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
12652
+ Form$2.Field,
12653
+ {
12654
+ control: form.control,
12655
+ name: "unit_price",
12656
+ render: ({ field: { onChange, ...field } }) => {
12657
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12658
+ ui.CurrencyInput,
12659
+ {
12660
+ ...field,
12661
+ symbol: getNativeSymbol(currencyCode),
12662
+ code: currencyCode,
12663
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
12664
+ }
12665
+ ) }) });
12666
+ }
12667
+ }
12668
+ ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
12669
+ /* @__PURE__ */ jsxRuntime.jsx(
12670
+ ui.IconButton,
12671
+ {
12672
+ type: "button",
12673
+ size: "small",
12674
+ onClick: editing ? onSubmit : () => {
12675
+ setEditing(true);
12676
+ },
12677
+ disabled: isPending,
12678
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
12679
+ }
12680
+ )
12681
+ ] }) }) });
12682
+ };
12683
+ const StackedModalTrigger = ({
12684
+ type,
12685
+ setModalContent
12686
+ }) => {
12687
+ const { setIsOpen } = useStackedModal();
12688
+ const onClick = React.useCallback(() => {
12689
+ setModalContent(type);
12690
+ setIsOpen(STACKED_MODAL_ID, true);
12691
+ }, [setModalContent, setIsOpen, type]);
12692
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
12693
+ };
12694
+ const VARIANT_PREFIX = "items";
12695
+ const LIMIT = 50;
12696
+ const ExistingItemsForm = ({ orderId, items }) => {
12697
+ const { setIsOpen } = useStackedModal();
12698
+ const [rowSelection, setRowSelection] = React.useState(
12699
+ items.reduce((acc, item) => {
12700
+ acc[item.variant_id] = true;
12701
+ return acc;
12702
+ }, {})
12703
+ );
12704
+ React.useEffect(() => {
12705
+ setRowSelection(
12706
+ items.reduce((acc, item) => {
12707
+ if (item.variant_id) {
12708
+ acc[item.variant_id] = true;
12709
+ }
12710
+ return acc;
12711
+ }, {})
12712
+ );
12713
+ }, [items]);
12714
+ const { q, order, offset } = useQueryParams(
12715
+ ["q", "order", "offset"],
12716
+ VARIANT_PREFIX
12717
+ );
12718
+ const { variants, count, isPending, isError, error } = useProductVariants(
12719
+ {
12720
+ q,
12721
+ order,
12722
+ offset: offset ? parseInt(offset) : void 0,
12723
+ limit: LIMIT
12724
+ },
12725
+ {
12726
+ placeholderData: reactQuery.keepPreviousData
12727
+ }
12728
+ );
12729
+ const columns = useColumns();
12730
+ const { mutateAsync } = useDraftOrderAddItems(orderId);
12731
+ const onSubmit = async () => {
12732
+ const ids = Object.keys(rowSelection).filter(
12733
+ (id) => !items.find((i) => i.variant_id === id)
12734
+ );
12735
+ await mutateAsync(
12736
+ {
12737
+ items: ids.map((id) => ({
12738
+ variant_id: id,
12739
+ quantity: 1
12740
+ }))
12741
+ },
12742
+ {
12743
+ onSuccess: () => {
12744
+ setRowSelection({});
12745
+ setIsOpen(STACKED_MODAL_ID, false);
12746
+ },
12747
+ onError: (e) => {
12748
+ ui.toast.error(e.message);
12749
+ }
12750
+ }
12751
+ );
12752
+ };
12753
+ if (isError) {
12754
+ throw error;
12755
+ }
12756
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12757
+ StackedFocusModal.Content,
12758
+ {
12759
+ onOpenAutoFocus: (e) => {
12760
+ e.preventDefault();
12761
+ const searchInput = document.querySelector(
12762
+ "[data-modal-id='modal-search-input']"
12763
+ );
12764
+ if (searchInput) {
12765
+ searchInput.focus();
12766
+ }
12767
+ },
12768
+ children: [
12769
+ /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
12770
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
12771
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
12772
+ ] }),
12773
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
12774
+ DataTable,
12957
12775
  {
12958
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12959
- stroke: "#A1A1AA",
12960
- strokeWidth: "1.5",
12961
- strokeLinecap: "round",
12962
- strokeLinejoin: "round"
12776
+ data: variants,
12777
+ columns,
12778
+ isLoading: isPending,
12779
+ getRowId: (row) => row.id,
12780
+ rowCount: count,
12781
+ prefix: VARIANT_PREFIX,
12782
+ layout: "fill",
12783
+ rowSelection: {
12784
+ state: rowSelection,
12785
+ onRowSelectionChange: setRowSelection,
12786
+ enableRowSelection: (row) => {
12787
+ return !items.find((i) => i.variant_id === row.original.id);
12788
+ }
12789
+ },
12790
+ autoFocusSearch: true
12963
12791
  }
12964
12792
  ) }),
12965
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12966
- "path",
12793
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12794
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12795
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
12796
+ ] }) })
12797
+ ]
12798
+ }
12799
+ );
12800
+ };
12801
+ const columnHelper = ui.createDataTableColumnHelper();
12802
+ const useColumns = () => {
12803
+ return React.useMemo(() => {
12804
+ return [
12805
+ columnHelper.select(),
12806
+ columnHelper.accessor("product.title", {
12807
+ header: "Product",
12808
+ cell: ({ row }) => {
12809
+ var _a, _b, _c;
12810
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
12811
+ /* @__PURE__ */ jsxRuntime.jsx(
12812
+ Thumbnail,
12813
+ {
12814
+ thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
12815
+ alt: (_b = row.original.product) == null ? void 0 : _b.title
12816
+ }
12817
+ ),
12818
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
12819
+ ] });
12820
+ },
12821
+ enableSorting: true
12822
+ }),
12823
+ columnHelper.accessor("title", {
12824
+ header: "Variant",
12825
+ enableSorting: true
12826
+ }),
12827
+ columnHelper.accessor("sku", {
12828
+ header: "SKU",
12829
+ cell: ({ getValue }) => {
12830
+ return getValue() ?? "-";
12831
+ },
12832
+ enableSorting: true
12833
+ }),
12834
+ columnHelper.accessor("updated_at", {
12835
+ header: "Updated",
12836
+ cell: ({ getValue }) => {
12837
+ return /* @__PURE__ */ jsxRuntime.jsx(
12838
+ ui.Tooltip,
12839
+ {
12840
+ content: getFullDate({ date: getValue(), includeTime: true }),
12841
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
12842
+ }
12843
+ );
12844
+ },
12845
+ enableSorting: true,
12846
+ sortAscLabel: "Oldest first",
12847
+ sortDescLabel: "Newest first"
12848
+ }),
12849
+ columnHelper.accessor("created_at", {
12850
+ header: "Created",
12851
+ cell: ({ getValue }) => {
12852
+ return /* @__PURE__ */ jsxRuntime.jsx(
12853
+ ui.Tooltip,
12854
+ {
12855
+ content: getFullDate({ date: getValue(), includeTime: true }),
12856
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
12857
+ }
12858
+ );
12859
+ },
12860
+ enableSorting: true,
12861
+ sortAscLabel: "Oldest first",
12862
+ sortDescLabel: "Newest first"
12863
+ })
12864
+ ];
12865
+ }, []);
12866
+ };
12867
+ const CustomItemForm = ({ orderId, currencyCode }) => {
12868
+ const { setIsOpen } = useStackedModal();
12869
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
12870
+ const form = reactHookForm.useForm({
12871
+ defaultValues: {
12872
+ title: "",
12873
+ quantity: 1,
12874
+ unit_price: ""
12875
+ },
12876
+ resolver: zod.zodResolver(customItemSchema)
12877
+ });
12878
+ const onSubmit = form.handleSubmit(async (data) => {
12879
+ await addItems(
12880
+ {
12881
+ items: [
12967
12882
  {
12968
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12969
- stroke: "#A1A1AA",
12970
- strokeWidth: "1.5",
12971
- strokeLinecap: "round",
12972
- strokeLinejoin: "round"
12883
+ title: data.title,
12884
+ quantity: data.quantity,
12885
+ unit_price: convertNumber(data.unit_price)
12973
12886
  }
12974
- ) }),
12975
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12976
- "path",
12887
+ ]
12888
+ },
12889
+ {
12890
+ onSuccess: () => {
12891
+ setIsOpen(STACKED_MODAL_ID, false);
12892
+ },
12893
+ onError: (e) => {
12894
+ ui.toast.error(e.message);
12895
+ }
12896
+ }
12897
+ );
12898
+ });
12899
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
12900
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12901
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
12902
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12903
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
12904
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
12905
+ ] }),
12906
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12907
+ /* @__PURE__ */ jsxRuntime.jsx(
12908
+ Form$2.Field,
12909
+ {
12910
+ control: form.control,
12911
+ name: "title",
12912
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12913
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12914
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
12915
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
12916
+ ] }),
12917
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12918
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12919
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12920
+ ] })
12921
+ ] }) })
12922
+ }
12923
+ ),
12924
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12925
+ /* @__PURE__ */ jsxRuntime.jsx(
12926
+ Form$2.Field,
12927
+ {
12928
+ control: form.control,
12929
+ name: "unit_price",
12930
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12931
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12932
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
12933
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
12934
+ ] }),
12935
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12936
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12937
+ ui.CurrencyInput,
12938
+ {
12939
+ symbol: getNativeSymbol(currencyCode),
12940
+ code: currencyCode,
12941
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
12942
+ ...field
12943
+ }
12944
+ ) }),
12945
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12946
+ ] })
12947
+ ] }) })
12948
+ }
12949
+ ),
12950
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12951
+ /* @__PURE__ */ jsxRuntime.jsx(
12952
+ Form$2.Field,
12953
+ {
12954
+ control: form.control,
12955
+ name: "quantity",
12956
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12957
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12958
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
12959
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
12960
+ ] }),
12961
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex-1", children: [
12962
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field, className: "w-full" }) }) }),
12963
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12964
+ ] })
12965
+ ] }) })
12966
+ }
12967
+ )
12968
+ ] }) }) }),
12969
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12970
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12971
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
12972
+ ] }) })
12973
+ ] }) }) });
12974
+ };
12975
+ const customItemSchema = objectType({
12976
+ title: stringType().min(1),
12977
+ quantity: numberType(),
12978
+ unit_price: unionType([numberType(), stringType()])
12979
+ });
12980
+ const Email = () => {
12981
+ const { id } = reactRouterDom.useParams();
12982
+ const { order, isPending, isError, error } = useOrder(id, {
12983
+ fields: "+email"
12984
+ });
12985
+ if (isError) {
12986
+ throw error;
12987
+ }
12988
+ const isReady = !isPending && !!order;
12989
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12990
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12991
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
12992
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
12993
+ ] }),
12994
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
12995
+ ] });
12996
+ };
12997
+ const EmailForm = ({ order }) => {
12998
+ const form = reactHookForm.useForm({
12999
+ defaultValues: {
13000
+ email: order.email ?? ""
13001
+ },
13002
+ resolver: zod.zodResolver(schema)
13003
+ });
13004
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
13005
+ const { handleSuccess } = useRouteModal();
13006
+ const onSubmit = form.handleSubmit(async (data) => {
13007
+ await mutateAsync(
13008
+ { email: data.email },
13009
+ {
13010
+ onSuccess: () => {
13011
+ handleSuccess();
13012
+ },
13013
+ onError: (error) => {
13014
+ ui.toast.error(error.message);
13015
+ }
13016
+ }
13017
+ );
13018
+ });
13019
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
13020
+ KeyboundForm,
13021
+ {
13022
+ className: "flex flex-1 flex-col overflow-hidden",
13023
+ onSubmit,
13024
+ children: [
13025
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
13026
+ Form$2.Field,
12977
13027
  {
12978
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12979
- stroke: "#A1A1AA",
12980
- strokeWidth: "1.5",
12981
- strokeLinecap: "round",
12982
- strokeLinejoin: "round"
13028
+ control: form.control,
13029
+ name: "email",
13030
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13031
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
13032
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13033
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13034
+ ] })
12983
13035
  }
12984
13036
  ) }),
12985
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12986
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12987
- "rect",
12988
- {
12989
- width: "12",
12990
- height: "12",
12991
- fill: "white",
12992
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12993
- }
12994
- ) }),
12995
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12996
- "rect",
12997
- {
12998
- width: "12",
12999
- height: "12",
13000
- fill: "white",
13001
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
13002
- }
13003
- ) }),
13004
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13005
- "rect",
13006
- {
13007
- width: "12",
13008
- height: "12",
13009
- fill: "white",
13010
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
13011
- }
13012
- ) }),
13013
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13014
- "rect",
13015
- {
13016
- width: "12",
13017
- height: "12",
13018
- fill: "white",
13019
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
13020
- }
13021
- ) }),
13022
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13023
- "rect",
13024
- {
13025
- width: "12",
13026
- height: "12",
13027
- fill: "white",
13028
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13029
- }
13030
- ) }),
13031
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13032
- "rect",
13033
- {
13034
- width: "12",
13035
- height: "12",
13036
- fill: "white",
13037
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13038
- }
13039
- ) })
13040
- ] })
13037
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13038
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13039
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13040
+ ] }) })
13041
13041
  ]
13042
13042
  }
13043
- );
13043
+ ) });
13044
13044
  };
13045
13045
  const schema = objectType({
13046
- customer_id: stringType().min(1)
13046
+ email: stringType().email()
13047
13047
  });
13048
13048
  const widgetModule = { widgets: [] };
13049
13049
  const routeModule = {
@@ -13065,30 +13065,18 @@ 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"
13075
13071
  },
13076
13072
  {
13077
- Component: Email,
13078
- path: "/draft-orders/:id/email"
13079
- },
13080
- {
13081
- Component: Items,
13082
- path: "/draft-orders/:id/items"
13073
+ Component: Metadata,
13074
+ path: "/draft-orders/:id/metadata"
13083
13075
  },
13084
13076
  {
13085
13077
  Component: Promotions,
13086
13078
  path: "/draft-orders/:id/promotions"
13087
13079
  },
13088
- {
13089
- Component: Metadata,
13090
- path: "/draft-orders/:id/metadata"
13091
- },
13092
13080
  {
13093
13081
  Component: SalesChannel,
13094
13082
  path: "/draft-orders/:id/sales-channel"
@@ -13104,6 +13092,18 @@ const routeModule = {
13104
13092
  {
13105
13093
  Component: TransferOwnership,
13106
13094
  path: "/draft-orders/:id/transfer-ownership"
13095
+ },
13096
+ {
13097
+ Component: BillingAddress,
13098
+ path: "/draft-orders/:id/billing-address"
13099
+ },
13100
+ {
13101
+ Component: Items,
13102
+ path: "/draft-orders/:id/items"
13103
+ },
13104
+ {
13105
+ Component: Email,
13106
+ path: "/draft-orders/:id/email"
13107
13107
  }
13108
13108
  ]
13109
13109
  }