@medusajs/draft-order 2.11.0-preview-20251020120209 → 2.11.0-preview-20251020141229

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.
@@ -9571,27 +9571,6 @@ const ID = () => {
9571
9571
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9572
9572
  ] });
9573
9573
  };
9574
- const CustomItems = () => {
9575
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9576
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9577
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9578
- ] });
9579
- };
9580
- const CustomItemsForm = () => {
9581
- const form = reactHookForm.useForm({
9582
- resolver: zod.zodResolver(schema$5)
9583
- });
9584
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9585
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9586
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9587
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9588
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9589
- ] }) })
9590
- ] }) });
9591
- };
9592
- const schema$5 = objectType({
9593
- email: stringType().email()
9594
- });
9595
9574
  const Email = () => {
9596
9575
  const { id } = reactRouterDom.useParams();
9597
9576
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9614,7 +9593,7 @@ const EmailForm = ({ order }) => {
9614
9593
  defaultValues: {
9615
9594
  email: order.email ?? ""
9616
9595
  },
9617
- resolver: zod.zodResolver(schema$4)
9596
+ resolver: zod.zodResolver(schema$5)
9618
9597
  });
9619
9598
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9620
9599
  const { handleSuccess } = useRouteModal();
@@ -9657,895 +9636,1019 @@ const EmailForm = ({ order }) => {
9657
9636
  }
9658
9637
  ) });
9659
9638
  };
9639
+ const schema$5 = objectType({
9640
+ email: stringType().email()
9641
+ });
9642
+ const CustomItems = () => {
9643
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9644
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9645
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9646
+ ] });
9647
+ };
9648
+ const CustomItemsForm = () => {
9649
+ const form = reactHookForm.useForm({
9650
+ resolver: zod.zodResolver(schema$4)
9651
+ });
9652
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9653
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9654
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9655
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9656
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9657
+ ] }) })
9658
+ ] }) });
9659
+ };
9660
9660
  const schema$4 = objectType({
9661
9661
  email: stringType().email()
9662
9662
  });
9663
- const NumberInput = React.forwardRef(
9664
- ({
9665
- value,
9666
- onChange,
9667
- size = "base",
9668
- min = 0,
9669
- max = 100,
9670
- step = 1,
9671
- className,
9672
- disabled,
9673
- ...props
9674
- }, ref) => {
9675
- const handleChange = (event) => {
9676
- const newValue = event.target.value === "" ? min : Number(event.target.value);
9677
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9678
- onChange(newValue);
9679
- }
9680
- };
9681
- const handleIncrement = () => {
9682
- const newValue = value + step;
9683
- if (max === void 0 || newValue <= max) {
9684
- onChange(newValue);
9685
- }
9686
- };
9687
- const handleDecrement = () => {
9688
- const newValue = value - step;
9689
- if (min === void 0 || newValue >= min) {
9690
- onChange(newValue);
9691
- }
9692
- };
9693
- return /* @__PURE__ */ jsxRuntime.jsxs(
9694
- "div",
9663
+ const BillingAddress = () => {
9664
+ const { id } = reactRouterDom.useParams();
9665
+ const { order, isPending, isError, error } = useOrder(id, {
9666
+ fields: "+billing_address"
9667
+ });
9668
+ if (isError) {
9669
+ throw error;
9670
+ }
9671
+ const isReady = !isPending && !!order;
9672
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9673
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9674
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
9675
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9676
+ ] }),
9677
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9678
+ ] });
9679
+ };
9680
+ const BillingAddressForm = ({ order }) => {
9681
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9682
+ const form = reactHookForm.useForm({
9683
+ defaultValues: {
9684
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9685
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9686
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9687
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9688
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9689
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9690
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9691
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9692
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9693
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9694
+ },
9695
+ resolver: zod.zodResolver(schema$3)
9696
+ });
9697
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9698
+ const { handleSuccess } = useRouteModal();
9699
+ const onSubmit = form.handleSubmit(async (data) => {
9700
+ await mutateAsync(
9701
+ { billing_address: data },
9695
9702
  {
9696
- className: ui.clx(
9697
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9698
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9699
- {
9700
- "h-7": size === "small",
9701
- "h-8": size === "base"
9702
- },
9703
- className
9704
- ),
9705
- children: [
9703
+ onSuccess: () => {
9704
+ handleSuccess();
9705
+ },
9706
+ onError: (error) => {
9707
+ ui.toast.error(error.message);
9708
+ }
9709
+ }
9710
+ );
9711
+ });
9712
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9713
+ KeyboundForm,
9714
+ {
9715
+ className: "flex flex-1 flex-col overflow-hidden",
9716
+ onSubmit,
9717
+ children: [
9718
+ /* @__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: [
9706
9719
  /* @__PURE__ */ jsxRuntime.jsx(
9707
- "input",
9720
+ Form$2.Field,
9708
9721
  {
9709
- ref,
9710
- type: "number",
9711
- value,
9712
- onChange: handleChange,
9713
- min,
9714
- max,
9715
- step,
9716
- className: ui.clx(
9717
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9718
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9719
- "placeholder:text-ui-fg-muted"
9720
- ),
9721
- ...props
9722
+ control: form.control,
9723
+ name: "country_code",
9724
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9725
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
9726
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
9727
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9728
+ ] })
9722
9729
  }
9723
9730
  ),
9724
- /* @__PURE__ */ jsxRuntime.jsxs(
9725
- "button",
9731
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9732
+ /* @__PURE__ */ jsxRuntime.jsx(
9733
+ Form$2.Field,
9734
+ {
9735
+ control: form.control,
9736
+ name: "first_name",
9737
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9738
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
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: "last_name",
9749
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9750
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
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(
9758
+ Form$2.Field,
9726
9759
  {
9727
- className: ui.clx(
9728
- "flex items-center justify-center outline-none transition-fg",
9729
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9730
- "focus:bg-ui-bg-field-component-hover",
9731
- "hover:bg-ui-bg-field-component-hover",
9732
- {
9733
- "size-7": size === "small",
9734
- "size-8": size === "base"
9735
- }
9736
- ),
9737
- type: "button",
9738
- onClick: handleDecrement,
9739
- disabled: min !== void 0 && value <= min || disabled,
9740
- children: [
9741
- /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
9742
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9743
- ]
9760
+ control: form.control,
9761
+ name: "company",
9762
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9763
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
9764
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9765
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9766
+ ] })
9744
9767
  }
9745
9768
  ),
9746
- /* @__PURE__ */ jsxRuntime.jsxs(
9747
- "button",
9769
+ /* @__PURE__ */ jsxRuntime.jsx(
9770
+ Form$2.Field,
9748
9771
  {
9749
- className: ui.clx(
9750
- "flex items-center justify-center outline-none transition-fg",
9751
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9752
- "focus:bg-ui-bg-field-hover",
9753
- "hover:bg-ui-bg-field-hover",
9754
- {
9755
- "size-7": size === "small",
9756
- "size-8": size === "base"
9757
- }
9758
- ),
9759
- type: "button",
9760
- onClick: handleIncrement,
9761
- disabled: max !== void 0 && value >= max || disabled,
9762
- children: [
9763
- /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
9764
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9765
- ]
9772
+ control: form.control,
9773
+ name: "address_1",
9774
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9775
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
9776
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9777
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9778
+ ] })
9766
9779
  }
9767
- )
9768
- ]
9769
- }
9770
- );
9771
- }
9772
- );
9773
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9774
- const productVariantsQueryKeys = {
9775
- list: (query2) => [
9776
- PRODUCT_VARIANTS_QUERY_KEY,
9777
- query2 ? query2 : void 0
9778
- ]
9779
- };
9780
- const useProductVariants = (query2, options) => {
9781
- const { data, ...rest } = reactQuery.useQuery({
9782
- queryKey: productVariantsQueryKeys.list(query2),
9783
- queryFn: async () => await sdk.admin.productVariant.list(query2),
9784
- ...options
9785
- });
9786
- return { ...data, ...rest };
9787
- };
9788
- const useCancelOrderEdit = ({ preview }) => {
9789
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9790
- const onCancel = React.useCallback(async () => {
9791
- if (!preview) {
9792
- return true;
9780
+ ),
9781
+ /* @__PURE__ */ jsxRuntime.jsx(
9782
+ Form$2.Field,
9783
+ {
9784
+ control: form.control,
9785
+ name: "address_2",
9786
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9787
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9788
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9789
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9790
+ ] })
9791
+ }
9792
+ ),
9793
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9794
+ /* @__PURE__ */ jsxRuntime.jsx(
9795
+ Form$2.Field,
9796
+ {
9797
+ control: form.control,
9798
+ name: "postal_code",
9799
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9800
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
9801
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9802
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9803
+ ] })
9804
+ }
9805
+ ),
9806
+ /* @__PURE__ */ jsxRuntime.jsx(
9807
+ Form$2.Field,
9808
+ {
9809
+ control: form.control,
9810
+ name: "city",
9811
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9812
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
9813
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9814
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9815
+ ] })
9816
+ }
9817
+ )
9818
+ ] }),
9819
+ /* @__PURE__ */ jsxRuntime.jsx(
9820
+ Form$2.Field,
9821
+ {
9822
+ control: form.control,
9823
+ name: "province",
9824
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9825
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9826
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9827
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9828
+ ] })
9829
+ }
9830
+ ),
9831
+ /* @__PURE__ */ jsxRuntime.jsx(
9832
+ Form$2.Field,
9833
+ {
9834
+ control: form.control,
9835
+ name: "phone",
9836
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9837
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
9838
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9839
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9840
+ ] })
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" }) }),
9846
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9847
+ ] }) })
9848
+ ]
9793
9849
  }
9794
- let res = false;
9795
- await cancelOrderEdit(void 0, {
9796
- onError: (e) => {
9797
- ui.toast.error(e.message);
9798
- },
9799
- onSuccess: () => {
9800
- res = true;
9801
- }
9802
- });
9803
- return res;
9804
- }, [preview, cancelOrderEdit]);
9805
- return { onCancel };
9850
+ ) });
9806
9851
  };
9807
- let IS_REQUEST_RUNNING = false;
9808
- const useInitiateOrderEdit = ({
9809
- preview
9810
- }) => {
9811
- const navigate = reactRouterDom.useNavigate();
9812
- const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
9813
- React.useEffect(() => {
9814
- async function run() {
9815
- if (IS_REQUEST_RUNNING || !preview) {
9816
- return;
9817
- }
9818
- if (preview.order_change) {
9819
- return;
9852
+ const schema$3 = addressSchema;
9853
+ const InlineTip = React.forwardRef(
9854
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
9855
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9856
+ return /* @__PURE__ */ jsxRuntime.jsxs(
9857
+ "div",
9858
+ {
9859
+ ref,
9860
+ className: ui.clx(
9861
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9862
+ className
9863
+ ),
9864
+ ...props,
9865
+ children: [
9866
+ /* @__PURE__ */ jsxRuntime.jsx(
9867
+ "div",
9868
+ {
9869
+ role: "presentation",
9870
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9871
+ "bg-ui-tag-orange-icon": variant === "warning"
9872
+ })
9873
+ }
9874
+ ),
9875
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
9876
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9877
+ labelValue,
9878
+ ":"
9879
+ ] }),
9880
+ " ",
9881
+ children
9882
+ ] })
9883
+ ]
9820
9884
  }
9821
- IS_REQUEST_RUNNING = true;
9822
- await mutateAsync(void 0, {
9823
- onError: (e) => {
9824
- ui.toast.error(e.message);
9825
- navigate(`/draft-orders/${preview.id}`, { replace: true });
9826
- return;
9827
- }
9828
- });
9829
- IS_REQUEST_RUNNING = false;
9830
- }
9831
- run();
9832
- }, [preview, navigate, mutateAsync]);
9833
- };
9834
- function convertNumber(value) {
9835
- return typeof value === "string" ? Number(value.replace(",", ".")) : value;
9836
- }
9837
- const STACKED_MODAL_ID = "items_stacked_modal";
9838
- const Items = () => {
9885
+ );
9886
+ }
9887
+ );
9888
+ InlineTip.displayName = "InlineTip";
9889
+ const MetadataFieldSchema = objectType({
9890
+ key: stringType(),
9891
+ disabled: booleanType().optional(),
9892
+ value: anyType()
9893
+ });
9894
+ const MetadataSchema = objectType({
9895
+ metadata: arrayType(MetadataFieldSchema)
9896
+ });
9897
+ const Metadata = () => {
9839
9898
  const { id } = reactRouterDom.useParams();
9840
- const {
9841
- order: preview,
9842
- isPending: isPreviewPending,
9843
- isError: isPreviewError,
9844
- error: previewError
9845
- } = useOrderPreview(id, void 0, {
9846
- placeholderData: reactQuery.keepPreviousData
9899
+ const { order, isPending, isError, error } = useOrder(id, {
9900
+ fields: "metadata"
9847
9901
  });
9848
- useInitiateOrderEdit({ preview });
9849
- const { draft_order, isPending, isError, error } = useDraftOrder(
9850
- id,
9851
- {
9852
- fields: "currency_code"
9853
- },
9854
- {
9855
- enabled: !!id
9856
- }
9857
- );
9858
- const { onCancel } = useCancelOrderEdit({ preview });
9859
9902
  if (isError) {
9860
9903
  throw error;
9861
9904
  }
9862
- if (isPreviewError) {
9863
- throw previewError;
9864
- }
9865
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
9866
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
9867
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
9868
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
9869
- ] }) });
9905
+ const isReady = !isPending && !!order;
9906
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9907
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9908
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
9909
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9910
+ ] }),
9911
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9912
+ ] });
9870
9913
  };
9871
- const ItemsForm = ({ preview, currencyCode }) => {
9872
- var _a;
9873
- const [isSubmitting, setIsSubmitting] = React.useState(false);
9874
- const [modalContent, setModalContent] = React.useState(
9875
- null
9876
- );
9914
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9915
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9916
+ const MetadataForm = ({ orderId, metadata }) => {
9877
9917
  const { handleSuccess } = useRouteModal();
9878
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
9879
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
9880
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
9881
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
9882
- const matches = React.useMemo(() => {
9883
- return matchSorter.matchSorter(preview.items, query2, {
9884
- keys: ["product_title", "variant_title", "variant_sku", "title"]
9885
- });
9886
- }, [preview.items, query2]);
9887
- const onSubmit = async () => {
9888
- setIsSubmitting(true);
9889
- let requestSucceeded = false;
9890
- await requestOrderEdit(void 0, {
9891
- onError: (e) => {
9892
- ui.toast.error(`Failed to request order edit: ${e.message}`);
9918
+ const hasUneditableRows = getHasUneditableRows(metadata);
9919
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9920
+ const form = reactHookForm.useForm({
9921
+ defaultValues: {
9922
+ metadata: getDefaultValues(metadata)
9923
+ },
9924
+ resolver: zod.zodResolver(MetadataSchema)
9925
+ });
9926
+ const handleSubmit = form.handleSubmit(async (data) => {
9927
+ const parsedData = parseValues(data);
9928
+ await mutateAsync(
9929
+ {
9930
+ metadata: parsedData
9893
9931
  },
9894
- onSuccess: () => {
9895
- requestSucceeded = true;
9932
+ {
9933
+ onSuccess: () => {
9934
+ ui.toast.success("Metadata updated");
9935
+ handleSuccess();
9936
+ },
9937
+ onError: (error) => {
9938
+ ui.toast.error(error.message);
9939
+ }
9896
9940
  }
9897
- });
9898
- if (!requestSucceeded) {
9899
- setIsSubmitting(false);
9900
- return;
9941
+ );
9942
+ });
9943
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
9944
+ control: form.control,
9945
+ name: "metadata"
9946
+ });
9947
+ function deleteRow(index) {
9948
+ remove(index);
9949
+ if (fields.length === 1) {
9950
+ insert(0, {
9951
+ key: "",
9952
+ value: "",
9953
+ disabled: false
9954
+ });
9901
9955
  }
9902
- await confirmOrderEdit(void 0, {
9903
- onError: (e) => {
9904
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
9905
- },
9906
- onSuccess: () => {
9907
- handleSuccess();
9908
- },
9909
- onSettled: () => {
9910
- setIsSubmitting(false);
9911
- }
9956
+ }
9957
+ function insertRow(index, position) {
9958
+ insert(index + (position === "above" ? 0 : 1), {
9959
+ key: "",
9960
+ value: "",
9961
+ disabled: false
9912
9962
  });
9913
- };
9914
- const onKeyDown = React.useCallback(
9915
- (e) => {
9916
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
9917
- if (modalContent || isSubmitting) {
9918
- return;
9919
- }
9920
- onSubmit();
9921
- }
9922
- },
9923
- [modalContent, isSubmitting, onSubmit]
9924
- );
9925
- React.useEffect(() => {
9926
- document.addEventListener("keydown", onKeyDown);
9927
- return () => {
9928
- document.removeEventListener("keydown", onKeyDown);
9929
- };
9930
- }, [onKeyDown]);
9931
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
9932
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
9933
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
9934
- StackedFocusModal,
9935
- {
9936
- id: STACKED_MODAL_ID,
9937
- onOpenChangeCallback: (open) => {
9938
- if (!open) {
9939
- setModalContent(null);
9940
- }
9941
- },
9942
- children: [
9943
- /* @__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: [
9944
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
9945
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
9946
- /* @__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" }) })
9963
+ }
9964
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9965
+ KeyboundForm,
9966
+ {
9967
+ onSubmit: handleSubmit,
9968
+ className: "flex flex-1 flex-col overflow-hidden",
9969
+ children: [
9970
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9971
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9972
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9973
+ /* @__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" }) }),
9974
+ /* @__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" }) })
9947
9975
  ] }),
9948
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
9949
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
9950
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
9951
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
9952
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
9953
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
9954
- ] }),
9955
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
9956
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
9957
- ui.Input,
9958
- {
9959
- type: "search",
9960
- placeholder: "Search items",
9961
- value: searchValue,
9962
- onChange: (e) => onSearchValueChange(e.target.value)
9963
- }
9964
- ) }),
9965
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
9966
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
9967
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
9976
+ fields.map((field, index) => {
9977
+ const isDisabled = field.disabled || false;
9978
+ let placeholder = "-";
9979
+ if (typeof field.value === "object") {
9980
+ placeholder = "{ ... }";
9981
+ }
9982
+ if (Array.isArray(field.value)) {
9983
+ placeholder = "[ ... ]";
9984
+ }
9985
+ return /* @__PURE__ */ jsxRuntime.jsx(
9986
+ ConditionalTooltip,
9987
+ {
9988
+ showTooltip: isDisabled,
9989
+ content: "This row is disabled because it contains non-primitive data.",
9990
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
9991
+ /* @__PURE__ */ jsxRuntime.jsxs(
9992
+ "div",
9993
+ {
9994
+ className: ui.clx("grid grid-cols-2 divide-x", {
9995
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
9996
+ }),
9997
+ children: [
9998
+ /* @__PURE__ */ jsxRuntime.jsx(
9999
+ Form$2.Field,
10000
+ {
10001
+ control: form.control,
10002
+ name: `metadata.${index}.key`,
10003
+ render: ({ field: field2 }) => {
10004
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10005
+ GridInput,
10006
+ {
10007
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10008
+ ...field2,
10009
+ disabled: isDisabled,
10010
+ placeholder: "Key"
10011
+ }
10012
+ ) }) });
10013
+ }
10014
+ }
10015
+ ),
10016
+ /* @__PURE__ */ jsxRuntime.jsx(
10017
+ Form$2.Field,
10018
+ {
10019
+ control: form.control,
10020
+ name: `metadata.${index}.value`,
10021
+ render: ({ field: { value, ...field2 } }) => {
10022
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10023
+ GridInput,
10024
+ {
10025
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
10026
+ ...field2,
10027
+ value: isDisabled ? placeholder : value,
10028
+ disabled: isDisabled,
10029
+ placeholder: "Value"
10030
+ }
10031
+ ) }) });
10032
+ }
10033
+ }
10034
+ )
10035
+ ]
10036
+ }
10037
+ ),
10038
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
9968
10039
  /* @__PURE__ */ jsxRuntime.jsx(
9969
- StackedModalTrigger$1,
10040
+ ui.DropdownMenu.Trigger,
9970
10041
  {
9971
- type: "add-items",
9972
- setModalContent
10042
+ className: ui.clx(
10043
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10044
+ {
10045
+ hidden: isDisabled
10046
+ }
10047
+ ),
10048
+ disabled: isDisabled,
10049
+ asChild: true,
10050
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
9973
10051
  }
9974
10052
  ),
9975
- /* @__PURE__ */ jsxRuntime.jsx(
9976
- StackedModalTrigger$1,
9977
- {
9978
- type: "add-custom-item",
9979
- setModalContent
9980
- }
9981
- )
10053
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10054
+ /* @__PURE__ */ jsxRuntime.jsxs(
10055
+ ui.DropdownMenu.Item,
10056
+ {
10057
+ className: "gap-x-2",
10058
+ onClick: () => insertRow(index, "above"),
10059
+ children: [
10060
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
10061
+ "Insert row above"
10062
+ ]
10063
+ }
10064
+ ),
10065
+ /* @__PURE__ */ jsxRuntime.jsxs(
10066
+ ui.DropdownMenu.Item,
10067
+ {
10068
+ className: "gap-x-2",
10069
+ onClick: () => insertRow(index, "below"),
10070
+ children: [
10071
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
10072
+ "Insert row below"
10073
+ ]
10074
+ }
10075
+ ),
10076
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
10077
+ /* @__PURE__ */ jsxRuntime.jsxs(
10078
+ ui.DropdownMenu.Item,
10079
+ {
10080
+ className: "gap-x-2",
10081
+ onClick: () => deleteRow(index),
10082
+ children: [
10083
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
10084
+ "Delete row"
10085
+ ]
10086
+ }
10087
+ )
10088
+ ] })
9982
10089
  ] })
9983
10090
  ] })
9984
- ] })
9985
- ] }),
9986
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
9987
- /* @__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: [
9988
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
9989
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
9990
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
9991
- /* @__PURE__ */ jsxRuntime.jsx("div", {})
9992
- ] }) }),
9993
- /* @__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: [
9994
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
9995
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
9996
- ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
9997
- Item,
9998
- {
9999
- item,
10000
- preview,
10001
- currencyCode
10002
- },
10003
- item.id
10004
- )) : /* @__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: [
10005
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10006
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
10007
- 'No items found for "',
10008
- query2,
10009
- '".'
10010
- ] })
10011
- ] }) })
10012
- ] })
10013
- ] }),
10014
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10015
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10016
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10017
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
10018
- ui.Text,
10019
- {
10020
- size: "small",
10021
- leading: "compact",
10022
- className: "text-ui-fg-subtle",
10023
- children: [
10024
- itemCount,
10025
- " ",
10026
- itemCount === 1 ? "item" : "items"
10027
- ]
10028
- }
10029
- ) }),
10030
- /* @__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) }) })
10031
- ] })
10032
- ] }) }),
10033
- modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
10034
- CustomItemForm,
10035
- {
10036
- orderId: preview.id,
10037
- currencyCode
10038
- }
10039
- ) : null)
10040
- ]
10041
- }
10042
- ) }),
10043
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10044
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10045
- /* @__PURE__ */ jsxRuntime.jsx(
10046
- ui.Button,
10047
- {
10048
- size: "small",
10049
- type: "button",
10050
- onClick: onSubmit,
10051
- isLoading: isSubmitting,
10052
- children: "Save"
10053
- }
10091
+ },
10092
+ field.id
10093
+ );
10094
+ })
10095
+ ] }),
10096
+ 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." })
10097
+ ] }),
10098
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10099
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10100
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10101
+ ] }) })
10102
+ ]
10103
+ }
10104
+ ) });
10105
+ };
10106
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
10107
+ return /* @__PURE__ */ jsxRuntime.jsx(
10108
+ "input",
10109
+ {
10110
+ ref,
10111
+ ...props,
10112
+ autoComplete: "off",
10113
+ className: ui.clx(
10114
+ "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",
10115
+ className
10054
10116
  )
10117
+ }
10118
+ );
10119
+ });
10120
+ GridInput.displayName = "MetadataForm.GridInput";
10121
+ const PlaceholderInner = () => {
10122
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10123
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10124
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10125
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
10126
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
10055
10127
  ] }) })
10056
10128
  ] });
10057
10129
  };
10058
- const Item = ({ item, preview, currencyCode }) => {
10059
- if (item.variant_id) {
10060
- return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
10130
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
10131
+ function getDefaultValues(metadata) {
10132
+ if (!metadata || !Object.keys(metadata).length) {
10133
+ return [
10134
+ {
10135
+ key: "",
10136
+ value: "",
10137
+ disabled: false
10138
+ }
10139
+ ];
10061
10140
  }
10062
- return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
10063
- };
10064
- const VariantItem = ({ item, preview, currencyCode }) => {
10065
- const [editing, setEditing] = React.useState(false);
10066
- const form = reactHookForm.useForm({
10067
- defaultValues: {
10068
- quantity: item.quantity,
10069
- unit_price: item.unit_price
10070
- },
10071
- resolver: zod.zodResolver(variantItemSchema)
10141
+ return Object.entries(metadata).map(([key, value]) => {
10142
+ if (!EDITABLE_TYPES.includes(typeof value)) {
10143
+ return {
10144
+ key,
10145
+ value,
10146
+ disabled: true
10147
+ };
10148
+ }
10149
+ let stringValue = value;
10150
+ if (typeof value !== "string") {
10151
+ stringValue = JSON.stringify(value);
10152
+ }
10153
+ return {
10154
+ key,
10155
+ value: stringValue,
10156
+ original_key: key
10157
+ };
10072
10158
  });
10073
- const actionId = React.useMemo(() => {
10074
- var _a, _b;
10075
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10076
- }, [item]);
10077
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10078
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10079
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10080
- const onSubmit = form.handleSubmit(async (data) => {
10081
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10082
- setEditing(false);
10159
+ }
10160
+ function parseValues(values) {
10161
+ const metadata = values.metadata;
10162
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10163
+ if (isEmpty) {
10164
+ return null;
10165
+ }
10166
+ const update = {};
10167
+ metadata.forEach((field) => {
10168
+ let key = field.key;
10169
+ let value = field.value;
10170
+ const disabled = field.disabled;
10171
+ if (!key || !value) {
10083
10172
  return;
10084
10173
  }
10085
- if (!actionId) {
10086
- await updateOriginalItem(
10087
- {
10088
- item_id: item.id,
10089
- quantity: data.quantity,
10090
- unit_price: convertNumber(data.unit_price)
10091
- },
10092
- {
10093
- onSuccess: () => {
10094
- setEditing(false);
10095
- },
10096
- onError: (e) => {
10097
- ui.toast.error(e.message);
10098
- }
10099
- }
10100
- );
10174
+ if (disabled) {
10175
+ update[key] = value;
10101
10176
  return;
10102
10177
  }
10103
- await updateActionItem(
10104
- {
10105
- action_id: actionId,
10106
- quantity: data.quantity,
10107
- unit_price: convertNumber(data.unit_price)
10108
- },
10109
- {
10110
- onSuccess: () => {
10111
- setEditing(false);
10112
- },
10113
- onError: (e) => {
10114
- ui.toast.error(e.message);
10115
- }
10178
+ key = key.trim();
10179
+ value = value.trim();
10180
+ if (value === "true") {
10181
+ update[key] = true;
10182
+ } else if (value === "false") {
10183
+ update[key] = false;
10184
+ } else {
10185
+ const parsedNumber = parseFloat(value);
10186
+ if (!isNaN(parsedNumber)) {
10187
+ update[key] = parsedNumber;
10188
+ } else {
10189
+ update[key] = value;
10116
10190
  }
10117
- );
10191
+ }
10118
10192
  });
10119
- 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: [
10120
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10121
- /* @__PURE__ */ jsxRuntime.jsx(
10122
- Thumbnail,
10123
- {
10124
- thumbnail: item.thumbnail,
10125
- alt: item.product_title ?? void 0
10126
- }
10127
- ),
10128
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10129
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10130
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10131
- /* @__PURE__ */ jsxRuntime.jsxs(
10132
- ui.Text,
10133
- {
10134
- size: "small",
10135
- leading: "compact",
10136
- className: "text-ui-fg-subtle",
10137
- children: [
10138
- "(",
10139
- item.variant_title,
10140
- ")"
10141
- ]
10142
- }
10143
- )
10144
- ] }),
10145
- /* @__PURE__ */ jsxRuntime.jsx(
10146
- ui.Text,
10147
- {
10148
- size: "small",
10149
- leading: "compact",
10150
- className: "text-ui-fg-subtle",
10151
- children: item.variant_sku
10152
- }
10153
- )
10154
- ] })
10155
- ] }),
10156
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10157
- Form$2.Field,
10158
- {
10159
- control: form.control,
10160
- name: "quantity",
10161
- render: ({ field }) => {
10162
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10163
- }
10193
+ return update;
10194
+ }
10195
+ function getHasUneditableRows(metadata) {
10196
+ if (!metadata) {
10197
+ return false;
10198
+ }
10199
+ return Object.values(metadata).some(
10200
+ (value) => !EDITABLE_TYPES.includes(typeof value)
10201
+ );
10202
+ }
10203
+ const NumberInput = React.forwardRef(
10204
+ ({
10205
+ value,
10206
+ onChange,
10207
+ size = "base",
10208
+ min = 0,
10209
+ max = 100,
10210
+ step = 1,
10211
+ className,
10212
+ disabled,
10213
+ ...props
10214
+ }, ref) => {
10215
+ const handleChange = (event) => {
10216
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
10217
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10218
+ onChange(newValue);
10164
10219
  }
10165
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10166
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10167
- Form$2.Field,
10168
- {
10169
- control: form.control,
10170
- name: "unit_price",
10171
- render: ({ field: { onChange, ...field } }) => {
10172
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10173
- ui.CurrencyInput,
10174
- {
10175
- ...field,
10176
- symbol: getNativeSymbol(currencyCode),
10177
- code: currencyCode,
10178
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10179
- }
10180
- ) }) });
10181
- }
10220
+ };
10221
+ const handleIncrement = () => {
10222
+ const newValue = value + step;
10223
+ if (max === void 0 || newValue <= max) {
10224
+ onChange(newValue);
10182
10225
  }
10183
- ) }) : /* @__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) }) }),
10184
- /* @__PURE__ */ jsxRuntime.jsx(
10185
- ui.IconButton,
10226
+ };
10227
+ const handleDecrement = () => {
10228
+ const newValue = value - step;
10229
+ if (min === void 0 || newValue >= min) {
10230
+ onChange(newValue);
10231
+ }
10232
+ };
10233
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10234
+ "div",
10186
10235
  {
10187
- type: "button",
10188
- size: "small",
10189
- onClick: editing ? onSubmit : () => {
10190
- setEditing(true);
10191
- },
10192
- disabled: isPending,
10193
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10236
+ className: ui.clx(
10237
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10238
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10239
+ {
10240
+ "h-7": size === "small",
10241
+ "h-8": size === "base"
10242
+ },
10243
+ className
10244
+ ),
10245
+ children: [
10246
+ /* @__PURE__ */ jsxRuntime.jsx(
10247
+ "input",
10248
+ {
10249
+ ref,
10250
+ type: "number",
10251
+ value,
10252
+ onChange: handleChange,
10253
+ min,
10254
+ max,
10255
+ step,
10256
+ className: ui.clx(
10257
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10258
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10259
+ "placeholder:text-ui-fg-muted"
10260
+ ),
10261
+ ...props
10262
+ }
10263
+ ),
10264
+ /* @__PURE__ */ jsxRuntime.jsxs(
10265
+ "button",
10266
+ {
10267
+ className: ui.clx(
10268
+ "flex items-center justify-center outline-none transition-fg",
10269
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10270
+ "focus:bg-ui-bg-field-component-hover",
10271
+ "hover:bg-ui-bg-field-component-hover",
10272
+ {
10273
+ "size-7": size === "small",
10274
+ "size-8": size === "base"
10275
+ }
10276
+ ),
10277
+ type: "button",
10278
+ onClick: handleDecrement,
10279
+ disabled: min !== void 0 && value <= min || disabled,
10280
+ children: [
10281
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
10282
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10283
+ ]
10284
+ }
10285
+ ),
10286
+ /* @__PURE__ */ jsxRuntime.jsxs(
10287
+ "button",
10288
+ {
10289
+ className: ui.clx(
10290
+ "flex items-center justify-center outline-none transition-fg",
10291
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10292
+ "focus:bg-ui-bg-field-hover",
10293
+ "hover:bg-ui-bg-field-hover",
10294
+ {
10295
+ "size-7": size === "small",
10296
+ "size-8": size === "base"
10297
+ }
10298
+ ),
10299
+ type: "button",
10300
+ onClick: handleIncrement,
10301
+ disabled: max !== void 0 && value >= max || disabled,
10302
+ children: [
10303
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
10304
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
10305
+ ]
10306
+ }
10307
+ )
10308
+ ]
10194
10309
  }
10195
- )
10196
- ] }) }) });
10310
+ );
10311
+ }
10312
+ );
10313
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
10314
+ const productVariantsQueryKeys = {
10315
+ list: (query2) => [
10316
+ PRODUCT_VARIANTS_QUERY_KEY,
10317
+ query2 ? query2 : void 0
10318
+ ]
10197
10319
  };
10198
- const variantItemSchema = objectType({
10199
- quantity: numberType(),
10200
- unit_price: unionType([numberType(), stringType()])
10201
- });
10202
- const CustomItem = ({ item, preview, currencyCode }) => {
10203
- const [editing, setEditing] = React.useState(false);
10204
- const { quantity, unit_price, title } = item;
10205
- const form = reactHookForm.useForm({
10206
- defaultValues: {
10207
- title,
10208
- quantity,
10209
- unit_price
10210
- },
10211
- resolver: zod.zodResolver(customItemSchema)
10320
+ const useProductVariants = (query2, options) => {
10321
+ const { data, ...rest } = reactQuery.useQuery({
10322
+ queryKey: productVariantsQueryKeys.list(query2),
10323
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
10324
+ ...options
10212
10325
  });
10213
- React.useEffect(() => {
10214
- form.reset({
10215
- title,
10216
- quantity,
10217
- unit_price
10218
- });
10219
- }, [form, title, quantity, unit_price]);
10220
- const actionId = React.useMemo(() => {
10221
- var _a, _b;
10222
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10223
- }, [item]);
10224
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10225
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10226
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10227
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10228
- const onSubmit = form.handleSubmit(async (data) => {
10229
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10230
- setEditing(false);
10231
- return;
10232
- }
10233
- if (!actionId) {
10234
- await updateOriginalItem(
10235
- {
10236
- item_id: item.id,
10237
- quantity: data.quantity,
10238
- unit_price: convertNumber(data.unit_price)
10239
- },
10240
- {
10241
- onSuccess: () => {
10242
- setEditing(false);
10243
- },
10244
- onError: (e) => {
10245
- ui.toast.error(e.message);
10246
- }
10247
- }
10248
- );
10249
- return;
10326
+ return { ...data, ...rest };
10327
+ };
10328
+ const useCancelOrderEdit = ({ preview }) => {
10329
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
10330
+ const onCancel = React.useCallback(async () => {
10331
+ if (!preview) {
10332
+ return true;
10250
10333
  }
10251
- if (data.quantity === 0) {
10252
- await removeActionItem(actionId, {
10253
- onSuccess: () => {
10254
- setEditing(false);
10255
- },
10334
+ let res = false;
10335
+ await cancelOrderEdit(void 0, {
10336
+ onError: (e) => {
10337
+ ui.toast.error(e.message);
10338
+ },
10339
+ onSuccess: () => {
10340
+ res = true;
10341
+ }
10342
+ });
10343
+ return res;
10344
+ }, [preview, cancelOrderEdit]);
10345
+ return { onCancel };
10346
+ };
10347
+ let IS_REQUEST_RUNNING = false;
10348
+ const useInitiateOrderEdit = ({
10349
+ preview
10350
+ }) => {
10351
+ const navigate = reactRouterDom.useNavigate();
10352
+ const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10353
+ React.useEffect(() => {
10354
+ async function run() {
10355
+ if (IS_REQUEST_RUNNING || !preview) {
10356
+ return;
10357
+ }
10358
+ if (preview.order_change) {
10359
+ return;
10360
+ }
10361
+ IS_REQUEST_RUNNING = true;
10362
+ await mutateAsync(void 0, {
10256
10363
  onError: (e) => {
10257
10364
  ui.toast.error(e.message);
10365
+ navigate(`/draft-orders/${preview.id}`, { replace: true });
10366
+ return;
10258
10367
  }
10259
10368
  });
10260
- return;
10369
+ IS_REQUEST_RUNNING = false;
10261
10370
  }
10262
- await updateActionItem(
10263
- {
10264
- action_id: actionId,
10265
- quantity: data.quantity,
10266
- unit_price: convertNumber(data.unit_price)
10267
- },
10268
- {
10269
- onSuccess: () => {
10270
- setEditing(false);
10271
- },
10272
- onError: (e) => {
10273
- ui.toast.error(e.message);
10274
- }
10275
- }
10276
- );
10371
+ run();
10372
+ }, [preview, navigate, mutateAsync]);
10373
+ };
10374
+ function convertNumber(value) {
10375
+ return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10376
+ }
10377
+ const STACKED_MODAL_ID = "items_stacked_modal";
10378
+ const Items = () => {
10379
+ const { id } = reactRouterDom.useParams();
10380
+ const {
10381
+ order: preview,
10382
+ isPending: isPreviewPending,
10383
+ isError: isPreviewError,
10384
+ error: previewError
10385
+ } = useOrderPreview(id, void 0, {
10386
+ placeholderData: reactQuery.keepPreviousData
10277
10387
  });
10278
- 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: [
10279
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
10280
- /* @__PURE__ */ jsxRuntime.jsx(
10281
- Thumbnail,
10282
- {
10283
- thumbnail: item.thumbnail,
10284
- alt: item.title ?? void 0
10285
- }
10286
- ),
10287
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10288
- Form$2.Field,
10289
- {
10290
- control: form.control,
10291
- name: "title",
10292
- render: ({ field }) => {
10293
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
10294
- }
10295
- }
10296
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
10297
- ] }),
10298
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10299
- Form$2.Field,
10300
- {
10301
- control: form.control,
10302
- name: "quantity",
10303
- render: ({ field }) => {
10304
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10305
- }
10306
- }
10307
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
10308
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10309
- Form$2.Field,
10310
- {
10311
- control: form.control,
10312
- name: "unit_price",
10313
- render: ({ field: { onChange, ...field } }) => {
10314
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10315
- ui.CurrencyInput,
10316
- {
10317
- ...field,
10318
- symbol: getNativeSymbol(currencyCode),
10319
- code: currencyCode,
10320
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10321
- }
10322
- ) }) });
10323
- }
10324
- }
10325
- ) : /* @__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) }) }),
10326
- /* @__PURE__ */ jsxRuntime.jsx(
10327
- ui.IconButton,
10328
- {
10329
- type: "button",
10330
- size: "small",
10331
- onClick: editing ? onSubmit : () => {
10332
- setEditing(true);
10333
- },
10334
- disabled: isPending,
10335
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10336
- }
10337
- )
10338
- ] }) }) });
10339
- };
10340
- const StackedModalTrigger$1 = ({
10341
- type,
10342
- setModalContent
10343
- }) => {
10344
- const { setIsOpen } = useStackedModal();
10345
- const onClick = React.useCallback(() => {
10346
- setModalContent(type);
10347
- setIsOpen(STACKED_MODAL_ID, true);
10348
- }, [setModalContent, setIsOpen, type]);
10349
- 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" }) });
10350
- };
10351
- const VARIANT_PREFIX = "items";
10352
- const LIMIT = 50;
10353
- const ExistingItemsForm = ({ orderId, items }) => {
10354
- const { setIsOpen } = useStackedModal();
10355
- const [rowSelection, setRowSelection] = React.useState(
10356
- items.reduce((acc, item) => {
10357
- acc[item.variant_id] = true;
10358
- return acc;
10359
- }, {})
10360
- );
10361
- React.useEffect(() => {
10362
- setRowSelection(
10363
- items.reduce((acc, item) => {
10364
- if (item.variant_id) {
10365
- acc[item.variant_id] = true;
10366
- }
10367
- return acc;
10368
- }, {})
10369
- );
10370
- }, [items]);
10371
- const { q, order, offset } = useQueryParams(
10372
- ["q", "order", "offset"],
10373
- VARIANT_PREFIX
10374
- );
10375
- const { variants, count, isPending, isError, error } = useProductVariants(
10388
+ useInitiateOrderEdit({ preview });
10389
+ const { draft_order, isPending, isError, error } = useDraftOrder(
10390
+ id,
10376
10391
  {
10377
- q,
10378
- order,
10379
- offset: offset ? parseInt(offset) : void 0,
10380
- limit: LIMIT
10392
+ fields: "currency_code"
10381
10393
  },
10382
10394
  {
10383
- placeholderData: reactQuery.keepPreviousData
10395
+ enabled: !!id
10384
10396
  }
10385
10397
  );
10386
- const columns = useColumns();
10387
- const { mutateAsync } = useDraftOrderAddItems(orderId);
10388
- const onSubmit = async () => {
10389
- const ids = Object.keys(rowSelection).filter(
10390
- (id) => !items.find((i) => i.variant_id === id)
10391
- );
10392
- await mutateAsync(
10393
- {
10394
- items: ids.map((id) => ({
10395
- variant_id: id,
10396
- quantity: 1
10397
- }))
10398
- },
10399
- {
10400
- onSuccess: () => {
10401
- setRowSelection({});
10402
- setIsOpen(STACKED_MODAL_ID, false);
10403
- },
10404
- onError: (e) => {
10405
- ui.toast.error(e.message);
10406
- }
10407
- }
10408
- );
10409
- };
10398
+ const { onCancel } = useCancelOrderEdit({ preview });
10410
10399
  if (isError) {
10411
10400
  throw error;
10412
10401
  }
10413
- return /* @__PURE__ */ jsxRuntime.jsxs(
10414
- StackedFocusModal.Content,
10415
- {
10416
- onOpenAutoFocus: (e) => {
10417
- e.preventDefault();
10418
- const searchInput = document.querySelector(
10419
- "[data-modal-id='modal-search-input']"
10420
- );
10421
- if (searchInput) {
10422
- searchInput.focus();
10423
- }
10402
+ if (isPreviewError) {
10403
+ throw previewError;
10404
+ }
10405
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10406
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10407
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10408
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10409
+ ] }) });
10410
+ };
10411
+ const ItemsForm = ({ preview, currencyCode }) => {
10412
+ var _a;
10413
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
10414
+ const [modalContent, setModalContent] = React.useState(
10415
+ null
10416
+ );
10417
+ const { handleSuccess } = useRouteModal();
10418
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10419
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10420
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10421
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10422
+ const matches = React.useMemo(() => {
10423
+ return matchSorter.matchSorter(preview.items, query2, {
10424
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
10425
+ });
10426
+ }, [preview.items, query2]);
10427
+ const onSubmit = async () => {
10428
+ setIsSubmitting(true);
10429
+ let requestSucceeded = false;
10430
+ await requestOrderEdit(void 0, {
10431
+ onError: (e) => {
10432
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
10424
10433
  },
10425
- children: [
10426
- /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
10427
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10428
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
10429
- ] }),
10430
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
10431
- DataTable,
10432
- {
10433
- data: variants,
10434
- columns,
10435
- isLoading: isPending,
10436
- getRowId: (row) => row.id,
10437
- rowCount: count,
10438
- prefix: VARIANT_PREFIX,
10439
- layout: "fill",
10440
- rowSelection: {
10441
- state: rowSelection,
10442
- onRowSelectionChange: setRowSelection,
10443
- enableRowSelection: (row) => {
10444
- return !items.find((i) => i.variant_id === row.original.id);
10445
- }
10446
- },
10447
- autoFocusSearch: true
10448
- }
10449
- ) }),
10450
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10451
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10452
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
10453
- ] }) })
10454
- ]
10434
+ onSuccess: () => {
10435
+ requestSucceeded = true;
10436
+ }
10437
+ });
10438
+ if (!requestSucceeded) {
10439
+ setIsSubmitting(false);
10440
+ return;
10455
10441
  }
10442
+ await confirmOrderEdit(void 0, {
10443
+ onError: (e) => {
10444
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
10445
+ },
10446
+ onSuccess: () => {
10447
+ handleSuccess();
10448
+ },
10449
+ onSettled: () => {
10450
+ setIsSubmitting(false);
10451
+ }
10452
+ });
10453
+ };
10454
+ const onKeyDown = React.useCallback(
10455
+ (e) => {
10456
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10457
+ if (modalContent || isSubmitting) {
10458
+ return;
10459
+ }
10460
+ onSubmit();
10461
+ }
10462
+ },
10463
+ [modalContent, isSubmitting, onSubmit]
10456
10464
  );
10457
- };
10458
- const columnHelper = ui.createDataTableColumnHelper();
10459
- const useColumns = () => {
10460
- return React.useMemo(() => {
10461
- return [
10462
- columnHelper.select(),
10463
- columnHelper.accessor("product.title", {
10464
- header: "Product",
10465
- cell: ({ row }) => {
10466
- var _a, _b, _c;
10467
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
10468
- /* @__PURE__ */ jsxRuntime.jsx(
10469
- Thumbnail,
10470
- {
10471
- thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
10472
- alt: (_b = row.original.product) == null ? void 0 : _b.title
10473
- }
10474
- ),
10475
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
10476
- ] });
10477
- },
10478
- enableSorting: true
10479
- }),
10480
- columnHelper.accessor("title", {
10481
- header: "Variant",
10482
- enableSorting: true
10483
- }),
10484
- columnHelper.accessor("sku", {
10485
- header: "SKU",
10486
- cell: ({ getValue }) => {
10487
- return getValue() ?? "-";
10488
- },
10489
- enableSorting: true
10490
- }),
10491
- columnHelper.accessor("updated_at", {
10492
- header: "Updated",
10493
- cell: ({ getValue }) => {
10494
- return /* @__PURE__ */ jsxRuntime.jsx(
10495
- ui.Tooltip,
10496
- {
10497
- content: getFullDate({ date: getValue(), includeTime: true }),
10498
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
10499
- }
10500
- );
10465
+ React.useEffect(() => {
10466
+ document.addEventListener("keydown", onKeyDown);
10467
+ return () => {
10468
+ document.removeEventListener("keydown", onKeyDown);
10469
+ };
10470
+ }, [onKeyDown]);
10471
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10472
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
10473
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
10474
+ StackedFocusModal,
10475
+ {
10476
+ id: STACKED_MODAL_ID,
10477
+ onOpenChangeCallback: (open) => {
10478
+ if (!open) {
10479
+ setModalContent(null);
10480
+ }
10501
10481
  },
10502
- enableSorting: true,
10503
- sortAscLabel: "Oldest first",
10504
- sortDescLabel: "Newest first"
10505
- }),
10506
- columnHelper.accessor("created_at", {
10507
- header: "Created",
10508
- cell: ({ getValue }) => {
10509
- return /* @__PURE__ */ jsxRuntime.jsx(
10510
- ui.Tooltip,
10482
+ children: [
10483
+ /* @__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: [
10484
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10485
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
10486
+ /* @__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" }) })
10487
+ ] }),
10488
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10489
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
10490
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10491
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10492
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10493
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10494
+ ] }),
10495
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
10496
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10497
+ ui.Input,
10498
+ {
10499
+ type: "search",
10500
+ placeholder: "Search items",
10501
+ value: searchValue,
10502
+ onChange: (e) => onSearchValueChange(e.target.value)
10503
+ }
10504
+ ) }),
10505
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10506
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
10507
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10508
+ /* @__PURE__ */ jsxRuntime.jsx(
10509
+ StackedModalTrigger$1,
10510
+ {
10511
+ type: "add-items",
10512
+ setModalContent
10513
+ }
10514
+ ),
10515
+ /* @__PURE__ */ jsxRuntime.jsx(
10516
+ StackedModalTrigger$1,
10517
+ {
10518
+ type: "add-custom-item",
10519
+ setModalContent
10520
+ }
10521
+ )
10522
+ ] })
10523
+ ] })
10524
+ ] })
10525
+ ] }),
10526
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10527
+ /* @__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: [
10528
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
10529
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10530
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
10531
+ /* @__PURE__ */ jsxRuntime.jsx("div", {})
10532
+ ] }) }),
10533
+ /* @__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: [
10534
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10535
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10536
+ ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
10537
+ Item,
10538
+ {
10539
+ item,
10540
+ preview,
10541
+ currencyCode
10542
+ },
10543
+ item.id
10544
+ )) : /* @__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: [
10545
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10546
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
10547
+ 'No items found for "',
10548
+ query2,
10549
+ '".'
10550
+ ] })
10551
+ ] }) })
10552
+ ] })
10553
+ ] }),
10554
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10555
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10556
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10557
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
10558
+ ui.Text,
10559
+ {
10560
+ size: "small",
10561
+ leading: "compact",
10562
+ className: "text-ui-fg-subtle",
10563
+ children: [
10564
+ itemCount,
10565
+ " ",
10566
+ itemCount === 1 ? "item" : "items"
10567
+ ]
10568
+ }
10569
+ ) }),
10570
+ /* @__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) }) })
10571
+ ] })
10572
+ ] }) }),
10573
+ modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
10574
+ CustomItemForm,
10511
10575
  {
10512
- content: getFullDate({ date: getValue(), includeTime: true }),
10513
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
10576
+ orderId: preview.id,
10577
+ currencyCode
10514
10578
  }
10515
- );
10516
- },
10517
- enableSorting: true,
10518
- sortAscLabel: "Oldest first",
10519
- sortDescLabel: "Newest first"
10520
- })
10521
- ];
10522
- }, []);
10579
+ ) : null)
10580
+ ]
10581
+ }
10582
+ ) }),
10583
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10584
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10585
+ /* @__PURE__ */ jsxRuntime.jsx(
10586
+ ui.Button,
10587
+ {
10588
+ size: "small",
10589
+ type: "button",
10590
+ onClick: onSubmit,
10591
+ isLoading: isSubmitting,
10592
+ children: "Save"
10593
+ }
10594
+ )
10595
+ ] }) })
10596
+ ] });
10523
10597
  };
10524
- const CustomItemForm = ({ orderId, currencyCode }) => {
10525
- const { setIsOpen } = useStackedModal();
10526
- const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
10598
+ const Item = ({ item, preview, currencyCode }) => {
10599
+ if (item.variant_id) {
10600
+ return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
10601
+ }
10602
+ return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
10603
+ };
10604
+ const VariantItem = ({ item, preview, currencyCode }) => {
10605
+ const [editing, setEditing] = React.useState(false);
10527
10606
  const form = reactHookForm.useForm({
10528
10607
  defaultValues: {
10529
- title: "",
10530
- quantity: 1,
10531
- unit_price: ""
10608
+ quantity: item.quantity,
10609
+ unit_price: item.unit_price
10532
10610
  },
10533
- resolver: zod.zodResolver(customItemSchema)
10611
+ resolver: zod.zodResolver(variantItemSchema)
10534
10612
  });
10613
+ const actionId = React.useMemo(() => {
10614
+ var _a, _b;
10615
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10616
+ }, [item]);
10617
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10618
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10619
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10535
10620
  const onSubmit = form.handleSubmit(async (data) => {
10536
- await addItems(
10537
- {
10538
- items: [
10539
- {
10540
- title: data.title,
10541
- quantity: data.quantity,
10542
- unit_price: convertNumber(data.unit_price)
10621
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10622
+ setEditing(false);
10623
+ return;
10624
+ }
10625
+ if (!actionId) {
10626
+ await updateOriginalItem(
10627
+ {
10628
+ item_id: item.id,
10629
+ quantity: data.quantity,
10630
+ unit_price: convertNumber(data.unit_price)
10631
+ },
10632
+ {
10633
+ onSuccess: () => {
10634
+ setEditing(false);
10635
+ },
10636
+ onError: (e) => {
10637
+ ui.toast.error(e.message);
10543
10638
  }
10544
- ]
10639
+ }
10640
+ );
10641
+ return;
10642
+ }
10643
+ await updateActionItem(
10644
+ {
10645
+ action_id: actionId,
10646
+ quantity: data.quantity,
10647
+ unit_price: convertNumber(data.unit_price)
10545
10648
  },
10546
10649
  {
10547
10650
  onSuccess: () => {
10548
- setIsOpen(STACKED_MODAL_ID, false);
10651
+ setEditing(false);
10549
10652
  },
10550
10653
  onError: (e) => {
10551
10654
  ui.toast.error(e.message);
@@ -10553,754 +10656,578 @@ const CustomItemForm = ({ orderId, currencyCode }) => {
10553
10656
  }
10554
10657
  );
10555
10658
  });
10556
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
10557
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
10558
- /* @__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: [
10559
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10560
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
10561
- /* @__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." }) })
10562
- ] }),
10563
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10659
+ 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: [
10660
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10564
10661
  /* @__PURE__ */ jsxRuntime.jsx(
10565
- Form$2.Field,
10662
+ Thumbnail,
10566
10663
  {
10567
- control: form.control,
10568
- name: "title",
10569
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10570
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10571
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
10572
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
10573
- ] }),
10574
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10575
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10576
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10577
- ] })
10578
- ] }) })
10664
+ thumbnail: item.thumbnail,
10665
+ alt: item.product_title ?? void 0
10579
10666
  }
10580
10667
  ),
10581
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10582
- /* @__PURE__ */ jsxRuntime.jsx(
10583
- Form$2.Field,
10584
- {
10585
- control: form.control,
10586
- name: "unit_price",
10587
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10588
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10589
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
10590
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
10591
- ] }),
10592
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10593
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10594
- ui.CurrencyInput,
10595
- {
10596
- symbol: getNativeSymbol(currencyCode),
10597
- code: currencyCode,
10598
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
10599
- ...field
10600
- }
10601
- ) }),
10602
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10603
- ] })
10604
- ] }) })
10668
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10669
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10670
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10671
+ /* @__PURE__ */ jsxRuntime.jsxs(
10672
+ ui.Text,
10673
+ {
10674
+ size: "small",
10675
+ leading: "compact",
10676
+ className: "text-ui-fg-subtle",
10677
+ children: [
10678
+ "(",
10679
+ item.variant_title,
10680
+ ")"
10681
+ ]
10682
+ }
10683
+ )
10684
+ ] }),
10685
+ /* @__PURE__ */ jsxRuntime.jsx(
10686
+ ui.Text,
10687
+ {
10688
+ size: "small",
10689
+ leading: "compact",
10690
+ className: "text-ui-fg-subtle",
10691
+ children: item.variant_sku
10692
+ }
10693
+ )
10694
+ ] })
10695
+ ] }),
10696
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10697
+ Form$2.Field,
10698
+ {
10699
+ control: form.control,
10700
+ name: "quantity",
10701
+ render: ({ field }) => {
10702
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10605
10703
  }
10606
- ),
10607
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10608
- /* @__PURE__ */ jsxRuntime.jsx(
10609
- Form$2.Field,
10610
- {
10611
- control: form.control,
10612
- name: "quantity",
10613
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10614
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10615
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
10616
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
10617
- ] }),
10618
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex-1", children: [
10619
- /* @__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" }) }) }),
10620
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10621
- ] })
10622
- ] }) })
10704
+ }
10705
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10706
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10707
+ Form$2.Field,
10708
+ {
10709
+ control: form.control,
10710
+ name: "unit_price",
10711
+ render: ({ field: { onChange, ...field } }) => {
10712
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10713
+ ui.CurrencyInput,
10714
+ {
10715
+ ...field,
10716
+ symbol: getNativeSymbol(currencyCode),
10717
+ code: currencyCode,
10718
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10719
+ }
10720
+ ) }) });
10623
10721
  }
10624
- )
10625
- ] }) }) }),
10626
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10627
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10628
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
10629
- ] }) })
10722
+ }
10723
+ ) }) : /* @__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) }) }),
10724
+ /* @__PURE__ */ jsxRuntime.jsx(
10725
+ ui.IconButton,
10726
+ {
10727
+ type: "button",
10728
+ size: "small",
10729
+ onClick: editing ? onSubmit : () => {
10730
+ setEditing(true);
10731
+ },
10732
+ disabled: isPending,
10733
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10734
+ }
10735
+ )
10630
10736
  ] }) }) });
10631
10737
  };
10632
- const customItemSchema = objectType({
10633
- title: stringType().min(1),
10738
+ const variantItemSchema = objectType({
10634
10739
  quantity: numberType(),
10635
10740
  unit_price: unionType([numberType(), stringType()])
10636
10741
  });
10637
- const InlineTip = React.forwardRef(
10638
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10639
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10640
- return /* @__PURE__ */ jsxRuntime.jsxs(
10641
- "div",
10642
- {
10643
- ref,
10644
- className: ui.clx(
10645
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10646
- className
10647
- ),
10648
- ...props,
10649
- children: [
10650
- /* @__PURE__ */ jsxRuntime.jsx(
10651
- "div",
10652
- {
10653
- role: "presentation",
10654
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10655
- "bg-ui-tag-orange-icon": variant === "warning"
10656
- })
10657
- }
10658
- ),
10659
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
10660
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10661
- labelValue,
10662
- ":"
10663
- ] }),
10664
- " ",
10665
- children
10666
- ] })
10667
- ]
10668
- }
10669
- );
10670
- }
10671
- );
10672
- InlineTip.displayName = "InlineTip";
10673
- const MetadataFieldSchema = objectType({
10674
- key: stringType(),
10675
- disabled: booleanType().optional(),
10676
- value: anyType()
10677
- });
10678
- const MetadataSchema = objectType({
10679
- metadata: arrayType(MetadataFieldSchema)
10680
- });
10681
- const Metadata = () => {
10682
- const { id } = reactRouterDom.useParams();
10683
- const { order, isPending, isError, error } = useOrder(id, {
10684
- fields: "metadata"
10685
- });
10686
- if (isError) {
10687
- throw error;
10688
- }
10689
- const isReady = !isPending && !!order;
10690
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10691
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10692
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
10693
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10694
- ] }),
10695
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10696
- ] });
10697
- };
10698
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10699
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10700
- const MetadataForm = ({ orderId, metadata }) => {
10701
- const { handleSuccess } = useRouteModal();
10702
- const hasUneditableRows = getHasUneditableRows(metadata);
10703
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10742
+ const CustomItem = ({ item, preview, currencyCode }) => {
10743
+ const [editing, setEditing] = React.useState(false);
10744
+ const { quantity, unit_price, title } = item;
10704
10745
  const form = reactHookForm.useForm({
10705
10746
  defaultValues: {
10706
- metadata: getDefaultValues(metadata)
10747
+ title,
10748
+ quantity,
10749
+ unit_price
10707
10750
  },
10708
- resolver: zod.zodResolver(MetadataSchema)
10709
- });
10710
- const handleSubmit = form.handleSubmit(async (data) => {
10711
- const parsedData = parseValues(data);
10712
- await mutateAsync(
10713
- {
10714
- metadata: parsedData
10715
- },
10716
- {
10717
- onSuccess: () => {
10718
- ui.toast.success("Metadata updated");
10719
- handleSuccess();
10720
- },
10721
- onError: (error) => {
10722
- ui.toast.error(error.message);
10723
- }
10724
- }
10725
- );
10726
- });
10727
- const { fields, insert, remove } = reactHookForm.useFieldArray({
10728
- control: form.control,
10729
- name: "metadata"
10751
+ resolver: zod.zodResolver(customItemSchema)
10730
10752
  });
10731
- function deleteRow(index) {
10732
- remove(index);
10733
- if (fields.length === 1) {
10734
- insert(0, {
10735
- key: "",
10736
- value: "",
10737
- disabled: false
10738
- });
10739
- }
10740
- }
10741
- function insertRow(index, position) {
10742
- insert(index + (position === "above" ? 0 : 1), {
10743
- key: "",
10744
- value: "",
10745
- disabled: false
10753
+ React.useEffect(() => {
10754
+ form.reset({
10755
+ title,
10756
+ quantity,
10757
+ unit_price
10746
10758
  });
10747
- }
10748
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10749
- KeyboundForm,
10750
- {
10751
- onSubmit: handleSubmit,
10752
- className: "flex flex-1 flex-col overflow-hidden",
10753
- children: [
10754
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10755
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10756
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10757
- /* @__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" }) }),
10758
- /* @__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" }) })
10759
- ] }),
10760
- fields.map((field, index) => {
10761
- const isDisabled = field.disabled || false;
10762
- let placeholder = "-";
10763
- if (typeof field.value === "object") {
10764
- placeholder = "{ ... }";
10765
- }
10766
- if (Array.isArray(field.value)) {
10767
- placeholder = "[ ... ]";
10768
- }
10769
- return /* @__PURE__ */ jsxRuntime.jsx(
10770
- ConditionalTooltip,
10771
- {
10772
- showTooltip: isDisabled,
10773
- content: "This row is disabled because it contains non-primitive data.",
10774
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
10775
- /* @__PURE__ */ jsxRuntime.jsxs(
10776
- "div",
10777
- {
10778
- className: ui.clx("grid grid-cols-2 divide-x", {
10779
- "overflow-hidden rounded-b-lg": index === fields.length - 1
10780
- }),
10781
- children: [
10782
- /* @__PURE__ */ jsxRuntime.jsx(
10783
- Form$2.Field,
10784
- {
10785
- control: form.control,
10786
- name: `metadata.${index}.key`,
10787
- render: ({ field: field2 }) => {
10788
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10789
- GridInput,
10790
- {
10791
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10792
- ...field2,
10793
- disabled: isDisabled,
10794
- placeholder: "Key"
10795
- }
10796
- ) }) });
10797
- }
10798
- }
10799
- ),
10800
- /* @__PURE__ */ jsxRuntime.jsx(
10801
- Form$2.Field,
10802
- {
10803
- control: form.control,
10804
- name: `metadata.${index}.value`,
10805
- render: ({ field: { value, ...field2 } }) => {
10806
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10807
- GridInput,
10808
- {
10809
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
10810
- ...field2,
10811
- value: isDisabled ? placeholder : value,
10812
- disabled: isDisabled,
10813
- placeholder: "Value"
10814
- }
10815
- ) }) });
10816
- }
10817
- }
10818
- )
10819
- ]
10820
- }
10821
- ),
10822
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10823
- /* @__PURE__ */ jsxRuntime.jsx(
10824
- ui.DropdownMenu.Trigger,
10825
- {
10826
- className: ui.clx(
10827
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10828
- {
10829
- hidden: isDisabled
10830
- }
10831
- ),
10832
- disabled: isDisabled,
10833
- asChild: true,
10834
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
10835
- }
10836
- ),
10837
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10838
- /* @__PURE__ */ jsxRuntime.jsxs(
10839
- ui.DropdownMenu.Item,
10840
- {
10841
- className: "gap-x-2",
10842
- onClick: () => insertRow(index, "above"),
10843
- children: [
10844
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
10845
- "Insert row above"
10846
- ]
10847
- }
10848
- ),
10849
- /* @__PURE__ */ jsxRuntime.jsxs(
10850
- ui.DropdownMenu.Item,
10851
- {
10852
- className: "gap-x-2",
10853
- onClick: () => insertRow(index, "below"),
10854
- children: [
10855
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
10856
- "Insert row below"
10857
- ]
10858
- }
10859
- ),
10860
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
10861
- /* @__PURE__ */ jsxRuntime.jsxs(
10862
- ui.DropdownMenu.Item,
10863
- {
10864
- className: "gap-x-2",
10865
- onClick: () => deleteRow(index),
10866
- children: [
10867
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
10868
- "Delete row"
10869
- ]
10870
- }
10871
- )
10872
- ] })
10873
- ] })
10874
- ] })
10875
- },
10876
- field.id
10877
- );
10878
- })
10879
- ] }),
10880
- 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." })
10881
- ] }),
10882
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10883
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10884
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10885
- ] }) })
10886
- ]
10887
- }
10888
- ) });
10889
- };
10890
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
10891
- return /* @__PURE__ */ jsxRuntime.jsx(
10892
- "input",
10893
- {
10894
- ref,
10895
- ...props,
10896
- autoComplete: "off",
10897
- className: ui.clx(
10898
- "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",
10899
- className
10900
- )
10901
- }
10902
- );
10903
- });
10904
- GridInput.displayName = "MetadataForm.GridInput";
10905
- const PlaceholderInner = () => {
10906
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10907
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10908
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10909
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
10910
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
10911
- ] }) })
10912
- ] });
10913
- };
10914
- const EDITABLE_TYPES = ["string", "number", "boolean"];
10915
- function getDefaultValues(metadata) {
10916
- if (!metadata || !Object.keys(metadata).length) {
10917
- return [
10918
- {
10919
- key: "",
10920
- value: "",
10921
- disabled: false
10922
- }
10923
- ];
10924
- }
10925
- return Object.entries(metadata).map(([key, value]) => {
10926
- if (!EDITABLE_TYPES.includes(typeof value)) {
10927
- return {
10928
- key,
10929
- value,
10930
- disabled: true
10931
- };
10932
- }
10933
- let stringValue = value;
10934
- if (typeof value !== "string") {
10935
- stringValue = JSON.stringify(value);
10759
+ }, [form, title, quantity, unit_price]);
10760
+ const actionId = React.useMemo(() => {
10761
+ var _a, _b;
10762
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10763
+ }, [item]);
10764
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10765
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10766
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10767
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10768
+ const onSubmit = form.handleSubmit(async (data) => {
10769
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10770
+ setEditing(false);
10771
+ return;
10936
10772
  }
10937
- return {
10938
- key,
10939
- value: stringValue,
10940
- original_key: key
10941
- };
10942
- });
10943
- }
10944
- function parseValues(values) {
10945
- const metadata = values.metadata;
10946
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10947
- if (isEmpty) {
10948
- return null;
10949
- }
10950
- const update = {};
10951
- metadata.forEach((field) => {
10952
- let key = field.key;
10953
- let value = field.value;
10954
- const disabled = field.disabled;
10955
- if (!key || !value) {
10773
+ if (!actionId) {
10774
+ await updateOriginalItem(
10775
+ {
10776
+ item_id: item.id,
10777
+ quantity: data.quantity,
10778
+ unit_price: convertNumber(data.unit_price)
10779
+ },
10780
+ {
10781
+ onSuccess: () => {
10782
+ setEditing(false);
10783
+ },
10784
+ onError: (e) => {
10785
+ ui.toast.error(e.message);
10786
+ }
10787
+ }
10788
+ );
10956
10789
  return;
10957
10790
  }
10958
- if (disabled) {
10959
- update[key] = value;
10791
+ if (data.quantity === 0) {
10792
+ await removeActionItem(actionId, {
10793
+ onSuccess: () => {
10794
+ setEditing(false);
10795
+ },
10796
+ onError: (e) => {
10797
+ ui.toast.error(e.message);
10798
+ }
10799
+ });
10960
10800
  return;
10961
10801
  }
10962
- key = key.trim();
10963
- value = value.trim();
10964
- if (value === "true") {
10965
- update[key] = true;
10966
- } else if (value === "false") {
10967
- update[key] = false;
10968
- } else {
10969
- const parsedNumber = parseFloat(value);
10970
- if (!isNaN(parsedNumber)) {
10971
- update[key] = parsedNumber;
10972
- } else {
10973
- update[key] = value;
10802
+ await updateActionItem(
10803
+ {
10804
+ action_id: actionId,
10805
+ quantity: data.quantity,
10806
+ unit_price: convertNumber(data.unit_price)
10807
+ },
10808
+ {
10809
+ onSuccess: () => {
10810
+ setEditing(false);
10811
+ },
10812
+ onError: (e) => {
10813
+ ui.toast.error(e.message);
10814
+ }
10974
10815
  }
10975
- }
10976
- });
10977
- return update;
10978
- }
10979
- function getHasUneditableRows(metadata) {
10980
- if (!metadata) {
10981
- return false;
10982
- }
10983
- return Object.values(metadata).some(
10984
- (value) => !EDITABLE_TYPES.includes(typeof value)
10985
- );
10986
- }
10987
- const PROMOTION_QUERY_KEY = "promotions";
10988
- const promotionsQueryKeys = {
10989
- list: (query2) => [
10990
- PROMOTION_QUERY_KEY,
10991
- query2 ? query2 : void 0
10992
- ],
10993
- detail: (id, query2) => [
10994
- PROMOTION_QUERY_KEY,
10995
- id,
10996
- query2 ? query2 : void 0
10997
- ]
10998
- };
10999
- const usePromotions = (query2, options) => {
11000
- const { data, ...rest } = reactQuery.useQuery({
11001
- queryKey: promotionsQueryKeys.list(query2),
11002
- queryFn: async () => sdk.admin.promotion.list(query2),
11003
- ...options
10816
+ );
11004
10817
  });
11005
- return { ...data, ...rest };
10818
+ 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: [
10819
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
10820
+ /* @__PURE__ */ jsxRuntime.jsx(
10821
+ Thumbnail,
10822
+ {
10823
+ thumbnail: item.thumbnail,
10824
+ alt: item.title ?? void 0
10825
+ }
10826
+ ),
10827
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10828
+ Form$2.Field,
10829
+ {
10830
+ control: form.control,
10831
+ name: "title",
10832
+ render: ({ field }) => {
10833
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
10834
+ }
10835
+ }
10836
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
10837
+ ] }),
10838
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10839
+ Form$2.Field,
10840
+ {
10841
+ control: form.control,
10842
+ name: "quantity",
10843
+ render: ({ field }) => {
10844
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10845
+ }
10846
+ }
10847
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
10848
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10849
+ Form$2.Field,
10850
+ {
10851
+ control: form.control,
10852
+ name: "unit_price",
10853
+ render: ({ field: { onChange, ...field } }) => {
10854
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10855
+ ui.CurrencyInput,
10856
+ {
10857
+ ...field,
10858
+ symbol: getNativeSymbol(currencyCode),
10859
+ code: currencyCode,
10860
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10861
+ }
10862
+ ) }) });
10863
+ }
10864
+ }
10865
+ ) : /* @__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) }) }),
10866
+ /* @__PURE__ */ jsxRuntime.jsx(
10867
+ ui.IconButton,
10868
+ {
10869
+ type: "button",
10870
+ size: "small",
10871
+ onClick: editing ? onSubmit : () => {
10872
+ setEditing(true);
10873
+ },
10874
+ disabled: isPending,
10875
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10876
+ }
10877
+ )
10878
+ ] }) }) });
11006
10879
  };
11007
- const Promotions = () => {
11008
- const { id } = reactRouterDom.useParams();
11009
- const {
11010
- order: preview,
11011
- isError: isPreviewError,
11012
- error: previewError
11013
- } = useOrderPreview(id, void 0);
11014
- useInitiateOrderEdit({ preview });
11015
- const { onCancel } = useCancelOrderEdit({ preview });
11016
- if (isPreviewError) {
11017
- throw previewError;
11018
- }
11019
- const isReady = !!preview;
11020
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11021
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11022
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11023
- ] });
10880
+ const StackedModalTrigger$1 = ({
10881
+ type,
10882
+ setModalContent
10883
+ }) => {
10884
+ const { setIsOpen } = useStackedModal();
10885
+ const onClick = React.useCallback(() => {
10886
+ setModalContent(type);
10887
+ setIsOpen(STACKED_MODAL_ID, true);
10888
+ }, [setModalContent, setIsOpen, type]);
10889
+ 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" }) });
11024
10890
  };
11025
- const PromotionForm = ({ preview }) => {
11026
- const { items, shipping_methods } = preview;
11027
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11028
- const [comboboxValue, setComboboxValue] = React.useState("");
11029
- const { handleSuccess } = useRouteModal();
11030
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11031
- const promoIds = getPromotionIds(items, shipping_methods);
11032
- const { promotions, isPending, isError, error } = usePromotions(
11033
- {
11034
- id: promoIds
11035
- },
11036
- {
11037
- enabled: !!promoIds.length
11038
- }
10891
+ const VARIANT_PREFIX = "items";
10892
+ const LIMIT = 50;
10893
+ const ExistingItemsForm = ({ orderId, items }) => {
10894
+ const { setIsOpen } = useStackedModal();
10895
+ const [rowSelection, setRowSelection] = React.useState(
10896
+ items.reduce((acc, item) => {
10897
+ acc[item.variant_id] = true;
10898
+ return acc;
10899
+ }, {})
11039
10900
  );
11040
- const comboboxData = useComboboxData({
11041
- queryKey: ["promotions", "combobox", promoIds],
11042
- queryFn: async (params) => {
11043
- return await sdk.admin.promotion.list({
11044
- ...params,
11045
- id: {
11046
- $nin: promoIds
10901
+ React.useEffect(() => {
10902
+ setRowSelection(
10903
+ items.reduce((acc, item) => {
10904
+ if (item.variant_id) {
10905
+ acc[item.variant_id] = true;
11047
10906
  }
11048
- });
10907
+ return acc;
10908
+ }, {})
10909
+ );
10910
+ }, [items]);
10911
+ const { q, order, offset } = useQueryParams(
10912
+ ["q", "order", "offset"],
10913
+ VARIANT_PREFIX
10914
+ );
10915
+ const { variants, count, isPending, isError, error } = useProductVariants(
10916
+ {
10917
+ q,
10918
+ order,
10919
+ offset: offset ? parseInt(offset) : void 0,
10920
+ limit: LIMIT
11049
10921
  },
11050
- getOptions: (data) => {
11051
- return data.promotions.map((promotion) => ({
11052
- label: promotion.code,
11053
- value: promotion.code
11054
- }));
11055
- }
11056
- });
11057
- const add = async (value) => {
11058
- if (!value) {
11059
- return;
10922
+ {
10923
+ placeholderData: reactQuery.keepPreviousData
11060
10924
  }
11061
- addPromotions(
10925
+ );
10926
+ const columns = useColumns();
10927
+ const { mutateAsync } = useDraftOrderAddItems(orderId);
10928
+ const onSubmit = async () => {
10929
+ const ids = Object.keys(rowSelection).filter(
10930
+ (id) => !items.find((i) => i.variant_id === id)
10931
+ );
10932
+ await mutateAsync(
11062
10933
  {
11063
- promo_codes: [value]
10934
+ items: ids.map((id) => ({
10935
+ variant_id: id,
10936
+ quantity: 1
10937
+ }))
11064
10938
  },
11065
10939
  {
10940
+ onSuccess: () => {
10941
+ setRowSelection({});
10942
+ setIsOpen(STACKED_MODAL_ID, false);
10943
+ },
11066
10944
  onError: (e) => {
11067
10945
  ui.toast.error(e.message);
11068
- comboboxData.onSearchValueChange("");
11069
- setComboboxValue("");
11070
- },
11071
- onSuccess: () => {
11072
- comboboxData.onSearchValueChange("");
11073
- setComboboxValue("");
11074
10946
  }
11075
10947
  }
11076
10948
  );
11077
10949
  };
11078
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11079
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11080
- const onSubmit = async () => {
11081
- setIsSubmitting(true);
11082
- let requestSucceeded = false;
11083
- await requestOrderEdit(void 0, {
11084
- onError: (e) => {
11085
- ui.toast.error(e.message);
11086
- },
11087
- onSuccess: () => {
11088
- requestSucceeded = true;
11089
- }
11090
- });
11091
- if (!requestSucceeded) {
11092
- setIsSubmitting(false);
11093
- return;
11094
- }
11095
- await confirmOrderEdit(void 0, {
11096
- onError: (e) => {
11097
- ui.toast.error(e.message);
11098
- },
11099
- onSuccess: () => {
11100
- handleSuccess();
11101
- },
11102
- onSettled: () => {
11103
- setIsSubmitting(false);
11104
- }
11105
- });
11106
- };
11107
10950
  if (isError) {
11108
10951
  throw error;
11109
10952
  }
11110
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11111
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11112
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11113
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11114
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11115
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
10953
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10954
+ StackedFocusModal.Content,
10955
+ {
10956
+ onOpenAutoFocus: (e) => {
10957
+ e.preventDefault();
10958
+ const searchInput = document.querySelector(
10959
+ "[data-modal-id='modal-search-input']"
10960
+ );
10961
+ if (searchInput) {
10962
+ searchInput.focus();
10963
+ }
10964
+ },
10965
+ children: [
10966
+ /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
10967
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10968
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
11116
10969
  ] }),
11117
- /* @__PURE__ */ jsxRuntime.jsx(
11118
- Combobox,
10970
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
10971
+ DataTable,
11119
10972
  {
11120
- id: "promotion-combobox",
11121
- "aria-describedby": "promotion-combobox-hint",
11122
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11123
- fetchNextPage: comboboxData.fetchNextPage,
11124
- options: comboboxData.options,
11125
- onSearchValueChange: comboboxData.onSearchValueChange,
11126
- searchValue: comboboxData.searchValue,
11127
- disabled: comboboxData.disabled || isAddingPromotions,
11128
- onChange: add,
11129
- value: comboboxValue
10973
+ data: variants,
10974
+ columns,
10975
+ isLoading: isPending,
10976
+ getRowId: (row) => row.id,
10977
+ rowCount: count,
10978
+ prefix: VARIANT_PREFIX,
10979
+ layout: "fill",
10980
+ rowSelection: {
10981
+ state: rowSelection,
10982
+ onRowSelectionChange: setRowSelection,
10983
+ enableRowSelection: (row) => {
10984
+ return !items.find((i) => i.variant_id === row.original.id);
10985
+ }
10986
+ },
10987
+ autoFocusSearch: true
11130
10988
  }
11131
- )
11132
- ] }),
11133
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11134
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11135
- PromotionItem,
11136
- {
11137
- promotion,
11138
- orderId: preview.id,
11139
- isLoading: isPending
10989
+ ) }),
10990
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10991
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10992
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
10993
+ ] }) })
10994
+ ]
10995
+ }
10996
+ );
10997
+ };
10998
+ const columnHelper = ui.createDataTableColumnHelper();
10999
+ const useColumns = () => {
11000
+ return React.useMemo(() => {
11001
+ return [
11002
+ columnHelper.select(),
11003
+ columnHelper.accessor("product.title", {
11004
+ header: "Product",
11005
+ cell: ({ row }) => {
11006
+ var _a, _b, _c;
11007
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
11008
+ /* @__PURE__ */ jsxRuntime.jsx(
11009
+ Thumbnail,
11010
+ {
11011
+ thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
11012
+ alt: (_b = row.original.product) == null ? void 0 : _b.title
11013
+ }
11014
+ ),
11015
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
11016
+ ] });
11140
11017
  },
11141
- promotion.id
11142
- )) })
11143
- ] }) }),
11144
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11145
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11146
- /* @__PURE__ */ jsxRuntime.jsx(
11147
- ui.Button,
11148
- {
11149
- size: "small",
11150
- type: "submit",
11151
- isLoading: isSubmitting || isAddingPromotions,
11152
- children: "Save"
11153
- }
11154
- )
11155
- ] }) })
11156
- ] });
11018
+ enableSorting: true
11019
+ }),
11020
+ columnHelper.accessor("title", {
11021
+ header: "Variant",
11022
+ enableSorting: true
11023
+ }),
11024
+ columnHelper.accessor("sku", {
11025
+ header: "SKU",
11026
+ cell: ({ getValue }) => {
11027
+ return getValue() ?? "-";
11028
+ },
11029
+ enableSorting: true
11030
+ }),
11031
+ columnHelper.accessor("updated_at", {
11032
+ header: "Updated",
11033
+ cell: ({ getValue }) => {
11034
+ return /* @__PURE__ */ jsxRuntime.jsx(
11035
+ ui.Tooltip,
11036
+ {
11037
+ content: getFullDate({ date: getValue(), includeTime: true }),
11038
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
11039
+ }
11040
+ );
11041
+ },
11042
+ enableSorting: true,
11043
+ sortAscLabel: "Oldest first",
11044
+ sortDescLabel: "Newest first"
11045
+ }),
11046
+ columnHelper.accessor("created_at", {
11047
+ header: "Created",
11048
+ cell: ({ getValue }) => {
11049
+ return /* @__PURE__ */ jsxRuntime.jsx(
11050
+ ui.Tooltip,
11051
+ {
11052
+ content: getFullDate({ date: getValue(), includeTime: true }),
11053
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
11054
+ }
11055
+ );
11056
+ },
11057
+ enableSorting: true,
11058
+ sortAscLabel: "Oldest first",
11059
+ sortDescLabel: "Newest first"
11060
+ })
11061
+ ];
11062
+ }, []);
11157
11063
  };
11158
- const PromotionItem = ({
11159
- promotion,
11160
- orderId,
11161
- isLoading
11162
- }) => {
11163
- var _a;
11164
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11165
- const onRemove = async () => {
11166
- removePromotions(
11064
+ const CustomItemForm = ({ orderId, currencyCode }) => {
11065
+ const { setIsOpen } = useStackedModal();
11066
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
11067
+ const form = reactHookForm.useForm({
11068
+ defaultValues: {
11069
+ title: "",
11070
+ quantity: 1,
11071
+ unit_price: ""
11072
+ },
11073
+ resolver: zod.zodResolver(customItemSchema)
11074
+ });
11075
+ const onSubmit = form.handleSubmit(async (data) => {
11076
+ await addItems(
11167
11077
  {
11168
- promo_codes: [promotion.code]
11078
+ items: [
11079
+ {
11080
+ title: data.title,
11081
+ quantity: data.quantity,
11082
+ unit_price: convertNumber(data.unit_price)
11083
+ }
11084
+ ]
11169
11085
  },
11170
11086
  {
11087
+ onSuccess: () => {
11088
+ setIsOpen(STACKED_MODAL_ID, false);
11089
+ },
11171
11090
  onError: (e) => {
11172
11091
  ui.toast.error(e.message);
11173
11092
  }
11174
- }
11175
- );
11176
- };
11177
- const displayValue = getDisplayValue(promotion);
11178
- return /* @__PURE__ */ jsxRuntime.jsxs(
11179
- "div",
11180
- {
11181
- className: ui.clx(
11182
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11093
+ }
11094
+ );
11095
+ });
11096
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
11097
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
11098
+ /* @__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: [
11099
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11100
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
11101
+ /* @__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." }) })
11102
+ ] }),
11103
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11104
+ /* @__PURE__ */ jsxRuntime.jsx(
11105
+ Form$2.Field,
11106
+ {
11107
+ control: form.control,
11108
+ name: "title",
11109
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11110
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11111
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
11112
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
11113
+ ] }),
11114
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11115
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11116
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11117
+ ] })
11118
+ ] }) })
11119
+ }
11120
+ ),
11121
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11122
+ /* @__PURE__ */ jsxRuntime.jsx(
11123
+ Form$2.Field,
11183
11124
  {
11184
- "animate-pulse": isLoading
11125
+ control: form.control,
11126
+ name: "unit_price",
11127
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11128
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11129
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
11130
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
11131
+ ] }),
11132
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11133
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11134
+ ui.CurrencyInput,
11135
+ {
11136
+ symbol: getNativeSymbol(currencyCode),
11137
+ code: currencyCode,
11138
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
11139
+ ...field
11140
+ }
11141
+ ) }),
11142
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11143
+ ] })
11144
+ ] }) })
11185
11145
  }
11186
11146
  ),
11187
- children: [
11188
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11189
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11190
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11191
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11192
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11193
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11147
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11148
+ /* @__PURE__ */ jsxRuntime.jsx(
11149
+ Form$2.Field,
11150
+ {
11151
+ control: form.control,
11152
+ name: "quantity",
11153
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11154
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11155
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
11156
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
11194
11157
  ] }),
11195
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11196
- ] })
11197
- ] }),
11198
- /* @__PURE__ */ jsxRuntime.jsx(
11199
- ui.IconButton,
11200
- {
11201
- size: "small",
11202
- type: "button",
11203
- variant: "transparent",
11204
- onClick: onRemove,
11205
- isLoading: isPending || isLoading,
11206
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11207
- }
11208
- )
11209
- ]
11210
- },
11211
- promotion.id
11212
- );
11158
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex-1", children: [
11159
+ /* @__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" }) }) }),
11160
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11161
+ ] })
11162
+ ] }) })
11163
+ }
11164
+ )
11165
+ ] }) }) }),
11166
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11167
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11168
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
11169
+ ] }) })
11170
+ ] }) }) });
11213
11171
  };
11214
- function getDisplayValue(promotion) {
11215
- var _a, _b, _c, _d;
11216
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11217
- if (!value) {
11218
- return null;
11219
- }
11220
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11221
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11222
- if (!currency) {
11223
- return null;
11224
- }
11225
- return getLocaleAmount(value, currency);
11226
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11227
- return formatPercentage(value);
11228
- }
11229
- return null;
11230
- }
11231
- const formatter = new Intl.NumberFormat([], {
11232
- style: "percent",
11233
- minimumFractionDigits: 2
11172
+ const customItemSchema = objectType({
11173
+ title: stringType().min(1),
11174
+ quantity: numberType(),
11175
+ unit_price: unionType([numberType(), stringType()])
11234
11176
  });
11235
- const formatPercentage = (value, isPercentageValue = false) => {
11236
- let val = value || 0;
11237
- if (!isPercentageValue) {
11238
- val = val / 100;
11239
- }
11240
- return formatter.format(val);
11241
- };
11242
- function getPromotionIds(items, shippingMethods) {
11243
- const promotionIds = /* @__PURE__ */ new Set();
11244
- for (const item of items) {
11245
- if (item.adjustments) {
11246
- for (const adjustment of item.adjustments) {
11247
- if (adjustment.promotion_id) {
11248
- promotionIds.add(adjustment.promotion_id);
11249
- }
11250
- }
11251
- }
11252
- }
11253
- for (const shippingMethod of shippingMethods) {
11254
- if (shippingMethod.adjustments) {
11255
- for (const adjustment of shippingMethod.adjustments) {
11256
- if (adjustment.promotion_id) {
11257
- promotionIds.add(adjustment.promotion_id);
11258
- }
11259
- }
11260
- }
11261
- }
11262
- return Array.from(promotionIds);
11263
- }
11264
- const SalesChannel = () => {
11177
+ const ShippingAddress = () => {
11265
11178
  const { id } = reactRouterDom.useParams();
11266
- const { draft_order, isPending, isError, error } = useDraftOrder(
11267
- id,
11268
- {
11269
- fields: "+sales_channel_id"
11270
- },
11271
- {
11272
- enabled: !!id
11273
- }
11274
- );
11179
+ const { order, isPending, isError, error } = useOrder(id, {
11180
+ fields: "+shipping_address"
11181
+ });
11275
11182
  if (isError) {
11276
11183
  throw error;
11277
11184
  }
11278
- const ISrEADY = !!draft_order && !isPending;
11185
+ const isReady = !isPending && !!order;
11279
11186
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11280
11187
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11281
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11282
- /* @__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" }) })
11188
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11189
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11283
11190
  ] }),
11284
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11191
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11285
11192
  ] });
11286
11193
  };
11287
- const SalesChannelForm = ({ order }) => {
11194
+ const ShippingAddressForm = ({ order }) => {
11195
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11288
11196
  const form = reactHookForm.useForm({
11289
11197
  defaultValues: {
11290
- sales_channel_id: order.sales_channel_id || ""
11198
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11199
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11200
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11201
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11202
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11203
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11204
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11205
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11206
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11207
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11291
11208
  },
11292
- resolver: zod.zodResolver(schema$3)
11209
+ resolver: zod.zodResolver(schema$2)
11293
11210
  });
11294
11211
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11295
11212
  const { handleSuccess } = useRouteModal();
11296
11213
  const onSubmit = form.handleSubmit(async (data) => {
11297
11214
  await mutateAsync(
11298
11215
  {
11299
- sales_channel_id: data.sales_channel_id
11216
+ shipping_address: {
11217
+ first_name: data.first_name,
11218
+ last_name: data.last_name,
11219
+ company: data.company,
11220
+ address_1: data.address_1,
11221
+ address_2: data.address_2,
11222
+ city: data.city,
11223
+ province: data.province,
11224
+ country_code: data.country_code,
11225
+ postal_code: data.postal_code,
11226
+ phone: data.phone
11227
+ }
11300
11228
  },
11301
11229
  {
11302
11230
  onSuccess: () => {
11303
- ui.toast.success("Sales channel updated");
11304
11231
  handleSuccess();
11305
11232
  },
11306
11233
  onError: (error) => {
@@ -11315,7 +11242,132 @@ const SalesChannelForm = ({ order }) => {
11315
11242
  className: "flex flex-1 flex-col overflow-hidden",
11316
11243
  onSubmit,
11317
11244
  children: [
11318
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11245
+ /* @__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: [
11246
+ /* @__PURE__ */ jsxRuntime.jsx(
11247
+ Form$2.Field,
11248
+ {
11249
+ control: form.control,
11250
+ name: "country_code",
11251
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11252
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11253
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11254
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11255
+ ] })
11256
+ }
11257
+ ),
11258
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11259
+ /* @__PURE__ */ jsxRuntime.jsx(
11260
+ Form$2.Field,
11261
+ {
11262
+ control: form.control,
11263
+ name: "first_name",
11264
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11265
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11266
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11267
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11268
+ ] })
11269
+ }
11270
+ ),
11271
+ /* @__PURE__ */ jsxRuntime.jsx(
11272
+ Form$2.Field,
11273
+ {
11274
+ control: form.control,
11275
+ name: "last_name",
11276
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11277
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11278
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11279
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11280
+ ] })
11281
+ }
11282
+ )
11283
+ ] }),
11284
+ /* @__PURE__ */ jsxRuntime.jsx(
11285
+ Form$2.Field,
11286
+ {
11287
+ control: form.control,
11288
+ name: "company",
11289
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11290
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11291
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11292
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11293
+ ] })
11294
+ }
11295
+ ),
11296
+ /* @__PURE__ */ jsxRuntime.jsx(
11297
+ Form$2.Field,
11298
+ {
11299
+ control: form.control,
11300
+ name: "address_1",
11301
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11302
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11303
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11304
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11305
+ ] })
11306
+ }
11307
+ ),
11308
+ /* @__PURE__ */ jsxRuntime.jsx(
11309
+ Form$2.Field,
11310
+ {
11311
+ control: form.control,
11312
+ name: "address_2",
11313
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11314
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11315
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11316
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11317
+ ] })
11318
+ }
11319
+ ),
11320
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11321
+ /* @__PURE__ */ jsxRuntime.jsx(
11322
+ Form$2.Field,
11323
+ {
11324
+ control: form.control,
11325
+ name: "postal_code",
11326
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11327
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11328
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11329
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11330
+ ] })
11331
+ }
11332
+ ),
11333
+ /* @__PURE__ */ jsxRuntime.jsx(
11334
+ Form$2.Field,
11335
+ {
11336
+ control: form.control,
11337
+ name: "city",
11338
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11339
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11340
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11341
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11342
+ ] })
11343
+ }
11344
+ )
11345
+ ] }),
11346
+ /* @__PURE__ */ jsxRuntime.jsx(
11347
+ Form$2.Field,
11348
+ {
11349
+ control: form.control,
11350
+ name: "province",
11351
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11352
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11353
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11354
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11355
+ ] })
11356
+ }
11357
+ ),
11358
+ /* @__PURE__ */ jsxRuntime.jsx(
11359
+ Form$2.Field,
11360
+ {
11361
+ control: form.control,
11362
+ name: "phone",
11363
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11364
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11365
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11366
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11367
+ ] })
11368
+ }
11369
+ )
11370
+ ] }) }),
11319
11371
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11320
11372
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11321
11373
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -11324,49 +11376,7 @@ const SalesChannelForm = ({ order }) => {
11324
11376
  }
11325
11377
  ) });
11326
11378
  };
11327
- const SalesChannelField = ({ control, order }) => {
11328
- const salesChannels = useComboboxData({
11329
- queryFn: async (params) => {
11330
- return await sdk.admin.salesChannel.list(params);
11331
- },
11332
- queryKey: ["sales-channels"],
11333
- getOptions: (data) => {
11334
- return data.sales_channels.map((salesChannel) => ({
11335
- label: salesChannel.name,
11336
- value: salesChannel.id
11337
- }));
11338
- },
11339
- defaultValue: order.sales_channel_id || void 0
11340
- });
11341
- return /* @__PURE__ */ jsxRuntime.jsx(
11342
- Form$2.Field,
11343
- {
11344
- control,
11345
- name: "sales_channel_id",
11346
- render: ({ field }) => {
11347
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11348
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11349
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11350
- Combobox,
11351
- {
11352
- options: salesChannels.options,
11353
- fetchNextPage: salesChannels.fetchNextPage,
11354
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11355
- searchValue: salesChannels.searchValue,
11356
- onSearchValueChange: salesChannels.onSearchValueChange,
11357
- placeholder: "Select sales channel",
11358
- ...field
11359
- }
11360
- ) }),
11361
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11362
- ] });
11363
- }
11364
- }
11365
- );
11366
- };
11367
- const schema$3 = objectType({
11368
- sales_channel_id: stringType().min(1)
11369
- });
11379
+ const schema$2 = addressSchema;
11370
11380
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11371
11381
  const Shipping = () => {
11372
11382
  var _a;
@@ -12085,298 +12095,478 @@ const ShippingOptionField = ({
12085
12095
  const shippingOptions = useComboboxData({
12086
12096
  queryKey: ["shipping_options", locationId, shippingProfileId],
12087
12097
  queryFn: async (params) => {
12088
- return await sdk.admin.shippingOption.list({
12089
- ...params,
12090
- stock_location_id: locationId,
12091
- shipping_profile_id: shippingProfileId
12092
- });
12098
+ return await sdk.admin.shippingOption.list({
12099
+ ...params,
12100
+ stock_location_id: locationId,
12101
+ shipping_profile_id: shippingProfileId
12102
+ });
12103
+ },
12104
+ getOptions: (data) => {
12105
+ return data.shipping_options.map((option) => {
12106
+ var _a2;
12107
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12108
+ (r) => r.attribute === "is_return" && r.value === "true"
12109
+ )) {
12110
+ return void 0;
12111
+ }
12112
+ return {
12113
+ label: option.name,
12114
+ value: option.id
12115
+ };
12116
+ }).filter(Boolean);
12117
+ },
12118
+ enabled: !!locationId && !!shippingProfileId,
12119
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12120
+ });
12121
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12122
+ return /* @__PURE__ */ jsxRuntime.jsx(
12123
+ Form$2.Field,
12124
+ {
12125
+ control,
12126
+ name: "shipping_option_id",
12127
+ render: ({ field }) => {
12128
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12129
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12130
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12131
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12132
+ ] }),
12133
+ /* @__PURE__ */ jsxRuntime.jsx(
12134
+ ConditionalTooltip,
12135
+ {
12136
+ content: tooltipContent,
12137
+ showTooltip: !locationId || !shippingProfileId,
12138
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12139
+ Combobox,
12140
+ {
12141
+ options: shippingOptions.options,
12142
+ fetchNextPage: shippingOptions.fetchNextPage,
12143
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12144
+ searchValue: shippingOptions.searchValue,
12145
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12146
+ placeholder: "Select shipping option",
12147
+ ...field,
12148
+ disabled: !locationId || !shippingProfileId
12149
+ }
12150
+ ) }) })
12151
+ }
12152
+ )
12153
+ ] }) });
12154
+ }
12155
+ }
12156
+ );
12157
+ };
12158
+ const CustomAmountField = ({
12159
+ control,
12160
+ currencyCode
12161
+ }) => {
12162
+ return /* @__PURE__ */ jsxRuntime.jsx(
12163
+ Form$2.Field,
12164
+ {
12165
+ control,
12166
+ name: "custom_amount",
12167
+ render: ({ field: { onChange, ...field } }) => {
12168
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12169
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12170
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12171
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12172
+ ] }),
12173
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12174
+ ui.CurrencyInput,
12175
+ {
12176
+ ...field,
12177
+ onValueChange: (value) => onChange(value),
12178
+ symbol: getNativeSymbol(currencyCode),
12179
+ code: currencyCode
12180
+ }
12181
+ ) })
12182
+ ] });
12183
+ }
12184
+ }
12185
+ );
12186
+ };
12187
+ const SalesChannel = () => {
12188
+ const { id } = reactRouterDom.useParams();
12189
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12190
+ id,
12191
+ {
12192
+ fields: "+sales_channel_id"
12193
+ },
12194
+ {
12195
+ enabled: !!id
12196
+ }
12197
+ );
12198
+ if (isError) {
12199
+ throw error;
12200
+ }
12201
+ const ISrEADY = !!draft_order && !isPending;
12202
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12203
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12204
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12205
+ /* @__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" }) })
12206
+ ] }),
12207
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12208
+ ] });
12209
+ };
12210
+ const SalesChannelForm = ({ order }) => {
12211
+ const form = reactHookForm.useForm({
12212
+ defaultValues: {
12213
+ sales_channel_id: order.sales_channel_id || ""
12214
+ },
12215
+ resolver: zod.zodResolver(schema$1)
12216
+ });
12217
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12218
+ const { handleSuccess } = useRouteModal();
12219
+ const onSubmit = form.handleSubmit(async (data) => {
12220
+ await mutateAsync(
12221
+ {
12222
+ sales_channel_id: data.sales_channel_id
12223
+ },
12224
+ {
12225
+ onSuccess: () => {
12226
+ ui.toast.success("Sales channel updated");
12227
+ handleSuccess();
12228
+ },
12229
+ onError: (error) => {
12230
+ ui.toast.error(error.message);
12231
+ }
12232
+ }
12233
+ );
12234
+ });
12235
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12236
+ KeyboundForm,
12237
+ {
12238
+ className: "flex flex-1 flex-col overflow-hidden",
12239
+ onSubmit,
12240
+ children: [
12241
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
12242
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12243
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12244
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12245
+ ] }) })
12246
+ ]
12247
+ }
12248
+ ) });
12249
+ };
12250
+ const SalesChannelField = ({ control, order }) => {
12251
+ const salesChannels = useComboboxData({
12252
+ queryFn: async (params) => {
12253
+ return await sdk.admin.salesChannel.list(params);
12093
12254
  },
12255
+ queryKey: ["sales-channels"],
12094
12256
  getOptions: (data) => {
12095
- return data.shipping_options.map((option) => {
12096
- var _a2;
12097
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12098
- (r) => r.attribute === "is_return" && r.value === "true"
12099
- )) {
12100
- return void 0;
12101
- }
12102
- return {
12103
- label: option.name,
12104
- value: option.id
12105
- };
12106
- }).filter(Boolean);
12257
+ return data.sales_channels.map((salesChannel) => ({
12258
+ label: salesChannel.name,
12259
+ value: salesChannel.id
12260
+ }));
12107
12261
  },
12108
- enabled: !!locationId && !!shippingProfileId,
12109
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12262
+ defaultValue: order.sales_channel_id || void 0
12110
12263
  });
12111
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12112
12264
  return /* @__PURE__ */ jsxRuntime.jsx(
12113
12265
  Form$2.Field,
12114
12266
  {
12115
12267
  control,
12116
- name: "shipping_option_id",
12268
+ name: "sales_channel_id",
12117
12269
  render: ({ field }) => {
12118
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12119
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12120
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12121
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12122
- ] }),
12123
- /* @__PURE__ */ jsxRuntime.jsx(
12124
- ConditionalTooltip,
12125
- {
12126
- content: tooltipContent,
12127
- showTooltip: !locationId || !shippingProfileId,
12128
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12129
- Combobox,
12130
- {
12131
- options: shippingOptions.options,
12132
- fetchNextPage: shippingOptions.fetchNextPage,
12133
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12134
- searchValue: shippingOptions.searchValue,
12135
- onSearchValueChange: shippingOptions.onSearchValueChange,
12136
- placeholder: "Select shipping option",
12137
- ...field,
12138
- disabled: !locationId || !shippingProfileId
12139
- }
12140
- ) }) })
12141
- }
12142
- )
12143
- ] }) });
12144
- }
12145
- }
12146
- );
12147
- };
12148
- const CustomAmountField = ({
12149
- control,
12150
- currencyCode
12151
- }) => {
12152
- return /* @__PURE__ */ jsxRuntime.jsx(
12153
- Form$2.Field,
12154
- {
12155
- control,
12156
- name: "custom_amount",
12157
- render: ({ field: { onChange, ...field } }) => {
12158
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12159
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12160
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12161
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12162
- ] }),
12270
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12271
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
12163
12272
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12164
- ui.CurrencyInput,
12273
+ Combobox,
12165
12274
  {
12166
- ...field,
12167
- onValueChange: (value) => onChange(value),
12168
- symbol: getNativeSymbol(currencyCode),
12169
- code: currencyCode
12275
+ options: salesChannels.options,
12276
+ fetchNextPage: salesChannels.fetchNextPage,
12277
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
12278
+ searchValue: salesChannels.searchValue,
12279
+ onSearchValueChange: salesChannels.onSearchValueChange,
12280
+ placeholder: "Select sales channel",
12281
+ ...field
12170
12282
  }
12171
- ) })
12283
+ ) }),
12284
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12172
12285
  ] });
12173
12286
  }
12174
12287
  }
12175
12288
  );
12176
12289
  };
12177
- const ShippingAddress = () => {
12290
+ const schema$1 = objectType({
12291
+ sales_channel_id: stringType().min(1)
12292
+ });
12293
+ const PROMOTION_QUERY_KEY = "promotions";
12294
+ const promotionsQueryKeys = {
12295
+ list: (query2) => [
12296
+ PROMOTION_QUERY_KEY,
12297
+ query2 ? query2 : void 0
12298
+ ],
12299
+ detail: (id, query2) => [
12300
+ PROMOTION_QUERY_KEY,
12301
+ id,
12302
+ query2 ? query2 : void 0
12303
+ ]
12304
+ };
12305
+ const usePromotions = (query2, options) => {
12306
+ const { data, ...rest } = reactQuery.useQuery({
12307
+ queryKey: promotionsQueryKeys.list(query2),
12308
+ queryFn: async () => sdk.admin.promotion.list(query2),
12309
+ ...options
12310
+ });
12311
+ return { ...data, ...rest };
12312
+ };
12313
+ const Promotions = () => {
12178
12314
  const { id } = reactRouterDom.useParams();
12179
- const { order, isPending, isError, error } = useOrder(id, {
12180
- fields: "+shipping_address"
12315
+ const {
12316
+ order: preview,
12317
+ isError: isPreviewError,
12318
+ error: previewError
12319
+ } = useOrderPreview(id, void 0);
12320
+ useInitiateOrderEdit({ preview });
12321
+ const { onCancel } = useCancelOrderEdit({ preview });
12322
+ if (isPreviewError) {
12323
+ throw previewError;
12324
+ }
12325
+ const isReady = !!preview;
12326
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
12327
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
12328
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
12329
+ ] });
12330
+ };
12331
+ const PromotionForm = ({ preview }) => {
12332
+ const { items, shipping_methods } = preview;
12333
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
12334
+ const [comboboxValue, setComboboxValue] = React.useState("");
12335
+ const { handleSuccess } = useRouteModal();
12336
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
12337
+ const promoIds = getPromotionIds(items, shipping_methods);
12338
+ const { promotions, isPending, isError, error } = usePromotions(
12339
+ {
12340
+ id: promoIds
12341
+ },
12342
+ {
12343
+ enabled: !!promoIds.length
12344
+ }
12345
+ );
12346
+ const comboboxData = useComboboxData({
12347
+ queryKey: ["promotions", "combobox", promoIds],
12348
+ queryFn: async (params) => {
12349
+ return await sdk.admin.promotion.list({
12350
+ ...params,
12351
+ id: {
12352
+ $nin: promoIds
12353
+ }
12354
+ });
12355
+ },
12356
+ getOptions: (data) => {
12357
+ return data.promotions.map((promotion) => ({
12358
+ label: promotion.code,
12359
+ value: promotion.code
12360
+ }));
12361
+ }
12181
12362
  });
12363
+ const add = async (value) => {
12364
+ if (!value) {
12365
+ return;
12366
+ }
12367
+ addPromotions(
12368
+ {
12369
+ promo_codes: [value]
12370
+ },
12371
+ {
12372
+ onError: (e) => {
12373
+ ui.toast.error(e.message);
12374
+ comboboxData.onSearchValueChange("");
12375
+ setComboboxValue("");
12376
+ },
12377
+ onSuccess: () => {
12378
+ comboboxData.onSearchValueChange("");
12379
+ setComboboxValue("");
12380
+ }
12381
+ }
12382
+ );
12383
+ };
12384
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12385
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
12386
+ const onSubmit = async () => {
12387
+ setIsSubmitting(true);
12388
+ let requestSucceeded = false;
12389
+ await requestOrderEdit(void 0, {
12390
+ onError: (e) => {
12391
+ ui.toast.error(e.message);
12392
+ },
12393
+ onSuccess: () => {
12394
+ requestSucceeded = true;
12395
+ }
12396
+ });
12397
+ if (!requestSucceeded) {
12398
+ setIsSubmitting(false);
12399
+ return;
12400
+ }
12401
+ await confirmOrderEdit(void 0, {
12402
+ onError: (e) => {
12403
+ ui.toast.error(e.message);
12404
+ },
12405
+ onSuccess: () => {
12406
+ handleSuccess();
12407
+ },
12408
+ onSettled: () => {
12409
+ setIsSubmitting(false);
12410
+ }
12411
+ });
12412
+ };
12182
12413
  if (isError) {
12183
12414
  throw error;
12184
12415
  }
12185
- const isReady = !isPending && !!order;
12186
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12187
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12188
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12189
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12190
- ] }),
12191
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12416
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
12417
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
12418
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
12419
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12420
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
12421
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
12422
+ ] }),
12423
+ /* @__PURE__ */ jsxRuntime.jsx(
12424
+ Combobox,
12425
+ {
12426
+ id: "promotion-combobox",
12427
+ "aria-describedby": "promotion-combobox-hint",
12428
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
12429
+ fetchNextPage: comboboxData.fetchNextPage,
12430
+ options: comboboxData.options,
12431
+ onSearchValueChange: comboboxData.onSearchValueChange,
12432
+ searchValue: comboboxData.searchValue,
12433
+ disabled: comboboxData.disabled || isAddingPromotions,
12434
+ onChange: add,
12435
+ value: comboboxValue
12436
+ }
12437
+ )
12438
+ ] }),
12439
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12440
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
12441
+ PromotionItem,
12442
+ {
12443
+ promotion,
12444
+ orderId: preview.id,
12445
+ isLoading: isPending
12446
+ },
12447
+ promotion.id
12448
+ )) })
12449
+ ] }) }),
12450
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12451
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12452
+ /* @__PURE__ */ jsxRuntime.jsx(
12453
+ ui.Button,
12454
+ {
12455
+ size: "small",
12456
+ type: "submit",
12457
+ isLoading: isSubmitting || isAddingPromotions,
12458
+ children: "Save"
12459
+ }
12460
+ )
12461
+ ] }) })
12192
12462
  ] });
12193
12463
  };
12194
- const ShippingAddressForm = ({ order }) => {
12195
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12196
- const form = reactHookForm.useForm({
12197
- defaultValues: {
12198
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12199
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12200
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12201
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12202
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12203
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12204
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12205
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12206
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12207
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12208
- },
12209
- resolver: zod.zodResolver(schema$2)
12210
- });
12211
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12212
- const { handleSuccess } = useRouteModal();
12213
- const onSubmit = form.handleSubmit(async (data) => {
12214
- await mutateAsync(
12464
+ const PromotionItem = ({
12465
+ promotion,
12466
+ orderId,
12467
+ isLoading
12468
+ }) => {
12469
+ var _a;
12470
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
12471
+ const onRemove = async () => {
12472
+ removePromotions(
12215
12473
  {
12216
- shipping_address: {
12217
- first_name: data.first_name,
12218
- last_name: data.last_name,
12219
- company: data.company,
12220
- address_1: data.address_1,
12221
- address_2: data.address_2,
12222
- city: data.city,
12223
- province: data.province,
12224
- country_code: data.country_code,
12225
- postal_code: data.postal_code,
12226
- phone: data.phone
12227
- }
12474
+ promo_codes: [promotion.code]
12228
12475
  },
12229
12476
  {
12230
- onSuccess: () => {
12231
- handleSuccess();
12232
- },
12233
- onError: (error) => {
12234
- ui.toast.error(error.message);
12477
+ onError: (e) => {
12478
+ ui.toast.error(e.message);
12235
12479
  }
12236
12480
  }
12237
12481
  );
12238
- });
12239
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12240
- KeyboundForm,
12482
+ };
12483
+ const displayValue = getDisplayValue(promotion);
12484
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12485
+ "div",
12241
12486
  {
12242
- className: "flex flex-1 flex-col overflow-hidden",
12243
- onSubmit,
12487
+ className: ui.clx(
12488
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
12489
+ {
12490
+ "animate-pulse": isLoading
12491
+ }
12492
+ ),
12244
12493
  children: [
12245
- /* @__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: [
12246
- /* @__PURE__ */ jsxRuntime.jsx(
12247
- Form$2.Field,
12248
- {
12249
- control: form.control,
12250
- name: "country_code",
12251
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12252
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12253
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12254
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12255
- ] })
12256
- }
12257
- ),
12258
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12259
- /* @__PURE__ */ jsxRuntime.jsx(
12260
- Form$2.Field,
12261
- {
12262
- control: form.control,
12263
- name: "first_name",
12264
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12265
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12266
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12267
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12268
- ] })
12269
- }
12270
- ),
12271
- /* @__PURE__ */ jsxRuntime.jsx(
12272
- Form$2.Field,
12273
- {
12274
- control: form.control,
12275
- name: "last_name",
12276
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12277
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12278
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12279
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12280
- ] })
12281
- }
12282
- )
12283
- ] }),
12284
- /* @__PURE__ */ jsxRuntime.jsx(
12285
- Form$2.Field,
12286
- {
12287
- control: form.control,
12288
- name: "company",
12289
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12290
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12291
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12292
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12293
- ] })
12294
- }
12295
- ),
12296
- /* @__PURE__ */ jsxRuntime.jsx(
12297
- Form$2.Field,
12298
- {
12299
- control: form.control,
12300
- name: "address_1",
12301
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12302
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12303
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12304
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12305
- ] })
12306
- }
12307
- ),
12308
- /* @__PURE__ */ jsxRuntime.jsx(
12309
- Form$2.Field,
12310
- {
12311
- control: form.control,
12312
- name: "address_2",
12313
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12314
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12315
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12316
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12317
- ] })
12318
- }
12319
- ),
12320
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12321
- /* @__PURE__ */ jsxRuntime.jsx(
12322
- Form$2.Field,
12323
- {
12324
- control: form.control,
12325
- name: "postal_code",
12326
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12327
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12328
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12329
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12330
- ] })
12331
- }
12332
- ),
12333
- /* @__PURE__ */ jsxRuntime.jsx(
12334
- Form$2.Field,
12335
- {
12336
- control: form.control,
12337
- name: "city",
12338
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12339
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12340
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12341
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12342
- ] })
12343
- }
12344
- )
12345
- ] }),
12346
- /* @__PURE__ */ jsxRuntime.jsx(
12347
- Form$2.Field,
12348
- {
12349
- control: form.control,
12350
- name: "province",
12351
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12352
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12353
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12354
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12355
- ] })
12356
- }
12357
- ),
12358
- /* @__PURE__ */ jsxRuntime.jsx(
12359
- Form$2.Field,
12360
- {
12361
- control: form.control,
12362
- name: "phone",
12363
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12364
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12365
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12366
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12367
- ] })
12368
- }
12369
- )
12370
- ] }) }),
12371
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12372
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12373
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12374
- ] }) })
12494
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12495
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
12496
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
12497
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
12498
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
12499
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
12500
+ ] }),
12501
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
12502
+ ] })
12503
+ ] }),
12504
+ /* @__PURE__ */ jsxRuntime.jsx(
12505
+ ui.IconButton,
12506
+ {
12507
+ size: "small",
12508
+ type: "button",
12509
+ variant: "transparent",
12510
+ onClick: onRemove,
12511
+ isLoading: isPending || isLoading,
12512
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
12513
+ }
12514
+ )
12375
12515
  ]
12516
+ },
12517
+ promotion.id
12518
+ );
12519
+ };
12520
+ function getDisplayValue(promotion) {
12521
+ var _a, _b, _c, _d;
12522
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
12523
+ if (!value) {
12524
+ return null;
12525
+ }
12526
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
12527
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
12528
+ if (!currency) {
12529
+ return null;
12376
12530
  }
12377
- ) });
12531
+ return getLocaleAmount(value, currency);
12532
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
12533
+ return formatPercentage(value);
12534
+ }
12535
+ return null;
12536
+ }
12537
+ const formatter = new Intl.NumberFormat([], {
12538
+ style: "percent",
12539
+ minimumFractionDigits: 2
12540
+ });
12541
+ const formatPercentage = (value, isPercentageValue = false) => {
12542
+ let val = value || 0;
12543
+ if (!isPercentageValue) {
12544
+ val = val / 100;
12545
+ }
12546
+ return formatter.format(val);
12378
12547
  };
12379
- const schema$2 = addressSchema;
12548
+ function getPromotionIds(items, shippingMethods) {
12549
+ const promotionIds = /* @__PURE__ */ new Set();
12550
+ for (const item of items) {
12551
+ if (item.adjustments) {
12552
+ for (const adjustment of item.adjustments) {
12553
+ if (adjustment.promotion_id) {
12554
+ promotionIds.add(adjustment.promotion_id);
12555
+ }
12556
+ }
12557
+ }
12558
+ }
12559
+ for (const shippingMethod of shippingMethods) {
12560
+ if (shippingMethod.adjustments) {
12561
+ for (const adjustment of shippingMethod.adjustments) {
12562
+ if (adjustment.promotion_id) {
12563
+ promotionIds.add(adjustment.promotion_id);
12564
+ }
12565
+ }
12566
+ }
12567
+ }
12568
+ return Array.from(promotionIds);
12569
+ }
12380
12570
  const TransferOwnership = () => {
12381
12571
  const { id } = reactRouterDom.useParams();
12382
12572
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12400,7 +12590,7 @@ const TransferOwnershipForm = ({ order }) => {
12400
12590
  defaultValues: {
12401
12591
  customer_id: order.customer_id || ""
12402
12592
  },
12403
- resolver: zod.zodResolver(schema$1)
12593
+ resolver: zod.zodResolver(schema)
12404
12594
  });
12405
12595
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12406
12596
  const { handleSuccess } = useRouteModal();
@@ -12850,199 +13040,9 @@ const Illustration = () => {
12850
13040
  }
12851
13041
  );
12852
13042
  };
12853
- const schema$1 = objectType({
13043
+ const schema = objectType({
12854
13044
  customer_id: stringType().min(1)
12855
13045
  });
12856
- const BillingAddress = () => {
12857
- const { id } = reactRouterDom.useParams();
12858
- const { order, isPending, isError, error } = useOrder(id, {
12859
- fields: "+billing_address"
12860
- });
12861
- if (isError) {
12862
- throw error;
12863
- }
12864
- const isReady = !isPending && !!order;
12865
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12866
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12867
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
12868
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12869
- ] }),
12870
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
12871
- ] });
12872
- };
12873
- const BillingAddressForm = ({ order }) => {
12874
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12875
- const form = reactHookForm.useForm({
12876
- defaultValues: {
12877
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12878
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12879
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12880
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12881
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12882
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12883
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12884
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12885
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12886
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12887
- },
12888
- resolver: zod.zodResolver(schema)
12889
- });
12890
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12891
- const { handleSuccess } = useRouteModal();
12892
- const onSubmit = form.handleSubmit(async (data) => {
12893
- await mutateAsync(
12894
- { billing_address: data },
12895
- {
12896
- onSuccess: () => {
12897
- handleSuccess();
12898
- },
12899
- onError: (error) => {
12900
- ui.toast.error(error.message);
12901
- }
12902
- }
12903
- );
12904
- });
12905
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12906
- KeyboundForm,
12907
- {
12908
- className: "flex flex-1 flex-col overflow-hidden",
12909
- onSubmit,
12910
- children: [
12911
- /* @__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: [
12912
- /* @__PURE__ */ jsxRuntime.jsx(
12913
- Form$2.Field,
12914
- {
12915
- control: form.control,
12916
- name: "country_code",
12917
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12918
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12919
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12920
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12921
- ] })
12922
- }
12923
- ),
12924
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12925
- /* @__PURE__ */ jsxRuntime.jsx(
12926
- Form$2.Field,
12927
- {
12928
- control: form.control,
12929
- name: "first_name",
12930
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12931
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12932
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12933
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12934
- ] })
12935
- }
12936
- ),
12937
- /* @__PURE__ */ jsxRuntime.jsx(
12938
- Form$2.Field,
12939
- {
12940
- control: form.control,
12941
- name: "last_name",
12942
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12943
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12944
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12945
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12946
- ] })
12947
- }
12948
- )
12949
- ] }),
12950
- /* @__PURE__ */ jsxRuntime.jsx(
12951
- Form$2.Field,
12952
- {
12953
- control: form.control,
12954
- name: "company",
12955
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12956
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12957
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12958
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12959
- ] })
12960
- }
12961
- ),
12962
- /* @__PURE__ */ jsxRuntime.jsx(
12963
- Form$2.Field,
12964
- {
12965
- control: form.control,
12966
- name: "address_1",
12967
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12968
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12969
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12970
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12971
- ] })
12972
- }
12973
- ),
12974
- /* @__PURE__ */ jsxRuntime.jsx(
12975
- Form$2.Field,
12976
- {
12977
- control: form.control,
12978
- name: "address_2",
12979
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12980
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12981
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12982
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12983
- ] })
12984
- }
12985
- ),
12986
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12987
- /* @__PURE__ */ jsxRuntime.jsx(
12988
- Form$2.Field,
12989
- {
12990
- control: form.control,
12991
- name: "postal_code",
12992
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12993
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12994
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12995
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12996
- ] })
12997
- }
12998
- ),
12999
- /* @__PURE__ */ jsxRuntime.jsx(
13000
- Form$2.Field,
13001
- {
13002
- control: form.control,
13003
- name: "city",
13004
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13005
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13006
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13007
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13008
- ] })
13009
- }
13010
- )
13011
- ] }),
13012
- /* @__PURE__ */ jsxRuntime.jsx(
13013
- Form$2.Field,
13014
- {
13015
- control: form.control,
13016
- name: "province",
13017
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13018
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13019
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13020
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13021
- ] })
13022
- }
13023
- ),
13024
- /* @__PURE__ */ jsxRuntime.jsx(
13025
- Form$2.Field,
13026
- {
13027
- control: form.control,
13028
- name: "phone",
13029
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13030
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13031
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13032
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13033
- ] })
13034
- }
13035
- )
13036
- ] }) }),
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
- ]
13042
- }
13043
- ) });
13044
- };
13045
- const schema = addressSchema;
13046
13046
  const widgetModule = { widgets: [] };
13047
13047
  const routeModule = {
13048
13048
  routes: [
@@ -13063,45 +13063,45 @@ const routeModule = {
13063
13063
  handle,
13064
13064
  loader,
13065
13065
  children: [
13066
- {
13067
- Component: CustomItems,
13068
- path: "/draft-orders/:id/custom-items"
13069
- },
13070
13066
  {
13071
13067
  Component: Email,
13072
13068
  path: "/draft-orders/:id/email"
13073
13069
  },
13074
13070
  {
13075
- Component: Items,
13076
- path: "/draft-orders/:id/items"
13071
+ Component: CustomItems,
13072
+ path: "/draft-orders/:id/custom-items"
13073
+ },
13074
+ {
13075
+ Component: BillingAddress,
13076
+ path: "/draft-orders/:id/billing-address"
13077
13077
  },
13078
13078
  {
13079
13079
  Component: Metadata,
13080
13080
  path: "/draft-orders/:id/metadata"
13081
13081
  },
13082
13082
  {
13083
- Component: Promotions,
13084
- path: "/draft-orders/:id/promotions"
13083
+ Component: Items,
13084
+ path: "/draft-orders/:id/items"
13085
13085
  },
13086
13086
  {
13087
- Component: SalesChannel,
13088
- path: "/draft-orders/:id/sales-channel"
13087
+ Component: ShippingAddress,
13088
+ path: "/draft-orders/:id/shipping-address"
13089
13089
  },
13090
13090
  {
13091
13091
  Component: Shipping,
13092
13092
  path: "/draft-orders/:id/shipping"
13093
13093
  },
13094
13094
  {
13095
- Component: ShippingAddress,
13096
- path: "/draft-orders/:id/shipping-address"
13095
+ Component: SalesChannel,
13096
+ path: "/draft-orders/:id/sales-channel"
13097
13097
  },
13098
13098
  {
13099
- Component: TransferOwnership,
13100
- path: "/draft-orders/:id/transfer-ownership"
13099
+ Component: Promotions,
13100
+ path: "/draft-orders/:id/promotions"
13101
13101
  },
13102
13102
  {
13103
- Component: BillingAddress,
13104
- path: "/draft-orders/:id/billing-address"
13103
+ Component: TransferOwnership,
13104
+ path: "/draft-orders/:id/transfer-ownership"
13105
13105
  }
13106
13106
  ]
13107
13107
  }