@medusajs/draft-order 2.10.2-preview-20250911120205 → 2.10.2-preview-20250911180158

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.
@@ -9567,6 +9567,196 @@ const ID = () => {
9567
9567
  /* @__PURE__ */ jsx(Outlet, {})
9568
9568
  ] });
9569
9569
  };
9570
+ const BillingAddress = () => {
9571
+ const { id } = useParams();
9572
+ const { order, isPending, isError, error } = useOrder(id, {
9573
+ fields: "+billing_address"
9574
+ });
9575
+ if (isError) {
9576
+ throw error;
9577
+ }
9578
+ const isReady = !isPending && !!order;
9579
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9580
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9581
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9582
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9583
+ ] }),
9584
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9585
+ ] });
9586
+ };
9587
+ const BillingAddressForm = ({ order }) => {
9588
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9589
+ const form = useForm({
9590
+ defaultValues: {
9591
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9592
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9593
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9594
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9595
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9596
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9597
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9598
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9599
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9600
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9601
+ },
9602
+ resolver: zodResolver(schema$5)
9603
+ });
9604
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9605
+ const { handleSuccess } = useRouteModal();
9606
+ const onSubmit = form.handleSubmit(async (data) => {
9607
+ await mutateAsync(
9608
+ { billing_address: data },
9609
+ {
9610
+ onSuccess: () => {
9611
+ handleSuccess();
9612
+ },
9613
+ onError: (error) => {
9614
+ toast.error(error.message);
9615
+ }
9616
+ }
9617
+ );
9618
+ });
9619
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9620
+ KeyboundForm,
9621
+ {
9622
+ className: "flex flex-1 flex-col overflow-hidden",
9623
+ onSubmit,
9624
+ children: [
9625
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
9626
+ /* @__PURE__ */ jsx(
9627
+ Form$2.Field,
9628
+ {
9629
+ control: form.control,
9630
+ name: "country_code",
9631
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9632
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9633
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9634
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9635
+ ] })
9636
+ }
9637
+ ),
9638
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9639
+ /* @__PURE__ */ jsx(
9640
+ Form$2.Field,
9641
+ {
9642
+ control: form.control,
9643
+ name: "first_name",
9644
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9645
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9646
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9647
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9648
+ ] })
9649
+ }
9650
+ ),
9651
+ /* @__PURE__ */ jsx(
9652
+ Form$2.Field,
9653
+ {
9654
+ control: form.control,
9655
+ name: "last_name",
9656
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9657
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9658
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9659
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9660
+ ] })
9661
+ }
9662
+ )
9663
+ ] }),
9664
+ /* @__PURE__ */ jsx(
9665
+ Form$2.Field,
9666
+ {
9667
+ control: form.control,
9668
+ name: "company",
9669
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9670
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9671
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9672
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9673
+ ] })
9674
+ }
9675
+ ),
9676
+ /* @__PURE__ */ jsx(
9677
+ Form$2.Field,
9678
+ {
9679
+ control: form.control,
9680
+ name: "address_1",
9681
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9682
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9683
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9684
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9685
+ ] })
9686
+ }
9687
+ ),
9688
+ /* @__PURE__ */ jsx(
9689
+ Form$2.Field,
9690
+ {
9691
+ control: form.control,
9692
+ name: "address_2",
9693
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9694
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9695
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9696
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9697
+ ] })
9698
+ }
9699
+ ),
9700
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9701
+ /* @__PURE__ */ jsx(
9702
+ Form$2.Field,
9703
+ {
9704
+ control: form.control,
9705
+ name: "postal_code",
9706
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9707
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9708
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9709
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9710
+ ] })
9711
+ }
9712
+ ),
9713
+ /* @__PURE__ */ jsx(
9714
+ Form$2.Field,
9715
+ {
9716
+ control: form.control,
9717
+ name: "city",
9718
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9719
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9720
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9721
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9722
+ ] })
9723
+ }
9724
+ )
9725
+ ] }),
9726
+ /* @__PURE__ */ jsx(
9727
+ Form$2.Field,
9728
+ {
9729
+ control: form.control,
9730
+ name: "province",
9731
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9732
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9733
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9734
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9735
+ ] })
9736
+ }
9737
+ ),
9738
+ /* @__PURE__ */ jsx(
9739
+ Form$2.Field,
9740
+ {
9741
+ control: form.control,
9742
+ name: "phone",
9743
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9744
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9745
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9746
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9747
+ ] })
9748
+ }
9749
+ )
9750
+ ] }) }),
9751
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9752
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9753
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9754
+ ] }) })
9755
+ ]
9756
+ }
9757
+ ) });
9758
+ };
9759
+ const schema$5 = addressSchema;
9570
9760
  const CustomItems = () => {
9571
9761
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9572
9762
  /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
@@ -9575,7 +9765,7 @@ const CustomItems = () => {
9575
9765
  };
9576
9766
  const CustomItemsForm = () => {
9577
9767
  const form = useForm({
9578
- resolver: zodResolver(schema$5)
9768
+ resolver: zodResolver(schema$4)
9579
9769
  });
9580
9770
  return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9581
9771
  /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
@@ -9585,46 +9775,114 @@ const CustomItemsForm = () => {
9585
9775
  ] }) })
9586
9776
  ] }) });
9587
9777
  };
9588
- const schema$5 = objectType({
9778
+ const schema$4 = objectType({
9589
9779
  email: stringType().email()
9590
9780
  });
9591
- const NumberInput = forwardRef(
9592
- ({
9593
- value,
9594
- onChange,
9595
- size = "base",
9596
- min = 0,
9597
- max = 100,
9598
- step = 1,
9599
- className,
9600
- disabled,
9601
- ...props
9602
- }, ref) => {
9603
- const handleChange = (event) => {
9604
- const newValue = event.target.value === "" ? min : Number(event.target.value);
9605
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9606
- onChange(newValue);
9607
- }
9608
- };
9609
- const handleIncrement = () => {
9610
- const newValue = value + step;
9611
- if (max === void 0 || newValue <= max) {
9612
- onChange(newValue);
9613
- }
9614
- };
9615
- const handleDecrement = () => {
9616
- const newValue = value - step;
9617
- if (min === void 0 || newValue >= min) {
9618
- onChange(newValue);
9619
- }
9620
- };
9621
- return /* @__PURE__ */ jsxs(
9622
- "div",
9781
+ const Email = () => {
9782
+ const { id } = useParams();
9783
+ const { order, isPending, isError, error } = useOrder(id, {
9784
+ fields: "+email"
9785
+ });
9786
+ if (isError) {
9787
+ throw error;
9788
+ }
9789
+ const isReady = !isPending && !!order;
9790
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9791
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9792
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9793
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9794
+ ] }),
9795
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9796
+ ] });
9797
+ };
9798
+ const EmailForm = ({ order }) => {
9799
+ const form = useForm({
9800
+ defaultValues: {
9801
+ email: order.email ?? ""
9802
+ },
9803
+ resolver: zodResolver(schema$3)
9804
+ });
9805
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9806
+ const { handleSuccess } = useRouteModal();
9807
+ const onSubmit = form.handleSubmit(async (data) => {
9808
+ await mutateAsync(
9809
+ { email: data.email },
9623
9810
  {
9624
- className: clx(
9625
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9626
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9627
- {
9811
+ onSuccess: () => {
9812
+ handleSuccess();
9813
+ },
9814
+ onError: (error) => {
9815
+ toast.error(error.message);
9816
+ }
9817
+ }
9818
+ );
9819
+ });
9820
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9821
+ KeyboundForm,
9822
+ {
9823
+ className: "flex flex-1 flex-col overflow-hidden",
9824
+ onSubmit,
9825
+ children: [
9826
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9827
+ Form$2.Field,
9828
+ {
9829
+ control: form.control,
9830
+ name: "email",
9831
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9832
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9833
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9834
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9835
+ ] })
9836
+ }
9837
+ ) }),
9838
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9839
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9840
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9841
+ ] }) })
9842
+ ]
9843
+ }
9844
+ ) });
9845
+ };
9846
+ const schema$3 = objectType({
9847
+ email: stringType().email()
9848
+ });
9849
+ const NumberInput = forwardRef(
9850
+ ({
9851
+ value,
9852
+ onChange,
9853
+ size = "base",
9854
+ min = 0,
9855
+ max = 100,
9856
+ step = 1,
9857
+ className,
9858
+ disabled,
9859
+ ...props
9860
+ }, ref) => {
9861
+ const handleChange = (event) => {
9862
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
9863
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9864
+ onChange(newValue);
9865
+ }
9866
+ };
9867
+ const handleIncrement = () => {
9868
+ const newValue = value + step;
9869
+ if (max === void 0 || newValue <= max) {
9870
+ onChange(newValue);
9871
+ }
9872
+ };
9873
+ const handleDecrement = () => {
9874
+ const newValue = value - step;
9875
+ if (min === void 0 || newValue >= min) {
9876
+ onChange(newValue);
9877
+ }
9878
+ };
9879
+ return /* @__PURE__ */ jsxs(
9880
+ "div",
9881
+ {
9882
+ className: clx(
9883
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9884
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9885
+ {
9628
9886
  "h-7": size === "small",
9629
9887
  "h-8": size === "base"
9630
9888
  },
@@ -11189,1629 +11447,1160 @@ function getPromotionIds(items, shippingMethods) {
11189
11447
  }
11190
11448
  return Array.from(promotionIds);
11191
11449
  }
11192
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11193
- const Shipping = () => {
11194
- var _a;
11450
+ const SalesChannel = () => {
11195
11451
  const { id } = useParams();
11196
- const { order, isPending, isError, error } = useOrder(id, {
11197
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11198
- });
11199
- const {
11200
- order: preview,
11201
- isPending: isPreviewPending,
11202
- isError: isPreviewError,
11203
- error: previewError
11204
- } = useOrderPreview(id);
11205
- useInitiateOrderEdit({ preview });
11206
- const { onCancel } = useCancelOrderEdit({ preview });
11207
- if (isError) {
11208
- throw error;
11209
- }
11210
- if (isPreviewError) {
11211
- throw previewError;
11212
- }
11213
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11214
- const isReady = preview && !isPreviewPending && order && !isPending;
11215
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11216
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11217
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11218
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11219
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11220
- ] }) }) }),
11221
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11222
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11223
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11224
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11225
- ] }) });
11226
- };
11227
- const ShippingForm = ({ preview, order }) => {
11228
- var _a;
11229
- const { setIsOpen } = useStackedModal();
11230
- const [isSubmitting, setIsSubmitting] = useState(false);
11231
- const [data, setData] = useState(null);
11232
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11233
- const { shipping_options } = useShippingOptions(
11452
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11453
+ id,
11234
11454
  {
11235
- id: appliedShippingOptionIds,
11236
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11455
+ fields: "+sales_channel_id"
11237
11456
  },
11238
11457
  {
11239
- enabled: appliedShippingOptionIds.length > 0
11458
+ enabled: !!id
11240
11459
  }
11241
11460
  );
11242
- const uniqueShippingProfiles = useMemo(() => {
11243
- const profiles = /* @__PURE__ */ new Map();
11244
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11245
- profiles.set(profile.id, profile);
11246
- });
11247
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11248
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11249
- });
11250
- return Array.from(profiles.values());
11251
- }, [order.items, shipping_options]);
11461
+ if (isError) {
11462
+ throw error;
11463
+ }
11464
+ const ISrEADY = !!draft_order && !isPending;
11465
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11466
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11467
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11468
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11469
+ ] }),
11470
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11471
+ ] });
11472
+ };
11473
+ const SalesChannelForm = ({ order }) => {
11474
+ const form = useForm({
11475
+ defaultValues: {
11476
+ sales_channel_id: order.sales_channel_id || ""
11477
+ },
11478
+ resolver: zodResolver(schema$2)
11479
+ });
11480
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11252
11481
  const { handleSuccess } = useRouteModal();
11253
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11254
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11255
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11256
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11257
- const onSubmit = async () => {
11258
- setIsSubmitting(true);
11259
- let requestSucceeded = false;
11260
- await requestOrderEdit(void 0, {
11261
- onError: (e) => {
11262
- toast.error(`Failed to request order edit: ${e.message}`);
11263
- },
11264
- onSuccess: () => {
11265
- requestSucceeded = true;
11266
- }
11267
- });
11268
- if (!requestSucceeded) {
11269
- setIsSubmitting(false);
11270
- return;
11271
- }
11272
- await confirmOrderEdit(void 0, {
11273
- onError: (e) => {
11274
- toast.error(`Failed to confirm order edit: ${e.message}`);
11275
- },
11276
- onSuccess: () => {
11277
- handleSuccess();
11482
+ const onSubmit = form.handleSubmit(async (data) => {
11483
+ await mutateAsync(
11484
+ {
11485
+ sales_channel_id: data.sales_channel_id
11278
11486
  },
11279
- onSettled: () => {
11280
- setIsSubmitting(false);
11281
- }
11282
- });
11283
- };
11284
- const onKeydown = useCallback(
11285
- (e) => {
11286
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11287
- if (data || isSubmitting) {
11288
- return;
11487
+ {
11488
+ onSuccess: () => {
11489
+ toast.success("Sales channel updated");
11490
+ handleSuccess();
11491
+ },
11492
+ onError: (error) => {
11493
+ toast.error(error.message);
11289
11494
  }
11290
- onSubmit();
11291
11495
  }
11496
+ );
11497
+ });
11498
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11499
+ KeyboundForm,
11500
+ {
11501
+ className: "flex flex-1 flex-col overflow-hidden",
11502
+ onSubmit,
11503
+ children: [
11504
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11505
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11506
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11507
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11508
+ ] }) })
11509
+ ]
11510
+ }
11511
+ ) });
11512
+ };
11513
+ const SalesChannelField = ({ control, order }) => {
11514
+ const salesChannels = useComboboxData({
11515
+ queryFn: async (params) => {
11516
+ return await sdk.admin.salesChannel.list(params);
11292
11517
  },
11293
- [data, isSubmitting, onSubmit]
11518
+ queryKey: ["sales-channels"],
11519
+ getOptions: (data) => {
11520
+ return data.sales_channels.map((salesChannel) => ({
11521
+ label: salesChannel.name,
11522
+ value: salesChannel.id
11523
+ }));
11524
+ },
11525
+ defaultValue: order.sales_channel_id || void 0
11526
+ });
11527
+ return /* @__PURE__ */ jsx(
11528
+ Form$2.Field,
11529
+ {
11530
+ control,
11531
+ name: "sales_channel_id",
11532
+ render: ({ field }) => {
11533
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11534
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11535
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11536
+ Combobox,
11537
+ {
11538
+ options: salesChannels.options,
11539
+ fetchNextPage: salesChannels.fetchNextPage,
11540
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11541
+ searchValue: salesChannels.searchValue,
11542
+ onSearchValueChange: salesChannels.onSearchValueChange,
11543
+ placeholder: "Select sales channel",
11544
+ ...field
11545
+ }
11546
+ ) }),
11547
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11548
+ ] });
11549
+ }
11550
+ }
11294
11551
  );
11295
- useEffect(() => {
11296
- document.addEventListener("keydown", onKeydown);
11297
- return () => {
11298
- document.removeEventListener("keydown", onKeydown);
11299
- };
11300
- }, [onKeydown]);
11301
- return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11302
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11303
- /* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11304
- /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11305
- /* @__PURE__ */ jsxs("div", { children: [
11306
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11307
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11308
- ] }),
11309
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11310
- /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11311
- /* @__PURE__ */ jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11552
+ };
11553
+ const schema$2 = objectType({
11554
+ sales_channel_id: stringType().min(1)
11555
+ });
11556
+ const ShippingAddress = () => {
11557
+ const { id } = useParams();
11558
+ const { order, isPending, isError, error } = useOrder(id, {
11559
+ fields: "+shipping_address"
11560
+ });
11561
+ if (isError) {
11562
+ throw error;
11563
+ }
11564
+ const isReady = !isPending && !!order;
11565
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11566
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11567
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11568
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11569
+ ] }),
11570
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11571
+ ] });
11572
+ };
11573
+ const ShippingAddressForm = ({ order }) => {
11574
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11575
+ const form = useForm({
11576
+ defaultValues: {
11577
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11578
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11579
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11580
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11581
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11582
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11583
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11584
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11585
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11586
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11587
+ },
11588
+ resolver: zodResolver(schema$1)
11589
+ });
11590
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11591
+ const { handleSuccess } = useRouteModal();
11592
+ const onSubmit = form.handleSubmit(async (data) => {
11593
+ await mutateAsync(
11594
+ {
11595
+ shipping_address: {
11596
+ first_name: data.first_name,
11597
+ last_name: data.last_name,
11598
+ company: data.company,
11599
+ address_1: data.address_1,
11600
+ address_2: data.address_2,
11601
+ city: data.city,
11602
+ province: data.province,
11603
+ country_code: data.country_code,
11604
+ postal_code: data.postal_code,
11605
+ phone: data.phone
11606
+ }
11607
+ },
11608
+ {
11609
+ onSuccess: () => {
11610
+ handleSuccess();
11611
+ },
11612
+ onError: (error) => {
11613
+ toast.error(error.message);
11614
+ }
11615
+ }
11616
+ );
11617
+ });
11618
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11619
+ KeyboundForm,
11620
+ {
11621
+ className: "flex flex-1 flex-col overflow-hidden",
11622
+ onSubmit,
11623
+ children: [
11624
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
11625
+ /* @__PURE__ */ jsx(
11626
+ Form$2.Field,
11627
+ {
11628
+ control: form.control,
11629
+ name: "country_code",
11630
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11631
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11632
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11633
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11634
+ ] })
11635
+ }
11636
+ ),
11637
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11312
11638
  /* @__PURE__ */ jsx(
11313
- Text,
11639
+ Form$2.Field,
11314
11640
  {
11315
- size: "xsmall",
11316
- weight: "plus",
11317
- className: "text-ui-fg-muted",
11318
- children: "Shipping profile"
11641
+ control: form.control,
11642
+ name: "first_name",
11643
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11644
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11645
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11646
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11647
+ ] })
11319
11648
  }
11320
11649
  ),
11321
11650
  /* @__PURE__ */ jsx(
11322
- Text,
11651
+ Form$2.Field,
11323
11652
  {
11324
- size: "xsmall",
11325
- weight: "plus",
11326
- className: "text-ui-fg-muted",
11327
- children: "Action"
11653
+ control: form.control,
11654
+ name: "last_name",
11655
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11656
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11657
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11658
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11659
+ ] })
11328
11660
  }
11329
11661
  )
11330
11662
  ] }),
11331
- /* @__PURE__ */ jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11332
- var _a2, _b, _c, _d, _e, _f, _g;
11333
- const items = getItemsWithShippingProfile(
11334
- profile.id,
11335
- order.items
11336
- );
11337
- const hasItems = items.length > 0;
11338
- const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11339
- (option) => option.shipping_profile_id === profile.id
11340
- );
11341
- const shippingMethod = preview.shipping_methods.find(
11342
- (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11343
- );
11344
- const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11345
- (action) => action.action === "SHIPPING_ADD"
11346
- );
11347
- return /* @__PURE__ */ jsxs(
11348
- Accordion.Item,
11663
+ /* @__PURE__ */ jsx(
11664
+ Form$2.Field,
11665
+ {
11666
+ control: form.control,
11667
+ name: "company",
11668
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11669
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11670
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11671
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11672
+ ] })
11673
+ }
11674
+ ),
11675
+ /* @__PURE__ */ jsx(
11676
+ Form$2.Field,
11677
+ {
11678
+ control: form.control,
11679
+ name: "address_1",
11680
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11681
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11682
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11683
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11684
+ ] })
11685
+ }
11686
+ ),
11687
+ /* @__PURE__ */ jsx(
11688
+ Form$2.Field,
11689
+ {
11690
+ control: form.control,
11691
+ name: "address_2",
11692
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11693
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11694
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11695
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11696
+ ] })
11697
+ }
11698
+ ),
11699
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11700
+ /* @__PURE__ */ jsx(
11701
+ Form$2.Field,
11349
11702
  {
11350
- value: profile.id,
11351
- className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11352
- children: [
11353
- /* @__PURE__ */ jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11354
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11355
- /* @__PURE__ */ jsx(Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
11356
- IconButton,
11357
- {
11358
- size: "2xsmall",
11359
- variant: "transparent",
11360
- className: "group/trigger",
11361
- disabled: !hasItems,
11362
- children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11363
- }
11364
- ) }),
11365
- !shippingOption ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
11366
- /* @__PURE__ */ jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsx(Shopping, { className: "text-ui-fg-subtle" }) }) }),
11367
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col flex-1", children: [
11368
- /* @__PURE__ */ jsx(
11369
- Text,
11370
- {
11371
- size: "small",
11372
- weight: "plus",
11373
- leading: "compact",
11374
- children: profile.name
11375
- }
11376
- ),
11377
- /* @__PURE__ */ jsxs(
11378
- Text,
11379
- {
11380
- size: "small",
11381
- leading: "compact",
11382
- className: "text-ui-fg-subtle",
11383
- children: [
11384
- items.length,
11385
- " ",
11386
- pluralize(items.length, "items", "item")
11387
- ]
11388
- }
11389
- )
11390
- ] })
11391
- ] }) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11392
- /* @__PURE__ */ jsx(
11393
- Tooltip,
11394
- {
11395
- content: /* @__PURE__ */ jsx("ul", { children: items.map((item) => {
11396
- var _a3, _b2, _c2;
11397
- return /* @__PURE__ */ jsx(
11398
- "li",
11399
- {
11400
- 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})`
11401
- },
11402
- item.id
11403
- );
11404
- }) }),
11405
- children: /* @__PURE__ */ jsxs(
11406
- Badge,
11407
- {
11408
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11409
- size: "xsmall",
11410
- children: [
11411
- /* @__PURE__ */ jsx(Shopping, { className: "shrink-0" }),
11412
- /* @__PURE__ */ jsxs("span", { className: "truncate", children: [
11413
- items.reduce(
11414
- (acc, item) => acc + item.quantity,
11415
- 0
11416
- ),
11417
- "x",
11418
- " ",
11419
- pluralize(items.length, "items", "item")
11420
- ] })
11421
- ]
11422
- }
11423
- )
11424
- }
11425
- ),
11426
- /* @__PURE__ */ jsx(
11427
- Tooltip,
11428
- {
11429
- content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11430
- children: /* @__PURE__ */ jsxs(
11431
- Badge,
11432
- {
11433
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11434
- size: "xsmall",
11435
- children: [
11436
- /* @__PURE__ */ jsx(Buildings, { className: "shrink-0" }),
11437
- /* @__PURE__ */ 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 })
11438
- ]
11439
- }
11440
- )
11441
- }
11442
- ),
11443
- /* @__PURE__ */ jsx(Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxs(
11444
- Badge,
11445
- {
11446
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11447
- size: "xsmall",
11448
- children: [
11449
- /* @__PURE__ */ jsx(TruckFast, { className: "shrink-0" }),
11450
- /* @__PURE__ */ jsx("span", { className: "truncate", children: shippingOption.name })
11451
- ]
11452
- }
11453
- ) })
11454
- ] })
11455
- ] }),
11456
- shippingOption ? /* @__PURE__ */ jsx(
11457
- ActionMenu,
11458
- {
11459
- groups: [
11460
- {
11461
- actions: [
11462
- hasItems ? {
11463
- label: "Edit shipping option",
11464
- icon: /* @__PURE__ */ jsx(Channels, {}),
11465
- onClick: () => {
11466
- setIsOpen(
11467
- STACKED_FOCUS_MODAL_ID,
11468
- true
11469
- );
11470
- setData({
11471
- shippingProfileId: profile.id,
11472
- shippingOption,
11473
- shippingMethod
11474
- });
11475
- }
11476
- } : void 0,
11477
- {
11478
- label: "Remove shipping option",
11479
- icon: /* @__PURE__ */ jsx(Trash, {}),
11480
- onClick: () => {
11481
- if (shippingMethod) {
11482
- if (addShippingMethodAction) {
11483
- removeActionShippingMethod(
11484
- addShippingMethodAction.id
11485
- );
11486
- } else {
11487
- removeShippingMethod(
11488
- shippingMethod.id
11489
- );
11490
- }
11491
- }
11492
- }
11493
- }
11494
- ].filter(Boolean)
11495
- }
11496
- ]
11497
- }
11498
- ) : /* @__PURE__ */ jsx(
11499
- StackedModalTrigger,
11500
- {
11501
- shippingProfileId: profile.id,
11502
- shippingOption,
11503
- shippingMethod,
11504
- setData,
11505
- children: "Add shipping option"
11506
- }
11507
- )
11508
- ] }),
11509
- /* @__PURE__ */ jsxs(Accordion.Content, { children: [
11510
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11511
- items.map((item, idx) => {
11512
- var _a3, _b2, _c2, _d2, _e2;
11513
- return /* @__PURE__ */ jsxs("div", { children: [
11514
- /* @__PURE__ */ jsxs(
11515
- "div",
11516
- {
11517
- className: "px-3 flex items-center gap-x-3",
11518
- children: [
11519
- /* @__PURE__ */ jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsx(
11520
- Divider,
11521
- {
11522
- variant: "dashed",
11523
- orientation: "vertical"
11524
- }
11525
- ) }),
11526
- /* @__PURE__ */ jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11527
- /* @__PURE__ */ jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxs(
11528
- Text,
11529
- {
11530
- size: "small",
11531
- leading: "compact",
11532
- className: "text-ui-fg-subtle",
11533
- children: [
11534
- item.quantity,
11535
- "x"
11536
- ]
11537
- }
11538
- ) }),
11539
- /* @__PURE__ */ jsx(Thumbnail, { thumbnail: item.thumbnail }),
11540
- /* @__PURE__ */ jsxs("div", { children: [
11541
- /* @__PURE__ */ jsxs(
11542
- Text,
11543
- {
11544
- size: "small",
11545
- leading: "compact",
11546
- weight: "plus",
11547
- children: [
11548
- (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
11549
- " (",
11550
- (_c2 = item.variant) == null ? void 0 : _c2.title,
11551
- ")"
11552
- ]
11553
- }
11554
- ),
11555
- /* @__PURE__ */ jsx(
11556
- Text,
11557
- {
11558
- size: "small",
11559
- leading: "compact",
11560
- className: "text-ui-fg-subtle",
11561
- children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
11562
- }
11563
- )
11564
- ] })
11565
- ] })
11566
- ]
11567
- },
11568
- item.id
11569
- ),
11570
- idx !== items.length - 1 && /* @__PURE__ */ jsx(Divider, { variant: "dashed" })
11571
- ] }, item.id);
11572
- })
11573
- ] })
11574
- ]
11575
- },
11576
- profile.id
11577
- );
11578
- }) })
11579
- ] }) })
11580
- ] }) }),
11581
- /* @__PURE__ */ jsx(
11582
- StackedFocusModal,
11583
- {
11584
- id: STACKED_FOCUS_MODAL_ID,
11585
- onOpenChangeCallback: (open) => {
11586
- if (!open) {
11587
- setData(null);
11703
+ control: form.control,
11704
+ name: "postal_code",
11705
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11706
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11707
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11708
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11709
+ ] })
11710
+ }
11711
+ ),
11712
+ /* @__PURE__ */ jsx(
11713
+ Form$2.Field,
11714
+ {
11715
+ control: form.control,
11716
+ name: "city",
11717
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11718
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11719
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11720
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11721
+ ] })
11722
+ }
11723
+ )
11724
+ ] }),
11725
+ /* @__PURE__ */ jsx(
11726
+ Form$2.Field,
11727
+ {
11728
+ control: form.control,
11729
+ name: "province",
11730
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11731
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11732
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11733
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11734
+ ] })
11588
11735
  }
11589
- return open;
11590
- },
11591
- children: data && /* @__PURE__ */ jsx(ShippingProfileForm, { data, order, preview })
11592
- }
11593
- )
11594
- ] }),
11595
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
11596
- /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11597
- /* @__PURE__ */ jsx(
11598
- Button,
11599
- {
11600
- size: "small",
11601
- type: "button",
11602
- isLoading: isSubmitting,
11603
- onClick: onSubmit,
11604
- children: "Save"
11605
- }
11606
- )
11607
- ] }) })
11608
- ] });
11736
+ ),
11737
+ /* @__PURE__ */ jsx(
11738
+ Form$2.Field,
11739
+ {
11740
+ control: form.control,
11741
+ name: "phone",
11742
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11743
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11744
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11745
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11746
+ ] })
11747
+ }
11748
+ )
11749
+ ] }) }),
11750
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11751
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11752
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11753
+ ] }) })
11754
+ ]
11755
+ }
11756
+ ) });
11609
11757
  };
11610
- const StackedModalTrigger = ({
11611
- shippingProfileId,
11612
- shippingOption,
11613
- shippingMethod,
11614
- setData,
11615
- children
11616
- }) => {
11617
- const { setIsOpen, getIsOpen } = useStackedModal();
11618
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11619
- const onToggle = () => {
11620
- if (isOpen) {
11621
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11622
- setData(null);
11623
- } else {
11624
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11625
- setData({
11626
- shippingProfileId,
11627
- shippingOption,
11628
- shippingMethod
11629
- });
11630
- }
11631
- };
11632
- return /* @__PURE__ */ jsx(
11633
- Button,
11634
- {
11635
- size: "small",
11636
- variant: "secondary",
11637
- onClick: onToggle,
11638
- className: "text-ui-fg-primary shrink-0",
11639
- children
11640
- }
11641
- );
11642
- };
11643
- const ShippingProfileForm = ({
11644
- data,
11645
- order,
11646
- preview
11647
- }) => {
11648
- var _a, _b, _c, _d, _e, _f;
11649
- const { setIsOpen } = useStackedModal();
11650
- const form = useForm({
11651
- resolver: zodResolver(shippingMethodSchema),
11652
- defaultValues: {
11653
- 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,
11654
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
11655
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
11656
- }
11758
+ const schema$1 = addressSchema;
11759
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11760
+ const Shipping = () => {
11761
+ var _a;
11762
+ const { id } = useParams();
11763
+ const { order, isPending, isError, error } = useOrder(id, {
11764
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11657
11765
  });
11658
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
11659
11766
  const {
11660
- mutateAsync: updateShippingMethod,
11661
- isPending: isUpdatingShippingMethod
11662
- } = useDraftOrderUpdateShippingMethod(order.id);
11663
- const onSubmit = form.handleSubmit(async (values) => {
11664
- if (isEqual(values, form.formState.defaultValues)) {
11665
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11666
- return;
11767
+ order: preview,
11768
+ isPending: isPreviewPending,
11769
+ isError: isPreviewError,
11770
+ error: previewError
11771
+ } = useOrderPreview(id);
11772
+ useInitiateOrderEdit({ preview });
11773
+ const { onCancel } = useCancelOrderEdit({ preview });
11774
+ if (isError) {
11775
+ throw error;
11776
+ }
11777
+ if (isPreviewError) {
11778
+ throw previewError;
11779
+ }
11780
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11781
+ const isReady = preview && !isPreviewPending && order && !isPending;
11782
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11783
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11784
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11785
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11786
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11787
+ ] }) }) }),
11788
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11789
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11790
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11791
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11792
+ ] }) });
11793
+ };
11794
+ const ShippingForm = ({ preview, order }) => {
11795
+ var _a;
11796
+ const { setIsOpen } = useStackedModal();
11797
+ const [isSubmitting, setIsSubmitting] = useState(false);
11798
+ const [data, setData] = useState(null);
11799
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11800
+ const { shipping_options } = useShippingOptions(
11801
+ {
11802
+ id: appliedShippingOptionIds,
11803
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11804
+ },
11805
+ {
11806
+ enabled: appliedShippingOptionIds.length > 0
11667
11807
  }
11668
- if (data.shippingMethod) {
11669
- await updateShippingMethod(
11670
- {
11671
- method_id: data.shippingMethod.id,
11672
- shipping_option_id: values.shipping_option_id,
11673
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11674
- },
11675
- {
11676
- onError: (e) => {
11677
- toast.error(e.message);
11678
- },
11679
- onSuccess: () => {
11680
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11681
- }
11682
- }
11683
- );
11808
+ );
11809
+ const uniqueShippingProfiles = useMemo(() => {
11810
+ const profiles = /* @__PURE__ */ new Map();
11811
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11812
+ profiles.set(profile.id, profile);
11813
+ });
11814
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11815
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11816
+ });
11817
+ return Array.from(profiles.values());
11818
+ }, [order.items, shipping_options]);
11819
+ const { handleSuccess } = useRouteModal();
11820
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11821
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11822
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11823
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11824
+ const onSubmit = async () => {
11825
+ setIsSubmitting(true);
11826
+ let requestSucceeded = false;
11827
+ await requestOrderEdit(void 0, {
11828
+ onError: (e) => {
11829
+ toast.error(`Failed to request order edit: ${e.message}`);
11830
+ },
11831
+ onSuccess: () => {
11832
+ requestSucceeded = true;
11833
+ }
11834
+ });
11835
+ if (!requestSucceeded) {
11836
+ setIsSubmitting(false);
11684
11837
  return;
11685
11838
  }
11686
- await addShippingMethod(
11687
- {
11688
- shipping_option_id: values.shipping_option_id,
11689
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11839
+ await confirmOrderEdit(void 0, {
11840
+ onError: (e) => {
11841
+ toast.error(`Failed to confirm order edit: ${e.message}`);
11690
11842
  },
11691
- {
11692
- onError: (e) => {
11693
- toast.error(e.message);
11694
- },
11695
- onSuccess: () => {
11696
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11843
+ onSuccess: () => {
11844
+ handleSuccess();
11845
+ },
11846
+ onSettled: () => {
11847
+ setIsSubmitting(false);
11848
+ }
11849
+ });
11850
+ };
11851
+ const onKeydown = useCallback(
11852
+ (e) => {
11853
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11854
+ if (data || isSubmitting) {
11855
+ return;
11697
11856
  }
11857
+ onSubmit();
11698
11858
  }
11699
- );
11700
- });
11701
- return /* @__PURE__ */ jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxs(
11702
- KeyboundForm,
11703
- {
11704
- className: "flex h-full flex-col overflow-hidden",
11705
- onSubmit,
11706
- children: [
11707
- /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
11708
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11709
- /* @__PURE__ */ jsxs("div", { children: [
11710
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11711
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(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." }) })
11712
- ] }),
11713
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11714
- /* @__PURE__ */ jsx(
11715
- LocationField,
11716
- {
11717
- control: form.control,
11718
- setValue: form.setValue
11719
- }
11720
- ),
11721
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11722
- /* @__PURE__ */ jsx(
11723
- ShippingOptionField,
11724
- {
11725
- shippingProfileId: data.shippingProfileId,
11726
- preview,
11727
- control: form.control
11728
- }
11729
- ),
11730
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11731
- /* @__PURE__ */ jsx(
11732
- CustomAmountField,
11733
- {
11734
- control: form.control,
11735
- currencyCode: order.currency_code
11736
- }
11737
- ),
11738
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11739
- /* @__PURE__ */ jsx(
11740
- ItemsPreview,
11741
- {
11742
- order,
11743
- shippingProfileId: data.shippingProfileId
11744
- }
11745
- )
11746
- ] }) }) }),
11747
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
11748
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11749
- /* @__PURE__ */ jsx(
11750
- Button,
11751
- {
11752
- size: "small",
11753
- type: "submit",
11754
- isLoading: isPending || isUpdatingShippingMethod,
11755
- children: data.shippingMethod ? "Update" : "Add"
11756
- }
11757
- )
11758
- ] }) })
11759
- ]
11760
- }
11761
- ) }) });
11762
- };
11763
- const shippingMethodSchema = objectType({
11764
- location_id: stringType(),
11765
- shipping_option_id: stringType(),
11766
- custom_amount: unionType([numberType(), stringType()]).optional()
11767
- });
11768
- const ItemsPreview = ({ order, shippingProfileId }) => {
11769
- const matches = order.items.filter(
11770
- (item) => {
11771
- var _a, _b, _c;
11772
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
11773
- }
11859
+ },
11860
+ [data, isSubmitting, onSubmit]
11774
11861
  );
11775
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
11776
- /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11777
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
11778
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
11779
- ] }) }),
11780
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11781
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
11782
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
11783
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
11784
- ] }),
11785
- /* @__PURE__ */ 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__ */ jsxs(
11786
- "div",
11787
- {
11788
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
11789
- children: [
11790
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
11791
- /* @__PURE__ */ jsx(
11792
- Thumbnail,
11793
- {
11794
- thumbnail: item.thumbnail,
11795
- alt: item.product_title ?? void 0
11796
- }
11797
- ),
11798
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11799
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
11800
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
11801
- /* @__PURE__ */ jsxs(
11802
- Text,
11803
- {
11804
- size: "small",
11805
- leading: "compact",
11806
- className: "text-ui-fg-subtle",
11807
- children: [
11808
- "(",
11809
- item.variant_title,
11810
- ")"
11811
- ]
11812
- }
11813
- )
11814
- ] }),
11815
- /* @__PURE__ */ jsx(
11816
- Text,
11817
- {
11818
- size: "small",
11819
- leading: "compact",
11820
- className: "text-ui-fg-subtle",
11821
- children: item.variant_sku
11822
- }
11823
- )
11824
- ] })
11825
- ] }),
11826
- /* @__PURE__ */ jsxs(
11862
+ useEffect(() => {
11863
+ document.addEventListener("keydown", onKeydown);
11864
+ return () => {
11865
+ document.removeEventListener("keydown", onKeydown);
11866
+ };
11867
+ }, [onKeydown]);
11868
+ return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11869
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11870
+ /* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11871
+ /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11872
+ /* @__PURE__ */ jsxs("div", { children: [
11873
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11874
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11875
+ ] }),
11876
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11877
+ /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11878
+ /* @__PURE__ */ jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11879
+ /* @__PURE__ */ jsx(
11827
11880
  Text,
11828
11881
  {
11829
- size: "small",
11830
- leading: "compact",
11831
- className: "text-ui-fg-subtle",
11832
- children: [
11833
- item.quantity,
11834
- "x"
11835
- ]
11882
+ size: "xsmall",
11883
+ weight: "plus",
11884
+ className: "text-ui-fg-muted",
11885
+ children: "Shipping profile"
11886
+ }
11887
+ ),
11888
+ /* @__PURE__ */ jsx(
11889
+ Text,
11890
+ {
11891
+ size: "xsmall",
11892
+ weight: "plus",
11893
+ className: "text-ui-fg-muted",
11894
+ children: "Action"
11836
11895
  }
11837
11896
  )
11838
- ]
11839
- },
11840
- item.id
11841
- )) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
11842
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
11843
- /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
11844
- 'No items found for "',
11845
- query,
11846
- '".'
11847
- ] })
11848
- ] }) })
11849
- ] })
11850
- ] });
11851
- };
11852
- const LocationField = ({ control, setValue }) => {
11853
- const locations = useComboboxData({
11854
- queryKey: ["locations"],
11855
- queryFn: async (params) => {
11856
- return await sdk.admin.stockLocation.list(params);
11857
- },
11858
- getOptions: (data) => {
11859
- return data.stock_locations.map((location) => ({
11860
- label: location.name,
11861
- value: location.id
11862
- }));
11863
- }
11864
- });
11865
- return /* @__PURE__ */ jsx(
11866
- Form$2.Field,
11867
- {
11868
- control,
11869
- name: "location_id",
11870
- render: ({ field: { onChange, ...field } }) => {
11871
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11872
- /* @__PURE__ */ jsxs("div", { children: [
11873
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
11874
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
11875
- ] }),
11876
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11877
- Combobox,
11878
- {
11879
- options: locations.options,
11880
- fetchNextPage: locations.fetchNextPage,
11881
- isFetchingNextPage: locations.isFetchingNextPage,
11882
- searchValue: locations.searchValue,
11883
- onSearchValueChange: locations.onSearchValueChange,
11884
- placeholder: "Select location",
11885
- onChange: (value) => {
11886
- setValue("shipping_option_id", "", {
11887
- shouldDirty: true,
11888
- shouldTouch: true
11889
- });
11890
- onChange(value);
11891
- },
11892
- ...field
11893
- }
11894
- ) })
11895
- ] }) });
11896
- }
11897
- }
11898
- );
11899
- };
11900
- const ShippingOptionField = ({
11901
- shippingProfileId,
11902
- preview,
11903
- control
11904
- }) => {
11905
- var _a;
11906
- const locationId = useWatch({ control, name: "location_id" });
11907
- const shippingOptions = useComboboxData({
11908
- queryKey: ["shipping_options", locationId, shippingProfileId],
11909
- queryFn: async (params) => {
11910
- return await sdk.admin.shippingOption.list({
11911
- ...params,
11912
- stock_location_id: locationId,
11913
- shipping_profile_id: shippingProfileId
11914
- });
11915
- },
11916
- getOptions: (data) => {
11917
- return data.shipping_options.map((option) => {
11918
- var _a2;
11919
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
11920
- (r) => r.attribute === "is_return" && r.value === "true"
11921
- )) {
11922
- return void 0;
11923
- }
11924
- return {
11925
- label: option.name,
11926
- value: option.id
11927
- };
11928
- }).filter(Boolean);
11929
- },
11930
- enabled: !!locationId && !!shippingProfileId,
11931
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
11932
- });
11933
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
11934
- return /* @__PURE__ */ jsx(
11935
- Form$2.Field,
11936
- {
11937
- control,
11938
- name: "shipping_option_id",
11939
- render: ({ field }) => {
11940
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11941
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11942
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
11943
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
11944
- ] }),
11945
- /* @__PURE__ */ jsx(
11946
- ConditionalTooltip,
11947
- {
11948
- content: tooltipContent,
11949
- showTooltip: !locationId || !shippingProfileId,
11950
- children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11951
- Combobox,
11952
- {
11953
- options: shippingOptions.options,
11954
- fetchNextPage: shippingOptions.fetchNextPage,
11955
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
11956
- searchValue: shippingOptions.searchValue,
11957
- onSearchValueChange: shippingOptions.onSearchValueChange,
11958
- placeholder: "Select shipping option",
11959
- ...field,
11960
- disabled: !locationId || !shippingProfileId
11961
- }
11962
- ) }) })
11963
- }
11964
- )
11965
- ] }) });
11966
- }
11967
- }
11968
- );
11969
- };
11970
- const CustomAmountField = ({
11971
- control,
11972
- currencyCode
11973
- }) => {
11974
- return /* @__PURE__ */ jsx(
11975
- Form$2.Field,
11976
- {
11977
- control,
11978
- name: "custom_amount",
11979
- render: ({ field: { onChange, ...field } }) => {
11980
- return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11981
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11982
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
11983
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
11984
11897
  ] }),
11985
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11986
- CurrencyInput,
11987
- {
11988
- ...field,
11989
- onValueChange: (value) => onChange(value),
11990
- symbol: getNativeSymbol(currencyCode),
11991
- code: currencyCode
11992
- }
11993
- ) })
11994
- ] });
11995
- }
11996
- }
11997
- );
11998
- };
11999
- const ShippingAddress = () => {
12000
- const { id } = useParams();
12001
- const { order, isPending, isError, error } = useOrder(id, {
12002
- fields: "+shipping_address"
12003
- });
12004
- if (isError) {
12005
- throw error;
12006
- }
12007
- const isReady = !isPending && !!order;
12008
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12009
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12010
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12011
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12012
- ] }),
12013
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12014
- ] });
12015
- };
12016
- const ShippingAddressForm = ({ order }) => {
12017
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12018
- const form = useForm({
12019
- defaultValues: {
12020
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12021
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12022
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12023
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12024
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12025
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12026
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12027
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12028
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12029
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12030
- },
12031
- resolver: zodResolver(schema$4)
12032
- });
12033
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12034
- const { handleSuccess } = useRouteModal();
12035
- const onSubmit = form.handleSubmit(async (data) => {
12036
- await mutateAsync(
12037
- {
12038
- shipping_address: {
12039
- first_name: data.first_name,
12040
- last_name: data.last_name,
12041
- company: data.company,
12042
- address_1: data.address_1,
12043
- address_2: data.address_2,
12044
- city: data.city,
12045
- province: data.province,
12046
- country_code: data.country_code,
12047
- postal_code: data.postal_code,
12048
- phone: data.phone
12049
- }
12050
- },
12051
- {
12052
- onSuccess: () => {
12053
- handleSuccess();
12054
- },
12055
- onError: (error) => {
12056
- toast.error(error.message);
12057
- }
12058
- }
12059
- );
12060
- });
12061
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12062
- KeyboundForm,
12063
- {
12064
- className: "flex flex-1 flex-col overflow-hidden",
12065
- onSubmit,
12066
- children: [
12067
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12068
- /* @__PURE__ */ jsx(
12069
- Form$2.Field,
12070
- {
12071
- control: form.control,
12072
- name: "country_code",
12073
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12074
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12075
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12076
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12077
- ] })
12078
- }
12079
- ),
12080
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12081
- /* @__PURE__ */ jsx(
12082
- Form$2.Field,
12083
- {
12084
- control: form.control,
12085
- name: "first_name",
12086
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12087
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12088
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12089
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12090
- ] })
12091
- }
12092
- ),
12093
- /* @__PURE__ */ jsx(
12094
- Form$2.Field,
12095
- {
12096
- control: form.control,
12097
- name: "last_name",
12098
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12099
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12100
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12101
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12102
- ] })
12103
- }
12104
- )
12105
- ] }),
12106
- /* @__PURE__ */ jsx(
12107
- Form$2.Field,
12108
- {
12109
- control: form.control,
12110
- name: "company",
12111
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12112
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12113
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12114
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12115
- ] })
12116
- }
12117
- ),
12118
- /* @__PURE__ */ jsx(
12119
- Form$2.Field,
12120
- {
12121
- control: form.control,
12122
- name: "address_1",
12123
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12124
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12125
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12126
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12127
- ] })
12128
- }
12129
- ),
12130
- /* @__PURE__ */ jsx(
12131
- Form$2.Field,
12132
- {
12133
- control: form.control,
12134
- name: "address_2",
12135
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12136
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12137
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12138
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12139
- ] })
12140
- }
12141
- ),
12142
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12143
- /* @__PURE__ */ jsx(
12144
- Form$2.Field,
12145
- {
12146
- control: form.control,
12147
- name: "postal_code",
12148
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12149
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12150
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12151
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12152
- ] })
12153
- }
12154
- ),
12155
- /* @__PURE__ */ jsx(
12156
- Form$2.Field,
11898
+ /* @__PURE__ */ jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11899
+ var _a2, _b, _c, _d, _e, _f, _g;
11900
+ const items = getItemsWithShippingProfile(
11901
+ profile.id,
11902
+ order.items
11903
+ );
11904
+ const hasItems = items.length > 0;
11905
+ const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11906
+ (option) => option.shipping_profile_id === profile.id
11907
+ );
11908
+ const shippingMethod = preview.shipping_methods.find(
11909
+ (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11910
+ );
11911
+ const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11912
+ (action) => action.action === "SHIPPING_ADD"
11913
+ );
11914
+ return /* @__PURE__ */ jsxs(
11915
+ Accordion.Item,
12157
11916
  {
12158
- control: form.control,
12159
- name: "city",
12160
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12161
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12162
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12163
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12164
- ] })
12165
- }
12166
- )
12167
- ] }),
12168
- /* @__PURE__ */ jsx(
12169
- Form$2.Field,
12170
- {
12171
- control: form.control,
12172
- name: "province",
12173
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12174
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12175
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12176
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12177
- ] })
12178
- }
12179
- ),
12180
- /* @__PURE__ */ jsx(
12181
- Form$2.Field,
12182
- {
12183
- control: form.control,
12184
- name: "phone",
12185
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12186
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12187
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12188
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12189
- ] })
12190
- }
12191
- )
12192
- ] }) }),
12193
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12194
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12195
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12196
- ] }) })
12197
- ]
12198
- }
12199
- ) });
12200
- };
12201
- const schema$4 = addressSchema;
12202
- const TransferOwnership = () => {
12203
- const { id } = useParams();
12204
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12205
- fields: "id,customer_id,customer.*"
12206
- });
12207
- if (isError) {
12208
- throw error;
12209
- }
12210
- const isReady = !isPending && !!draft_order;
12211
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12212
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12213
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12214
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12215
- ] }),
12216
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12217
- ] });
12218
- };
12219
- const TransferOwnershipForm = ({ order }) => {
12220
- var _a, _b;
12221
- const form = useForm({
12222
- defaultValues: {
12223
- customer_id: order.customer_id || ""
12224
- },
12225
- resolver: zodResolver(schema$3)
12226
- });
12227
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12228
- const { handleSuccess } = useRouteModal();
12229
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12230
- const currentCustomer = order.customer ? {
12231
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12232
- value: order.customer.id
12233
- } : null;
12234
- const onSubmit = form.handleSubmit(async (data) => {
12235
- await mutateAsync(
12236
- { customer_id: data.customer_id },
12237
- {
12238
- onSuccess: () => {
12239
- toast.success("Customer updated");
12240
- handleSuccess();
12241
- },
12242
- onError: (error) => {
12243
- toast.error(error.message);
12244
- }
12245
- }
12246
- );
12247
- });
12248
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12249
- KeyboundForm,
12250
- {
12251
- className: "flex flex-1 flex-col overflow-hidden",
12252
- onSubmit,
12253
- children: [
12254
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12255
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12256
- currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12257
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12258
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12259
- /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12260
- ] }),
12261
- /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12262
- /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12263
- /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12264
- ] })
12265
- ] }),
12266
- /* @__PURE__ */ jsx(
12267
- CustomerField,
12268
- {
12269
- control: form.control,
12270
- currentCustomerId: order.customer_id
12271
- }
12272
- )
12273
- ] }),
12274
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12275
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12276
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12277
- ] }) })
12278
- ]
12279
- }
12280
- ) });
12281
- };
12282
- const CustomerField = ({ control, currentCustomerId }) => {
12283
- const customers = useComboboxData({
12284
- queryFn: async (params) => {
12285
- return await sdk.admin.customer.list({
12286
- ...params,
12287
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12288
- });
12289
- },
12290
- queryKey: ["customers"],
12291
- getOptions: (data) => {
12292
- return data.customers.map((customer) => {
12293
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12294
- return {
12295
- label: name ? `${name} (${customer.email})` : customer.email,
12296
- value: customer.id
12297
- };
12298
- });
12299
- }
12300
- });
12301
- return /* @__PURE__ */ jsx(
12302
- Form$2.Field,
12303
- {
12304
- name: "customer_id",
12305
- control,
12306
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
12307
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12308
- /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
12309
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12310
- ] }),
12311
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12312
- Combobox,
12313
- {
12314
- options: customers.options,
12315
- fetchNextPage: customers.fetchNextPage,
12316
- isFetchingNextPage: customers.isFetchingNextPage,
12317
- searchValue: customers.searchValue,
12318
- onSearchValueChange: customers.onSearchValueChange,
12319
- placeholder: "Select customer",
12320
- ...field
12321
- }
12322
- ) }),
12323
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12324
- ] })
12325
- }
12326
- );
12327
- };
12328
- const Illustration = () => {
12329
- return /* @__PURE__ */ jsxs(
12330
- "svg",
12331
- {
12332
- width: "280",
12333
- height: "180",
12334
- viewBox: "0 0 280 180",
12335
- fill: "none",
12336
- xmlns: "http://www.w3.org/2000/svg",
12337
- children: [
12338
- /* @__PURE__ */ jsx(
12339
- "rect",
12340
- {
12341
- x: "0.00428286",
12342
- y: "-0.742904",
12343
- width: "33.5",
12344
- height: "65.5",
12345
- rx: "6.75",
12346
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12347
- fill: "#D4D4D8",
12348
- stroke: "#52525B",
12349
- strokeWidth: "1.5"
12350
- }
12351
- ),
12352
- /* @__PURE__ */ jsx(
12353
- "rect",
12354
- {
12355
- x: "0.00428286",
12356
- y: "-0.742904",
12357
- width: "33.5",
12358
- height: "65.5",
12359
- rx: "6.75",
12360
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12361
- fill: "white",
12362
- stroke: "#52525B",
12363
- strokeWidth: "1.5"
12364
- }
12365
- ),
12366
- /* @__PURE__ */ jsx(
12367
- "path",
12368
- {
12369
- d: "M180.579 107.142L179.126 107.959",
12370
- stroke: "#52525B",
12371
- strokeWidth: "1.5",
12372
- strokeLinecap: "round",
12373
- strokeLinejoin: "round"
12374
- }
12375
- ),
12376
- /* @__PURE__ */ jsx(
12377
- "path",
12378
- {
12379
- opacity: "0.88",
12380
- d: "M182.305 109.546L180.257 109.534",
12381
- stroke: "#52525B",
12382
- strokeWidth: "1.5",
12383
- strokeLinecap: "round",
12384
- strokeLinejoin: "round"
12385
- }
12386
- ),
12387
- /* @__PURE__ */ jsx(
12388
- "path",
12389
- {
12390
- opacity: "0.75",
12391
- d: "M180.551 111.93L179.108 111.096",
12392
- stroke: "#52525B",
12393
- strokeWidth: "1.5",
12394
- strokeLinecap: "round",
12395
- strokeLinejoin: "round"
12396
- }
12397
- ),
12398
- /* @__PURE__ */ jsx(
12399
- "path",
12400
- {
12401
- opacity: "0.63",
12402
- d: "M176.347 112.897L176.354 111.73",
12403
- stroke: "#52525B",
12404
- strokeWidth: "1.5",
12405
- strokeLinecap: "round",
12406
- strokeLinejoin: "round"
12407
- }
12408
- ),
12409
- /* @__PURE__ */ jsx(
12410
- "path",
12411
- {
12412
- opacity: "0.5",
12413
- d: "M172.153 111.881L173.606 111.064",
12414
- stroke: "#52525B",
12415
- strokeWidth: "1.5",
12416
- strokeLinecap: "round",
12417
- strokeLinejoin: "round"
12418
- }
12419
- ),
12420
- /* @__PURE__ */ jsx(
12421
- "path",
12422
- {
12423
- opacity: "0.38",
12424
- d: "M170.428 109.478L172.476 109.489",
12425
- stroke: "#52525B",
12426
- strokeWidth: "1.5",
12427
- strokeLinecap: "round",
12428
- strokeLinejoin: "round"
12429
- }
12430
- ),
12431
- /* @__PURE__ */ jsx(
12432
- "path",
12433
- {
12434
- opacity: "0.25",
12435
- d: "M172.181 107.094L173.624 107.928",
12436
- stroke: "#52525B",
12437
- strokeWidth: "1.5",
12438
- strokeLinecap: "round",
12439
- strokeLinejoin: "round"
12440
- }
12441
- ),
12442
- /* @__PURE__ */ jsx(
12443
- "path",
12444
- {
12445
- opacity: "0.13",
12446
- d: "M176.386 106.126L176.379 107.294",
12447
- stroke: "#52525B",
12448
- strokeWidth: "1.5",
12449
- strokeLinecap: "round",
12450
- strokeLinejoin: "round"
12451
- }
12452
- ),
12453
- /* @__PURE__ */ jsx(
12454
- "rect",
12455
- {
12456
- width: "12",
12457
- height: "3",
12458
- rx: "1.5",
12459
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12460
- fill: "#D4D4D8"
12461
- }
12462
- ),
12463
- /* @__PURE__ */ jsx(
12464
- "rect",
12465
- {
12466
- x: "0.00428286",
12467
- y: "-0.742904",
12468
- width: "33.5",
12469
- height: "65.5",
12470
- rx: "6.75",
12471
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12472
- fill: "#D4D4D8",
12473
- stroke: "#52525B",
12474
- strokeWidth: "1.5"
12475
- }
12476
- ),
12477
- /* @__PURE__ */ jsx(
12478
- "rect",
12479
- {
12480
- x: "0.00428286",
12481
- y: "-0.742904",
12482
- width: "33.5",
12483
- height: "65.5",
12484
- rx: "6.75",
12485
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12486
- fill: "white",
12487
- stroke: "#52525B",
12488
- strokeWidth: "1.5"
12489
- }
12490
- ),
12491
- /* @__PURE__ */ jsx(
12492
- "rect",
12493
- {
12494
- width: "12",
12495
- height: "3",
12496
- rx: "1.5",
12497
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12498
- fill: "#D4D4D8"
12499
- }
12500
- ),
12501
- /* @__PURE__ */ jsx(
12502
- "rect",
12503
- {
12504
- width: "17",
12505
- height: "3",
12506
- rx: "1.5",
12507
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12508
- fill: "#D4D4D8"
12509
- }
12510
- ),
12511
- /* @__PURE__ */ jsx(
12512
- "rect",
12513
- {
12514
- width: "12",
12515
- height: "3",
12516
- rx: "1.5",
12517
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12518
- fill: "#D4D4D8"
12519
- }
12520
- ),
12521
- /* @__PURE__ */ jsx(
12522
- "path",
12523
- {
12524
- 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",
12525
- fill: "#A1A1AA"
12526
- }
12527
- ),
12528
- /* @__PURE__ */ jsx(
12529
- "rect",
12530
- {
12531
- width: "17",
12532
- height: "3",
12533
- rx: "1.5",
12534
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12535
- fill: "#A1A1AA"
12536
- }
12537
- ),
12538
- /* @__PURE__ */ jsx(
12539
- "rect",
12540
- {
12541
- width: "12",
12542
- height: "3",
12543
- rx: "1.5",
12544
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12545
- fill: "#A1A1AA"
12546
- }
12547
- ),
12548
- /* @__PURE__ */ jsx(
12549
- "path",
12550
- {
12551
- 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",
12552
- fill: "#52525B"
12553
- }
12554
- ),
12555
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
12556
- "path",
12557
- {
12558
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12559
- stroke: "#A1A1AA",
12560
- strokeWidth: "1.5",
12561
- strokeLinecap: "round",
12562
- strokeLinejoin: "round"
12563
- }
12564
- ) }),
12565
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
12566
- "path",
12567
- {
12568
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12569
- stroke: "#A1A1AA",
12570
- strokeWidth: "1.5",
12571
- strokeLinecap: "round",
12572
- strokeLinejoin: "round"
12573
- }
12574
- ) }),
12575
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
12576
- "path",
12577
- {
12578
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12579
- stroke: "#A1A1AA",
12580
- strokeWidth: "1.5",
12581
- strokeLinecap: "round",
12582
- strokeLinejoin: "round"
12583
- }
12584
- ) }),
12585
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
12586
- "path",
12587
- {
12588
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12589
- stroke: "#A1A1AA",
12590
- strokeWidth: "1.5",
12591
- strokeLinecap: "round",
12592
- strokeLinejoin: "round"
12593
- }
12594
- ) }),
12595
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12596
- "path",
12597
- {
12598
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12599
- stroke: "#A1A1AA",
12600
- strokeWidth: "1.5",
12601
- strokeLinecap: "round",
12602
- strokeLinejoin: "round"
12603
- }
12604
- ) }),
12605
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12606
- "path",
12607
- {
12608
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12609
- stroke: "#A1A1AA",
12610
- strokeWidth: "1.5",
12611
- strokeLinecap: "round",
12612
- strokeLinejoin: "round"
12613
- }
12614
- ) }),
12615
- /* @__PURE__ */ jsxs("defs", { children: [
12616
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12617
- "rect",
12618
- {
12619
- width: "12",
12620
- height: "12",
12621
- fill: "white",
12622
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
11917
+ value: profile.id,
11918
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11919
+ children: [
11920
+ /* @__PURE__ */ jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11921
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11922
+ /* @__PURE__ */ jsx(Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
11923
+ IconButton,
11924
+ {
11925
+ size: "2xsmall",
11926
+ variant: "transparent",
11927
+ className: "group/trigger",
11928
+ disabled: !hasItems,
11929
+ children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11930
+ }
11931
+ ) }),
11932
+ !shippingOption ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
11933
+ /* @__PURE__ */ jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsx(Shopping, { className: "text-ui-fg-subtle" }) }) }),
11934
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col flex-1", children: [
11935
+ /* @__PURE__ */ jsx(
11936
+ Text,
11937
+ {
11938
+ size: "small",
11939
+ weight: "plus",
11940
+ leading: "compact",
11941
+ children: profile.name
11942
+ }
11943
+ ),
11944
+ /* @__PURE__ */ jsxs(
11945
+ Text,
11946
+ {
11947
+ size: "small",
11948
+ leading: "compact",
11949
+ className: "text-ui-fg-subtle",
11950
+ children: [
11951
+ items.length,
11952
+ " ",
11953
+ pluralize(items.length, "items", "item")
11954
+ ]
11955
+ }
11956
+ )
11957
+ ] })
11958
+ ] }) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11959
+ /* @__PURE__ */ jsx(
11960
+ Tooltip,
11961
+ {
11962
+ content: /* @__PURE__ */ jsx("ul", { children: items.map((item) => {
11963
+ var _a3, _b2, _c2;
11964
+ return /* @__PURE__ */ jsx(
11965
+ "li",
11966
+ {
11967
+ 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})`
11968
+ },
11969
+ item.id
11970
+ );
11971
+ }) }),
11972
+ children: /* @__PURE__ */ jsxs(
11973
+ Badge,
11974
+ {
11975
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11976
+ size: "xsmall",
11977
+ children: [
11978
+ /* @__PURE__ */ jsx(Shopping, { className: "shrink-0" }),
11979
+ /* @__PURE__ */ jsxs("span", { className: "truncate", children: [
11980
+ items.reduce(
11981
+ (acc, item) => acc + item.quantity,
11982
+ 0
11983
+ ),
11984
+ "x",
11985
+ " ",
11986
+ pluralize(items.length, "items", "item")
11987
+ ] })
11988
+ ]
11989
+ }
11990
+ )
11991
+ }
11992
+ ),
11993
+ /* @__PURE__ */ jsx(
11994
+ Tooltip,
11995
+ {
11996
+ content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11997
+ children: /* @__PURE__ */ jsxs(
11998
+ Badge,
11999
+ {
12000
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12001
+ size: "xsmall",
12002
+ children: [
12003
+ /* @__PURE__ */ jsx(Buildings, { className: "shrink-0" }),
12004
+ /* @__PURE__ */ 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 })
12005
+ ]
12006
+ }
12007
+ )
12008
+ }
12009
+ ),
12010
+ /* @__PURE__ */ jsx(Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxs(
12011
+ Badge,
12012
+ {
12013
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12014
+ size: "xsmall",
12015
+ children: [
12016
+ /* @__PURE__ */ jsx(TruckFast, { className: "shrink-0" }),
12017
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: shippingOption.name })
12018
+ ]
12019
+ }
12020
+ ) })
12021
+ ] })
12022
+ ] }),
12023
+ shippingOption ? /* @__PURE__ */ jsx(
12024
+ ActionMenu,
12025
+ {
12026
+ groups: [
12027
+ {
12028
+ actions: [
12029
+ hasItems ? {
12030
+ label: "Edit shipping option",
12031
+ icon: /* @__PURE__ */ jsx(Channels, {}),
12032
+ onClick: () => {
12033
+ setIsOpen(
12034
+ STACKED_FOCUS_MODAL_ID,
12035
+ true
12036
+ );
12037
+ setData({
12038
+ shippingProfileId: profile.id,
12039
+ shippingOption,
12040
+ shippingMethod
12041
+ });
12042
+ }
12043
+ } : void 0,
12044
+ {
12045
+ label: "Remove shipping option",
12046
+ icon: /* @__PURE__ */ jsx(Trash, {}),
12047
+ onClick: () => {
12048
+ if (shippingMethod) {
12049
+ if (addShippingMethodAction) {
12050
+ removeActionShippingMethod(
12051
+ addShippingMethodAction.id
12052
+ );
12053
+ } else {
12054
+ removeShippingMethod(
12055
+ shippingMethod.id
12056
+ );
12057
+ }
12058
+ }
12059
+ }
12060
+ }
12061
+ ].filter(Boolean)
12062
+ }
12063
+ ]
12064
+ }
12065
+ ) : /* @__PURE__ */ jsx(
12066
+ StackedModalTrigger,
12067
+ {
12068
+ shippingProfileId: profile.id,
12069
+ shippingOption,
12070
+ shippingMethod,
12071
+ setData,
12072
+ children: "Add shipping option"
12073
+ }
12074
+ )
12075
+ ] }),
12076
+ /* @__PURE__ */ jsxs(Accordion.Content, { children: [
12077
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12078
+ items.map((item, idx) => {
12079
+ var _a3, _b2, _c2, _d2, _e2;
12080
+ return /* @__PURE__ */ jsxs("div", { children: [
12081
+ /* @__PURE__ */ jsxs(
12082
+ "div",
12083
+ {
12084
+ className: "px-3 flex items-center gap-x-3",
12085
+ children: [
12086
+ /* @__PURE__ */ jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsx(
12087
+ Divider,
12088
+ {
12089
+ variant: "dashed",
12090
+ orientation: "vertical"
12091
+ }
12092
+ ) }),
12093
+ /* @__PURE__ */ jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
12094
+ /* @__PURE__ */ jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxs(
12095
+ Text,
12096
+ {
12097
+ size: "small",
12098
+ leading: "compact",
12099
+ className: "text-ui-fg-subtle",
12100
+ children: [
12101
+ item.quantity,
12102
+ "x"
12103
+ ]
12104
+ }
12105
+ ) }),
12106
+ /* @__PURE__ */ jsx(Thumbnail, { thumbnail: item.thumbnail }),
12107
+ /* @__PURE__ */ jsxs("div", { children: [
12108
+ /* @__PURE__ */ jsxs(
12109
+ Text,
12110
+ {
12111
+ size: "small",
12112
+ leading: "compact",
12113
+ weight: "plus",
12114
+ children: [
12115
+ (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
12116
+ " (",
12117
+ (_c2 = item.variant) == null ? void 0 : _c2.title,
12118
+ ")"
12119
+ ]
12120
+ }
12121
+ ),
12122
+ /* @__PURE__ */ jsx(
12123
+ Text,
12124
+ {
12125
+ size: "small",
12126
+ leading: "compact",
12127
+ className: "text-ui-fg-subtle",
12128
+ children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
12129
+ }
12130
+ )
12131
+ ] })
12132
+ ] })
12133
+ ]
12134
+ },
12135
+ item.id
12136
+ ),
12137
+ idx !== items.length - 1 && /* @__PURE__ */ jsx(Divider, { variant: "dashed" })
12138
+ ] }, item.id);
12139
+ })
12140
+ ] })
12141
+ ]
12142
+ },
12143
+ profile.id
12144
+ );
12145
+ }) })
12146
+ ] }) })
12147
+ ] }) }),
12148
+ /* @__PURE__ */ jsx(
12149
+ StackedFocusModal,
12150
+ {
12151
+ id: STACKED_FOCUS_MODAL_ID,
12152
+ onOpenChangeCallback: (open) => {
12153
+ if (!open) {
12154
+ setData(null);
12623
12155
  }
12624
- ) }),
12625
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12626
- "rect",
12156
+ return open;
12157
+ },
12158
+ children: data && /* @__PURE__ */ jsx(ShippingProfileForm, { data, order, preview })
12159
+ }
12160
+ )
12161
+ ] }),
12162
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
12163
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12164
+ /* @__PURE__ */ jsx(
12165
+ Button,
12166
+ {
12167
+ size: "small",
12168
+ type: "button",
12169
+ isLoading: isSubmitting,
12170
+ onClick: onSubmit,
12171
+ children: "Save"
12172
+ }
12173
+ )
12174
+ ] }) })
12175
+ ] });
12176
+ };
12177
+ const StackedModalTrigger = ({
12178
+ shippingProfileId,
12179
+ shippingOption,
12180
+ shippingMethod,
12181
+ setData,
12182
+ children
12183
+ }) => {
12184
+ const { setIsOpen, getIsOpen } = useStackedModal();
12185
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12186
+ const onToggle = () => {
12187
+ if (isOpen) {
12188
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12189
+ setData(null);
12190
+ } else {
12191
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12192
+ setData({
12193
+ shippingProfileId,
12194
+ shippingOption,
12195
+ shippingMethod
12196
+ });
12197
+ }
12198
+ };
12199
+ return /* @__PURE__ */ jsx(
12200
+ Button,
12201
+ {
12202
+ size: "small",
12203
+ variant: "secondary",
12204
+ onClick: onToggle,
12205
+ className: "text-ui-fg-primary shrink-0",
12206
+ children
12207
+ }
12208
+ );
12209
+ };
12210
+ const ShippingProfileForm = ({
12211
+ data,
12212
+ order,
12213
+ preview
12214
+ }) => {
12215
+ var _a, _b, _c, _d, _e, _f;
12216
+ const { setIsOpen } = useStackedModal();
12217
+ const form = useForm({
12218
+ resolver: zodResolver(shippingMethodSchema),
12219
+ defaultValues: {
12220
+ 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,
12221
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12222
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12223
+ }
12224
+ });
12225
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12226
+ const {
12227
+ mutateAsync: updateShippingMethod,
12228
+ isPending: isUpdatingShippingMethod
12229
+ } = useDraftOrderUpdateShippingMethod(order.id);
12230
+ const onSubmit = form.handleSubmit(async (values) => {
12231
+ if (isEqual(values, form.formState.defaultValues)) {
12232
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12233
+ return;
12234
+ }
12235
+ if (data.shippingMethod) {
12236
+ await updateShippingMethod(
12237
+ {
12238
+ method_id: data.shippingMethod.id,
12239
+ shipping_option_id: values.shipping_option_id,
12240
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12241
+ },
12242
+ {
12243
+ onError: (e) => {
12244
+ toast.error(e.message);
12245
+ },
12246
+ onSuccess: () => {
12247
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12248
+ }
12249
+ }
12250
+ );
12251
+ return;
12252
+ }
12253
+ await addShippingMethod(
12254
+ {
12255
+ shipping_option_id: values.shipping_option_id,
12256
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12257
+ },
12258
+ {
12259
+ onError: (e) => {
12260
+ toast.error(e.message);
12261
+ },
12262
+ onSuccess: () => {
12263
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12264
+ }
12265
+ }
12266
+ );
12267
+ });
12268
+ return /* @__PURE__ */ jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxs(
12269
+ KeyboundForm,
12270
+ {
12271
+ className: "flex h-full flex-col overflow-hidden",
12272
+ onSubmit,
12273
+ children: [
12274
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12275
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12276
+ /* @__PURE__ */ jsxs("div", { children: [
12277
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12278
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(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." }) })
12279
+ ] }),
12280
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12281
+ /* @__PURE__ */ jsx(
12282
+ LocationField,
12627
12283
  {
12628
- width: "12",
12629
- height: "12",
12630
- fill: "white",
12631
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12284
+ control: form.control,
12285
+ setValue: form.setValue
12632
12286
  }
12633
- ) }),
12634
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12635
- "rect",
12287
+ ),
12288
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12289
+ /* @__PURE__ */ jsx(
12290
+ ShippingOptionField,
12636
12291
  {
12637
- width: "12",
12638
- height: "12",
12639
- fill: "white",
12640
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12292
+ shippingProfileId: data.shippingProfileId,
12293
+ preview,
12294
+ control: form.control
12641
12295
  }
12642
- ) }),
12643
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12644
- "rect",
12296
+ ),
12297
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12298
+ /* @__PURE__ */ jsx(
12299
+ CustomAmountField,
12645
12300
  {
12646
- width: "12",
12647
- height: "12",
12648
- fill: "white",
12649
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12301
+ control: form.control,
12302
+ currencyCode: order.currency_code
12650
12303
  }
12651
- ) }),
12652
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12653
- "rect",
12304
+ ),
12305
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12306
+ /* @__PURE__ */ jsx(
12307
+ ItemsPreview,
12654
12308
  {
12655
- width: "12",
12656
- height: "12",
12657
- fill: "white",
12658
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12309
+ order,
12310
+ shippingProfileId: data.shippingProfileId
12659
12311
  }
12660
- ) }),
12661
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
12662
- "rect",
12312
+ )
12313
+ ] }) }) }),
12314
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
12315
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12316
+ /* @__PURE__ */ jsx(
12317
+ Button,
12663
12318
  {
12664
- width: "12",
12665
- height: "12",
12666
- fill: "white",
12667
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12319
+ size: "small",
12320
+ type: "submit",
12321
+ isLoading: isPending || isUpdatingShippingMethod,
12322
+ children: data.shippingMethod ? "Update" : "Add"
12668
12323
  }
12669
- ) })
12670
- ] })
12324
+ )
12325
+ ] }) })
12671
12326
  ]
12672
12327
  }
12673
- );
12328
+ ) }) });
12674
12329
  };
12675
- const schema$3 = objectType({
12676
- customer_id: stringType().min(1)
12330
+ const shippingMethodSchema = objectType({
12331
+ location_id: stringType(),
12332
+ shipping_option_id: stringType(),
12333
+ custom_amount: unionType([numberType(), stringType()]).optional()
12677
12334
  });
12678
- const SalesChannel = () => {
12679
- const { id } = useParams();
12680
- const { draft_order, isPending, isError, error } = useDraftOrder(
12681
- id,
12682
- {
12683
- fields: "+sales_channel_id"
12684
- },
12685
- {
12686
- enabled: !!id
12335
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12336
+ const matches = order.items.filter(
12337
+ (item) => {
12338
+ var _a, _b, _c;
12339
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12687
12340
  }
12688
12341
  );
12689
- if (isError) {
12690
- throw error;
12691
- }
12692
- const ISrEADY = !!draft_order && !isPending;
12693
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12694
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12695
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
12696
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12697
- ] }),
12698
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
12342
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
12343
+ /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12344
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12345
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12346
+ ] }) }),
12347
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12348
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12349
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
12350
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
12351
+ ] }),
12352
+ /* @__PURE__ */ 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__ */ jsxs(
12353
+ "div",
12354
+ {
12355
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12356
+ children: [
12357
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12358
+ /* @__PURE__ */ jsx(
12359
+ Thumbnail,
12360
+ {
12361
+ thumbnail: item.thumbnail,
12362
+ alt: item.product_title ?? void 0
12363
+ }
12364
+ ),
12365
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12366
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
12367
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12368
+ /* @__PURE__ */ jsxs(
12369
+ Text,
12370
+ {
12371
+ size: "small",
12372
+ leading: "compact",
12373
+ className: "text-ui-fg-subtle",
12374
+ children: [
12375
+ "(",
12376
+ item.variant_title,
12377
+ ")"
12378
+ ]
12379
+ }
12380
+ )
12381
+ ] }),
12382
+ /* @__PURE__ */ jsx(
12383
+ Text,
12384
+ {
12385
+ size: "small",
12386
+ leading: "compact",
12387
+ className: "text-ui-fg-subtle",
12388
+ children: item.variant_sku
12389
+ }
12390
+ )
12391
+ ] })
12392
+ ] }),
12393
+ /* @__PURE__ */ jsxs(
12394
+ Text,
12395
+ {
12396
+ size: "small",
12397
+ leading: "compact",
12398
+ className: "text-ui-fg-subtle",
12399
+ children: [
12400
+ item.quantity,
12401
+ "x"
12402
+ ]
12403
+ }
12404
+ )
12405
+ ]
12406
+ },
12407
+ item.id
12408
+ )) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12409
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12410
+ /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12411
+ 'No items found for "',
12412
+ query,
12413
+ '".'
12414
+ ] })
12415
+ ] }) })
12416
+ ] })
12699
12417
  ] });
12700
12418
  };
12701
- const SalesChannelForm = ({ order }) => {
12702
- const form = useForm({
12703
- defaultValues: {
12704
- sales_channel_id: order.sales_channel_id || ""
12419
+ const LocationField = ({ control, setValue }) => {
12420
+ const locations = useComboboxData({
12421
+ queryKey: ["locations"],
12422
+ queryFn: async (params) => {
12423
+ return await sdk.admin.stockLocation.list(params);
12705
12424
  },
12706
- resolver: zodResolver(schema$2)
12425
+ getOptions: (data) => {
12426
+ return data.stock_locations.map((location) => ({
12427
+ label: location.name,
12428
+ value: location.id
12429
+ }));
12430
+ }
12707
12431
  });
12708
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12709
- const { handleSuccess } = useRouteModal();
12710
- const onSubmit = form.handleSubmit(async (data) => {
12711
- await mutateAsync(
12712
- {
12713
- sales_channel_id: data.sales_channel_id
12714
- },
12715
- {
12716
- onSuccess: () => {
12717
- toast.success("Sales channel updated");
12718
- handleSuccess();
12719
- },
12720
- onError: (error) => {
12721
- toast.error(error.message);
12722
- }
12432
+ return /* @__PURE__ */ jsx(
12433
+ Form$2.Field,
12434
+ {
12435
+ control,
12436
+ name: "location_id",
12437
+ render: ({ field: { onChange, ...field } }) => {
12438
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12439
+ /* @__PURE__ */ jsxs("div", { children: [
12440
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
12441
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12442
+ ] }),
12443
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12444
+ Combobox,
12445
+ {
12446
+ options: locations.options,
12447
+ fetchNextPage: locations.fetchNextPage,
12448
+ isFetchingNextPage: locations.isFetchingNextPage,
12449
+ searchValue: locations.searchValue,
12450
+ onSearchValueChange: locations.onSearchValueChange,
12451
+ placeholder: "Select location",
12452
+ onChange: (value) => {
12453
+ setValue("shipping_option_id", "", {
12454
+ shouldDirty: true,
12455
+ shouldTouch: true
12456
+ });
12457
+ onChange(value);
12458
+ },
12459
+ ...field
12460
+ }
12461
+ ) })
12462
+ ] }) });
12723
12463
  }
12724
- );
12725
- });
12726
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12727
- KeyboundForm,
12728
- {
12729
- className: "flex flex-1 flex-col overflow-hidden",
12730
- onSubmit,
12731
- children: [
12732
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
12733
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12734
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12735
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12736
- ] }) })
12737
- ]
12738
12464
  }
12739
- ) });
12465
+ );
12740
12466
  };
12741
- const SalesChannelField = ({ control, order }) => {
12742
- const salesChannels = useComboboxData({
12467
+ const ShippingOptionField = ({
12468
+ shippingProfileId,
12469
+ preview,
12470
+ control
12471
+ }) => {
12472
+ var _a;
12473
+ const locationId = useWatch({ control, name: "location_id" });
12474
+ const shippingOptions = useComboboxData({
12475
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12743
12476
  queryFn: async (params) => {
12744
- return await sdk.admin.salesChannel.list(params);
12477
+ return await sdk.admin.shippingOption.list({
12478
+ ...params,
12479
+ stock_location_id: locationId,
12480
+ shipping_profile_id: shippingProfileId
12481
+ });
12745
12482
  },
12746
- queryKey: ["sales-channels"],
12747
12483
  getOptions: (data) => {
12748
- return data.sales_channels.map((salesChannel) => ({
12749
- label: salesChannel.name,
12750
- value: salesChannel.id
12751
- }));
12484
+ return data.shipping_options.map((option) => {
12485
+ var _a2;
12486
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12487
+ (r) => r.attribute === "is_return" && r.value === "true"
12488
+ )) {
12489
+ return void 0;
12490
+ }
12491
+ return {
12492
+ label: option.name,
12493
+ value: option.id
12494
+ };
12495
+ }).filter(Boolean);
12752
12496
  },
12753
- defaultValue: order.sales_channel_id || void 0
12497
+ enabled: !!locationId && !!shippingProfileId,
12498
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12754
12499
  });
12500
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12755
12501
  return /* @__PURE__ */ jsx(
12756
12502
  Form$2.Field,
12757
12503
  {
12758
12504
  control,
12759
- name: "sales_channel_id",
12505
+ name: "shipping_option_id",
12760
12506
  render: ({ field }) => {
12761
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12762
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
12507
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12508
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12509
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12510
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12511
+ ] }),
12512
+ /* @__PURE__ */ jsx(
12513
+ ConditionalTooltip,
12514
+ {
12515
+ content: tooltipContent,
12516
+ showTooltip: !locationId || !shippingProfileId,
12517
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12518
+ Combobox,
12519
+ {
12520
+ options: shippingOptions.options,
12521
+ fetchNextPage: shippingOptions.fetchNextPage,
12522
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12523
+ searchValue: shippingOptions.searchValue,
12524
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12525
+ placeholder: "Select shipping option",
12526
+ ...field,
12527
+ disabled: !locationId || !shippingProfileId
12528
+ }
12529
+ ) }) })
12530
+ }
12531
+ )
12532
+ ] }) });
12533
+ }
12534
+ }
12535
+ );
12536
+ };
12537
+ const CustomAmountField = ({
12538
+ control,
12539
+ currencyCode
12540
+ }) => {
12541
+ return /* @__PURE__ */ jsx(
12542
+ Form$2.Field,
12543
+ {
12544
+ control,
12545
+ name: "custom_amount",
12546
+ render: ({ field: { onChange, ...field } }) => {
12547
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12548
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12549
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12550
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12551
+ ] }),
12763
12552
  /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12764
- Combobox,
12553
+ CurrencyInput,
12765
12554
  {
12766
- options: salesChannels.options,
12767
- fetchNextPage: salesChannels.fetchNextPage,
12768
- isFetchingNextPage: salesChannels.isFetchingNextPage,
12769
- searchValue: salesChannels.searchValue,
12770
- onSearchValueChange: salesChannels.onSearchValueChange,
12771
- placeholder: "Select sales channel",
12772
- ...field
12555
+ ...field,
12556
+ onValueChange: (value) => onChange(value),
12557
+ symbol: getNativeSymbol(currencyCode),
12558
+ code: currencyCode
12773
12559
  }
12774
- ) }),
12775
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12560
+ ) })
12776
12561
  ] });
12777
12562
  }
12778
12563
  }
12779
12564
  );
12780
12565
  };
12781
- const schema$2 = objectType({
12782
- sales_channel_id: stringType().min(1)
12783
- });
12784
- const Email = () => {
12566
+ const TransferOwnership = () => {
12785
12567
  const { id } = useParams();
12786
- const { order, isPending, isError, error } = useOrder(id, {
12787
- fields: "+email"
12568
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12569
+ fields: "id,customer_id,customer.*"
12788
12570
  });
12789
12571
  if (isError) {
12790
12572
  throw error;
12791
12573
  }
12792
- const isReady = !isPending && !!order;
12574
+ const isReady = !isPending && !!draft_order;
12793
12575
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12794
12576
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12795
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
12796
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
12577
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12578
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12797
12579
  ] }),
12798
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
12580
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12799
12581
  ] });
12800
12582
  };
12801
- const EmailForm = ({ order }) => {
12583
+ const TransferOwnershipForm = ({ order }) => {
12584
+ var _a, _b;
12802
12585
  const form = useForm({
12803
12586
  defaultValues: {
12804
- email: order.email ?? ""
12587
+ customer_id: order.customer_id || ""
12805
12588
  },
12806
- resolver: zodResolver(schema$1)
12589
+ resolver: zodResolver(schema)
12807
12590
  });
12808
12591
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12809
12592
  const { handleSuccess } = useRouteModal();
12593
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12594
+ const currentCustomer = order.customer ? {
12595
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12596
+ value: order.customer.id
12597
+ } : null;
12810
12598
  const onSubmit = form.handleSubmit(async (data) => {
12811
12599
  await mutateAsync(
12812
- { email: data.email },
12600
+ { customer_id: data.customer_id },
12813
12601
  {
12814
12602
  onSuccess: () => {
12603
+ toast.success("Customer updated");
12815
12604
  handleSuccess();
12816
12605
  },
12817
12606
  onError: (error) => {
@@ -12826,219 +12615,430 @@ const EmailForm = ({ order }) => {
12826
12615
  className: "flex flex-1 flex-col overflow-hidden",
12827
12616
  onSubmit,
12828
12617
  children: [
12829
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
12830
- Form$2.Field,
12831
- {
12832
- control: form.control,
12833
- name: "email",
12834
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12835
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
12836
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12837
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12618
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12619
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12620
+ currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12621
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12622
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12623
+ /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12624
+ ] }),
12625
+ /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12626
+ /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12627
+ /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12838
12628
  ] })
12839
- }
12840
- ) }),
12841
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12842
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12629
+ ] }),
12630
+ /* @__PURE__ */ jsx(
12631
+ CustomerField,
12632
+ {
12633
+ control: form.control,
12634
+ currentCustomerId: order.customer_id
12635
+ }
12636
+ )
12637
+ ] }),
12638
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12639
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12843
12640
  /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12844
12641
  ] }) })
12845
12642
  ]
12846
12643
  }
12847
12644
  ) });
12848
12645
  };
12849
- const schema$1 = objectType({
12850
- email: stringType().email()
12851
- });
12852
- const BillingAddress = () => {
12853
- const { id } = useParams();
12854
- const { order, isPending, isError, error } = useOrder(id, {
12855
- fields: "+billing_address"
12856
- });
12857
- if (isError) {
12858
- throw error;
12859
- }
12860
- const isReady = !isPending && !!order;
12861
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12862
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12863
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
12864
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12865
- ] }),
12866
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12867
- ] });
12868
- };
12869
- const BillingAddressForm = ({ order }) => {
12870
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12871
- const form = useForm({
12872
- defaultValues: {
12873
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12874
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12875
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12876
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12877
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12878
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12879
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12880
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12881
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12882
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12646
+ const CustomerField = ({ control, currentCustomerId }) => {
12647
+ const customers = useComboboxData({
12648
+ queryFn: async (params) => {
12649
+ return await sdk.admin.customer.list({
12650
+ ...params,
12651
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12652
+ });
12883
12653
  },
12884
- resolver: zodResolver(schema)
12885
- });
12886
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12887
- const { handleSuccess } = useRouteModal();
12888
- const onSubmit = form.handleSubmit(async (data) => {
12889
- await mutateAsync(
12890
- { billing_address: data },
12891
- {
12892
- onSuccess: () => {
12893
- handleSuccess();
12894
- },
12895
- onError: (error) => {
12896
- toast.error(error.message);
12897
- }
12898
- }
12899
- );
12654
+ queryKey: ["customers"],
12655
+ getOptions: (data) => {
12656
+ return data.customers.map((customer) => {
12657
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12658
+ return {
12659
+ label: name ? `${name} (${customer.email})` : customer.email,
12660
+ value: customer.id
12661
+ };
12662
+ });
12663
+ }
12900
12664
  });
12901
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12902
- KeyboundForm,
12665
+ return /* @__PURE__ */ jsx(
12666
+ Form$2.Field,
12903
12667
  {
12904
- className: "flex flex-1 flex-col overflow-hidden",
12905
- onSubmit,
12668
+ name: "customer_id",
12669
+ control,
12670
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
12671
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12672
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
12673
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12674
+ ] }),
12675
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12676
+ Combobox,
12677
+ {
12678
+ options: customers.options,
12679
+ fetchNextPage: customers.fetchNextPage,
12680
+ isFetchingNextPage: customers.isFetchingNextPage,
12681
+ searchValue: customers.searchValue,
12682
+ onSearchValueChange: customers.onSearchValueChange,
12683
+ placeholder: "Select customer",
12684
+ ...field
12685
+ }
12686
+ ) }),
12687
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12688
+ ] })
12689
+ }
12690
+ );
12691
+ };
12692
+ const Illustration = () => {
12693
+ return /* @__PURE__ */ jsxs(
12694
+ "svg",
12695
+ {
12696
+ width: "280",
12697
+ height: "180",
12698
+ viewBox: "0 0 280 180",
12699
+ fill: "none",
12700
+ xmlns: "http://www.w3.org/2000/svg",
12906
12701
  children: [
12907
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12908
- /* @__PURE__ */ jsx(
12909
- Form$2.Field,
12702
+ /* @__PURE__ */ jsx(
12703
+ "rect",
12704
+ {
12705
+ x: "0.00428286",
12706
+ y: "-0.742904",
12707
+ width: "33.5",
12708
+ height: "65.5",
12709
+ rx: "6.75",
12710
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12711
+ fill: "#D4D4D8",
12712
+ stroke: "#52525B",
12713
+ strokeWidth: "1.5"
12714
+ }
12715
+ ),
12716
+ /* @__PURE__ */ jsx(
12717
+ "rect",
12718
+ {
12719
+ x: "0.00428286",
12720
+ y: "-0.742904",
12721
+ width: "33.5",
12722
+ height: "65.5",
12723
+ rx: "6.75",
12724
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12725
+ fill: "white",
12726
+ stroke: "#52525B",
12727
+ strokeWidth: "1.5"
12728
+ }
12729
+ ),
12730
+ /* @__PURE__ */ jsx(
12731
+ "path",
12732
+ {
12733
+ d: "M180.579 107.142L179.126 107.959",
12734
+ stroke: "#52525B",
12735
+ strokeWidth: "1.5",
12736
+ strokeLinecap: "round",
12737
+ strokeLinejoin: "round"
12738
+ }
12739
+ ),
12740
+ /* @__PURE__ */ jsx(
12741
+ "path",
12742
+ {
12743
+ opacity: "0.88",
12744
+ d: "M182.305 109.546L180.257 109.534",
12745
+ stroke: "#52525B",
12746
+ strokeWidth: "1.5",
12747
+ strokeLinecap: "round",
12748
+ strokeLinejoin: "round"
12749
+ }
12750
+ ),
12751
+ /* @__PURE__ */ jsx(
12752
+ "path",
12753
+ {
12754
+ opacity: "0.75",
12755
+ d: "M180.551 111.93L179.108 111.096",
12756
+ stroke: "#52525B",
12757
+ strokeWidth: "1.5",
12758
+ strokeLinecap: "round",
12759
+ strokeLinejoin: "round"
12760
+ }
12761
+ ),
12762
+ /* @__PURE__ */ jsx(
12763
+ "path",
12764
+ {
12765
+ opacity: "0.63",
12766
+ d: "M176.347 112.897L176.354 111.73",
12767
+ stroke: "#52525B",
12768
+ strokeWidth: "1.5",
12769
+ strokeLinecap: "round",
12770
+ strokeLinejoin: "round"
12771
+ }
12772
+ ),
12773
+ /* @__PURE__ */ jsx(
12774
+ "path",
12775
+ {
12776
+ opacity: "0.5",
12777
+ d: "M172.153 111.881L173.606 111.064",
12778
+ stroke: "#52525B",
12779
+ strokeWidth: "1.5",
12780
+ strokeLinecap: "round",
12781
+ strokeLinejoin: "round"
12782
+ }
12783
+ ),
12784
+ /* @__PURE__ */ jsx(
12785
+ "path",
12786
+ {
12787
+ opacity: "0.38",
12788
+ d: "M170.428 109.478L172.476 109.489",
12789
+ stroke: "#52525B",
12790
+ strokeWidth: "1.5",
12791
+ strokeLinecap: "round",
12792
+ strokeLinejoin: "round"
12793
+ }
12794
+ ),
12795
+ /* @__PURE__ */ jsx(
12796
+ "path",
12797
+ {
12798
+ opacity: "0.25",
12799
+ d: "M172.181 107.094L173.624 107.928",
12800
+ stroke: "#52525B",
12801
+ strokeWidth: "1.5",
12802
+ strokeLinecap: "round",
12803
+ strokeLinejoin: "round"
12804
+ }
12805
+ ),
12806
+ /* @__PURE__ */ jsx(
12807
+ "path",
12808
+ {
12809
+ opacity: "0.13",
12810
+ d: "M176.386 106.126L176.379 107.294",
12811
+ stroke: "#52525B",
12812
+ strokeWidth: "1.5",
12813
+ strokeLinecap: "round",
12814
+ strokeLinejoin: "round"
12815
+ }
12816
+ ),
12817
+ /* @__PURE__ */ jsx(
12818
+ "rect",
12819
+ {
12820
+ width: "12",
12821
+ height: "3",
12822
+ rx: "1.5",
12823
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12824
+ fill: "#D4D4D8"
12825
+ }
12826
+ ),
12827
+ /* @__PURE__ */ jsx(
12828
+ "rect",
12829
+ {
12830
+ x: "0.00428286",
12831
+ y: "-0.742904",
12832
+ width: "33.5",
12833
+ height: "65.5",
12834
+ rx: "6.75",
12835
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12836
+ fill: "#D4D4D8",
12837
+ stroke: "#52525B",
12838
+ strokeWidth: "1.5"
12839
+ }
12840
+ ),
12841
+ /* @__PURE__ */ jsx(
12842
+ "rect",
12843
+ {
12844
+ x: "0.00428286",
12845
+ y: "-0.742904",
12846
+ width: "33.5",
12847
+ height: "65.5",
12848
+ rx: "6.75",
12849
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12850
+ fill: "white",
12851
+ stroke: "#52525B",
12852
+ strokeWidth: "1.5"
12853
+ }
12854
+ ),
12855
+ /* @__PURE__ */ jsx(
12856
+ "rect",
12857
+ {
12858
+ width: "12",
12859
+ height: "3",
12860
+ rx: "1.5",
12861
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12862
+ fill: "#D4D4D8"
12863
+ }
12864
+ ),
12865
+ /* @__PURE__ */ jsx(
12866
+ "rect",
12867
+ {
12868
+ width: "17",
12869
+ height: "3",
12870
+ rx: "1.5",
12871
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12872
+ fill: "#D4D4D8"
12873
+ }
12874
+ ),
12875
+ /* @__PURE__ */ jsx(
12876
+ "rect",
12877
+ {
12878
+ width: "12",
12879
+ height: "3",
12880
+ rx: "1.5",
12881
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12882
+ fill: "#D4D4D8"
12883
+ }
12884
+ ),
12885
+ /* @__PURE__ */ jsx(
12886
+ "path",
12887
+ {
12888
+ 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",
12889
+ fill: "#A1A1AA"
12890
+ }
12891
+ ),
12892
+ /* @__PURE__ */ jsx(
12893
+ "rect",
12894
+ {
12895
+ width: "17",
12896
+ height: "3",
12897
+ rx: "1.5",
12898
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12899
+ fill: "#A1A1AA"
12900
+ }
12901
+ ),
12902
+ /* @__PURE__ */ jsx(
12903
+ "rect",
12904
+ {
12905
+ width: "12",
12906
+ height: "3",
12907
+ rx: "1.5",
12908
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12909
+ fill: "#A1A1AA"
12910
+ }
12911
+ ),
12912
+ /* @__PURE__ */ jsx(
12913
+ "path",
12914
+ {
12915
+ 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",
12916
+ fill: "#52525B"
12917
+ }
12918
+ ),
12919
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
12920
+ "path",
12921
+ {
12922
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12923
+ stroke: "#A1A1AA",
12924
+ strokeWidth: "1.5",
12925
+ strokeLinecap: "round",
12926
+ strokeLinejoin: "round"
12927
+ }
12928
+ ) }),
12929
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
12930
+ "path",
12931
+ {
12932
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12933
+ stroke: "#A1A1AA",
12934
+ strokeWidth: "1.5",
12935
+ strokeLinecap: "round",
12936
+ strokeLinejoin: "round"
12937
+ }
12938
+ ) }),
12939
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
12940
+ "path",
12941
+ {
12942
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12943
+ stroke: "#A1A1AA",
12944
+ strokeWidth: "1.5",
12945
+ strokeLinecap: "round",
12946
+ strokeLinejoin: "round"
12947
+ }
12948
+ ) }),
12949
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
12950
+ "path",
12951
+ {
12952
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12953
+ stroke: "#A1A1AA",
12954
+ strokeWidth: "1.5",
12955
+ strokeLinecap: "round",
12956
+ strokeLinejoin: "round"
12957
+ }
12958
+ ) }),
12959
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12960
+ "path",
12961
+ {
12962
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12963
+ stroke: "#A1A1AA",
12964
+ strokeWidth: "1.5",
12965
+ strokeLinecap: "round",
12966
+ strokeLinejoin: "round"
12967
+ }
12968
+ ) }),
12969
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12970
+ "path",
12971
+ {
12972
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12973
+ stroke: "#A1A1AA",
12974
+ strokeWidth: "1.5",
12975
+ strokeLinecap: "round",
12976
+ strokeLinejoin: "round"
12977
+ }
12978
+ ) }),
12979
+ /* @__PURE__ */ jsxs("defs", { children: [
12980
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12981
+ "rect",
12910
12982
  {
12911
- control: form.control,
12912
- name: "country_code",
12913
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12914
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12915
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12916
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12917
- ] })
12983
+ width: "12",
12984
+ height: "12",
12985
+ fill: "white",
12986
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12918
12987
  }
12919
- ),
12920
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12921
- /* @__PURE__ */ jsx(
12922
- Form$2.Field,
12923
- {
12924
- control: form.control,
12925
- name: "first_name",
12926
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12927
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12928
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12929
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12930
- ] })
12931
- }
12932
- ),
12933
- /* @__PURE__ */ jsx(
12934
- Form$2.Field,
12935
- {
12936
- control: form.control,
12937
- name: "last_name",
12938
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12939
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12940
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12941
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12942
- ] })
12943
- }
12944
- )
12945
- ] }),
12946
- /* @__PURE__ */ jsx(
12947
- Form$2.Field,
12988
+ ) }),
12989
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12990
+ "rect",
12948
12991
  {
12949
- control: form.control,
12950
- name: "company",
12951
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12952
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12953
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12954
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12955
- ] })
12992
+ width: "12",
12993
+ height: "12",
12994
+ fill: "white",
12995
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12956
12996
  }
12957
- ),
12958
- /* @__PURE__ */ jsx(
12959
- Form$2.Field,
12997
+ ) }),
12998
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12999
+ "rect",
12960
13000
  {
12961
- control: form.control,
12962
- name: "address_1",
12963
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12964
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12965
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12966
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12967
- ] })
13001
+ width: "12",
13002
+ height: "12",
13003
+ fill: "white",
13004
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12968
13005
  }
12969
- ),
12970
- /* @__PURE__ */ jsx(
12971
- Form$2.Field,
13006
+ ) }),
13007
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
13008
+ "rect",
12972
13009
  {
12973
- control: form.control,
12974
- name: "address_2",
12975
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12976
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12977
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12978
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12979
- ] })
13010
+ width: "12",
13011
+ height: "12",
13012
+ fill: "white",
13013
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12980
13014
  }
12981
- ),
12982
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12983
- /* @__PURE__ */ jsx(
12984
- Form$2.Field,
12985
- {
12986
- control: form.control,
12987
- name: "postal_code",
12988
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12989
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12990
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12991
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12992
- ] })
12993
- }
12994
- ),
12995
- /* @__PURE__ */ jsx(
12996
- Form$2.Field,
12997
- {
12998
- control: form.control,
12999
- name: "city",
13000
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13001
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
13002
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13003
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13004
- ] })
13005
- }
13006
- )
13007
- ] }),
13008
- /* @__PURE__ */ jsx(
13009
- Form$2.Field,
13015
+ ) }),
13016
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
13017
+ "rect",
13010
13018
  {
13011
- control: form.control,
13012
- name: "province",
13013
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13014
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13015
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13016
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13017
- ] })
13019
+ width: "12",
13020
+ height: "12",
13021
+ fill: "white",
13022
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13018
13023
  }
13019
- ),
13020
- /* @__PURE__ */ jsx(
13021
- Form$2.Field,
13024
+ ) }),
13025
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
13026
+ "rect",
13022
13027
  {
13023
- control: form.control,
13024
- name: "phone",
13025
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13026
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13027
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13028
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13029
- ] })
13028
+ width: "12",
13029
+ height: "12",
13030
+ fill: "white",
13031
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13030
13032
  }
13031
- )
13032
- ] }) }),
13033
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13034
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13035
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13036
- ] }) })
13033
+ ) })
13034
+ ] })
13037
13035
  ]
13038
13036
  }
13039
- ) });
13037
+ );
13040
13038
  };
13041
- const schema = addressSchema;
13039
+ const schema = objectType({
13040
+ customer_id: stringType().min(1)
13041
+ });
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
13044
13044
  routes: [
@@ -13059,10 +13059,18 @@ const routeModule = {
13059
13059
  handle,
13060
13060
  loader,
13061
13061
  children: [
13062
+ {
13063
+ Component: BillingAddress,
13064
+ path: "/draft-orders/:id/billing-address"
13065
+ },
13062
13066
  {
13063
13067
  Component: CustomItems,
13064
13068
  path: "/draft-orders/:id/custom-items"
13065
13069
  },
13070
+ {
13071
+ Component: Email,
13072
+ path: "/draft-orders/:id/email"
13073
+ },
13066
13074
  {
13067
13075
  Component: Items,
13068
13076
  path: "/draft-orders/:id/items"
@@ -13076,28 +13084,20 @@ const routeModule = {
13076
13084
  path: "/draft-orders/:id/promotions"
13077
13085
  },
13078
13086
  {
13079
- Component: Shipping,
13080
- path: "/draft-orders/:id/shipping"
13087
+ Component: SalesChannel,
13088
+ path: "/draft-orders/:id/sales-channel"
13081
13089
  },
13082
13090
  {
13083
13091
  Component: ShippingAddress,
13084
13092
  path: "/draft-orders/:id/shipping-address"
13085
13093
  },
13086
13094
  {
13087
- Component: TransferOwnership,
13088
- path: "/draft-orders/:id/transfer-ownership"
13089
- },
13090
- {
13091
- Component: SalesChannel,
13092
- path: "/draft-orders/:id/sales-channel"
13093
- },
13094
- {
13095
- Component: Email,
13096
- path: "/draft-orders/:id/email"
13095
+ Component: Shipping,
13096
+ path: "/draft-orders/:id/shipping"
13097
13097
  },
13098
13098
  {
13099
- Component: BillingAddress,
13100
- path: "/draft-orders/:id/billing-address"
13099
+ Component: TransferOwnership,
13100
+ path: "/draft-orders/:id/transfer-ownership"
13101
13101
  }
13102
13102
  ]
13103
13103
  }