@medusajs/draft-order 2.11.4-preview-20251118180132 → 2.11.4-preview-20251119032041

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.
@@ -9572,196 +9572,27 @@ const ID = () => {
9572
9572
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9573
9573
  ] });
9574
9574
  };
9575
- const BillingAddress = () => {
9576
- const { id } = reactRouterDom.useParams();
9577
- const { order, isPending, isError, error } = useOrder(id, {
9578
- fields: "+billing_address"
9579
- });
9580
- if (isError) {
9581
- throw error;
9582
- }
9583
- const isReady = !isPending && !!order;
9575
+ const CustomItems = () => {
9584
9576
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9585
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9586
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
9587
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9588
- ] }),
9589
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9577
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9578
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9590
9579
  ] });
9591
9580
  };
9592
- const BillingAddressForm = ({ order }) => {
9593
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9581
+ const CustomItemsForm = () => {
9594
9582
  const form = reactHookForm.useForm({
9595
- defaultValues: {
9596
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9597
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9598
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9599
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9600
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9601
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9602
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9603
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9604
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9605
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9606
- },
9607
9583
  resolver: zod.zodResolver(schema$5)
9608
9584
  });
9609
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9610
- const { handleSuccess } = useRouteModal();
9611
- const onSubmit = form.handleSubmit(async (data) => {
9612
- await mutateAsync(
9613
- { billing_address: data },
9614
- {
9615
- onSuccess: () => {
9616
- handleSuccess();
9617
- },
9618
- onError: (error) => {
9619
- ui.toast.error(error.message);
9620
- }
9621
- }
9622
- );
9623
- });
9624
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9625
- KeyboundForm,
9626
- {
9627
- className: "flex flex-1 flex-col overflow-hidden",
9628
- onSubmit,
9629
- children: [
9630
- /* @__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: [
9631
- /* @__PURE__ */ jsxRuntime.jsx(
9632
- Form$2.Field,
9633
- {
9634
- control: form.control,
9635
- name: "country_code",
9636
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9637
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
9638
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
9639
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9640
- ] })
9641
- }
9642
- ),
9643
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9644
- /* @__PURE__ */ jsxRuntime.jsx(
9645
- Form$2.Field,
9646
- {
9647
- control: form.control,
9648
- name: "first_name",
9649
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9650
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
9651
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9652
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9653
- ] })
9654
- }
9655
- ),
9656
- /* @__PURE__ */ jsxRuntime.jsx(
9657
- Form$2.Field,
9658
- {
9659
- control: form.control,
9660
- name: "last_name",
9661
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9662
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
9663
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9664
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9665
- ] })
9666
- }
9667
- )
9668
- ] }),
9669
- /* @__PURE__ */ jsxRuntime.jsx(
9670
- Form$2.Field,
9671
- {
9672
- control: form.control,
9673
- name: "company",
9674
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9675
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
9676
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9677
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9678
- ] })
9679
- }
9680
- ),
9681
- /* @__PURE__ */ jsxRuntime.jsx(
9682
- Form$2.Field,
9683
- {
9684
- control: form.control,
9685
- name: "address_1",
9686
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9687
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
9688
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9689
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9690
- ] })
9691
- }
9692
- ),
9693
- /* @__PURE__ */ jsxRuntime.jsx(
9694
- Form$2.Field,
9695
- {
9696
- control: form.control,
9697
- name: "address_2",
9698
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9699
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9700
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9701
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9702
- ] })
9703
- }
9704
- ),
9705
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9706
- /* @__PURE__ */ jsxRuntime.jsx(
9707
- Form$2.Field,
9708
- {
9709
- control: form.control,
9710
- name: "postal_code",
9711
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9712
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
9713
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9714
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9715
- ] })
9716
- }
9717
- ),
9718
- /* @__PURE__ */ jsxRuntime.jsx(
9719
- Form$2.Field,
9720
- {
9721
- control: form.control,
9722
- name: "city",
9723
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9724
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
9725
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9726
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9727
- ] })
9728
- }
9729
- )
9730
- ] }),
9731
- /* @__PURE__ */ jsxRuntime.jsx(
9732
- Form$2.Field,
9733
- {
9734
- control: form.control,
9735
- name: "province",
9736
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9737
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9738
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9739
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9740
- ] })
9741
- }
9742
- ),
9743
- /* @__PURE__ */ jsxRuntime.jsx(
9744
- Form$2.Field,
9745
- {
9746
- control: form.control,
9747
- name: "phone",
9748
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9749
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
9750
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9751
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9752
- ] })
9753
- }
9754
- )
9755
- ] }) }),
9756
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9757
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9758
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9759
- ] }) })
9760
- ]
9761
- }
9762
- ) });
9585
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9586
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9587
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9588
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9589
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9590
+ ] }) })
9591
+ ] }) });
9763
9592
  };
9764
- const schema$5 = addressSchema;
9593
+ const schema$5 = objectType({
9594
+ email: stringType().email()
9595
+ });
9765
9596
  const Email = () => {
9766
9597
  const { id } = reactRouterDom.useParams();
9767
9598
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9830,27 +9661,6 @@ const EmailForm = ({ order }) => {
9830
9661
  const schema$4 = objectType({
9831
9662
  email: stringType().email()
9832
9663
  });
9833
- const CustomItems = () => {
9834
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9835
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9836
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9837
- ] });
9838
- };
9839
- const CustomItemsForm = () => {
9840
- const form = reactHookForm.useForm({
9841
- resolver: zod.zodResolver(schema$3)
9842
- });
9843
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9844
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9845
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9846
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9847
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9848
- ] }) })
9849
- ] }) });
9850
- };
9851
- const schema$3 = objectType({
9852
- email: stringType().email()
9853
- });
9854
9664
  const NumberInput = React.forwardRef(
9855
9665
  ({
9856
9666
  value,
@@ -10825,460 +10635,455 @@ const customItemSchema = objectType({
10825
10635
  quantity: numberType(),
10826
10636
  unit_price: unionType([numberType(), stringType()])
10827
10637
  });
10828
- const PROMOTION_QUERY_KEY = "promotions";
10829
- const promotionsQueryKeys = {
10830
- list: (query2) => [
10831
- PROMOTION_QUERY_KEY,
10832
- query2 ? query2 : void 0
10833
- ],
10834
- detail: (id, query2) => [
10835
- PROMOTION_QUERY_KEY,
10836
- id,
10837
- query2 ? query2 : void 0
10838
- ]
10839
- };
10840
- const usePromotions = (query2, options) => {
10841
- const { data, ...rest } = reactQuery.useQuery({
10842
- queryKey: promotionsQueryKeys.list(query2),
10843
- queryFn: async () => sdk.admin.promotion.list(query2),
10844
- ...options
10845
- });
10846
- return { ...data, ...rest };
10847
- };
10848
- const Promotions = () => {
10849
- const { id } = reactRouterDom.useParams();
10850
- const {
10851
- order: preview,
10852
- isError: isPreviewError,
10853
- error: previewError
10854
- } = useOrderPreview(id, void 0);
10855
- useInitiateOrderEdit({ preview });
10856
- const { onCancel } = useCancelOrderEdit({ preview });
10857
- if (isPreviewError) {
10858
- throw previewError;
10859
- }
10860
- const isReady = !!preview;
10861
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
10862
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
10863
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
10864
- ] });
10865
- };
10866
- const PromotionForm = ({ preview }) => {
10867
- const { items, shipping_methods } = preview;
10868
- const [isSubmitting, setIsSubmitting] = React.useState(false);
10869
- const [comboboxValue, setComboboxValue] = React.useState("");
10870
- const { handleSuccess } = useRouteModal();
10871
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10872
- const promoIds = getPromotionIds(items, shipping_methods);
10873
- const { promotions, isPending, isError, error } = usePromotions(
10874
- {
10875
- id: promoIds
10876
- },
10877
- {
10878
- enabled: !!promoIds.length
10879
- }
10880
- );
10881
- const comboboxData = useComboboxData({
10882
- queryKey: ["promotions", "combobox", promoIds],
10883
- queryFn: async (params) => {
10884
- return await sdk.admin.promotion.list({
10885
- ...params,
10886
- id: {
10887
- $nin: promoIds
10888
- }
10889
- });
10890
- },
10891
- getOptions: (data) => {
10892
- return data.promotions.map((promotion) => ({
10893
- label: promotion.code,
10894
- value: promotion.code
10895
- }));
10896
- }
10897
- });
10898
- const add = async (value) => {
10899
- if (!value) {
10900
- return;
10901
- }
10902
- addPromotions(
10903
- {
10904
- promo_codes: [value]
10905
- },
10638
+ const InlineTip = React.forwardRef(
10639
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
10640
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10641
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10642
+ "div",
10906
10643
  {
10907
- onError: (e) => {
10908
- ui.toast.error(e.message);
10909
- comboboxData.onSearchValueChange("");
10910
- setComboboxValue("");
10911
- },
10912
- onSuccess: () => {
10913
- comboboxData.onSearchValueChange("");
10914
- setComboboxValue("");
10915
- }
10644
+ ref,
10645
+ className: ui.clx(
10646
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10647
+ className
10648
+ ),
10649
+ ...props,
10650
+ children: [
10651
+ /* @__PURE__ */ jsxRuntime.jsx(
10652
+ "div",
10653
+ {
10654
+ role: "presentation",
10655
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10656
+ "bg-ui-tag-orange-icon": variant === "warning"
10657
+ })
10658
+ }
10659
+ ),
10660
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
10661
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10662
+ labelValue,
10663
+ ":"
10664
+ ] }),
10665
+ " ",
10666
+ children
10667
+ ] })
10668
+ ]
10916
10669
  }
10917
10670
  );
10918
- };
10919
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10920
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
10921
- const onSubmit = async () => {
10922
- setIsSubmitting(true);
10923
- let requestSucceeded = false;
10924
- await requestOrderEdit(void 0, {
10925
- onError: (e) => {
10926
- ui.toast.error(e.message);
10927
- },
10928
- onSuccess: () => {
10929
- requestSucceeded = true;
10930
- }
10931
- });
10932
- if (!requestSucceeded) {
10933
- setIsSubmitting(false);
10934
- return;
10935
- }
10936
- await confirmOrderEdit(void 0, {
10937
- onError: (e) => {
10938
- ui.toast.error(e.message);
10939
- },
10940
- onSuccess: () => {
10941
- handleSuccess();
10942
- },
10943
- onSettled: () => {
10944
- setIsSubmitting(false);
10945
- }
10946
- });
10947
- };
10671
+ }
10672
+ );
10673
+ InlineTip.displayName = "InlineTip";
10674
+ const MetadataFieldSchema = objectType({
10675
+ key: stringType(),
10676
+ disabled: booleanType().optional(),
10677
+ value: anyType()
10678
+ });
10679
+ const MetadataSchema = objectType({
10680
+ metadata: arrayType(MetadataFieldSchema)
10681
+ });
10682
+ const Metadata = () => {
10683
+ const { id } = reactRouterDom.useParams();
10684
+ const { order, isPending, isError, error } = useOrder(id, {
10685
+ fields: "metadata"
10686
+ });
10948
10687
  if (isError) {
10949
10688
  throw error;
10950
10689
  }
10951
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
10952
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
10953
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
10954
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10955
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
10956
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
10957
- ] }),
10958
- /* @__PURE__ */ jsxRuntime.jsx(
10959
- Combobox,
10960
- {
10961
- id: "promotion-combobox",
10962
- "aria-describedby": "promotion-combobox-hint",
10963
- isFetchingNextPage: comboboxData.isFetchingNextPage,
10964
- fetchNextPage: comboboxData.fetchNextPage,
10965
- options: comboboxData.options,
10966
- onSearchValueChange: comboboxData.onSearchValueChange,
10967
- searchValue: comboboxData.searchValue,
10968
- disabled: comboboxData.disabled || isAddingPromotions,
10969
- onChange: add,
10970
- value: comboboxValue
10971
- }
10972
- )
10973
- ] }),
10974
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10975
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
10976
- PromotionItem,
10977
- {
10978
- promotion,
10979
- orderId: preview.id,
10980
- isLoading: isPending
10981
- },
10982
- promotion.id
10983
- )) })
10984
- ] }) }),
10985
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10986
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10987
- /* @__PURE__ */ jsxRuntime.jsx(
10988
- ui.Button,
10989
- {
10990
- size: "small",
10991
- type: "submit",
10992
- isLoading: isSubmitting || isAddingPromotions,
10993
- children: "Save"
10994
- }
10995
- )
10996
- ] }) })
10690
+ const isReady = !isPending && !!order;
10691
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10692
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10693
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
10694
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10695
+ ] }),
10696
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10997
10697
  ] });
10998
10698
  };
10999
- const PromotionItem = ({
11000
- promotion,
11001
- orderId,
11002
- isLoading
11003
- }) => {
11004
- var _a;
11005
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11006
- const onRemove = async () => {
11007
- removePromotions(
10699
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10700
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10701
+ const MetadataForm = ({ orderId, metadata }) => {
10702
+ const { handleSuccess } = useRouteModal();
10703
+ const hasUneditableRows = getHasUneditableRows(metadata);
10704
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10705
+ const form = reactHookForm.useForm({
10706
+ defaultValues: {
10707
+ metadata: getDefaultValues(metadata)
10708
+ },
10709
+ resolver: zod.zodResolver(MetadataSchema)
10710
+ });
10711
+ const handleSubmit = form.handleSubmit(async (data) => {
10712
+ const parsedData = parseValues(data);
10713
+ await mutateAsync(
11008
10714
  {
11009
- promo_codes: [promotion.code]
10715
+ metadata: parsedData
11010
10716
  },
11011
10717
  {
11012
- onError: (e) => {
11013
- ui.toast.error(e.message);
10718
+ onSuccess: () => {
10719
+ ui.toast.success("Metadata updated");
10720
+ handleSuccess();
10721
+ },
10722
+ onError: (error) => {
10723
+ ui.toast.error(error.message);
11014
10724
  }
11015
10725
  }
11016
10726
  );
11017
- };
11018
- const displayValue = getDisplayValue(promotion);
11019
- return /* @__PURE__ */ jsxRuntime.jsxs(
11020
- "div",
10727
+ });
10728
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
10729
+ control: form.control,
10730
+ name: "metadata"
10731
+ });
10732
+ function deleteRow(index) {
10733
+ remove(index);
10734
+ if (fields.length === 1) {
10735
+ insert(0, {
10736
+ key: "",
10737
+ value: "",
10738
+ disabled: false
10739
+ });
10740
+ }
10741
+ }
10742
+ function insertRow(index, position) {
10743
+ insert(index + (position === "above" ? 0 : 1), {
10744
+ key: "",
10745
+ value: "",
10746
+ disabled: false
10747
+ });
10748
+ }
10749
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10750
+ KeyboundForm,
11021
10751
  {
11022
- className: ui.clx(
11023
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11024
- {
11025
- "animate-pulse": isLoading
11026
- }
11027
- ),
10752
+ onSubmit: handleSubmit,
10753
+ className: "flex flex-1 flex-col overflow-hidden",
11028
10754
  children: [
11029
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11030
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11031
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11032
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11033
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11034
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
10755
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10756
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10757
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
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_KEY_LABEL_ID, children: "Key" }) }),
10759
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
11035
10760
  ] }),
11036
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11037
- ] })
10761
+ fields.map((field, index) => {
10762
+ const isDisabled = field.disabled || false;
10763
+ let placeholder = "-";
10764
+ if (typeof field.value === "object") {
10765
+ placeholder = "{ ... }";
10766
+ }
10767
+ if (Array.isArray(field.value)) {
10768
+ placeholder = "[ ... ]";
10769
+ }
10770
+ return /* @__PURE__ */ jsxRuntime.jsx(
10771
+ ConditionalTooltip,
10772
+ {
10773
+ showTooltip: isDisabled,
10774
+ content: "This row is disabled because it contains non-primitive data.",
10775
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
10776
+ /* @__PURE__ */ jsxRuntime.jsxs(
10777
+ "div",
10778
+ {
10779
+ className: ui.clx("grid grid-cols-2 divide-x", {
10780
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
10781
+ }),
10782
+ children: [
10783
+ /* @__PURE__ */ jsxRuntime.jsx(
10784
+ Form$2.Field,
10785
+ {
10786
+ control: form.control,
10787
+ name: `metadata.${index}.key`,
10788
+ render: ({ field: field2 }) => {
10789
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10790
+ GridInput,
10791
+ {
10792
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10793
+ ...field2,
10794
+ disabled: isDisabled,
10795
+ placeholder: "Key"
10796
+ }
10797
+ ) }) });
10798
+ }
10799
+ }
10800
+ ),
10801
+ /* @__PURE__ */ jsxRuntime.jsx(
10802
+ Form$2.Field,
10803
+ {
10804
+ control: form.control,
10805
+ name: `metadata.${index}.value`,
10806
+ render: ({ field: { value, ...field2 } }) => {
10807
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10808
+ GridInput,
10809
+ {
10810
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
10811
+ ...field2,
10812
+ value: isDisabled ? placeholder : value,
10813
+ disabled: isDisabled,
10814
+ placeholder: "Value"
10815
+ }
10816
+ ) }) });
10817
+ }
10818
+ }
10819
+ )
10820
+ ]
10821
+ }
10822
+ ),
10823
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10824
+ /* @__PURE__ */ jsxRuntime.jsx(
10825
+ ui.DropdownMenu.Trigger,
10826
+ {
10827
+ className: ui.clx(
10828
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10829
+ {
10830
+ hidden: isDisabled
10831
+ }
10832
+ ),
10833
+ disabled: isDisabled,
10834
+ asChild: true,
10835
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
10836
+ }
10837
+ ),
10838
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10839
+ /* @__PURE__ */ jsxRuntime.jsxs(
10840
+ ui.DropdownMenu.Item,
10841
+ {
10842
+ className: "gap-x-2",
10843
+ onClick: () => insertRow(index, "above"),
10844
+ children: [
10845
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
10846
+ "Insert row above"
10847
+ ]
10848
+ }
10849
+ ),
10850
+ /* @__PURE__ */ jsxRuntime.jsxs(
10851
+ ui.DropdownMenu.Item,
10852
+ {
10853
+ className: "gap-x-2",
10854
+ onClick: () => insertRow(index, "below"),
10855
+ children: [
10856
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
10857
+ "Insert row below"
10858
+ ]
10859
+ }
10860
+ ),
10861
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
10862
+ /* @__PURE__ */ jsxRuntime.jsxs(
10863
+ ui.DropdownMenu.Item,
10864
+ {
10865
+ className: "gap-x-2",
10866
+ onClick: () => deleteRow(index),
10867
+ children: [
10868
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
10869
+ "Delete row"
10870
+ ]
10871
+ }
10872
+ )
10873
+ ] })
10874
+ ] })
10875
+ ] })
10876
+ },
10877
+ field.id
10878
+ );
10879
+ })
10880
+ ] }),
10881
+ 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." })
11038
10882
  ] }),
11039
- /* @__PURE__ */ jsxRuntime.jsx(
11040
- ui.IconButton,
11041
- {
11042
- size: "small",
11043
- type: "button",
11044
- variant: "transparent",
11045
- onClick: onRemove,
11046
- isLoading: isPending || isLoading,
11047
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11048
- }
11049
- )
10883
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10884
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10885
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10886
+ ] }) })
11050
10887
  ]
11051
- },
11052
- promotion.id
11053
- );
11054
- };
11055
- function getDisplayValue(promotion) {
11056
- var _a, _b, _c, _d;
11057
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11058
- if (!value) {
11059
- return null;
11060
- }
11061
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11062
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11063
- if (!currency) {
11064
- return null;
11065
10888
  }
11066
- return getLocaleAmount(value, currency);
11067
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11068
- return formatPercentage(value);
11069
- }
11070
- return null;
11071
- }
11072
- const formatter = new Intl.NumberFormat([], {
11073
- style: "percent",
11074
- minimumFractionDigits: 2
11075
- });
11076
- const formatPercentage = (value, isPercentageValue = false) => {
11077
- let val = value || 0;
11078
- if (!isPercentageValue) {
11079
- val = val / 100;
11080
- }
11081
- return formatter.format(val);
10889
+ ) });
11082
10890
  };
11083
- function getPromotionIds(items, shippingMethods) {
11084
- const promotionIds = /* @__PURE__ */ new Set();
11085
- for (const item of items) {
11086
- if (item.adjustments) {
11087
- for (const adjustment of item.adjustments) {
11088
- if (adjustment.promotion_id) {
11089
- promotionIds.add(adjustment.promotion_id);
11090
- }
11091
- }
11092
- }
11093
- }
11094
- for (const shippingMethod of shippingMethods) {
11095
- if (shippingMethod.adjustments) {
11096
- for (const adjustment of shippingMethod.adjustments) {
11097
- if (adjustment.promotion_id) {
11098
- promotionIds.add(adjustment.promotion_id);
11099
- }
11100
- }
11101
- }
11102
- }
11103
- return Array.from(promotionIds);
11104
- }
11105
- const SalesChannel = () => {
11106
- const { id } = reactRouterDom.useParams();
11107
- const { draft_order, isPending, isError, error } = useDraftOrder(
11108
- id,
11109
- {
11110
- fields: "+sales_channel_id"
11111
- },
10891
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
10892
+ return /* @__PURE__ */ jsxRuntime.jsx(
10893
+ "input",
11112
10894
  {
11113
- enabled: !!id
10895
+ ref,
10896
+ ...props,
10897
+ autoComplete: "off",
10898
+ className: ui.clx(
10899
+ "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",
10900
+ className
10901
+ )
11114
10902
  }
11115
10903
  );
11116
- if (isError) {
11117
- throw error;
11118
- }
11119
- const ISrEADY = !!draft_order && !isPending;
11120
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11121
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11122
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11123
- /* @__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" }) })
11124
- ] }),
11125
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
10904
+ });
10905
+ GridInput.displayName = "MetadataForm.GridInput";
10906
+ const PlaceholderInner = () => {
10907
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10908
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10909
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10910
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
10911
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
10912
+ ] }) })
11126
10913
  ] });
11127
10914
  };
11128
- const SalesChannelForm = ({ order }) => {
11129
- const form = reactHookForm.useForm({
11130
- defaultValues: {
11131
- sales_channel_id: order.sales_channel_id || ""
11132
- },
11133
- resolver: zod.zodResolver(schema$2)
11134
- });
11135
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11136
- const { handleSuccess } = useRouteModal();
11137
- const onSubmit = form.handleSubmit(async (data) => {
11138
- await mutateAsync(
11139
- {
11140
- sales_channel_id: data.sales_channel_id
11141
- },
10915
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
10916
+ function getDefaultValues(metadata) {
10917
+ if (!metadata || !Object.keys(metadata).length) {
10918
+ return [
11142
10919
  {
11143
- onSuccess: () => {
11144
- ui.toast.success("Sales channel updated");
11145
- handleSuccess();
11146
- },
11147
- onError: (error) => {
11148
- ui.toast.error(error.message);
11149
- }
10920
+ key: "",
10921
+ value: "",
10922
+ disabled: false
11150
10923
  }
11151
- );
11152
- });
11153
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11154
- KeyboundForm,
11155
- {
11156
- className: "flex flex-1 flex-col overflow-hidden",
11157
- onSubmit,
11158
- children: [
11159
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11160
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11161
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11162
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11163
- ] }) })
11164
- ]
10924
+ ];
10925
+ }
10926
+ return Object.entries(metadata).map(([key, value]) => {
10927
+ if (!EDITABLE_TYPES.includes(typeof value)) {
10928
+ return {
10929
+ key,
10930
+ value,
10931
+ disabled: true
10932
+ };
11165
10933
  }
11166
- ) });
11167
- };
11168
- const SalesChannelField = ({ control, order }) => {
11169
- const salesChannels = useComboboxData({
11170
- queryFn: async (params) => {
11171
- return await sdk.admin.salesChannel.list(params);
11172
- },
11173
- queryKey: ["sales-channels"],
11174
- getOptions: (data) => {
11175
- return data.sales_channels.map((salesChannel) => ({
11176
- label: salesChannel.name,
11177
- value: salesChannel.id
11178
- }));
11179
- },
11180
- defaultValue: order.sales_channel_id || void 0
10934
+ let stringValue = value;
10935
+ if (typeof value !== "string") {
10936
+ stringValue = JSON.stringify(value);
10937
+ }
10938
+ return {
10939
+ key,
10940
+ value: stringValue,
10941
+ original_key: key
10942
+ };
11181
10943
  });
11182
- return /* @__PURE__ */ jsxRuntime.jsx(
11183
- Form$2.Field,
11184
- {
11185
- control,
11186
- name: "sales_channel_id",
11187
- render: ({ field }) => {
11188
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11189
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11190
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11191
- Combobox,
11192
- {
11193
- options: salesChannels.options,
11194
- fetchNextPage: salesChannels.fetchNextPage,
11195
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11196
- searchValue: salesChannels.searchValue,
11197
- onSearchValueChange: salesChannels.onSearchValueChange,
11198
- placeholder: "Select sales channel",
11199
- ...field
11200
- }
11201
- ) }),
11202
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11203
- ] });
10944
+ }
10945
+ function parseValues(values) {
10946
+ const metadata = values.metadata;
10947
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10948
+ if (isEmpty) {
10949
+ return null;
10950
+ }
10951
+ const update = {};
10952
+ metadata.forEach((field) => {
10953
+ let key = field.key;
10954
+ let value = field.value;
10955
+ const disabled = field.disabled;
10956
+ if (!key || !value) {
10957
+ return;
10958
+ }
10959
+ if (disabled) {
10960
+ update[key] = value;
10961
+ return;
10962
+ }
10963
+ key = key.trim();
10964
+ value = value.trim();
10965
+ if (value === "true") {
10966
+ update[key] = true;
10967
+ } else if (value === "false") {
10968
+ update[key] = false;
10969
+ } else {
10970
+ const parsedNumber = parseFloat(value);
10971
+ if (!isNaN(parsedNumber)) {
10972
+ update[key] = parsedNumber;
10973
+ } else {
10974
+ update[key] = value;
11204
10975
  }
11205
10976
  }
10977
+ });
10978
+ return update;
10979
+ }
10980
+ function getHasUneditableRows(metadata) {
10981
+ if (!metadata) {
10982
+ return false;
10983
+ }
10984
+ return Object.values(metadata).some(
10985
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11206
10986
  );
10987
+ }
10988
+ const PROMOTION_QUERY_KEY = "promotions";
10989
+ const promotionsQueryKeys = {
10990
+ list: (query2) => [
10991
+ PROMOTION_QUERY_KEY,
10992
+ query2 ? query2 : void 0
10993
+ ],
10994
+ detail: (id, query2) => [
10995
+ PROMOTION_QUERY_KEY,
10996
+ id,
10997
+ query2 ? query2 : void 0
10998
+ ]
11207
10999
  };
11208
- const schema$2 = objectType({
11209
- sales_channel_id: stringType().min(1)
11210
- });
11211
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11212
- const Shipping = () => {
11213
- var _a;
11214
- const { id } = reactRouterDom.useParams();
11215
- const { order, isPending, isError, error } = useOrder(id, {
11216
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11000
+ const usePromotions = (query2, options) => {
11001
+ const { data, ...rest } = reactQuery.useQuery({
11002
+ queryKey: promotionsQueryKeys.list(query2),
11003
+ queryFn: async () => sdk.admin.promotion.list(query2),
11004
+ ...options
11217
11005
  });
11006
+ return { ...data, ...rest };
11007
+ };
11008
+ const Promotions = () => {
11009
+ const { id } = reactRouterDom.useParams();
11218
11010
  const {
11219
11011
  order: preview,
11220
- isPending: isPreviewPending,
11221
11012
  isError: isPreviewError,
11222
11013
  error: previewError
11223
- } = useOrderPreview(id);
11014
+ } = useOrderPreview(id, void 0);
11224
11015
  useInitiateOrderEdit({ preview });
11225
11016
  const { onCancel } = useCancelOrderEdit({ preview });
11226
- if (isError) {
11227
- throw error;
11228
- }
11229
11017
  if (isPreviewError) {
11230
11018
  throw previewError;
11231
11019
  }
11232
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11233
- const isReady = preview && !isPreviewPending && order && !isPending;
11234
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11235
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11236
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11237
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11238
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11239
- ] }) }) }),
11240
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11241
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11242
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11243
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11244
- ] }) });
11020
+ const isReady = !!preview;
11021
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11022
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11023
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11024
+ ] });
11245
11025
  };
11246
- const ShippingForm = ({ preview, order }) => {
11247
- var _a;
11248
- const { setIsOpen } = useStackedModal();
11026
+ const PromotionForm = ({ preview }) => {
11027
+ const { items, shipping_methods } = preview;
11249
11028
  const [isSubmitting, setIsSubmitting] = React.useState(false);
11250
- const [data, setData] = React.useState(null);
11251
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11252
- const { shipping_options } = useShippingOptions(
11029
+ const [comboboxValue, setComboboxValue] = React.useState("");
11030
+ const { handleSuccess } = useRouteModal();
11031
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11032
+ const promoIds = getPromotionIds(items, shipping_methods);
11033
+ const { promotions, isPending, isError, error } = usePromotions(
11253
11034
  {
11254
- id: appliedShippingOptionIds,
11255
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11035
+ id: promoIds
11256
11036
  },
11257
11037
  {
11258
- enabled: appliedShippingOptionIds.length > 0
11038
+ enabled: !!promoIds.length
11259
11039
  }
11260
11040
  );
11261
- const uniqueShippingProfiles = React.useMemo(() => {
11262
- const profiles = /* @__PURE__ */ new Map();
11263
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11264
- profiles.set(profile.id, profile);
11265
- });
11266
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11267
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11268
- });
11269
- return Array.from(profiles.values());
11270
- }, [order.items, shipping_options]);
11271
- const { handleSuccess } = useRouteModal();
11041
+ const comboboxData = useComboboxData({
11042
+ queryKey: ["promotions", "combobox", promoIds],
11043
+ queryFn: async (params) => {
11044
+ return await sdk.admin.promotion.list({
11045
+ ...params,
11046
+ id: {
11047
+ $nin: promoIds
11048
+ }
11049
+ });
11050
+ },
11051
+ getOptions: (data) => {
11052
+ return data.promotions.map((promotion) => ({
11053
+ label: promotion.code,
11054
+ value: promotion.code
11055
+ }));
11056
+ }
11057
+ });
11058
+ const add = async (value) => {
11059
+ if (!value) {
11060
+ return;
11061
+ }
11062
+ addPromotions(
11063
+ {
11064
+ promo_codes: [value]
11065
+ },
11066
+ {
11067
+ onError: (e) => {
11068
+ ui.toast.error(e.message);
11069
+ comboboxData.onSearchValueChange("");
11070
+ setComboboxValue("");
11071
+ },
11072
+ onSuccess: () => {
11073
+ comboboxData.onSearchValueChange("");
11074
+ setComboboxValue("");
11075
+ }
11076
+ }
11077
+ );
11078
+ };
11272
11079
  const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11273
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11274
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11275
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11080
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11276
11081
  const onSubmit = async () => {
11277
11082
  setIsSubmitting(true);
11278
11083
  let requestSucceeded = false;
11279
11084
  await requestOrderEdit(void 0, {
11280
11085
  onError: (e) => {
11281
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11086
+ ui.toast.error(e.message);
11282
11087
  },
11283
11088
  onSuccess: () => {
11284
11089
  requestSucceeded = true;
@@ -11290,7 +11095,7 @@ const ShippingForm = ({ preview, order }) => {
11290
11095
  }
11291
11096
  await confirmOrderEdit(void 0, {
11292
11097
  onError: (e) => {
11293
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11098
+ ui.toast.error(e.message);
11294
11099
  },
11295
11100
  onSuccess: () => {
11296
11101
  handleSuccess();
@@ -11300,754 +11105,492 @@ const ShippingForm = ({ preview, order }) => {
11300
11105
  }
11301
11106
  });
11302
11107
  };
11303
- const onKeydown = React.useCallback(
11304
- (e) => {
11305
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11306
- if (data || isSubmitting) {
11307
- return;
11308
- }
11309
- onSubmit();
11310
- }
11311
- },
11312
- [data, isSubmitting, onSubmit]
11313
- );
11314
- React.useEffect(() => {
11315
- document.addEventListener("keydown", onKeydown);
11316
- return () => {
11317
- document.removeEventListener("keydown", onKeydown);
11318
- };
11319
- }, [onKeydown]);
11320
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11321
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11322
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11323
- /* @__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: [
11108
+ if (isError) {
11109
+ throw error;
11110
+ }
11111
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11112
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11113
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11114
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11115
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11116
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11117
+ ] }),
11118
+ /* @__PURE__ */ jsxRuntime.jsx(
11119
+ Combobox,
11120
+ {
11121
+ id: "promotion-combobox",
11122
+ "aria-describedby": "promotion-combobox-hint",
11123
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11124
+ fetchNextPage: comboboxData.fetchNextPage,
11125
+ options: comboboxData.options,
11126
+ onSearchValueChange: comboboxData.onSearchValueChange,
11127
+ searchValue: comboboxData.searchValue,
11128
+ disabled: comboboxData.disabled || isAddingPromotions,
11129
+ onChange: add,
11130
+ value: comboboxValue
11131
+ }
11132
+ )
11133
+ ] }),
11134
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11135
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11136
+ PromotionItem,
11137
+ {
11138
+ promotion,
11139
+ orderId: preview.id,
11140
+ isLoading: isPending
11141
+ },
11142
+ promotion.id
11143
+ )) })
11144
+ ] }) }),
11145
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11146
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11147
+ /* @__PURE__ */ jsxRuntime.jsx(
11148
+ ui.Button,
11149
+ {
11150
+ size: "small",
11151
+ type: "submit",
11152
+ isLoading: isSubmitting || isAddingPromotions,
11153
+ children: "Save"
11154
+ }
11155
+ )
11156
+ ] }) })
11157
+ ] });
11158
+ };
11159
+ const PromotionItem = ({
11160
+ promotion,
11161
+ orderId,
11162
+ isLoading
11163
+ }) => {
11164
+ var _a;
11165
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11166
+ const onRemove = async () => {
11167
+ removePromotions(
11168
+ {
11169
+ promo_codes: [promotion.code]
11170
+ },
11171
+ {
11172
+ onError: (e) => {
11173
+ ui.toast.error(e.message);
11174
+ }
11175
+ }
11176
+ );
11177
+ };
11178
+ const displayValue = getDisplayValue(promotion);
11179
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11180
+ "div",
11181
+ {
11182
+ className: ui.clx(
11183
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11184
+ {
11185
+ "animate-pulse": isLoading
11186
+ }
11187
+ ),
11188
+ children: [
11324
11189
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11325
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11326
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11190
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11191
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11192
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11193
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11194
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11195
+ ] }),
11196
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11197
+ ] })
11327
11198
  ] }),
11328
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11329
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11330
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
11199
+ /* @__PURE__ */ jsxRuntime.jsx(
11200
+ ui.IconButton,
11201
+ {
11202
+ size: "small",
11203
+ type: "button",
11204
+ variant: "transparent",
11205
+ onClick: onRemove,
11206
+ isLoading: isPending || isLoading,
11207
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11208
+ }
11209
+ )
11210
+ ]
11211
+ },
11212
+ promotion.id
11213
+ );
11214
+ };
11215
+ function getDisplayValue(promotion) {
11216
+ var _a, _b, _c, _d;
11217
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11218
+ if (!value) {
11219
+ return null;
11220
+ }
11221
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11222
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11223
+ if (!currency) {
11224
+ return null;
11225
+ }
11226
+ return getLocaleAmount(value, currency);
11227
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11228
+ return formatPercentage(value);
11229
+ }
11230
+ return null;
11231
+ }
11232
+ const formatter = new Intl.NumberFormat([], {
11233
+ style: "percent",
11234
+ minimumFractionDigits: 2
11235
+ });
11236
+ const formatPercentage = (value, isPercentageValue = false) => {
11237
+ let val = value || 0;
11238
+ if (!isPercentageValue) {
11239
+ val = val / 100;
11240
+ }
11241
+ return formatter.format(val);
11242
+ };
11243
+ function getPromotionIds(items, shippingMethods) {
11244
+ const promotionIds = /* @__PURE__ */ new Set();
11245
+ for (const item of items) {
11246
+ if (item.adjustments) {
11247
+ for (const adjustment of item.adjustments) {
11248
+ if (adjustment.promotion_id) {
11249
+ promotionIds.add(adjustment.promotion_id);
11250
+ }
11251
+ }
11252
+ }
11253
+ }
11254
+ for (const shippingMethod of shippingMethods) {
11255
+ if (shippingMethod.adjustments) {
11256
+ for (const adjustment of shippingMethod.adjustments) {
11257
+ if (adjustment.promotion_id) {
11258
+ promotionIds.add(adjustment.promotion_id);
11259
+ }
11260
+ }
11261
+ }
11262
+ }
11263
+ return Array.from(promotionIds);
11264
+ }
11265
+ const BillingAddress = () => {
11266
+ const { id } = reactRouterDom.useParams();
11267
+ const { order, isPending, isError, error } = useOrder(id, {
11268
+ fields: "+billing_address"
11269
+ });
11270
+ if (isError) {
11271
+ throw error;
11272
+ }
11273
+ const isReady = !isPending && !!order;
11274
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11275
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11276
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
11277
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
11278
+ ] }),
11279
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
11280
+ ] });
11281
+ };
11282
+ const BillingAddressForm = ({ order }) => {
11283
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11284
+ const form = reactHookForm.useForm({
11285
+ defaultValues: {
11286
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
11287
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
11288
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
11289
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
11290
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
11291
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
11292
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
11293
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
11294
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
11295
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
11296
+ },
11297
+ resolver: zod.zodResolver(schema$3)
11298
+ });
11299
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11300
+ const { handleSuccess } = useRouteModal();
11301
+ const onSubmit = form.handleSubmit(async (data) => {
11302
+ await mutateAsync(
11303
+ { billing_address: data },
11304
+ {
11305
+ onSuccess: () => {
11306
+ handleSuccess();
11307
+ },
11308
+ onError: (error) => {
11309
+ ui.toast.error(error.message);
11310
+ }
11311
+ }
11312
+ );
11313
+ });
11314
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11315
+ KeyboundForm,
11316
+ {
11317
+ className: "flex flex-1 flex-col overflow-hidden",
11318
+ onSubmit,
11319
+ children: [
11320
+ /* @__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: [
11321
+ /* @__PURE__ */ jsxRuntime.jsx(
11322
+ Form$2.Field,
11323
+ {
11324
+ control: form.control,
11325
+ name: "country_code",
11326
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11327
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11328
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11329
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11330
+ ] })
11331
+ }
11332
+ ),
11333
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11331
11334
  /* @__PURE__ */ jsxRuntime.jsx(
11332
- ui.Text,
11335
+ Form$2.Field,
11333
11336
  {
11334
- size: "xsmall",
11335
- weight: "plus",
11336
- className: "text-ui-fg-muted",
11337
- children: "Shipping profile"
11337
+ control: form.control,
11338
+ name: "first_name",
11339
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11340
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11341
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11342
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11343
+ ] })
11338
11344
  }
11339
11345
  ),
11340
11346
  /* @__PURE__ */ jsxRuntime.jsx(
11341
- ui.Text,
11347
+ Form$2.Field,
11342
11348
  {
11343
- size: "xsmall",
11344
- weight: "plus",
11345
- className: "text-ui-fg-muted",
11346
- children: "Action"
11347
- }
11348
- )
11349
- ] }),
11350
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11351
- var _a2, _b, _c, _d, _e, _f, _g;
11352
- const items = getItemsWithShippingProfile(
11353
- profile.id,
11354
- order.items
11355
- );
11356
- const hasItems = items.length > 0;
11357
- const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11358
- (option) => option.shipping_profile_id === profile.id
11359
- );
11360
- const shippingMethod = preview.shipping_methods.find(
11361
- (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11362
- );
11363
- const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11364
- (action) => action.action === "SHIPPING_ADD"
11365
- );
11366
- return /* @__PURE__ */ jsxRuntime.jsxs(
11367
- radixUi.Accordion.Item,
11349
+ control: form.control,
11350
+ name: "last_name",
11351
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11352
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
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
+ ] }),
11359
+ /* @__PURE__ */ jsxRuntime.jsx(
11360
+ Form$2.Field,
11361
+ {
11362
+ control: form.control,
11363
+ name: "company",
11364
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11365
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11366
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11367
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11368
+ ] })
11369
+ }
11370
+ ),
11371
+ /* @__PURE__ */ jsxRuntime.jsx(
11372
+ Form$2.Field,
11373
+ {
11374
+ control: form.control,
11375
+ name: "address_1",
11376
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11377
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11378
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11379
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11380
+ ] })
11381
+ }
11382
+ ),
11383
+ /* @__PURE__ */ jsxRuntime.jsx(
11384
+ Form$2.Field,
11385
+ {
11386
+ control: form.control,
11387
+ name: "address_2",
11388
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11389
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11390
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11391
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11392
+ ] })
11393
+ }
11394
+ ),
11395
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11396
+ /* @__PURE__ */ jsxRuntime.jsx(
11397
+ Form$2.Field,
11368
11398
  {
11369
- value: profile.id,
11370
- className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11371
- children: [
11372
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-3 px-3 py-2", children: [
11373
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3 overflow-hidden", children: [
11374
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
11375
- ui.IconButton,
11376
- {
11377
- size: "2xsmall",
11378
- variant: "transparent",
11379
- className: "group/trigger",
11380
- disabled: !hasItems,
11381
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "transition-transform group-data-[state=open]/trigger:rotate-90" })
11382
- }
11383
- ) }),
11384
- !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11385
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "shadow-borders-base flex size-7 items-center justify-center rounded-md", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-ui-bg-component-hover flex size-6 items-center justify-center rounded", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "text-ui-fg-subtle" }) }) }),
11386
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col", children: [
11387
- /* @__PURE__ */ jsxRuntime.jsx(
11388
- ui.Text,
11389
- {
11390
- size: "small",
11391
- weight: "plus",
11392
- leading: "compact",
11393
- children: profile.name
11394
- }
11395
- ),
11396
- /* @__PURE__ */ jsxRuntime.jsxs(
11397
- ui.Text,
11398
- {
11399
- size: "small",
11400
- leading: "compact",
11401
- className: "text-ui-fg-subtle",
11402
- children: [
11403
- items.length,
11404
- " ",
11405
- pluralize(items.length, "items", "item")
11406
- ]
11407
- }
11408
- )
11409
- ] })
11410
- ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full flex-1 items-center gap-[5px] overflow-hidden max-sm:flex-col max-sm:items-start", children: [
11411
- /* @__PURE__ */ jsxRuntime.jsx(
11412
- ui.Tooltip,
11413
- {
11414
- content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
11415
- var _a3, _b2, _c2;
11416
- return /* @__PURE__ */ jsxRuntime.jsx(
11417
- "li",
11418
- {
11419
- children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
11420
- },
11421
- item.id
11422
- );
11423
- }) }),
11424
- children: /* @__PURE__ */ jsxRuntime.jsxs(
11425
- ui.Badge,
11426
- {
11427
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11428
- size: "xsmall",
11429
- children: [
11430
- /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
11431
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
11432
- items.reduce(
11433
- (acc, item) => acc + item.quantity,
11434
- 0
11435
- ),
11436
- "x",
11437
- " ",
11438
- pluralize(items.length, "items", "item")
11439
- ] })
11440
- ]
11441
- }
11442
- )
11443
- }
11444
- ),
11445
- /* @__PURE__ */ jsxRuntime.jsx(
11446
- ui.Tooltip,
11447
- {
11448
- content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11449
- children: /* @__PURE__ */ jsxRuntime.jsxs(
11450
- ui.Badge,
11451
- {
11452
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11453
- size: "xsmall",
11454
- children: [
11455
- /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
11456
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
11457
- ]
11458
- }
11459
- )
11460
- }
11461
- ),
11462
- /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
11463
- ui.Badge,
11464
- {
11465
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11466
- size: "xsmall",
11467
- children: [
11468
- /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
11469
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
11470
- ]
11471
- }
11472
- ) })
11473
- ] })
11474
- ] }),
11475
- shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
11476
- ActionMenu,
11477
- {
11478
- groups: [
11479
- {
11480
- actions: [
11481
- hasItems ? {
11482
- label: "Edit shipping option",
11483
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
11484
- onClick: () => {
11485
- setIsOpen(
11486
- STACKED_FOCUS_MODAL_ID,
11487
- true
11488
- );
11489
- setData({
11490
- shippingProfileId: profile.id,
11491
- shippingOption,
11492
- shippingMethod
11493
- });
11494
- }
11495
- } : void 0,
11496
- {
11497
- label: "Remove shipping option",
11498
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
11499
- onClick: () => {
11500
- if (shippingMethod) {
11501
- if (addShippingMethodAction) {
11502
- removeActionShippingMethod(
11503
- addShippingMethodAction.id
11504
- );
11505
- } else {
11506
- removeShippingMethod(
11507
- shippingMethod.id
11508
- );
11509
- }
11510
- }
11511
- }
11512
- }
11513
- ].filter(Boolean)
11514
- }
11515
- ]
11516
- }
11517
- ) : /* @__PURE__ */ jsxRuntime.jsx(
11518
- StackedModalTrigger,
11519
- {
11520
- shippingProfileId: profile.id,
11521
- shippingOption,
11522
- shippingMethod,
11523
- setData,
11524
- children: "Add shipping option"
11525
- }
11526
- )
11527
- ] }),
11528
- /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
11529
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11530
- items.map((item, idx) => {
11531
- var _a3, _b2, _c2, _d2, _e2;
11532
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11533
- /* @__PURE__ */ jsxRuntime.jsxs(
11534
- "div",
11535
- {
11536
- className: "flex items-center gap-x-3 px-3",
11537
- children: [
11538
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-[56px] w-5 flex-col items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
11539
- ui.Divider,
11540
- {
11541
- variant: "dashed",
11542
- orientation: "vertical"
11543
- }
11544
- ) }),
11545
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 py-2", children: [
11546
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex size-7 items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
11547
- ui.Text,
11548
- {
11549
- size: "small",
11550
- leading: "compact",
11551
- className: "text-ui-fg-subtle",
11552
- children: [
11553
- item.quantity,
11554
- "x"
11555
- ]
11556
- }
11557
- ) }),
11558
- /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
11559
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11560
- /* @__PURE__ */ jsxRuntime.jsxs(
11561
- ui.Text,
11562
- {
11563
- size: "small",
11564
- leading: "compact",
11565
- weight: "plus",
11566
- children: [
11567
- (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
11568
- " (",
11569
- (_c2 = item.variant) == null ? void 0 : _c2.title,
11570
- ")"
11571
- ]
11572
- }
11573
- ),
11574
- /* @__PURE__ */ jsxRuntime.jsx(
11575
- ui.Text,
11576
- {
11577
- size: "small",
11578
- leading: "compact",
11579
- className: "text-ui-fg-subtle",
11580
- children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
11581
- }
11582
- )
11583
- ] })
11584
- ] })
11585
- ]
11586
- },
11587
- item.id
11588
- ),
11589
- idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
11590
- ] }, item.id);
11591
- })
11592
- ] })
11593
- ]
11594
- },
11595
- profile.id
11596
- );
11597
- }) })
11598
- ] }) })
11599
- ] }) }),
11600
- /* @__PURE__ */ jsxRuntime.jsx(
11601
- StackedFocusModal,
11602
- {
11603
- id: STACKED_FOCUS_MODAL_ID,
11604
- onOpenChangeCallback: (open) => {
11605
- if (!open) {
11606
- setData(null);
11399
+ control: form.control,
11400
+ name: "postal_code",
11401
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11402
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11403
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11404
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11405
+ ] })
11406
+ }
11407
+ ),
11408
+ /* @__PURE__ */ jsxRuntime.jsx(
11409
+ Form$2.Field,
11410
+ {
11411
+ control: form.control,
11412
+ name: "city",
11413
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11414
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11415
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11416
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11417
+ ] })
11418
+ }
11419
+ )
11420
+ ] }),
11421
+ /* @__PURE__ */ jsxRuntime.jsx(
11422
+ Form$2.Field,
11423
+ {
11424
+ control: form.control,
11425
+ name: "province",
11426
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11427
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11428
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11429
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11430
+ ] })
11607
11431
  }
11608
- return open;
11609
- },
11610
- children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
11611
- }
11612
- )
11613
- ] }),
11614
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11615
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11616
- /* @__PURE__ */ jsxRuntime.jsx(
11617
- ui.Button,
11618
- {
11619
- size: "small",
11620
- type: "button",
11621
- isLoading: isSubmitting,
11622
- onClick: onSubmit,
11623
- children: "Save"
11624
- }
11625
- )
11626
- ] }) })
11627
- ] });
11628
- };
11629
- const StackedModalTrigger = ({
11630
- shippingProfileId,
11631
- shippingOption,
11632
- shippingMethod,
11633
- setData,
11634
- children
11635
- }) => {
11636
- const { setIsOpen, getIsOpen } = useStackedModal();
11637
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11638
- const onToggle = () => {
11639
- if (isOpen) {
11640
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11641
- setData(null);
11642
- } else {
11643
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11644
- setData({
11645
- shippingProfileId,
11646
- shippingOption,
11647
- shippingMethod
11648
- });
11432
+ ),
11433
+ /* @__PURE__ */ jsxRuntime.jsx(
11434
+ Form$2.Field,
11435
+ {
11436
+ control: form.control,
11437
+ name: "phone",
11438
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11439
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11440
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11441
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11442
+ ] })
11443
+ }
11444
+ )
11445
+ ] }) }),
11446
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11447
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11448
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11449
+ ] }) })
11450
+ ]
11649
11451
  }
11650
- };
11651
- return /* @__PURE__ */ jsxRuntime.jsx(
11652
- ui.Button,
11452
+ ) });
11453
+ };
11454
+ const schema$3 = addressSchema;
11455
+ const SalesChannel = () => {
11456
+ const { id } = reactRouterDom.useParams();
11457
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11458
+ id,
11653
11459
  {
11654
- size: "small",
11655
- variant: "secondary",
11656
- onClick: onToggle,
11657
- className: "text-ui-fg-primary shrink-0",
11658
- children
11460
+ fields: "+sales_channel_id"
11461
+ },
11462
+ {
11463
+ enabled: !!id
11659
11464
  }
11660
11465
  );
11466
+ if (isError) {
11467
+ throw error;
11468
+ }
11469
+ const ISrEADY = !!draft_order && !isPending;
11470
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11471
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11472
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11473
+ /* @__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" }) })
11474
+ ] }),
11475
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11476
+ ] });
11661
11477
  };
11662
- const ShippingProfileForm = ({
11663
- data,
11664
- order,
11665
- preview
11666
- }) => {
11667
- var _a, _b, _c, _d, _e, _f;
11668
- const { setIsOpen } = useStackedModal();
11478
+ const SalesChannelForm = ({ order }) => {
11669
11479
  const form = reactHookForm.useForm({
11670
- resolver: zod.zodResolver(shippingMethodSchema),
11671
11480
  defaultValues: {
11672
- location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
11673
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
11674
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
11675
- }
11481
+ sales_channel_id: order.sales_channel_id || ""
11482
+ },
11483
+ resolver: zod.zodResolver(schema$2)
11676
11484
  });
11677
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
11678
- const {
11679
- mutateAsync: updateShippingMethod,
11680
- isPending: isUpdatingShippingMethod
11681
- } = useDraftOrderUpdateShippingMethod(order.id);
11682
- const onSubmit = form.handleSubmit(async (values) => {
11683
- if (isEqual__default.default(values, form.formState.defaultValues)) {
11684
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11685
- return;
11686
- }
11687
- if (data.shippingMethod) {
11688
- await updateShippingMethod(
11689
- {
11690
- method_id: data.shippingMethod.id,
11691
- shipping_option_id: values.shipping_option_id,
11692
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11693
- },
11694
- {
11695
- onError: (e) => {
11696
- ui.toast.error(e.message);
11697
- },
11698
- onSuccess: () => {
11699
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11700
- }
11701
- }
11702
- );
11703
- return;
11704
- }
11705
- await addShippingMethod(
11485
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11486
+ const { handleSuccess } = useRouteModal();
11487
+ const onSubmit = form.handleSubmit(async (data) => {
11488
+ await mutateAsync(
11706
11489
  {
11707
- shipping_option_id: values.shipping_option_id,
11708
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11490
+ sales_channel_id: data.sales_channel_id
11709
11491
  },
11710
11492
  {
11711
- onError: (e) => {
11712
- ui.toast.error(e.message);
11713
- },
11714
11493
  onSuccess: () => {
11715
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11494
+ ui.toast.success("Sales channel updated");
11495
+ handleSuccess();
11496
+ },
11497
+ onError: (error) => {
11498
+ ui.toast.error(error.message);
11716
11499
  }
11717
11500
  }
11718
11501
  );
11719
11502
  });
11720
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11503
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11721
11504
  KeyboundForm,
11722
11505
  {
11723
- className: "flex h-full flex-col overflow-hidden",
11506
+ className: "flex flex-1 flex-col overflow-hidden",
11724
11507
  onSubmit,
11725
11508
  children: [
11726
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
11727
- /* @__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-6 py-16", children: [
11728
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11729
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11730
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
11731
- ] }),
11732
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11733
- /* @__PURE__ */ jsxRuntime.jsx(
11734
- LocationField,
11735
- {
11736
- control: form.control,
11737
- setValue: form.setValue
11738
- }
11739
- ),
11740
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11741
- /* @__PURE__ */ jsxRuntime.jsx(
11742
- ShippingOptionField,
11743
- {
11744
- shippingProfileId: data.shippingProfileId,
11745
- preview,
11746
- control: form.control
11747
- }
11748
- ),
11749
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11750
- /* @__PURE__ */ jsxRuntime.jsx(
11751
- CustomAmountField,
11752
- {
11753
- control: form.control,
11754
- currencyCode: order.currency_code
11755
- }
11756
- ),
11757
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11758
- /* @__PURE__ */ jsxRuntime.jsx(
11759
- ItemsPreview,
11760
- {
11761
- order,
11762
- shippingProfileId: data.shippingProfileId
11763
- }
11764
- )
11765
- ] }) }) }),
11766
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11767
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11768
- /* @__PURE__ */ jsxRuntime.jsx(
11769
- ui.Button,
11770
- {
11771
- size: "small",
11772
- type: "submit",
11773
- isLoading: isPending || isUpdatingShippingMethod,
11774
- children: data.shippingMethod ? "Update" : "Add"
11775
- }
11776
- )
11509
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11510
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11511
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11512
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11777
11513
  ] }) })
11778
11514
  ]
11779
11515
  }
11780
- ) }) });
11781
- };
11782
- const shippingMethodSchema = objectType({
11783
- location_id: stringType(),
11784
- shipping_option_id: stringType(),
11785
- custom_amount: unionType([numberType(), stringType()]).optional()
11786
- });
11787
- const ItemsPreview = ({ order, shippingProfileId }) => {
11788
- const matches = order.items.filter(
11789
- (item) => {
11790
- var _a, _b, _c;
11791
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
11792
- }
11793
- );
11794
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
11795
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11796
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
11797
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
11798
- ] }) }),
11799
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11800
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-2 gap-3 px-4 py-2", children: [
11801
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
11802
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
11803
- ] }),
11804
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
11805
- "div",
11806
- {
11807
- className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-2 items-center gap-3 rounded-lg px-4 py-2",
11808
- children: [
11809
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11810
- /* @__PURE__ */ jsxRuntime.jsx(
11811
- Thumbnail,
11812
- {
11813
- thumbnail: item.thumbnail,
11814
- alt: item.product_title ?? void 0
11815
- }
11816
- ),
11817
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11818
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
11819
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
11820
- /* @__PURE__ */ jsxRuntime.jsxs(
11821
- ui.Text,
11822
- {
11823
- size: "small",
11824
- leading: "compact",
11825
- className: "text-ui-fg-subtle",
11826
- children: [
11827
- "(",
11828
- item.variant_title,
11829
- ")"
11830
- ]
11831
- }
11832
- )
11833
- ] }),
11834
- /* @__PURE__ */ jsxRuntime.jsx(
11835
- ui.Text,
11836
- {
11837
- size: "small",
11838
- leading: "compact",
11839
- className: "text-ui-fg-subtle",
11840
- children: item.variant_sku
11841
- }
11842
- )
11843
- ] })
11844
- ] }),
11845
- /* @__PURE__ */ jsxRuntime.jsxs(
11846
- ui.Text,
11847
- {
11848
- size: "small",
11849
- leading: "compact",
11850
- className: "text-ui-fg-subtle",
11851
- children: [
11852
- item.quantity,
11853
- "x"
11854
- ]
11855
- }
11856
- )
11857
- ]
11858
- },
11859
- item.id
11860
- )) : /* @__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: [
11861
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
11862
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
11863
- 'No items found for "',
11864
- query,
11865
- '".'
11866
- ] })
11867
- ] }) })
11868
- ] })
11869
- ] });
11516
+ ) });
11870
11517
  };
11871
- const LocationField = ({ control, setValue }) => {
11872
- const locations = useComboboxData({
11873
- queryKey: ["locations"],
11518
+ const SalesChannelField = ({ control, order }) => {
11519
+ const salesChannels = useComboboxData({
11874
11520
  queryFn: async (params) => {
11875
- return await sdk.admin.stockLocation.list(params);
11521
+ return await sdk.admin.salesChannel.list(params);
11876
11522
  },
11523
+ queryKey: ["sales-channels"],
11877
11524
  getOptions: (data) => {
11878
- return data.stock_locations.map((location) => ({
11879
- label: location.name,
11880
- value: location.id
11525
+ return data.sales_channels.map((salesChannel) => ({
11526
+ label: salesChannel.name,
11527
+ value: salesChannel.id
11881
11528
  }));
11882
- }
11529
+ },
11530
+ defaultValue: order.sales_channel_id || void 0
11883
11531
  });
11884
11532
  return /* @__PURE__ */ jsxRuntime.jsx(
11885
11533
  Form$2.Field,
11886
11534
  {
11887
11535
  control,
11888
- name: "location_id",
11889
- render: ({ field: { onChange, ...field } }) => {
11890
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11891
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11892
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
11893
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
11894
- ] }),
11536
+ name: "sales_channel_id",
11537
+ render: ({ field }) => {
11538
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11539
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11895
11540
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11896
11541
  Combobox,
11897
11542
  {
11898
- options: locations.options,
11899
- fetchNextPage: locations.fetchNextPage,
11900
- isFetchingNextPage: locations.isFetchingNextPage,
11901
- searchValue: locations.searchValue,
11902
- onSearchValueChange: locations.onSearchValueChange,
11903
- placeholder: "Select location",
11904
- onChange: (value) => {
11905
- setValue("shipping_option_id", "", {
11906
- shouldDirty: true,
11907
- shouldTouch: true
11908
- });
11909
- onChange(value);
11910
- },
11543
+ options: salesChannels.options,
11544
+ fetchNextPage: salesChannels.fetchNextPage,
11545
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11546
+ searchValue: salesChannels.searchValue,
11547
+ onSearchValueChange: salesChannels.onSearchValueChange,
11548
+ placeholder: "Select sales channel",
11911
11549
  ...field
11912
11550
  }
11913
- ) })
11914
- ] }) });
11551
+ ) }),
11552
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11553
+ ] });
11915
11554
  }
11916
11555
  }
11917
11556
  );
11918
11557
  };
11919
- const ShippingOptionField = ({
11920
- shippingProfileId,
11921
- preview,
11922
- control
11923
- }) => {
11924
- var _a;
11925
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
11926
- const shippingOptions = useComboboxData({
11927
- queryKey: ["shipping_options", locationId, shippingProfileId],
11928
- queryFn: async (params) => {
11929
- return await sdk.admin.shippingOption.list({
11930
- ...params,
11931
- stock_location_id: locationId,
11932
- shipping_profile_id: shippingProfileId
11933
- });
11934
- },
11935
- getOptions: (data) => {
11936
- return data.shipping_options.map((option) => {
11937
- var _a2;
11938
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
11939
- (r) => r.attribute === "is_return" && r.value === "true"
11940
- )) {
11941
- return void 0;
11942
- }
11943
- return {
11944
- label: option.name,
11945
- value: option.id
11946
- };
11947
- }).filter(Boolean);
11558
+ const schema$2 = objectType({
11559
+ sales_channel_id: stringType().min(1)
11560
+ });
11561
+ const ShippingAddress = () => {
11562
+ const { id } = reactRouterDom.useParams();
11563
+ const { order, isPending, isError, error } = useOrder(id, {
11564
+ fields: "+shipping_address"
11565
+ });
11566
+ if (isError) {
11567
+ throw error;
11568
+ }
11569
+ const isReady = !isPending && !!order;
11570
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11571
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11572
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11573
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11574
+ ] }),
11575
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11576
+ ] });
11577
+ };
11578
+ const ShippingAddressForm = ({ order }) => {
11579
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11580
+ const form = reactHookForm.useForm({
11581
+ defaultValues: {
11582
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11583
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11584
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11585
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11586
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11587
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11588
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11589
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11590
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11591
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11948
11592
  },
11949
- enabled: !!locationId && !!shippingProfileId,
11950
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
11951
- });
11952
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
11953
- return /* @__PURE__ */ jsxRuntime.jsx(
11954
- Form$2.Field,
11955
- {
11956
- control,
11957
- name: "shipping_option_id",
11958
- render: ({ field }) => {
11959
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11960
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11961
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
11962
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
11963
- ] }),
11964
- /* @__PURE__ */ jsxRuntime.jsx(
11965
- ConditionalTooltip,
11966
- {
11967
- content: tooltipContent,
11968
- showTooltip: !locationId || !shippingProfileId,
11969
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11970
- Combobox,
11971
- {
11972
- options: shippingOptions.options,
11973
- fetchNextPage: shippingOptions.fetchNextPage,
11974
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
11975
- searchValue: shippingOptions.searchValue,
11976
- onSearchValueChange: shippingOptions.onSearchValueChange,
11977
- placeholder: "Select shipping option",
11978
- ...field,
11979
- disabled: !locationId || !shippingProfileId
11980
- }
11981
- ) }) })
11982
- }
11983
- )
11984
- ] }) });
11985
- }
11986
- }
11987
- );
11988
- };
11989
- const CustomAmountField = ({
11990
- control,
11991
- currencyCode
11992
- }) => {
11993
- return /* @__PURE__ */ jsxRuntime.jsx(
11994
- Form$2.Field,
11995
- {
11996
- control,
11997
- name: "custom_amount",
11998
- render: ({ field: { onChange, ...field } }) => {
11999
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12000
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12001
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12002
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12003
- ] }),
12004
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12005
- ui.CurrencyInput,
12006
- {
12007
- ...field,
12008
- onValueChange: (value) => onChange(value),
12009
- symbol: getNativeSymbol(currencyCode),
12010
- code: currencyCode
12011
- }
12012
- ) })
12013
- ] });
12014
- }
12015
- }
12016
- );
12017
- };
12018
- const ShippingAddress = () => {
12019
- const { id } = reactRouterDom.useParams();
12020
- const { order, isPending, isError, error } = useOrder(id, {
12021
- fields: "+shipping_address"
12022
- });
12023
- if (isError) {
12024
- throw error;
12025
- }
12026
- const isReady = !isPending && !!order;
12027
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12028
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12029
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12030
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12031
- ] }),
12032
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12033
- ] });
12034
- };
12035
- const ShippingAddressForm = ({ order }) => {
12036
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12037
- const form = reactHookForm.useForm({
12038
- defaultValues: {
12039
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12040
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12041
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12042
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12043
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12044
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12045
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12046
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12047
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12048
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12049
- },
12050
- resolver: zod.zodResolver(schema$1)
11593
+ resolver: zod.zodResolver(schema$1)
12051
11594
  });
12052
11595
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12053
11596
  const { handleSuccess } = useRouteModal();
@@ -12218,564 +11761,851 @@ const ShippingAddressForm = ({ order }) => {
12218
11761
  ) });
12219
11762
  };
12220
11763
  const schema$1 = addressSchema;
12221
- const TransferOwnership = () => {
11764
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11765
+ const Shipping = () => {
11766
+ var _a;
12222
11767
  const { id } = reactRouterDom.useParams();
12223
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12224
- fields: "id,customer_id,customer.*"
11768
+ const { order, isPending, isError, error } = useOrder(id, {
11769
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
12225
11770
  });
11771
+ const {
11772
+ order: preview,
11773
+ isPending: isPreviewPending,
11774
+ isError: isPreviewError,
11775
+ error: previewError
11776
+ } = useOrderPreview(id);
11777
+ useInitiateOrderEdit({ preview });
11778
+ const { onCancel } = useCancelOrderEdit({ preview });
12226
11779
  if (isError) {
12227
11780
  throw error;
12228
11781
  }
12229
- const isReady = !isPending && !!draft_order;
12230
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12231
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12232
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12233
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12234
- ] }),
12235
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12236
- ] });
11782
+ if (isPreviewError) {
11783
+ throw previewError;
11784
+ }
11785
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11786
+ const isReady = preview && !isPreviewPending && order && !isPending;
11787
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11788
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11789
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11790
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11791
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11792
+ ] }) }) }),
11793
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11794
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11795
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11796
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11797
+ ] }) });
12237
11798
  };
12238
- const TransferOwnershipForm = ({ order }) => {
12239
- var _a, _b;
12240
- const form = reactHookForm.useForm({
12241
- defaultValues: {
12242
- customer_id: order.customer_id || ""
12243
- },
12244
- resolver: zod.zodResolver(schema)
12245
- });
12246
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12247
- const { handleSuccess } = useRouteModal();
12248
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12249
- const currentCustomer = order.customer ? {
12250
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12251
- value: order.customer.id
12252
- } : null;
12253
- const onSubmit = form.handleSubmit(async (data) => {
12254
- await mutateAsync(
12255
- { customer_id: data.customer_id },
12256
- {
12257
- onSuccess: () => {
12258
- ui.toast.success("Customer updated");
12259
- handleSuccess();
12260
- },
12261
- onError: (error) => {
12262
- ui.toast.error(error.message);
12263
- }
12264
- }
12265
- );
12266
- });
12267
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12268
- KeyboundForm,
11799
+ const ShippingForm = ({ preview, order }) => {
11800
+ var _a;
11801
+ const { setIsOpen } = useStackedModal();
11802
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11803
+ const [data, setData] = React.useState(null);
11804
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11805
+ const { shipping_options } = useShippingOptions(
12269
11806
  {
12270
- className: "flex flex-1 flex-col overflow-hidden",
12271
- onSubmit,
12272
- children: [
12273
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12274
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12275
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12276
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12277
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12278
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12279
- ] }),
12280
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12281
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12282
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12283
- ] })
12284
- ] }),
12285
- /* @__PURE__ */ jsxRuntime.jsx(
12286
- CustomerField,
12287
- {
12288
- control: form.control,
12289
- currentCustomerId: order.customer_id
12290
- }
12291
- )
12292
- ] }),
12293
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12294
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12295
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12296
- ] }) })
12297
- ]
12298
- }
12299
- ) });
12300
- };
12301
- const CustomerField = ({ control, currentCustomerId }) => {
12302
- const customers = useComboboxData({
12303
- queryFn: async (params) => {
12304
- return await sdk.admin.customer.list({
12305
- ...params,
12306
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12307
- });
11807
+ id: appliedShippingOptionIds,
11808
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
12308
11809
  },
12309
- queryKey: ["customers"],
12310
- getOptions: (data) => {
12311
- return data.customers.map((customer) => {
12312
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12313
- return {
12314
- label: name ? `${name} (${customer.email})` : customer.email,
12315
- value: customer.id
12316
- };
12317
- });
12318
- }
12319
- });
12320
- return /* @__PURE__ */ jsxRuntime.jsx(
12321
- Form$2.Field,
12322
11810
  {
12323
- name: "customer_id",
12324
- control,
12325
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12326
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12327
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12328
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12329
- ] }),
12330
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12331
- Combobox,
12332
- {
12333
- options: customers.options,
12334
- fetchNextPage: customers.fetchNextPage,
12335
- isFetchingNextPage: customers.isFetchingNextPage,
12336
- searchValue: customers.searchValue,
12337
- onSearchValueChange: customers.onSearchValueChange,
12338
- placeholder: "Select customer",
12339
- ...field
12340
- }
12341
- ) }),
12342
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12343
- ] })
11811
+ enabled: appliedShippingOptionIds.length > 0
12344
11812
  }
12345
11813
  );
12346
- };
12347
- const Illustration = () => {
12348
- return /* @__PURE__ */ jsxRuntime.jsxs(
12349
- "svg",
12350
- {
12351
- width: "280",
12352
- height: "180",
12353
- viewBox: "0 0 280 180",
12354
- fill: "none",
12355
- xmlns: "http://www.w3.org/2000/svg",
12356
- children: [
12357
- /* @__PURE__ */ jsxRuntime.jsx(
12358
- "rect",
12359
- {
12360
- x: "0.00428286",
12361
- y: "-0.742904",
12362
- width: "33.5",
12363
- height: "65.5",
12364
- rx: "6.75",
12365
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12366
- fill: "#D4D4D8",
12367
- stroke: "#52525B",
12368
- strokeWidth: "1.5"
12369
- }
12370
- ),
12371
- /* @__PURE__ */ jsxRuntime.jsx(
12372
- "rect",
12373
- {
12374
- x: "0.00428286",
12375
- y: "-0.742904",
12376
- width: "33.5",
12377
- height: "65.5",
12378
- rx: "6.75",
12379
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12380
- fill: "white",
12381
- stroke: "#52525B",
12382
- strokeWidth: "1.5"
12383
- }
12384
- ),
12385
- /* @__PURE__ */ jsxRuntime.jsx(
12386
- "path",
12387
- {
12388
- d: "M180.579 107.142L179.126 107.959",
12389
- stroke: "#52525B",
12390
- strokeWidth: "1.5",
12391
- strokeLinecap: "round",
12392
- strokeLinejoin: "round"
12393
- }
12394
- ),
12395
- /* @__PURE__ */ jsxRuntime.jsx(
12396
- "path",
12397
- {
12398
- opacity: "0.88",
12399
- d: "M182.305 109.546L180.257 109.534",
12400
- stroke: "#52525B",
12401
- strokeWidth: "1.5",
12402
- strokeLinecap: "round",
12403
- strokeLinejoin: "round"
12404
- }
12405
- ),
12406
- /* @__PURE__ */ jsxRuntime.jsx(
12407
- "path",
12408
- {
12409
- opacity: "0.75",
12410
- d: "M180.551 111.93L179.108 111.096",
12411
- stroke: "#52525B",
12412
- strokeWidth: "1.5",
12413
- strokeLinecap: "round",
12414
- strokeLinejoin: "round"
12415
- }
12416
- ),
12417
- /* @__PURE__ */ jsxRuntime.jsx(
12418
- "path",
12419
- {
12420
- opacity: "0.63",
12421
- d: "M176.347 112.897L176.354 111.73",
12422
- stroke: "#52525B",
12423
- strokeWidth: "1.5",
12424
- strokeLinecap: "round",
12425
- strokeLinejoin: "round"
12426
- }
12427
- ),
12428
- /* @__PURE__ */ jsxRuntime.jsx(
12429
- "path",
12430
- {
12431
- opacity: "0.5",
12432
- d: "M172.153 111.881L173.606 111.064",
12433
- stroke: "#52525B",
12434
- strokeWidth: "1.5",
12435
- strokeLinecap: "round",
12436
- strokeLinejoin: "round"
12437
- }
12438
- ),
12439
- /* @__PURE__ */ jsxRuntime.jsx(
12440
- "path",
12441
- {
12442
- opacity: "0.38",
12443
- d: "M170.428 109.478L172.476 109.489",
12444
- stroke: "#52525B",
12445
- strokeWidth: "1.5",
12446
- strokeLinecap: "round",
12447
- strokeLinejoin: "round"
12448
- }
12449
- ),
12450
- /* @__PURE__ */ jsxRuntime.jsx(
12451
- "path",
12452
- {
12453
- opacity: "0.25",
12454
- d: "M172.181 107.094L173.624 107.928",
12455
- stroke: "#52525B",
12456
- strokeWidth: "1.5",
12457
- strokeLinecap: "round",
12458
- strokeLinejoin: "round"
12459
- }
12460
- ),
12461
- /* @__PURE__ */ jsxRuntime.jsx(
12462
- "path",
12463
- {
12464
- opacity: "0.13",
12465
- d: "M176.386 106.126L176.379 107.294",
12466
- stroke: "#52525B",
12467
- strokeWidth: "1.5",
12468
- strokeLinecap: "round",
12469
- strokeLinejoin: "round"
12470
- }
12471
- ),
12472
- /* @__PURE__ */ jsxRuntime.jsx(
12473
- "rect",
12474
- {
12475
- width: "12",
12476
- height: "3",
12477
- rx: "1.5",
12478
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12479
- fill: "#D4D4D8"
12480
- }
12481
- ),
12482
- /* @__PURE__ */ jsxRuntime.jsx(
12483
- "rect",
12484
- {
12485
- x: "0.00428286",
12486
- y: "-0.742904",
12487
- width: "33.5",
12488
- height: "65.5",
12489
- rx: "6.75",
12490
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12491
- fill: "#D4D4D8",
12492
- stroke: "#52525B",
12493
- strokeWidth: "1.5"
12494
- }
12495
- ),
12496
- /* @__PURE__ */ jsxRuntime.jsx(
12497
- "rect",
12498
- {
12499
- x: "0.00428286",
12500
- y: "-0.742904",
12501
- width: "33.5",
12502
- height: "65.5",
12503
- rx: "6.75",
12504
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12505
- fill: "white",
12506
- stroke: "#52525B",
12507
- strokeWidth: "1.5"
12508
- }
12509
- ),
12510
- /* @__PURE__ */ jsxRuntime.jsx(
12511
- "rect",
12512
- {
12513
- width: "12",
12514
- height: "3",
12515
- rx: "1.5",
12516
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12517
- fill: "#D4D4D8"
12518
- }
12519
- ),
12520
- /* @__PURE__ */ jsxRuntime.jsx(
12521
- "rect",
12522
- {
12523
- width: "17",
12524
- height: "3",
12525
- rx: "1.5",
12526
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12527
- fill: "#D4D4D8"
12528
- }
12529
- ),
12530
- /* @__PURE__ */ jsxRuntime.jsx(
12531
- "rect",
12532
- {
12533
- width: "12",
12534
- height: "3",
12535
- rx: "1.5",
12536
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12537
- fill: "#D4D4D8"
12538
- }
12539
- ),
12540
- /* @__PURE__ */ jsxRuntime.jsx(
12541
- "path",
12542
- {
12543
- d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
12544
- fill: "#A1A1AA"
12545
- }
12546
- ),
12547
- /* @__PURE__ */ jsxRuntime.jsx(
12548
- "rect",
12549
- {
12550
- width: "17",
12551
- height: "3",
12552
- rx: "1.5",
12553
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12554
- fill: "#A1A1AA"
12555
- }
12556
- ),
12557
- /* @__PURE__ */ jsxRuntime.jsx(
12558
- "rect",
12559
- {
12560
- width: "12",
12561
- height: "3",
12562
- rx: "1.5",
12563
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12564
- fill: "#A1A1AA"
12565
- }
12566
- ),
12567
- /* @__PURE__ */ jsxRuntime.jsx(
12568
- "path",
12569
- {
12570
- d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12571
- fill: "#52525B"
12572
- }
12573
- ),
12574
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12575
- "path",
12576
- {
12577
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12578
- stroke: "#A1A1AA",
12579
- strokeWidth: "1.5",
12580
- strokeLinecap: "round",
12581
- strokeLinejoin: "round"
12582
- }
12583
- ) }),
12584
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12585
- "path",
12586
- {
12587
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12588
- stroke: "#A1A1AA",
12589
- strokeWidth: "1.5",
12590
- strokeLinecap: "round",
12591
- strokeLinejoin: "round"
12592
- }
12593
- ) }),
12594
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12595
- "path",
12596
- {
12597
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12598
- stroke: "#A1A1AA",
12599
- strokeWidth: "1.5",
12600
- strokeLinecap: "round",
12601
- strokeLinejoin: "round"
12602
- }
12603
- ) }),
12604
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12605
- "path",
12606
- {
12607
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12608
- stroke: "#A1A1AA",
12609
- strokeWidth: "1.5",
12610
- strokeLinecap: "round",
12611
- strokeLinejoin: "round"
12612
- }
12613
- ) }),
12614
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12615
- "path",
12616
- {
12617
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12618
- stroke: "#A1A1AA",
12619
- strokeWidth: "1.5",
12620
- strokeLinecap: "round",
12621
- strokeLinejoin: "round"
12622
- }
12623
- ) }),
12624
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12625
- "path",
12626
- {
12627
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12628
- stroke: "#A1A1AA",
12629
- strokeWidth: "1.5",
12630
- strokeLinecap: "round",
12631
- strokeLinejoin: "round"
11814
+ const uniqueShippingProfiles = React.useMemo(() => {
11815
+ const profiles = /* @__PURE__ */ new Map();
11816
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11817
+ profiles.set(profile.id, profile);
11818
+ });
11819
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11820
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11821
+ });
11822
+ return Array.from(profiles.values());
11823
+ }, [order.items, shipping_options]);
11824
+ const { handleSuccess } = useRouteModal();
11825
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11826
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11827
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11828
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11829
+ const onSubmit = async () => {
11830
+ setIsSubmitting(true);
11831
+ let requestSucceeded = false;
11832
+ await requestOrderEdit(void 0, {
11833
+ onError: (e) => {
11834
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11835
+ },
11836
+ onSuccess: () => {
11837
+ requestSucceeded = true;
11838
+ }
11839
+ });
11840
+ if (!requestSucceeded) {
11841
+ setIsSubmitting(false);
11842
+ return;
11843
+ }
11844
+ await confirmOrderEdit(void 0, {
11845
+ onError: (e) => {
11846
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11847
+ },
11848
+ onSuccess: () => {
11849
+ handleSuccess();
11850
+ },
11851
+ onSettled: () => {
11852
+ setIsSubmitting(false);
11853
+ }
11854
+ });
11855
+ };
11856
+ const onKeydown = React.useCallback(
11857
+ (e) => {
11858
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11859
+ if (data || isSubmitting) {
11860
+ return;
11861
+ }
11862
+ onSubmit();
11863
+ }
11864
+ },
11865
+ [data, isSubmitting, onSubmit]
11866
+ );
11867
+ React.useEffect(() => {
11868
+ document.addEventListener("keydown", onKeydown);
11869
+ return () => {
11870
+ document.removeEventListener("keydown", onKeydown);
11871
+ };
11872
+ }, [onKeydown]);
11873
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11874
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11875
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11876
+ /* @__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: [
11877
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11878
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11879
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11880
+ ] }),
11881
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11882
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11883
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
11884
+ /* @__PURE__ */ jsxRuntime.jsx(
11885
+ ui.Text,
11886
+ {
11887
+ size: "xsmall",
11888
+ weight: "plus",
11889
+ className: "text-ui-fg-muted",
11890
+ children: "Shipping profile"
11891
+ }
11892
+ ),
11893
+ /* @__PURE__ */ jsxRuntime.jsx(
11894
+ ui.Text,
11895
+ {
11896
+ size: "xsmall",
11897
+ weight: "plus",
11898
+ className: "text-ui-fg-muted",
11899
+ children: "Action"
11900
+ }
11901
+ )
11902
+ ] }),
11903
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11904
+ var _a2, _b, _c, _d, _e, _f, _g;
11905
+ const items = getItemsWithShippingProfile(
11906
+ profile.id,
11907
+ order.items
11908
+ );
11909
+ const hasItems = items.length > 0;
11910
+ const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11911
+ (option) => option.shipping_profile_id === profile.id
11912
+ );
11913
+ const shippingMethod = preview.shipping_methods.find(
11914
+ (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11915
+ );
11916
+ const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11917
+ (action) => action.action === "SHIPPING_ADD"
11918
+ );
11919
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11920
+ radixUi.Accordion.Item,
11921
+ {
11922
+ value: profile.id,
11923
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11924
+ children: [
11925
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-3 px-3 py-2", children: [
11926
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3 overflow-hidden", children: [
11927
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
11928
+ ui.IconButton,
11929
+ {
11930
+ size: "2xsmall",
11931
+ variant: "transparent",
11932
+ className: "group/trigger",
11933
+ disabled: !hasItems,
11934
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "transition-transform group-data-[state=open]/trigger:rotate-90" })
11935
+ }
11936
+ ) }),
11937
+ !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11938
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "shadow-borders-base flex size-7 items-center justify-center rounded-md", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-ui-bg-component-hover flex size-6 items-center justify-center rounded", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "text-ui-fg-subtle" }) }) }),
11939
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col", children: [
11940
+ /* @__PURE__ */ jsxRuntime.jsx(
11941
+ ui.Text,
11942
+ {
11943
+ size: "small",
11944
+ weight: "plus",
11945
+ leading: "compact",
11946
+ children: profile.name
11947
+ }
11948
+ ),
11949
+ /* @__PURE__ */ jsxRuntime.jsxs(
11950
+ ui.Text,
11951
+ {
11952
+ size: "small",
11953
+ leading: "compact",
11954
+ className: "text-ui-fg-subtle",
11955
+ children: [
11956
+ items.length,
11957
+ " ",
11958
+ pluralize(items.length, "items", "item")
11959
+ ]
11960
+ }
11961
+ )
11962
+ ] })
11963
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full flex-1 items-center gap-[5px] overflow-hidden max-sm:flex-col max-sm:items-start", children: [
11964
+ /* @__PURE__ */ jsxRuntime.jsx(
11965
+ ui.Tooltip,
11966
+ {
11967
+ content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
11968
+ var _a3, _b2, _c2;
11969
+ return /* @__PURE__ */ jsxRuntime.jsx(
11970
+ "li",
11971
+ {
11972
+ children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
11973
+ },
11974
+ item.id
11975
+ );
11976
+ }) }),
11977
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
11978
+ ui.Badge,
11979
+ {
11980
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11981
+ size: "xsmall",
11982
+ children: [
11983
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
11984
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
11985
+ items.reduce(
11986
+ (acc, item) => acc + item.quantity,
11987
+ 0
11988
+ ),
11989
+ "x",
11990
+ " ",
11991
+ pluralize(items.length, "items", "item")
11992
+ ] })
11993
+ ]
11994
+ }
11995
+ )
11996
+ }
11997
+ ),
11998
+ /* @__PURE__ */ jsxRuntime.jsx(
11999
+ ui.Tooltip,
12000
+ {
12001
+ content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
12002
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
12003
+ ui.Badge,
12004
+ {
12005
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
12006
+ size: "xsmall",
12007
+ children: [
12008
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
12009
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
12010
+ ]
12011
+ }
12012
+ )
12013
+ }
12014
+ ),
12015
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
12016
+ ui.Badge,
12017
+ {
12018
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
12019
+ size: "xsmall",
12020
+ children: [
12021
+ /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
12022
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
12023
+ ]
12024
+ }
12025
+ ) })
12026
+ ] })
12027
+ ] }),
12028
+ shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
12029
+ ActionMenu,
12030
+ {
12031
+ groups: [
12032
+ {
12033
+ actions: [
12034
+ hasItems ? {
12035
+ label: "Edit shipping option",
12036
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
12037
+ onClick: () => {
12038
+ setIsOpen(
12039
+ STACKED_FOCUS_MODAL_ID,
12040
+ true
12041
+ );
12042
+ setData({
12043
+ shippingProfileId: profile.id,
12044
+ shippingOption,
12045
+ shippingMethod
12046
+ });
12047
+ }
12048
+ } : void 0,
12049
+ {
12050
+ label: "Remove shipping option",
12051
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
12052
+ onClick: () => {
12053
+ if (shippingMethod) {
12054
+ if (addShippingMethodAction) {
12055
+ removeActionShippingMethod(
12056
+ addShippingMethodAction.id
12057
+ );
12058
+ } else {
12059
+ removeShippingMethod(
12060
+ shippingMethod.id
12061
+ );
12062
+ }
12063
+ }
12064
+ }
12065
+ }
12066
+ ].filter(Boolean)
12067
+ }
12068
+ ]
12069
+ }
12070
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
12071
+ StackedModalTrigger,
12072
+ {
12073
+ shippingProfileId: profile.id,
12074
+ shippingOption,
12075
+ shippingMethod,
12076
+ setData,
12077
+ children: "Add shipping option"
12078
+ }
12079
+ )
12080
+ ] }),
12081
+ /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
12082
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12083
+ items.map((item, idx) => {
12084
+ var _a3, _b2, _c2, _d2, _e2;
12085
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12086
+ /* @__PURE__ */ jsxRuntime.jsxs(
12087
+ "div",
12088
+ {
12089
+ className: "flex items-center gap-x-3 px-3",
12090
+ children: [
12091
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-[56px] w-5 flex-col items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
12092
+ ui.Divider,
12093
+ {
12094
+ variant: "dashed",
12095
+ orientation: "vertical"
12096
+ }
12097
+ ) }),
12098
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 py-2", children: [
12099
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex size-7 items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
12100
+ ui.Text,
12101
+ {
12102
+ size: "small",
12103
+ leading: "compact",
12104
+ className: "text-ui-fg-subtle",
12105
+ children: [
12106
+ item.quantity,
12107
+ "x"
12108
+ ]
12109
+ }
12110
+ ) }),
12111
+ /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
12112
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12113
+ /* @__PURE__ */ jsxRuntime.jsxs(
12114
+ ui.Text,
12115
+ {
12116
+ size: "small",
12117
+ leading: "compact",
12118
+ weight: "plus",
12119
+ children: [
12120
+ (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
12121
+ " (",
12122
+ (_c2 = item.variant) == null ? void 0 : _c2.title,
12123
+ ")"
12124
+ ]
12125
+ }
12126
+ ),
12127
+ /* @__PURE__ */ jsxRuntime.jsx(
12128
+ ui.Text,
12129
+ {
12130
+ size: "small",
12131
+ leading: "compact",
12132
+ className: "text-ui-fg-subtle",
12133
+ children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
12134
+ }
12135
+ )
12136
+ ] })
12137
+ ] })
12138
+ ]
12139
+ },
12140
+ item.id
12141
+ ),
12142
+ idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
12143
+ ] }, item.id);
12144
+ })
12145
+ ] })
12146
+ ]
12147
+ },
12148
+ profile.id
12149
+ );
12150
+ }) })
12151
+ ] }) })
12152
+ ] }) }),
12153
+ /* @__PURE__ */ jsxRuntime.jsx(
12154
+ StackedFocusModal,
12155
+ {
12156
+ id: STACKED_FOCUS_MODAL_ID,
12157
+ onOpenChangeCallback: (open) => {
12158
+ if (!open) {
12159
+ setData(null);
12160
+ }
12161
+ return open;
12162
+ },
12163
+ children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
12164
+ }
12165
+ )
12166
+ ] }),
12167
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12168
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12169
+ /* @__PURE__ */ jsxRuntime.jsx(
12170
+ ui.Button,
12171
+ {
12172
+ size: "small",
12173
+ type: "button",
12174
+ isLoading: isSubmitting,
12175
+ onClick: onSubmit,
12176
+ children: "Save"
12177
+ }
12178
+ )
12179
+ ] }) })
12180
+ ] });
12181
+ };
12182
+ const StackedModalTrigger = ({
12183
+ shippingProfileId,
12184
+ shippingOption,
12185
+ shippingMethod,
12186
+ setData,
12187
+ children
12188
+ }) => {
12189
+ const { setIsOpen, getIsOpen } = useStackedModal();
12190
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12191
+ const onToggle = () => {
12192
+ if (isOpen) {
12193
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12194
+ setData(null);
12195
+ } else {
12196
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12197
+ setData({
12198
+ shippingProfileId,
12199
+ shippingOption,
12200
+ shippingMethod
12201
+ });
12202
+ }
12203
+ };
12204
+ return /* @__PURE__ */ jsxRuntime.jsx(
12205
+ ui.Button,
12206
+ {
12207
+ size: "small",
12208
+ variant: "secondary",
12209
+ onClick: onToggle,
12210
+ className: "text-ui-fg-primary shrink-0",
12211
+ children
12212
+ }
12213
+ );
12214
+ };
12215
+ const ShippingProfileForm = ({
12216
+ data,
12217
+ order,
12218
+ preview
12219
+ }) => {
12220
+ var _a, _b, _c, _d, _e, _f;
12221
+ const { setIsOpen } = useStackedModal();
12222
+ const form = reactHookForm.useForm({
12223
+ resolver: zod.zodResolver(shippingMethodSchema),
12224
+ defaultValues: {
12225
+ location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12226
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12227
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12228
+ }
12229
+ });
12230
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12231
+ const {
12232
+ mutateAsync: updateShippingMethod,
12233
+ isPending: isUpdatingShippingMethod
12234
+ } = useDraftOrderUpdateShippingMethod(order.id);
12235
+ const onSubmit = form.handleSubmit(async (values) => {
12236
+ if (isEqual__default.default(values, form.formState.defaultValues)) {
12237
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12238
+ return;
12239
+ }
12240
+ if (data.shippingMethod) {
12241
+ await updateShippingMethod(
12242
+ {
12243
+ method_id: data.shippingMethod.id,
12244
+ shipping_option_id: values.shipping_option_id,
12245
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12246
+ },
12247
+ {
12248
+ onError: (e) => {
12249
+ ui.toast.error(e.message);
12250
+ },
12251
+ onSuccess: () => {
12252
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12632
12253
  }
12633
- ) }),
12634
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12635
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12636
- "rect",
12254
+ }
12255
+ );
12256
+ return;
12257
+ }
12258
+ await addShippingMethod(
12259
+ {
12260
+ shipping_option_id: values.shipping_option_id,
12261
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12262
+ },
12263
+ {
12264
+ onError: (e) => {
12265
+ ui.toast.error(e.message);
12266
+ },
12267
+ onSuccess: () => {
12268
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12269
+ }
12270
+ }
12271
+ );
12272
+ });
12273
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12274
+ KeyboundForm,
12275
+ {
12276
+ className: "flex h-full flex-col overflow-hidden",
12277
+ onSubmit,
12278
+ children: [
12279
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12280
+ /* @__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-6 py-16", children: [
12281
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12282
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12283
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12284
+ ] }),
12285
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12286
+ /* @__PURE__ */ jsxRuntime.jsx(
12287
+ LocationField,
12637
12288
  {
12638
- width: "12",
12639
- height: "12",
12640
- fill: "white",
12641
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12289
+ control: form.control,
12290
+ setValue: form.setValue
12642
12291
  }
12643
- ) }),
12644
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12645
- "rect",
12292
+ ),
12293
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12294
+ /* @__PURE__ */ jsxRuntime.jsx(
12295
+ ShippingOptionField,
12646
12296
  {
12647
- width: "12",
12648
- height: "12",
12649
- fill: "white",
12650
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12297
+ shippingProfileId: data.shippingProfileId,
12298
+ preview,
12299
+ control: form.control
12651
12300
  }
12652
- ) }),
12653
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12654
- "rect",
12301
+ ),
12302
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12303
+ /* @__PURE__ */ jsxRuntime.jsx(
12304
+ CustomAmountField,
12655
12305
  {
12656
- width: "12",
12657
- height: "12",
12658
- fill: "white",
12659
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12306
+ control: form.control,
12307
+ currencyCode: order.currency_code
12660
12308
  }
12661
- ) }),
12662
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12663
- "rect",
12309
+ ),
12310
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12311
+ /* @__PURE__ */ jsxRuntime.jsx(
12312
+ ItemsPreview,
12664
12313
  {
12665
- width: "12",
12666
- height: "12",
12667
- fill: "white",
12668
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12314
+ order,
12315
+ shippingProfileId: data.shippingProfileId
12669
12316
  }
12670
- ) }),
12671
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12672
- "rect",
12317
+ )
12318
+ ] }) }) }),
12319
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12320
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12321
+ /* @__PURE__ */ jsxRuntime.jsx(
12322
+ ui.Button,
12673
12323
  {
12674
- width: "12",
12675
- height: "12",
12676
- fill: "white",
12677
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12324
+ size: "small",
12325
+ type: "submit",
12326
+ isLoading: isPending || isUpdatingShippingMethod,
12327
+ children: data.shippingMethod ? "Update" : "Add"
12678
12328
  }
12679
- ) }),
12680
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12681
- "rect",
12329
+ )
12330
+ ] }) })
12331
+ ]
12332
+ }
12333
+ ) }) });
12334
+ };
12335
+ const shippingMethodSchema = objectType({
12336
+ location_id: stringType(),
12337
+ shipping_option_id: stringType(),
12338
+ custom_amount: unionType([numberType(), stringType()]).optional()
12339
+ });
12340
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12341
+ const matches = order.items.filter(
12342
+ (item) => {
12343
+ var _a, _b, _c;
12344
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12345
+ }
12346
+ );
12347
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12348
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12349
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12350
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12351
+ ] }) }),
12352
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12353
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-2 gap-3 px-4 py-2", children: [
12354
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12355
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12356
+ ] }),
12357
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
12358
+ "div",
12359
+ {
12360
+ className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-2 items-center gap-3 rounded-lg px-4 py-2",
12361
+ children: [
12362
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12363
+ /* @__PURE__ */ jsxRuntime.jsx(
12364
+ Thumbnail,
12365
+ {
12366
+ thumbnail: item.thumbnail,
12367
+ alt: item.product_title ?? void 0
12368
+ }
12369
+ ),
12370
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12371
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12372
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12373
+ /* @__PURE__ */ jsxRuntime.jsxs(
12374
+ ui.Text,
12375
+ {
12376
+ size: "small",
12377
+ leading: "compact",
12378
+ className: "text-ui-fg-subtle",
12379
+ children: [
12380
+ "(",
12381
+ item.variant_title,
12382
+ ")"
12383
+ ]
12384
+ }
12385
+ )
12386
+ ] }),
12387
+ /* @__PURE__ */ jsxRuntime.jsx(
12388
+ ui.Text,
12389
+ {
12390
+ size: "small",
12391
+ leading: "compact",
12392
+ className: "text-ui-fg-subtle",
12393
+ children: item.variant_sku
12394
+ }
12395
+ )
12396
+ ] })
12397
+ ] }),
12398
+ /* @__PURE__ */ jsxRuntime.jsxs(
12399
+ ui.Text,
12400
+ {
12401
+ size: "small",
12402
+ leading: "compact",
12403
+ className: "text-ui-fg-subtle",
12404
+ children: [
12405
+ item.quantity,
12406
+ "x"
12407
+ ]
12408
+ }
12409
+ )
12410
+ ]
12411
+ },
12412
+ item.id
12413
+ )) : /* @__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: [
12414
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12415
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12416
+ 'No items found for "',
12417
+ query,
12418
+ '".'
12419
+ ] })
12420
+ ] }) })
12421
+ ] })
12422
+ ] });
12423
+ };
12424
+ const LocationField = ({ control, setValue }) => {
12425
+ const locations = useComboboxData({
12426
+ queryKey: ["locations"],
12427
+ queryFn: async (params) => {
12428
+ return await sdk.admin.stockLocation.list(params);
12429
+ },
12430
+ getOptions: (data) => {
12431
+ return data.stock_locations.map((location) => ({
12432
+ label: location.name,
12433
+ value: location.id
12434
+ }));
12435
+ }
12436
+ });
12437
+ return /* @__PURE__ */ jsxRuntime.jsx(
12438
+ Form$2.Field,
12439
+ {
12440
+ control,
12441
+ name: "location_id",
12442
+ render: ({ field: { onChange, ...field } }) => {
12443
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12444
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12445
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12446
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12447
+ ] }),
12448
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12449
+ Combobox,
12682
12450
  {
12683
- width: "12",
12684
- height: "12",
12685
- fill: "white",
12686
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12451
+ options: locations.options,
12452
+ fetchNextPage: locations.fetchNextPage,
12453
+ isFetchingNextPage: locations.isFetchingNextPage,
12454
+ searchValue: locations.searchValue,
12455
+ onSearchValueChange: locations.onSearchValueChange,
12456
+ placeholder: "Select location",
12457
+ onChange: (value) => {
12458
+ setValue("shipping_option_id", "", {
12459
+ shouldDirty: true,
12460
+ shouldTouch: true
12461
+ });
12462
+ onChange(value);
12463
+ },
12464
+ ...field
12687
12465
  }
12688
12466
  ) })
12689
- ] })
12690
- ]
12467
+ ] }) });
12468
+ }
12691
12469
  }
12692
12470
  );
12693
12471
  };
12694
- const schema = objectType({
12695
- customer_id: stringType().min(1)
12696
- });
12697
- const InlineTip = React.forwardRef(
12698
- ({ variant = "tip", label, className, children, ...props }, ref) => {
12699
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
12700
- return /* @__PURE__ */ jsxRuntime.jsxs(
12701
- "div",
12702
- {
12703
- ref,
12704
- className: ui.clx(
12705
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
12706
- className
12707
- ),
12708
- ...props,
12709
- children: [
12472
+ const ShippingOptionField = ({
12473
+ shippingProfileId,
12474
+ preview,
12475
+ control
12476
+ }) => {
12477
+ var _a;
12478
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12479
+ const shippingOptions = useComboboxData({
12480
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12481
+ queryFn: async (params) => {
12482
+ return await sdk.admin.shippingOption.list({
12483
+ ...params,
12484
+ stock_location_id: locationId,
12485
+ shipping_profile_id: shippingProfileId
12486
+ });
12487
+ },
12488
+ getOptions: (data) => {
12489
+ return data.shipping_options.map((option) => {
12490
+ var _a2;
12491
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12492
+ (r) => r.attribute === "is_return" && r.value === "true"
12493
+ )) {
12494
+ return void 0;
12495
+ }
12496
+ return {
12497
+ label: option.name,
12498
+ value: option.id
12499
+ };
12500
+ }).filter(Boolean);
12501
+ },
12502
+ enabled: !!locationId && !!shippingProfileId,
12503
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12504
+ });
12505
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12506
+ return /* @__PURE__ */ jsxRuntime.jsx(
12507
+ Form$2.Field,
12508
+ {
12509
+ control,
12510
+ name: "shipping_option_id",
12511
+ render: ({ field }) => {
12512
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12513
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12514
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12515
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12516
+ ] }),
12710
12517
  /* @__PURE__ */ jsxRuntime.jsx(
12711
- "div",
12518
+ ConditionalTooltip,
12712
12519
  {
12713
- role: "presentation",
12714
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
12715
- "bg-ui-tag-orange-icon": variant === "warning"
12716
- })
12520
+ content: tooltipContent,
12521
+ showTooltip: !locationId || !shippingProfileId,
12522
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12523
+ Combobox,
12524
+ {
12525
+ options: shippingOptions.options,
12526
+ fetchNextPage: shippingOptions.fetchNextPage,
12527
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12528
+ searchValue: shippingOptions.searchValue,
12529
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12530
+ placeholder: "Select shipping option",
12531
+ ...field,
12532
+ disabled: !locationId || !shippingProfileId
12533
+ }
12534
+ ) }) })
12535
+ }
12536
+ )
12537
+ ] }) });
12538
+ }
12539
+ }
12540
+ );
12541
+ };
12542
+ const CustomAmountField = ({
12543
+ control,
12544
+ currencyCode
12545
+ }) => {
12546
+ return /* @__PURE__ */ jsxRuntime.jsx(
12547
+ Form$2.Field,
12548
+ {
12549
+ control,
12550
+ name: "custom_amount",
12551
+ render: ({ field: { onChange, ...field } }) => {
12552
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12553
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12554
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12555
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12556
+ ] }),
12557
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12558
+ ui.CurrencyInput,
12559
+ {
12560
+ ...field,
12561
+ onValueChange: (value) => onChange(value),
12562
+ symbol: getNativeSymbol(currencyCode),
12563
+ code: currencyCode
12717
12564
  }
12718
- ),
12719
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
12720
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
12721
- labelValue,
12722
- ":"
12723
- ] }),
12724
- " ",
12725
- children
12726
- ] })
12727
- ]
12565
+ ) })
12566
+ ] });
12728
12567
  }
12729
- );
12730
- }
12731
- );
12732
- InlineTip.displayName = "InlineTip";
12733
- const MetadataFieldSchema = objectType({
12734
- key: stringType(),
12735
- disabled: booleanType().optional(),
12736
- value: anyType()
12737
- });
12738
- const MetadataSchema = objectType({
12739
- metadata: arrayType(MetadataFieldSchema)
12740
- });
12741
- const Metadata = () => {
12568
+ }
12569
+ );
12570
+ };
12571
+ const TransferOwnership = () => {
12742
12572
  const { id } = reactRouterDom.useParams();
12743
- const { order, isPending, isError, error } = useOrder(id, {
12744
- fields: "metadata"
12573
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12574
+ fields: "id,customer_id,customer.*"
12745
12575
  });
12746
12576
  if (isError) {
12747
12577
  throw error;
12748
12578
  }
12749
- const isReady = !isPending && !!order;
12579
+ const isReady = !isPending && !!draft_order;
12750
12580
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12751
12581
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12752
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
12753
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
12582
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12583
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12754
12584
  ] }),
12755
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
12585
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12756
12586
  ] });
12757
12587
  };
12758
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
12759
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
12760
- const MetadataForm = ({ orderId, metadata }) => {
12761
- const { handleSuccess } = useRouteModal();
12762
- const hasUneditableRows = getHasUneditableRows(metadata);
12763
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
12588
+ const TransferOwnershipForm = ({ order }) => {
12589
+ var _a, _b;
12764
12590
  const form = reactHookForm.useForm({
12765
12591
  defaultValues: {
12766
- metadata: getDefaultValues(metadata)
12592
+ customer_id: order.customer_id || ""
12767
12593
  },
12768
- resolver: zod.zodResolver(MetadataSchema)
12594
+ resolver: zod.zodResolver(schema)
12769
12595
  });
12770
- const handleSubmit = form.handleSubmit(async (data) => {
12771
- const parsedData = parseValues(data);
12596
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12597
+ const { handleSuccess } = useRouteModal();
12598
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12599
+ const currentCustomer = order.customer ? {
12600
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12601
+ value: order.customer.id
12602
+ } : null;
12603
+ const onSubmit = form.handleSubmit(async (data) => {
12772
12604
  await mutateAsync(
12773
- {
12774
- metadata: parsedData
12775
- },
12605
+ { customer_id: data.customer_id },
12776
12606
  {
12777
12607
  onSuccess: () => {
12778
- ui.toast.success("Metadata updated");
12608
+ ui.toast.success("Customer updated");
12779
12609
  handleSuccess();
12780
12610
  },
12781
12611
  onError: (error) => {
@@ -12784,266 +12614,436 @@ const MetadataForm = ({ orderId, metadata }) => {
12784
12614
  }
12785
12615
  );
12786
12616
  });
12787
- const { fields, insert, remove } = reactHookForm.useFieldArray({
12788
- control: form.control,
12789
- name: "metadata"
12790
- });
12791
- function deleteRow(index) {
12792
- remove(index);
12793
- if (fields.length === 1) {
12794
- insert(0, {
12795
- key: "",
12796
- value: "",
12797
- disabled: false
12798
- });
12799
- }
12800
- }
12801
- function insertRow(index, position) {
12802
- insert(index + (position === "above" ? 0 : 1), {
12803
- key: "",
12804
- value: "",
12805
- disabled: false
12806
- });
12807
- }
12808
12617
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12809
12618
  KeyboundForm,
12810
12619
  {
12811
- onSubmit: handleSubmit,
12812
12620
  className: "flex flex-1 flex-col overflow-hidden",
12621
+ onSubmit,
12813
12622
  children: [
12814
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
12815
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
12816
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
12817
- /* @__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" }) }),
12818
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
12623
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12624
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12625
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12626
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12627
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12628
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12819
12629
  ] }),
12820
- fields.map((field, index) => {
12821
- const isDisabled = field.disabled || false;
12822
- let placeholder = "-";
12823
- if (typeof field.value === "object") {
12824
- placeholder = "{ ... }";
12825
- }
12826
- if (Array.isArray(field.value)) {
12827
- placeholder = "[ ... ]";
12828
- }
12829
- return /* @__PURE__ */ jsxRuntime.jsx(
12830
- ConditionalTooltip,
12831
- {
12832
- showTooltip: isDisabled,
12833
- content: "This row is disabled because it contains non-primitive data.",
12834
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
12835
- /* @__PURE__ */ jsxRuntime.jsxs(
12836
- "div",
12837
- {
12838
- className: ui.clx("grid grid-cols-2 divide-x", {
12839
- "overflow-hidden rounded-b-lg": index === fields.length - 1
12840
- }),
12841
- children: [
12842
- /* @__PURE__ */ jsxRuntime.jsx(
12843
- Form$2.Field,
12844
- {
12845
- control: form.control,
12846
- name: `metadata.${index}.key`,
12847
- render: ({ field: field2 }) => {
12848
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12849
- GridInput,
12850
- {
12851
- "aria-labelledby": METADATA_KEY_LABEL_ID,
12852
- ...field2,
12853
- disabled: isDisabled,
12854
- placeholder: "Key"
12855
- }
12856
- ) }) });
12857
- }
12858
- }
12859
- ),
12860
- /* @__PURE__ */ jsxRuntime.jsx(
12861
- Form$2.Field,
12862
- {
12863
- control: form.control,
12864
- name: `metadata.${index}.value`,
12865
- render: ({ field: { value, ...field2 } }) => {
12866
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12867
- GridInput,
12868
- {
12869
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
12870
- ...field2,
12871
- value: isDisabled ? placeholder : value,
12872
- disabled: isDisabled,
12873
- placeholder: "Value"
12874
- }
12875
- ) }) });
12876
- }
12877
- }
12878
- )
12879
- ]
12880
- }
12881
- ),
12882
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
12883
- /* @__PURE__ */ jsxRuntime.jsx(
12884
- ui.DropdownMenu.Trigger,
12885
- {
12886
- className: ui.clx(
12887
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
12888
- {
12889
- hidden: isDisabled
12890
- }
12891
- ),
12892
- disabled: isDisabled,
12893
- asChild: true,
12894
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
12895
- }
12896
- ),
12897
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
12898
- /* @__PURE__ */ jsxRuntime.jsxs(
12899
- ui.DropdownMenu.Item,
12900
- {
12901
- className: "gap-x-2",
12902
- onClick: () => insertRow(index, "above"),
12903
- children: [
12904
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
12905
- "Insert row above"
12906
- ]
12907
- }
12908
- ),
12909
- /* @__PURE__ */ jsxRuntime.jsxs(
12910
- ui.DropdownMenu.Item,
12911
- {
12912
- className: "gap-x-2",
12913
- onClick: () => insertRow(index, "below"),
12914
- children: [
12915
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
12916
- "Insert row below"
12917
- ]
12918
- }
12919
- ),
12920
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
12921
- /* @__PURE__ */ jsxRuntime.jsxs(
12922
- ui.DropdownMenu.Item,
12923
- {
12924
- className: "gap-x-2",
12925
- onClick: () => deleteRow(index),
12926
- children: [
12927
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
12928
- "Delete row"
12929
- ]
12930
- }
12931
- )
12932
- ] })
12933
- ] })
12934
- ] })
12935
- },
12936
- field.id
12937
- );
12938
- })
12630
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12631
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12632
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12633
+ ] })
12939
12634
  ] }),
12940
- 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." })
12635
+ /* @__PURE__ */ jsxRuntime.jsx(
12636
+ CustomerField,
12637
+ {
12638
+ control: form.control,
12639
+ currentCustomerId: order.customer_id
12640
+ }
12641
+ )
12642
+ ] }),
12643
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12644
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12645
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12646
+ ] }) })
12647
+ ]
12648
+ }
12649
+ ) });
12650
+ };
12651
+ const CustomerField = ({ control, currentCustomerId }) => {
12652
+ const customers = useComboboxData({
12653
+ queryFn: async (params) => {
12654
+ return await sdk.admin.customer.list({
12655
+ ...params,
12656
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12657
+ });
12658
+ },
12659
+ queryKey: ["customers"],
12660
+ getOptions: (data) => {
12661
+ return data.customers.map((customer) => {
12662
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12663
+ return {
12664
+ label: name ? `${name} (${customer.email})` : customer.email,
12665
+ value: customer.id
12666
+ };
12667
+ });
12668
+ }
12669
+ });
12670
+ return /* @__PURE__ */ jsxRuntime.jsx(
12671
+ Form$2.Field,
12672
+ {
12673
+ name: "customer_id",
12674
+ control,
12675
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12676
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12677
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12678
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12941
12679
  ] }),
12942
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12943
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12944
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12945
- ] }) })
12680
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12681
+ Combobox,
12682
+ {
12683
+ options: customers.options,
12684
+ fetchNextPage: customers.fetchNextPage,
12685
+ isFetchingNextPage: customers.isFetchingNextPage,
12686
+ searchValue: customers.searchValue,
12687
+ onSearchValueChange: customers.onSearchValueChange,
12688
+ placeholder: "Select customer",
12689
+ ...field
12690
+ }
12691
+ ) }),
12692
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12693
+ ] })
12694
+ }
12695
+ );
12696
+ };
12697
+ const Illustration = () => {
12698
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12699
+ "svg",
12700
+ {
12701
+ width: "280",
12702
+ height: "180",
12703
+ viewBox: "0 0 280 180",
12704
+ fill: "none",
12705
+ xmlns: "http://www.w3.org/2000/svg",
12706
+ children: [
12707
+ /* @__PURE__ */ jsxRuntime.jsx(
12708
+ "rect",
12709
+ {
12710
+ x: "0.00428286",
12711
+ y: "-0.742904",
12712
+ width: "33.5",
12713
+ height: "65.5",
12714
+ rx: "6.75",
12715
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12716
+ fill: "#D4D4D8",
12717
+ stroke: "#52525B",
12718
+ strokeWidth: "1.5"
12719
+ }
12720
+ ),
12721
+ /* @__PURE__ */ jsxRuntime.jsx(
12722
+ "rect",
12723
+ {
12724
+ x: "0.00428286",
12725
+ y: "-0.742904",
12726
+ width: "33.5",
12727
+ height: "65.5",
12728
+ rx: "6.75",
12729
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12730
+ fill: "white",
12731
+ stroke: "#52525B",
12732
+ strokeWidth: "1.5"
12733
+ }
12734
+ ),
12735
+ /* @__PURE__ */ jsxRuntime.jsx(
12736
+ "path",
12737
+ {
12738
+ d: "M180.579 107.142L179.126 107.959",
12739
+ stroke: "#52525B",
12740
+ strokeWidth: "1.5",
12741
+ strokeLinecap: "round",
12742
+ strokeLinejoin: "round"
12743
+ }
12744
+ ),
12745
+ /* @__PURE__ */ jsxRuntime.jsx(
12746
+ "path",
12747
+ {
12748
+ opacity: "0.88",
12749
+ d: "M182.305 109.546L180.257 109.534",
12750
+ stroke: "#52525B",
12751
+ strokeWidth: "1.5",
12752
+ strokeLinecap: "round",
12753
+ strokeLinejoin: "round"
12754
+ }
12755
+ ),
12756
+ /* @__PURE__ */ jsxRuntime.jsx(
12757
+ "path",
12758
+ {
12759
+ opacity: "0.75",
12760
+ d: "M180.551 111.93L179.108 111.096",
12761
+ stroke: "#52525B",
12762
+ strokeWidth: "1.5",
12763
+ strokeLinecap: "round",
12764
+ strokeLinejoin: "round"
12765
+ }
12766
+ ),
12767
+ /* @__PURE__ */ jsxRuntime.jsx(
12768
+ "path",
12769
+ {
12770
+ opacity: "0.63",
12771
+ d: "M176.347 112.897L176.354 111.73",
12772
+ stroke: "#52525B",
12773
+ strokeWidth: "1.5",
12774
+ strokeLinecap: "round",
12775
+ strokeLinejoin: "round"
12776
+ }
12777
+ ),
12778
+ /* @__PURE__ */ jsxRuntime.jsx(
12779
+ "path",
12780
+ {
12781
+ opacity: "0.5",
12782
+ d: "M172.153 111.881L173.606 111.064",
12783
+ stroke: "#52525B",
12784
+ strokeWidth: "1.5",
12785
+ strokeLinecap: "round",
12786
+ strokeLinejoin: "round"
12787
+ }
12788
+ ),
12789
+ /* @__PURE__ */ jsxRuntime.jsx(
12790
+ "path",
12791
+ {
12792
+ opacity: "0.38",
12793
+ d: "M170.428 109.478L172.476 109.489",
12794
+ stroke: "#52525B",
12795
+ strokeWidth: "1.5",
12796
+ strokeLinecap: "round",
12797
+ strokeLinejoin: "round"
12798
+ }
12799
+ ),
12800
+ /* @__PURE__ */ jsxRuntime.jsx(
12801
+ "path",
12802
+ {
12803
+ opacity: "0.25",
12804
+ d: "M172.181 107.094L173.624 107.928",
12805
+ stroke: "#52525B",
12806
+ strokeWidth: "1.5",
12807
+ strokeLinecap: "round",
12808
+ strokeLinejoin: "round"
12809
+ }
12810
+ ),
12811
+ /* @__PURE__ */ jsxRuntime.jsx(
12812
+ "path",
12813
+ {
12814
+ opacity: "0.13",
12815
+ d: "M176.386 106.126L176.379 107.294",
12816
+ stroke: "#52525B",
12817
+ strokeWidth: "1.5",
12818
+ strokeLinecap: "round",
12819
+ strokeLinejoin: "round"
12820
+ }
12821
+ ),
12822
+ /* @__PURE__ */ jsxRuntime.jsx(
12823
+ "rect",
12824
+ {
12825
+ width: "12",
12826
+ height: "3",
12827
+ rx: "1.5",
12828
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12829
+ fill: "#D4D4D8"
12830
+ }
12831
+ ),
12832
+ /* @__PURE__ */ jsxRuntime.jsx(
12833
+ "rect",
12834
+ {
12835
+ x: "0.00428286",
12836
+ y: "-0.742904",
12837
+ width: "33.5",
12838
+ height: "65.5",
12839
+ rx: "6.75",
12840
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12841
+ fill: "#D4D4D8",
12842
+ stroke: "#52525B",
12843
+ strokeWidth: "1.5"
12844
+ }
12845
+ ),
12846
+ /* @__PURE__ */ jsxRuntime.jsx(
12847
+ "rect",
12848
+ {
12849
+ x: "0.00428286",
12850
+ y: "-0.742904",
12851
+ width: "33.5",
12852
+ height: "65.5",
12853
+ rx: "6.75",
12854
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12855
+ fill: "white",
12856
+ stroke: "#52525B",
12857
+ strokeWidth: "1.5"
12858
+ }
12859
+ ),
12860
+ /* @__PURE__ */ jsxRuntime.jsx(
12861
+ "rect",
12862
+ {
12863
+ width: "12",
12864
+ height: "3",
12865
+ rx: "1.5",
12866
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12867
+ fill: "#D4D4D8"
12868
+ }
12869
+ ),
12870
+ /* @__PURE__ */ jsxRuntime.jsx(
12871
+ "rect",
12872
+ {
12873
+ width: "17",
12874
+ height: "3",
12875
+ rx: "1.5",
12876
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12877
+ fill: "#D4D4D8"
12878
+ }
12879
+ ),
12880
+ /* @__PURE__ */ jsxRuntime.jsx(
12881
+ "rect",
12882
+ {
12883
+ width: "12",
12884
+ height: "3",
12885
+ rx: "1.5",
12886
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12887
+ fill: "#D4D4D8"
12888
+ }
12889
+ ),
12890
+ /* @__PURE__ */ jsxRuntime.jsx(
12891
+ "path",
12892
+ {
12893
+ d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
12894
+ fill: "#A1A1AA"
12895
+ }
12896
+ ),
12897
+ /* @__PURE__ */ jsxRuntime.jsx(
12898
+ "rect",
12899
+ {
12900
+ width: "17",
12901
+ height: "3",
12902
+ rx: "1.5",
12903
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12904
+ fill: "#A1A1AA"
12905
+ }
12906
+ ),
12907
+ /* @__PURE__ */ jsxRuntime.jsx(
12908
+ "rect",
12909
+ {
12910
+ width: "12",
12911
+ height: "3",
12912
+ rx: "1.5",
12913
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12914
+ fill: "#A1A1AA"
12915
+ }
12916
+ ),
12917
+ /* @__PURE__ */ jsxRuntime.jsx(
12918
+ "path",
12919
+ {
12920
+ d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12921
+ fill: "#52525B"
12922
+ }
12923
+ ),
12924
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12925
+ "path",
12926
+ {
12927
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12928
+ stroke: "#A1A1AA",
12929
+ strokeWidth: "1.5",
12930
+ strokeLinecap: "round",
12931
+ strokeLinejoin: "round"
12932
+ }
12933
+ ) }),
12934
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12935
+ "path",
12936
+ {
12937
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12938
+ stroke: "#A1A1AA",
12939
+ strokeWidth: "1.5",
12940
+ strokeLinecap: "round",
12941
+ strokeLinejoin: "round"
12942
+ }
12943
+ ) }),
12944
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12945
+ "path",
12946
+ {
12947
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12948
+ stroke: "#A1A1AA",
12949
+ strokeWidth: "1.5",
12950
+ strokeLinecap: "round",
12951
+ strokeLinejoin: "round"
12952
+ }
12953
+ ) }),
12954
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12955
+ "path",
12956
+ {
12957
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12958
+ stroke: "#A1A1AA",
12959
+ strokeWidth: "1.5",
12960
+ strokeLinecap: "round",
12961
+ strokeLinejoin: "round"
12962
+ }
12963
+ ) }),
12964
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12965
+ "path",
12966
+ {
12967
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12968
+ stroke: "#A1A1AA",
12969
+ strokeWidth: "1.5",
12970
+ strokeLinecap: "round",
12971
+ strokeLinejoin: "round"
12972
+ }
12973
+ ) }),
12974
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12975
+ "path",
12976
+ {
12977
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12978
+ stroke: "#A1A1AA",
12979
+ strokeWidth: "1.5",
12980
+ strokeLinecap: "round",
12981
+ strokeLinejoin: "round"
12982
+ }
12983
+ ) }),
12984
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12985
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12986
+ "rect",
12987
+ {
12988
+ width: "12",
12989
+ height: "12",
12990
+ fill: "white",
12991
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12992
+ }
12993
+ ) }),
12994
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12995
+ "rect",
12996
+ {
12997
+ width: "12",
12998
+ height: "12",
12999
+ fill: "white",
13000
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
13001
+ }
13002
+ ) }),
13003
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13004
+ "rect",
13005
+ {
13006
+ width: "12",
13007
+ height: "12",
13008
+ fill: "white",
13009
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
13010
+ }
13011
+ ) }),
13012
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13013
+ "rect",
13014
+ {
13015
+ width: "12",
13016
+ height: "12",
13017
+ fill: "white",
13018
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
13019
+ }
13020
+ ) }),
13021
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13022
+ "rect",
13023
+ {
13024
+ width: "12",
13025
+ height: "12",
13026
+ fill: "white",
13027
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13028
+ }
13029
+ ) }),
13030
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13031
+ "rect",
13032
+ {
13033
+ width: "12",
13034
+ height: "12",
13035
+ fill: "white",
13036
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13037
+ }
13038
+ ) })
13039
+ ] })
12946
13040
  ]
12947
13041
  }
12948
- ) });
12949
- };
12950
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
12951
- return /* @__PURE__ */ jsxRuntime.jsx(
12952
- "input",
12953
- {
12954
- ref,
12955
- ...props,
12956
- autoComplete: "off",
12957
- className: ui.clx(
12958
- "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",
12959
- className
12960
- )
12961
- }
12962
13042
  );
12963
- });
12964
- GridInput.displayName = "MetadataForm.GridInput";
12965
- const PlaceholderInner = () => {
12966
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
12967
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
12968
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12969
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
12970
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
12971
- ] }) })
12972
- ] });
12973
13043
  };
12974
- const EDITABLE_TYPES = ["string", "number", "boolean"];
12975
- function getDefaultValues(metadata) {
12976
- if (!metadata || !Object.keys(metadata).length) {
12977
- return [
12978
- {
12979
- key: "",
12980
- value: "",
12981
- disabled: false
12982
- }
12983
- ];
12984
- }
12985
- return Object.entries(metadata).map(([key, value]) => {
12986
- if (!EDITABLE_TYPES.includes(typeof value)) {
12987
- return {
12988
- key,
12989
- value,
12990
- disabled: true
12991
- };
12992
- }
12993
- let stringValue = value;
12994
- if (typeof value !== "string") {
12995
- stringValue = JSON.stringify(value);
12996
- }
12997
- return {
12998
- key,
12999
- value: stringValue,
13000
- original_key: key
13001
- };
13002
- });
13003
- }
13004
- function parseValues(values) {
13005
- const metadata = values.metadata;
13006
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
13007
- if (isEmpty) {
13008
- return null;
13009
- }
13010
- const update = {};
13011
- metadata.forEach((field) => {
13012
- let key = field.key;
13013
- let value = field.value;
13014
- const disabled = field.disabled;
13015
- if (!key || !value) {
13016
- return;
13017
- }
13018
- if (disabled) {
13019
- update[key] = value;
13020
- return;
13021
- }
13022
- key = key.trim();
13023
- value = value.trim();
13024
- if (value === "true") {
13025
- update[key] = true;
13026
- } else if (value === "false") {
13027
- update[key] = false;
13028
- } else {
13029
- const parsedNumber = parseFloat(value);
13030
- if (!isNaN(parsedNumber)) {
13031
- update[key] = parsedNumber;
13032
- } else {
13033
- update[key] = value;
13034
- }
13035
- }
13036
- });
13037
- return update;
13038
- }
13039
- function getHasUneditableRows(metadata) {
13040
- if (!metadata) {
13041
- return false;
13042
- }
13043
- return Object.values(metadata).some(
13044
- (value) => !EDITABLE_TYPES.includes(typeof value)
13045
- );
13046
- }
13044
+ const schema = objectType({
13045
+ customer_id: stringType().min(1)
13046
+ });
13047
13047
  const widgetModule = { widgets: [] };
13048
13048
  const routeModule = {
13049
13049
  routes: [
@@ -13065,44 +13065,44 @@ const routeModule = {
13065
13065
  loader,
13066
13066
  children: [
13067
13067
  {
13068
- Component: BillingAddress,
13069
- path: "/draft-orders/:id/billing-address"
13068
+ Component: CustomItems,
13069
+ path: "/draft-orders/:id/custom-items"
13070
13070
  },
13071
13071
  {
13072
13072
  Component: Email,
13073
13073
  path: "/draft-orders/:id/email"
13074
13074
  },
13075
- {
13076
- Component: CustomItems,
13077
- path: "/draft-orders/:id/custom-items"
13078
- },
13079
13075
  {
13080
13076
  Component: Items,
13081
13077
  path: "/draft-orders/:id/items"
13082
13078
  },
13079
+ {
13080
+ Component: Metadata,
13081
+ path: "/draft-orders/:id/metadata"
13082
+ },
13083
13083
  {
13084
13084
  Component: Promotions,
13085
13085
  path: "/draft-orders/:id/promotions"
13086
13086
  },
13087
13087
  {
13088
- Component: SalesChannel,
13089
- path: "/draft-orders/:id/sales-channel"
13088
+ Component: BillingAddress,
13089
+ path: "/draft-orders/:id/billing-address"
13090
13090
  },
13091
13091
  {
13092
- Component: Shipping,
13093
- path: "/draft-orders/:id/shipping"
13092
+ Component: SalesChannel,
13093
+ path: "/draft-orders/:id/sales-channel"
13094
13094
  },
13095
13095
  {
13096
13096
  Component: ShippingAddress,
13097
13097
  path: "/draft-orders/:id/shipping-address"
13098
13098
  },
13099
13099
  {
13100
- Component: TransferOwnership,
13101
- path: "/draft-orders/:id/transfer-ownership"
13100
+ Component: Shipping,
13101
+ path: "/draft-orders/:id/shipping"
13102
13102
  },
13103
13103
  {
13104
- Component: Metadata,
13105
- path: "/draft-orders/:id/metadata"
13104
+ Component: TransferOwnership,
13105
+ path: "/draft-orders/:id/transfer-ownership"
13106
13106
  }
13107
13107
  ]
13108
13108
  }