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

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
  },
@@ -10562,543 +10820,193 @@ const customItemSchema = objectType({
10562
10820
  quantity: numberType(),
10563
10821
  unit_price: unionType([numberType(), stringType()])
10564
10822
  });
10565
- const InlineTip = forwardRef(
10566
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10567
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10568
- return /* @__PURE__ */ jsxs(
10569
- "div",
10570
- {
10571
- ref,
10572
- className: clx(
10573
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10574
- className
10575
- ),
10576
- ...props,
10577
- children: [
10578
- /* @__PURE__ */ jsx(
10579
- "div",
10580
- {
10581
- role: "presentation",
10582
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10583
- "bg-ui-tag-orange-icon": variant === "warning"
10584
- })
10585
- }
10586
- ),
10587
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10588
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10589
- labelValue,
10590
- ":"
10591
- ] }),
10592
- " ",
10593
- children
10594
- ] })
10595
- ]
10596
- }
10597
- );
10598
- }
10599
- );
10600
- InlineTip.displayName = "InlineTip";
10601
- const MetadataFieldSchema = objectType({
10602
- key: stringType(),
10603
- disabled: booleanType().optional(),
10604
- value: anyType()
10605
- });
10606
- const MetadataSchema = objectType({
10607
- metadata: arrayType(MetadataFieldSchema)
10608
- });
10609
- const Metadata = () => {
10610
- const { id } = useParams();
10611
- const { order, isPending, isError, error } = useOrder(id, {
10612
- fields: "metadata"
10823
+ const PROMOTION_QUERY_KEY = "promotions";
10824
+ const promotionsQueryKeys = {
10825
+ list: (query2) => [
10826
+ PROMOTION_QUERY_KEY,
10827
+ query2 ? query2 : void 0
10828
+ ],
10829
+ detail: (id, query2) => [
10830
+ PROMOTION_QUERY_KEY,
10831
+ id,
10832
+ query2 ? query2 : void 0
10833
+ ]
10834
+ };
10835
+ const usePromotions = (query2, options) => {
10836
+ const { data, ...rest } = useQuery({
10837
+ queryKey: promotionsQueryKeys.list(query2),
10838
+ queryFn: async () => sdk.admin.promotion.list(query2),
10839
+ ...options
10613
10840
  });
10614
- if (isError) {
10615
- throw error;
10841
+ return { ...data, ...rest };
10842
+ };
10843
+ const Promotions = () => {
10844
+ const { id } = useParams();
10845
+ const {
10846
+ order: preview,
10847
+ isError: isPreviewError,
10848
+ error: previewError
10849
+ } = useOrderPreview(id, void 0);
10850
+ useInitiateOrderEdit({ preview });
10851
+ const { onCancel } = useCancelOrderEdit({ preview });
10852
+ if (isPreviewError) {
10853
+ throw previewError;
10616
10854
  }
10617
- const isReady = !isPending && !!order;
10618
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10619
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10620
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10621
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10622
- ] }),
10623
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10855
+ const isReady = !!preview;
10856
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
10857
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
10858
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
10624
10859
  ] });
10625
10860
  };
10626
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10627
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10628
- const MetadataForm = ({ orderId, metadata }) => {
10861
+ const PromotionForm = ({ preview }) => {
10862
+ const { items, shipping_methods } = preview;
10863
+ const [isSubmitting, setIsSubmitting] = useState(false);
10864
+ const [comboboxValue, setComboboxValue] = useState("");
10629
10865
  const { handleSuccess } = useRouteModal();
10630
- const hasUneditableRows = getHasUneditableRows(metadata);
10631
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10632
- const form = useForm({
10633
- defaultValues: {
10634
- metadata: getDefaultValues(metadata)
10866
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10867
+ const promoIds = getPromotionIds(items, shipping_methods);
10868
+ const { promotions, isPending, isError, error } = usePromotions(
10869
+ {
10870
+ id: promoIds
10635
10871
  },
10636
- resolver: zodResolver(MetadataSchema)
10872
+ {
10873
+ enabled: !!promoIds.length
10874
+ }
10875
+ );
10876
+ const comboboxData = useComboboxData({
10877
+ queryKey: ["promotions", "combobox", promoIds],
10878
+ queryFn: async (params) => {
10879
+ return await sdk.admin.promotion.list({
10880
+ ...params,
10881
+ id: {
10882
+ $nin: promoIds
10883
+ }
10884
+ });
10885
+ },
10886
+ getOptions: (data) => {
10887
+ return data.promotions.map((promotion) => ({
10888
+ label: promotion.code,
10889
+ value: promotion.code
10890
+ }));
10891
+ }
10637
10892
  });
10638
- const handleSubmit = form.handleSubmit(async (data) => {
10639
- const parsedData = parseValues(data);
10640
- await mutateAsync(
10893
+ const add = async (value) => {
10894
+ if (!value) {
10895
+ return;
10896
+ }
10897
+ addPromotions(
10641
10898
  {
10642
- metadata: parsedData
10899
+ promo_codes: [value]
10643
10900
  },
10644
10901
  {
10645
- onSuccess: () => {
10646
- toast.success("Metadata updated");
10647
- handleSuccess();
10902
+ onError: (e) => {
10903
+ toast.error(e.message);
10904
+ comboboxData.onSearchValueChange("");
10905
+ setComboboxValue("");
10648
10906
  },
10649
- onError: (error) => {
10650
- toast.error(error.message);
10907
+ onSuccess: () => {
10908
+ comboboxData.onSearchValueChange("");
10909
+ setComboboxValue("");
10651
10910
  }
10652
10911
  }
10653
10912
  );
10654
- });
10655
- const { fields, insert, remove } = useFieldArray({
10656
- control: form.control,
10657
- name: "metadata"
10658
- });
10659
- function deleteRow(index) {
10660
- remove(index);
10661
- if (fields.length === 1) {
10662
- insert(0, {
10663
- key: "",
10664
- value: "",
10665
- disabled: false
10666
- });
10913
+ };
10914
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10915
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
10916
+ const onSubmit = async () => {
10917
+ setIsSubmitting(true);
10918
+ let requestSucceeded = false;
10919
+ await requestOrderEdit(void 0, {
10920
+ onError: (e) => {
10921
+ toast.error(e.message);
10922
+ },
10923
+ onSuccess: () => {
10924
+ requestSucceeded = true;
10925
+ }
10926
+ });
10927
+ if (!requestSucceeded) {
10928
+ setIsSubmitting(false);
10929
+ return;
10667
10930
  }
10668
- }
10669
- function insertRow(index, position) {
10670
- insert(index + (position === "above" ? 0 : 1), {
10671
- key: "",
10672
- value: "",
10673
- disabled: false
10931
+ await confirmOrderEdit(void 0, {
10932
+ onError: (e) => {
10933
+ toast.error(e.message);
10934
+ },
10935
+ onSuccess: () => {
10936
+ handleSuccess();
10937
+ },
10938
+ onSettled: () => {
10939
+ setIsSubmitting(false);
10940
+ }
10674
10941
  });
10942
+ };
10943
+ if (isError) {
10944
+ throw error;
10675
10945
  }
10676
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10677
- KeyboundForm,
10678
- {
10679
- onSubmit: handleSubmit,
10680
- className: "flex flex-1 flex-col overflow-hidden",
10681
- children: [
10682
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10683
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10684
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10685
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10686
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
10687
- ] }),
10688
- fields.map((field, index) => {
10689
- const isDisabled = field.disabled || false;
10690
- let placeholder = "-";
10691
- if (typeof field.value === "object") {
10692
- placeholder = "{ ... }";
10693
- }
10694
- if (Array.isArray(field.value)) {
10695
- placeholder = "[ ... ]";
10696
- }
10697
- return /* @__PURE__ */ jsx(
10698
- ConditionalTooltip,
10699
- {
10700
- showTooltip: isDisabled,
10701
- content: "This row is disabled because it contains non-primitive data.",
10702
- children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
10703
- /* @__PURE__ */ jsxs(
10704
- "div",
10705
- {
10706
- className: clx("grid grid-cols-2 divide-x", {
10707
- "overflow-hidden rounded-b-lg": index === fields.length - 1
10708
- }),
10709
- children: [
10710
- /* @__PURE__ */ jsx(
10711
- Form$2.Field,
10712
- {
10713
- control: form.control,
10714
- name: `metadata.${index}.key`,
10715
- render: ({ field: field2 }) => {
10716
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10717
- GridInput,
10718
- {
10719
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10720
- ...field2,
10721
- disabled: isDisabled,
10722
- placeholder: "Key"
10723
- }
10724
- ) }) });
10725
- }
10726
- }
10727
- ),
10728
- /* @__PURE__ */ jsx(
10729
- Form$2.Field,
10730
- {
10731
- control: form.control,
10732
- name: `metadata.${index}.value`,
10733
- render: ({ field: { value, ...field2 } }) => {
10734
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10735
- GridInput,
10736
- {
10737
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
10738
- ...field2,
10739
- value: isDisabled ? placeholder : value,
10740
- disabled: isDisabled,
10741
- placeholder: "Value"
10742
- }
10743
- ) }) });
10744
- }
10745
- }
10746
- )
10747
- ]
10748
- }
10749
- ),
10750
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10751
- /* @__PURE__ */ jsx(
10752
- DropdownMenu.Trigger,
10753
- {
10754
- className: clx(
10755
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10756
- {
10757
- hidden: isDisabled
10758
- }
10759
- ),
10760
- disabled: isDisabled,
10761
- asChild: true,
10762
- children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
10763
- }
10764
- ),
10765
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
10766
- /* @__PURE__ */ jsxs(
10767
- DropdownMenu.Item,
10768
- {
10769
- className: "gap-x-2",
10770
- onClick: () => insertRow(index, "above"),
10771
- children: [
10772
- /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
10773
- "Insert row above"
10774
- ]
10775
- }
10776
- ),
10777
- /* @__PURE__ */ jsxs(
10778
- DropdownMenu.Item,
10779
- {
10780
- className: "gap-x-2",
10781
- onClick: () => insertRow(index, "below"),
10782
- children: [
10783
- /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
10784
- "Insert row below"
10785
- ]
10786
- }
10787
- ),
10788
- /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
10789
- /* @__PURE__ */ jsxs(
10790
- DropdownMenu.Item,
10791
- {
10792
- className: "gap-x-2",
10793
- onClick: () => deleteRow(index),
10794
- children: [
10795
- /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
10796
- "Delete row"
10797
- ]
10798
- }
10799
- )
10800
- ] })
10801
- ] })
10802
- ] })
10803
- },
10804
- field.id
10805
- );
10806
- })
10807
- ] }),
10808
- hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
10946
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
10947
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
10948
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
10949
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10950
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
10951
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
10809
10952
  ] }),
10810
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10811
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10812
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10813
- ] }) })
10814
- ]
10815
- }
10816
- ) });
10817
- };
10818
- const GridInput = forwardRef(({ className, ...props }, ref) => {
10819
- return /* @__PURE__ */ jsx(
10820
- "input",
10821
- {
10822
- ref,
10823
- ...props,
10824
- autoComplete: "off",
10825
- className: clx(
10826
- "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
10827
- className
10953
+ /* @__PURE__ */ jsx(
10954
+ Combobox,
10955
+ {
10956
+ id: "promotion-combobox",
10957
+ "aria-describedby": "promotion-combobox-hint",
10958
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
10959
+ fetchNextPage: comboboxData.fetchNextPage,
10960
+ options: comboboxData.options,
10961
+ onSearchValueChange: comboboxData.onSearchValueChange,
10962
+ searchValue: comboboxData.searchValue,
10963
+ disabled: comboboxData.disabled || isAddingPromotions,
10964
+ onChange: add,
10965
+ value: comboboxValue
10966
+ }
10967
+ )
10968
+ ] }),
10969
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10970
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
10971
+ PromotionItem,
10972
+ {
10973
+ promotion,
10974
+ orderId: preview.id,
10975
+ isLoading: isPending
10976
+ },
10977
+ promotion.id
10978
+ )) })
10979
+ ] }) }),
10980
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10981
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10982
+ /* @__PURE__ */ jsx(
10983
+ Button,
10984
+ {
10985
+ size: "small",
10986
+ type: "submit",
10987
+ isLoading: isSubmitting || isAddingPromotions,
10988
+ children: "Save"
10989
+ }
10828
10990
  )
10829
- }
10830
- );
10831
- });
10832
- GridInput.displayName = "MetadataForm.GridInput";
10833
- const PlaceholderInner = () => {
10834
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10835
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10836
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10837
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
10838
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
10839
10991
  ] }) })
10840
10992
  ] });
10841
10993
  };
10842
- const EDITABLE_TYPES = ["string", "number", "boolean"];
10843
- function getDefaultValues(metadata) {
10844
- if (!metadata || !Object.keys(metadata).length) {
10845
- return [
10994
+ const PromotionItem = ({
10995
+ promotion,
10996
+ orderId,
10997
+ isLoading
10998
+ }) => {
10999
+ var _a;
11000
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11001
+ const onRemove = async () => {
11002
+ removePromotions(
10846
11003
  {
10847
- key: "",
10848
- value: "",
10849
- disabled: false
10850
- }
10851
- ];
10852
- }
10853
- return Object.entries(metadata).map(([key, value]) => {
10854
- if (!EDITABLE_TYPES.includes(typeof value)) {
10855
- return {
10856
- key,
10857
- value,
10858
- disabled: true
10859
- };
10860
- }
10861
- let stringValue = value;
10862
- if (typeof value !== "string") {
10863
- stringValue = JSON.stringify(value);
10864
- }
10865
- return {
10866
- key,
10867
- value: stringValue,
10868
- original_key: key
10869
- };
10870
- });
10871
- }
10872
- function parseValues(values) {
10873
- const metadata = values.metadata;
10874
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10875
- if (isEmpty) {
10876
- return null;
10877
- }
10878
- const update = {};
10879
- metadata.forEach((field) => {
10880
- let key = field.key;
10881
- let value = field.value;
10882
- const disabled = field.disabled;
10883
- if (!key || !value) {
10884
- return;
10885
- }
10886
- if (disabled) {
10887
- update[key] = value;
10888
- return;
10889
- }
10890
- key = key.trim();
10891
- value = value.trim();
10892
- if (value === "true") {
10893
- update[key] = true;
10894
- } else if (value === "false") {
10895
- update[key] = false;
10896
- } else {
10897
- const parsedNumber = parseFloat(value);
10898
- if (!isNaN(parsedNumber)) {
10899
- update[key] = parsedNumber;
10900
- } else {
10901
- update[key] = value;
10902
- }
10903
- }
10904
- });
10905
- return update;
10906
- }
10907
- function getHasUneditableRows(metadata) {
10908
- if (!metadata) {
10909
- return false;
10910
- }
10911
- return Object.values(metadata).some(
10912
- (value) => !EDITABLE_TYPES.includes(typeof value)
10913
- );
10914
- }
10915
- const PROMOTION_QUERY_KEY = "promotions";
10916
- const promotionsQueryKeys = {
10917
- list: (query2) => [
10918
- PROMOTION_QUERY_KEY,
10919
- query2 ? query2 : void 0
10920
- ],
10921
- detail: (id, query2) => [
10922
- PROMOTION_QUERY_KEY,
10923
- id,
10924
- query2 ? query2 : void 0
10925
- ]
10926
- };
10927
- const usePromotions = (query2, options) => {
10928
- const { data, ...rest } = useQuery({
10929
- queryKey: promotionsQueryKeys.list(query2),
10930
- queryFn: async () => sdk.admin.promotion.list(query2),
10931
- ...options
10932
- });
10933
- return { ...data, ...rest };
10934
- };
10935
- const Promotions = () => {
10936
- const { id } = useParams();
10937
- const {
10938
- order: preview,
10939
- isError: isPreviewError,
10940
- error: previewError
10941
- } = useOrderPreview(id, void 0);
10942
- useInitiateOrderEdit({ preview });
10943
- const { onCancel } = useCancelOrderEdit({ preview });
10944
- if (isPreviewError) {
10945
- throw previewError;
10946
- }
10947
- const isReady = !!preview;
10948
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
10949
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
10950
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
10951
- ] });
10952
- };
10953
- const PromotionForm = ({ preview }) => {
10954
- const { items, shipping_methods } = preview;
10955
- const [isSubmitting, setIsSubmitting] = useState(false);
10956
- const [comboboxValue, setComboboxValue] = useState("");
10957
- const { handleSuccess } = useRouteModal();
10958
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10959
- const promoIds = getPromotionIds(items, shipping_methods);
10960
- const { promotions, isPending, isError, error } = usePromotions(
10961
- {
10962
- id: promoIds
10963
- },
10964
- {
10965
- enabled: !!promoIds.length
10966
- }
10967
- );
10968
- const comboboxData = useComboboxData({
10969
- queryKey: ["promotions", "combobox", promoIds],
10970
- queryFn: async (params) => {
10971
- return await sdk.admin.promotion.list({
10972
- ...params,
10973
- id: {
10974
- $nin: promoIds
10975
- }
10976
- });
10977
- },
10978
- getOptions: (data) => {
10979
- return data.promotions.map((promotion) => ({
10980
- label: promotion.code,
10981
- value: promotion.code
10982
- }));
10983
- }
10984
- });
10985
- const add = async (value) => {
10986
- if (!value) {
10987
- return;
10988
- }
10989
- addPromotions(
10990
- {
10991
- promo_codes: [value]
10992
- },
10993
- {
10994
- onError: (e) => {
10995
- toast.error(e.message);
10996
- comboboxData.onSearchValueChange("");
10997
- setComboboxValue("");
10998
- },
10999
- onSuccess: () => {
11000
- comboboxData.onSearchValueChange("");
11001
- setComboboxValue("");
11002
- }
11003
- }
11004
- );
11005
- };
11006
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11007
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11008
- const onSubmit = async () => {
11009
- setIsSubmitting(true);
11010
- let requestSucceeded = false;
11011
- await requestOrderEdit(void 0, {
11012
- onError: (e) => {
11013
- toast.error(e.message);
11014
- },
11015
- onSuccess: () => {
11016
- requestSucceeded = true;
11017
- }
11018
- });
11019
- if (!requestSucceeded) {
11020
- setIsSubmitting(false);
11021
- return;
11022
- }
11023
- await confirmOrderEdit(void 0, {
11024
- onError: (e) => {
11025
- toast.error(e.message);
11026
- },
11027
- onSuccess: () => {
11028
- handleSuccess();
11029
- },
11030
- onSettled: () => {
11031
- setIsSubmitting(false);
11032
- }
11033
- });
11034
- };
11035
- if (isError) {
11036
- throw error;
11037
- }
11038
- return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11039
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11040
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11041
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11042
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11043
- /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11044
- ] }),
11045
- /* @__PURE__ */ jsx(
11046
- Combobox,
11047
- {
11048
- id: "promotion-combobox",
11049
- "aria-describedby": "promotion-combobox-hint",
11050
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11051
- fetchNextPage: comboboxData.fetchNextPage,
11052
- options: comboboxData.options,
11053
- onSearchValueChange: comboboxData.onSearchValueChange,
11054
- searchValue: comboboxData.searchValue,
11055
- disabled: comboboxData.disabled || isAddingPromotions,
11056
- onChange: add,
11057
- value: comboboxValue
11058
- }
11059
- )
11060
- ] }),
11061
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11062
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11063
- PromotionItem,
11064
- {
11065
- promotion,
11066
- orderId: preview.id,
11067
- isLoading: isPending
11068
- },
11069
- promotion.id
11070
- )) })
11071
- ] }) }),
11072
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11073
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11074
- /* @__PURE__ */ jsx(
11075
- Button,
11076
- {
11077
- size: "small",
11078
- type: "submit",
11079
- isLoading: isSubmitting || isAddingPromotions,
11080
- children: "Save"
11081
- }
11082
- )
11083
- ] }) })
11084
- ] });
11085
- };
11086
- const PromotionItem = ({
11087
- promotion,
11088
- orderId,
11089
- isLoading
11090
- }) => {
11091
- var _a;
11092
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11093
- const onRemove = async () => {
11094
- removePromotions(
11095
- {
11096
- promo_codes: [promotion.code]
11097
- },
11098
- {
11099
- onError: (e) => {
11100
- toast.error(e.message);
11101
- }
11004
+ promo_codes: [promotion.code]
11005
+ },
11006
+ {
11007
+ onError: (e) => {
11008
+ toast.error(e.message);
11009
+ }
11102
11010
  }
11103
11011
  );
11104
11012
  };
@@ -11189,1602 +11097,1273 @@ function getPromotionIds(items, shippingMethods) {
11189
11097
  }
11190
11098
  return Array.from(promotionIds);
11191
11099
  }
11192
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11193
- const Shipping = () => {
11194
- var _a;
11195
- 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 });
11100
+ const InlineTip = forwardRef(
11101
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
11102
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
11103
+ return /* @__PURE__ */ jsxs(
11104
+ "div",
11105
+ {
11106
+ ref,
11107
+ className: clx(
11108
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
11109
+ className
11110
+ ),
11111
+ ...props,
11112
+ children: [
11113
+ /* @__PURE__ */ jsx(
11114
+ "div",
11115
+ {
11116
+ role: "presentation",
11117
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
11118
+ "bg-ui-tag-orange-icon": variant === "warning"
11119
+ })
11120
+ }
11121
+ ),
11122
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
11123
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
11124
+ labelValue,
11125
+ ":"
11126
+ ] }),
11127
+ " ",
11128
+ children
11129
+ ] })
11130
+ ]
11131
+ }
11132
+ );
11133
+ }
11134
+ );
11135
+ InlineTip.displayName = "InlineTip";
11136
+ const MetadataFieldSchema = objectType({
11137
+ key: stringType(),
11138
+ disabled: booleanType().optional(),
11139
+ value: anyType()
11140
+ });
11141
+ const MetadataSchema = objectType({
11142
+ metadata: arrayType(MetadataFieldSchema)
11143
+ });
11144
+ const Metadata = () => {
11145
+ const { id } = useParams();
11146
+ const { order, isPending, isError, error } = useOrder(id, {
11147
+ fields: "metadata"
11148
+ });
11207
11149
  if (isError) {
11208
11150
  throw error;
11209
11151
  }
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
- ] }) });
11152
+ const isReady = !isPending && !!order;
11153
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11154
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11155
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
11156
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
11157
+ ] }),
11158
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11159
+ ] });
11226
11160
  };
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(
11234
- {
11235
- id: appliedShippingOptionIds,
11236
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11237
- },
11238
- {
11239
- enabled: appliedShippingOptionIds.length > 0
11240
- }
11241
- );
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]);
11161
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
11162
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
11163
+ const MetadataForm = ({ orderId, metadata }) => {
11252
11164
  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}`);
11165
+ const hasUneditableRows = getHasUneditableRows(metadata);
11166
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
11167
+ const form = useForm({
11168
+ defaultValues: {
11169
+ metadata: getDefaultValues(metadata)
11170
+ },
11171
+ resolver: zodResolver(MetadataSchema)
11172
+ });
11173
+ const handleSubmit = form.handleSubmit(async (data) => {
11174
+ const parsedData = parseValues(data);
11175
+ await mutateAsync(
11176
+ {
11177
+ metadata: parsedData
11263
11178
  },
11264
- onSuccess: () => {
11265
- requestSucceeded = true;
11179
+ {
11180
+ onSuccess: () => {
11181
+ toast.success("Metadata updated");
11182
+ handleSuccess();
11183
+ },
11184
+ onError: (error) => {
11185
+ toast.error(error.message);
11186
+ }
11266
11187
  }
11267
- });
11268
- if (!requestSucceeded) {
11269
- setIsSubmitting(false);
11270
- return;
11188
+ );
11189
+ });
11190
+ const { fields, insert, remove } = useFieldArray({
11191
+ control: form.control,
11192
+ name: "metadata"
11193
+ });
11194
+ function deleteRow(index) {
11195
+ remove(index);
11196
+ if (fields.length === 1) {
11197
+ insert(0, {
11198
+ key: "",
11199
+ value: "",
11200
+ disabled: false
11201
+ });
11271
11202
  }
11272
- await confirmOrderEdit(void 0, {
11273
- onError: (e) => {
11274
- toast.error(`Failed to confirm order edit: ${e.message}`);
11275
- },
11276
- onSuccess: () => {
11277
- handleSuccess();
11278
- },
11279
- onSettled: () => {
11280
- setIsSubmitting(false);
11281
- }
11203
+ }
11204
+ function insertRow(index, position) {
11205
+ insert(index + (position === "above" ? 0 : 1), {
11206
+ key: "",
11207
+ value: "",
11208
+ disabled: false
11282
11209
  });
11283
- };
11284
- const onKeydown = useCallback(
11285
- (e) => {
11286
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11287
- if (data || isSubmitting) {
11288
- return;
11289
- }
11290
- onSubmit();
11291
- }
11292
- },
11293
- [data, isSubmitting, onSubmit]
11294
- );
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: [
11312
- /* @__PURE__ */ jsx(
11313
- Text,
11314
- {
11315
- size: "xsmall",
11316
- weight: "plus",
11317
- className: "text-ui-fg-muted",
11318
- children: "Shipping profile"
11210
+ }
11211
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11212
+ KeyboundForm,
11213
+ {
11214
+ onSubmit: handleSubmit,
11215
+ className: "flex flex-1 flex-col overflow-hidden",
11216
+ children: [
11217
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
11218
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
11219
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
11220
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
11221
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
11222
+ ] }),
11223
+ fields.map((field, index) => {
11224
+ const isDisabled = field.disabled || false;
11225
+ let placeholder = "-";
11226
+ if (typeof field.value === "object") {
11227
+ placeholder = "{ ... }";
11319
11228
  }
11320
- ),
11321
- /* @__PURE__ */ jsx(
11322
- Text,
11323
- {
11324
- size: "xsmall",
11325
- weight: "plus",
11326
- className: "text-ui-fg-muted",
11327
- children: "Action"
11229
+ if (Array.isArray(field.value)) {
11230
+ placeholder = "[ ... ]";
11328
11231
  }
11329
- )
11330
- ] }),
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,
11349
- {
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: [
11232
+ return /* @__PURE__ */ jsx(
11233
+ ConditionalTooltip,
11234
+ {
11235
+ showTooltip: isDisabled,
11236
+ content: "This row is disabled because it contains non-primitive data.",
11237
+ children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
11238
+ /* @__PURE__ */ jsxs(
11239
+ "div",
11240
+ {
11241
+ className: clx("grid grid-cols-2 divide-x", {
11242
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
11243
+ }),
11244
+ children: [
11368
11245
  /* @__PURE__ */ jsx(
11369
- Text,
11246
+ Form$2.Field,
11370
11247
  {
11371
- size: "small",
11372
- weight: "plus",
11373
- leading: "compact",
11374
- children: profile.name
11248
+ control: form.control,
11249
+ name: `metadata.${index}.key`,
11250
+ render: ({ field: field2 }) => {
11251
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11252
+ GridInput,
11253
+ {
11254
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
11255
+ ...field2,
11256
+ disabled: isDisabled,
11257
+ placeholder: "Key"
11258
+ }
11259
+ ) }) });
11260
+ }
11375
11261
  }
11376
11262
  ),
11377
- /* @__PURE__ */ jsxs(
11378
- Text,
11263
+ /* @__PURE__ */ jsx(
11264
+ Form$2.Field,
11379
11265
  {
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
- ]
11266
+ control: form.control,
11267
+ name: `metadata.${index}.value`,
11268
+ render: ({ field: { value, ...field2 } }) => {
11269
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11270
+ GridInput,
11271
+ {
11272
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
11273
+ ...field2,
11274
+ value: isDisabled ? placeholder : value,
11275
+ disabled: isDisabled,
11276
+ placeholder: "Value"
11277
+ }
11278
+ ) }) });
11279
+ }
11388
11280
  }
11389
11281
  )
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,
11282
+ ]
11283
+ }
11284
+ ),
11285
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
11286
+ /* @__PURE__ */ jsx(
11287
+ DropdownMenu.Trigger,
11288
+ {
11289
+ className: clx(
11290
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11291
+ {
11292
+ hidden: isDisabled
11293
+ }
11294
+ ),
11295
+ disabled: isDisabled,
11296
+ asChild: true,
11297
+ children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
11298
+ }
11299
+ ),
11300
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
11301
+ /* @__PURE__ */ jsxs(
11302
+ DropdownMenu.Item,
11394
11303
  {
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
- )
11304
+ className: "gap-x-2",
11305
+ onClick: () => insertRow(index, "above"),
11306
+ children: [
11307
+ /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
11308
+ "Insert row above"
11309
+ ]
11424
11310
  }
11425
11311
  ),
11426
- /* @__PURE__ */ jsx(
11427
- Tooltip,
11312
+ /* @__PURE__ */ jsxs(
11313
+ DropdownMenu.Item,
11428
11314
  {
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
- )
11315
+ className: "gap-x-2",
11316
+ onClick: () => insertRow(index, "below"),
11317
+ children: [
11318
+ /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
11319
+ "Insert row below"
11320
+ ]
11441
11321
  }
11442
11322
  ),
11443
- /* @__PURE__ */ jsx(Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxs(
11444
- Badge,
11323
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
11324
+ /* @__PURE__ */ jsxs(
11325
+ DropdownMenu.Item,
11445
11326
  {
11446
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11447
- size: "xsmall",
11327
+ className: "gap-x-2",
11328
+ onClick: () => deleteRow(index),
11448
11329
  children: [
11449
- /* @__PURE__ */ jsx(TruckFast, { className: "shrink-0" }),
11450
- /* @__PURE__ */ jsx("span", { className: "truncate", children: shippingOption.name })
11330
+ /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
11331
+ "Delete row"
11451
11332
  ]
11452
11333
  }
11453
- ) })
11334
+ )
11454
11335
  ] })
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
- })
11336
+ ] })
11573
11337
  ] })
11574
- ]
11575
- },
11576
- profile.id
11577
- );
11578
- }) })
11338
+ },
11339
+ field.id
11340
+ );
11341
+ })
11342
+ ] }),
11343
+ hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
11344
+ ] }),
11345
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11346
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11347
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11579
11348
  ] }) })
11580
- ] }) }),
11581
- /* @__PURE__ */ jsx(
11582
- StackedFocusModal,
11583
- {
11584
- id: STACKED_FOCUS_MODAL_ID,
11585
- onOpenChangeCallback: (open) => {
11586
- if (!open) {
11587
- setData(null);
11588
- }
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
- ] });
11609
- };
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
- });
11349
+ ]
11630
11350
  }
11631
- };
11351
+ ) });
11352
+ };
11353
+ const GridInput = forwardRef(({ className, ...props }, ref) => {
11632
11354
  return /* @__PURE__ */ jsx(
11633
- Button,
11355
+ "input",
11634
11356
  {
11635
- size: "small",
11636
- variant: "secondary",
11637
- onClick: onToggle,
11638
- className: "text-ui-fg-primary shrink-0",
11639
- children
11357
+ ref,
11358
+ ...props,
11359
+ autoComplete: "off",
11360
+ className: clx(
11361
+ "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
11362
+ className
11363
+ )
11640
11364
  }
11641
11365
  );
11366
+ });
11367
+ GridInput.displayName = "MetadataForm.GridInput";
11368
+ const PlaceholderInner = () => {
11369
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11370
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11371
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11372
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
11373
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
11374
+ ] }) })
11375
+ ] });
11642
11376
  };
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
11377
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11378
+ function getDefaultValues(metadata) {
11379
+ if (!metadata || !Object.keys(metadata).length) {
11380
+ return [
11381
+ {
11382
+ key: "",
11383
+ value: "",
11384
+ disabled: false
11385
+ }
11386
+ ];
11387
+ }
11388
+ return Object.entries(metadata).map(([key, value]) => {
11389
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11390
+ return {
11391
+ key,
11392
+ value,
11393
+ disabled: true
11394
+ };
11395
+ }
11396
+ let stringValue = value;
11397
+ if (typeof value !== "string") {
11398
+ stringValue = JSON.stringify(value);
11656
11399
  }
11400
+ return {
11401
+ key,
11402
+ value: stringValue,
11403
+ original_key: key
11404
+ };
11657
11405
  });
11658
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
11659
- 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);
11406
+ }
11407
+ function parseValues(values) {
11408
+ const metadata = values.metadata;
11409
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11410
+ if (isEmpty) {
11411
+ return null;
11412
+ }
11413
+ const update = {};
11414
+ metadata.forEach((field) => {
11415
+ let key = field.key;
11416
+ let value = field.value;
11417
+ const disabled = field.disabled;
11418
+ if (!key || !value) {
11666
11419
  return;
11667
11420
  }
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
- );
11421
+ if (disabled) {
11422
+ update[key] = value;
11684
11423
  return;
11685
11424
  }
11686
- await addShippingMethod(
11687
- {
11688
- shipping_option_id: values.shipping_option_id,
11689
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11690
- },
11691
- {
11692
- onError: (e) => {
11693
- toast.error(e.message);
11694
- },
11695
- onSuccess: () => {
11696
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11697
- }
11425
+ key = key.trim();
11426
+ value = value.trim();
11427
+ if (value === "true") {
11428
+ update[key] = true;
11429
+ } else if (value === "false") {
11430
+ update[key] = false;
11431
+ } else {
11432
+ const parsedNumber = parseFloat(value);
11433
+ if (!isNaN(parsedNumber)) {
11434
+ update[key] = parsedNumber;
11435
+ } else {
11436
+ update[key] = value;
11698
11437
  }
11699
- );
11438
+ }
11700
11439
  });
11701
- return /* @__PURE__ */ jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxs(
11702
- KeyboundForm,
11440
+ return update;
11441
+ }
11442
+ function getHasUneditableRows(metadata) {
11443
+ if (!metadata) {
11444
+ return false;
11445
+ }
11446
+ return Object.values(metadata).some(
11447
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11448
+ );
11449
+ }
11450
+ const SalesChannel = () => {
11451
+ const { id } = useParams();
11452
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11453
+ id,
11703
11454
  {
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;
11455
+ fields: "+sales_channel_id"
11456
+ },
11457
+ {
11458
+ enabled: !!id
11773
11459
  }
11774
11460
  );
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(
11827
- Text,
11828
- {
11829
- size: "small",
11830
- leading: "compact",
11831
- className: "text-ui-fg-subtle",
11832
- children: [
11833
- item.quantity,
11834
- "x"
11835
- ]
11836
- }
11837
- )
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
- ] })
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 })
11850
11471
  ] });
11851
11472
  };
11852
- const LocationField = ({ control, setValue }) => {
11853
- const locations = useComboboxData({
11854
- queryKey: ["locations"],
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);
11481
+ const { handleSuccess } = useRouteModal();
11482
+ const onSubmit = form.handleSubmit(async (data) => {
11483
+ await mutateAsync(
11484
+ {
11485
+ sales_channel_id: data.sales_channel_id
11486
+ },
11487
+ {
11488
+ onSuccess: () => {
11489
+ toast.success("Sales channel updated");
11490
+ handleSuccess();
11491
+ },
11492
+ onError: (error) => {
11493
+ toast.error(error.message);
11494
+ }
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({
11855
11515
  queryFn: async (params) => {
11856
- return await sdk.admin.stockLocation.list(params);
11516
+ return await sdk.admin.salesChannel.list(params);
11857
11517
  },
11518
+ queryKey: ["sales-channels"],
11858
11519
  getOptions: (data) => {
11859
- return data.stock_locations.map((location) => ({
11860
- label: location.name,
11861
- value: location.id
11520
+ return data.sales_channels.map((salesChannel) => ({
11521
+ label: salesChannel.name,
11522
+ value: salesChannel.id
11862
11523
  }));
11863
- }
11524
+ },
11525
+ defaultValue: order.sales_channel_id || void 0
11864
11526
  });
11865
11527
  return /* @__PURE__ */ jsx(
11866
11528
  Form$2.Field,
11867
11529
  {
11868
11530
  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
- ] }),
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" }),
11876
11535
  /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11877
11536
  Combobox,
11878
11537
  {
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
- },
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",
11892
11544
  ...field
11893
11545
  }
11894
- ) })
11895
- ] }) });
11546
+ ) }),
11547
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11548
+ ] });
11896
11549
  }
11897
11550
  }
11898
11551
  );
11899
11552
  };
11900
- const ShippingOptionField = ({
11901
- shippingProfileId,
11902
- preview,
11903
- control
11904
- }) => {
11553
+ const schema$2 = objectType({
11554
+ sales_channel_id: stringType().min(1)
11555
+ });
11556
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11557
+ const Shipping = () => {
11905
11558
  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
- ] }),
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
11559
  const { id } = useParams();
12001
11560
  const { order, isPending, isError, error } = useOrder(id, {
12002
- fields: "+shipping_address"
11561
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
12003
11562
  });
11563
+ const {
11564
+ order: preview,
11565
+ isPending: isPreviewPending,
11566
+ isError: isPreviewError,
11567
+ error: previewError
11568
+ } = useOrderPreview(id);
11569
+ useInitiateOrderEdit({ preview });
11570
+ const { onCancel } = useCancelOrderEdit({ preview });
12004
11571
  if (isError) {
12005
11572
  throw error;
12006
11573
  }
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
- ] });
11574
+ if (isPreviewError) {
11575
+ throw previewError;
11576
+ }
11577
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11578
+ const isReady = preview && !isPreviewPending && order && !isPending;
11579
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11580
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11581
+ /* @__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: [
11582
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11583
+ /* @__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." }) })
11584
+ ] }) }) }),
11585
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11586
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11587
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11588
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11589
+ ] }) });
12015
11590
  };
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) ?? ""
11591
+ const ShippingForm = ({ preview, order }) => {
11592
+ var _a;
11593
+ const { setIsOpen } = useStackedModal();
11594
+ const [isSubmitting, setIsSubmitting] = useState(false);
11595
+ const [data, setData] = useState(null);
11596
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11597
+ const { shipping_options } = useShippingOptions(
11598
+ {
11599
+ id: appliedShippingOptionIds,
11600
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
12030
11601
  },
12031
- resolver: zodResolver(schema$4)
12032
- });
12033
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11602
+ {
11603
+ enabled: appliedShippingOptionIds.length > 0
11604
+ }
11605
+ );
11606
+ const uniqueShippingProfiles = useMemo(() => {
11607
+ const profiles = /* @__PURE__ */ new Map();
11608
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11609
+ profiles.set(profile.id, profile);
11610
+ });
11611
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11612
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11613
+ });
11614
+ return Array.from(profiles.values());
11615
+ }, [order.items, shipping_options]);
12034
11616
  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
- }
11617
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11618
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11619
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11620
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11621
+ const onSubmit = async () => {
11622
+ setIsSubmitting(true);
11623
+ let requestSucceeded = false;
11624
+ await requestOrderEdit(void 0, {
11625
+ onError: (e) => {
11626
+ toast.error(`Failed to request order edit: ${e.message}`);
12050
11627
  },
12051
- {
12052
- onSuccess: () => {
12053
- handleSuccess();
12054
- },
12055
- onError: (error) => {
12056
- toast.error(error.message);
11628
+ onSuccess: () => {
11629
+ requestSucceeded = true;
11630
+ }
11631
+ });
11632
+ if (!requestSucceeded) {
11633
+ setIsSubmitting(false);
11634
+ return;
11635
+ }
11636
+ await confirmOrderEdit(void 0, {
11637
+ onError: (e) => {
11638
+ toast.error(`Failed to confirm order edit: ${e.message}`);
11639
+ },
11640
+ onSuccess: () => {
11641
+ handleSuccess();
11642
+ },
11643
+ onSettled: () => {
11644
+ setIsSubmitting(false);
11645
+ }
11646
+ });
11647
+ };
11648
+ const onKeydown = useCallback(
11649
+ (e) => {
11650
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11651
+ if (data || isSubmitting) {
11652
+ return;
12057
11653
  }
11654
+ onSubmit();
12058
11655
  }
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: [
11656
+ },
11657
+ [data, isSubmitting, onSubmit]
11658
+ );
11659
+ useEffect(() => {
11660
+ document.addEventListener("keydown", onKeydown);
11661
+ return () => {
11662
+ document.removeEventListener("keydown", onKeydown);
11663
+ };
11664
+ }, [onKeydown]);
11665
+ return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11666
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11667
+ /* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11668
+ /* @__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: [
11669
+ /* @__PURE__ */ jsxs("div", { children: [
11670
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11671
+ /* @__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." }) })
11672
+ ] }),
11673
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11674
+ /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11675
+ /* @__PURE__ */ jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
12143
11676
  /* @__PURE__ */ jsx(
12144
- Form$2.Field,
11677
+ Text,
12145
11678
  {
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
- ] })
11679
+ size: "xsmall",
11680
+ weight: "plus",
11681
+ className: "text-ui-fg-muted",
11682
+ children: "Shipping profile"
12153
11683
  }
12154
11684
  ),
12155
11685
  /* @__PURE__ */ jsx(
12156
- Form$2.Field,
11686
+ Text,
12157
11687
  {
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
- ] })
11688
+ size: "xsmall",
11689
+ weight: "plus",
11690
+ className: "text-ui-fg-muted",
11691
+ children: "Action"
12165
11692
  }
12166
11693
  )
12167
11694
  ] }),
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)"
11695
+ /* @__PURE__ */ jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11696
+ var _a2, _b, _c, _d, _e, _f, _g;
11697
+ const items = getItemsWithShippingProfile(
11698
+ profile.id,
11699
+ order.items
11700
+ );
11701
+ const hasItems = items.length > 0;
11702
+ const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11703
+ (option) => option.shipping_profile_id === profile.id
11704
+ );
11705
+ const shippingMethod = preview.shipping_methods.find(
11706
+ (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11707
+ );
11708
+ const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11709
+ (action) => action.action === "SHIPPING_ADD"
11710
+ );
11711
+ return /* @__PURE__ */ jsxs(
11712
+ Accordion.Item,
11713
+ {
11714
+ value: profile.id,
11715
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11716
+ children: [
11717
+ /* @__PURE__ */ jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11718
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11719
+ /* @__PURE__ */ jsx(Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
11720
+ IconButton,
11721
+ {
11722
+ size: "2xsmall",
11723
+ variant: "transparent",
11724
+ className: "group/trigger",
11725
+ disabled: !hasItems,
11726
+ children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11727
+ }
11728
+ ) }),
11729
+ !shippingOption ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
11730
+ /* @__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" }) }) }),
11731
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col flex-1", children: [
11732
+ /* @__PURE__ */ jsx(
11733
+ Text,
11734
+ {
11735
+ size: "small",
11736
+ weight: "plus",
11737
+ leading: "compact",
11738
+ children: profile.name
11739
+ }
11740
+ ),
11741
+ /* @__PURE__ */ jsxs(
11742
+ Text,
11743
+ {
11744
+ size: "small",
11745
+ leading: "compact",
11746
+ className: "text-ui-fg-subtle",
11747
+ children: [
11748
+ items.length,
11749
+ " ",
11750
+ pluralize(items.length, "items", "item")
11751
+ ]
11752
+ }
11753
+ )
11754
+ ] })
11755
+ ] }) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11756
+ /* @__PURE__ */ jsx(
11757
+ Tooltip,
11758
+ {
11759
+ content: /* @__PURE__ */ jsx("ul", { children: items.map((item) => {
11760
+ var _a3, _b2, _c2;
11761
+ return /* @__PURE__ */ jsx(
11762
+ "li",
11763
+ {
11764
+ 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})`
11765
+ },
11766
+ item.id
11767
+ );
11768
+ }) }),
11769
+ children: /* @__PURE__ */ jsxs(
11770
+ Badge,
11771
+ {
11772
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11773
+ size: "xsmall",
11774
+ children: [
11775
+ /* @__PURE__ */ jsx(Shopping, { className: "shrink-0" }),
11776
+ /* @__PURE__ */ jsxs("span", { className: "truncate", children: [
11777
+ items.reduce(
11778
+ (acc, item) => acc + item.quantity,
11779
+ 0
11780
+ ),
11781
+ "x",
11782
+ " ",
11783
+ pluralize(items.length, "items", "item")
11784
+ ] })
11785
+ ]
11786
+ }
11787
+ )
11788
+ }
11789
+ ),
11790
+ /* @__PURE__ */ jsx(
11791
+ Tooltip,
11792
+ {
11793
+ content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11794
+ children: /* @__PURE__ */ jsxs(
11795
+ Badge,
11796
+ {
11797
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11798
+ size: "xsmall",
11799
+ children: [
11800
+ /* @__PURE__ */ jsx(Buildings, { className: "shrink-0" }),
11801
+ /* @__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 })
11802
+ ]
11803
+ }
11804
+ )
11805
+ }
11806
+ ),
11807
+ /* @__PURE__ */ jsx(Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxs(
11808
+ Badge,
11809
+ {
11810
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11811
+ size: "xsmall",
11812
+ children: [
11813
+ /* @__PURE__ */ jsx(TruckFast, { className: "shrink-0" }),
11814
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: shippingOption.name })
11815
+ ]
11816
+ }
11817
+ ) })
11818
+ ] })
11819
+ ] }),
11820
+ shippingOption ? /* @__PURE__ */ jsx(
11821
+ ActionMenu,
11822
+ {
11823
+ groups: [
11824
+ {
11825
+ actions: [
11826
+ hasItems ? {
11827
+ label: "Edit shipping option",
11828
+ icon: /* @__PURE__ */ jsx(Channels, {}),
11829
+ onClick: () => {
11830
+ setIsOpen(
11831
+ STACKED_FOCUS_MODAL_ID,
11832
+ true
11833
+ );
11834
+ setData({
11835
+ shippingProfileId: profile.id,
11836
+ shippingOption,
11837
+ shippingMethod
11838
+ });
11839
+ }
11840
+ } : void 0,
11841
+ {
11842
+ label: "Remove shipping option",
11843
+ icon: /* @__PURE__ */ jsx(Trash, {}),
11844
+ onClick: () => {
11845
+ if (shippingMethod) {
11846
+ if (addShippingMethodAction) {
11847
+ removeActionShippingMethod(
11848
+ addShippingMethodAction.id
11849
+ );
11850
+ } else {
11851
+ removeShippingMethod(
11852
+ shippingMethod.id
11853
+ );
11854
+ }
11855
+ }
11856
+ }
11857
+ }
11858
+ ].filter(Boolean)
11859
+ }
11860
+ ]
11861
+ }
11862
+ ) : /* @__PURE__ */ jsx(
11863
+ StackedModalTrigger,
11864
+ {
11865
+ shippingProfileId: profile.id,
11866
+ shippingOption,
11867
+ shippingMethod,
11868
+ setData,
11869
+ children: "Add shipping option"
11870
+ }
11871
+ )
11872
+ ] }),
11873
+ /* @__PURE__ */ jsxs(Accordion.Content, { children: [
11874
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11875
+ items.map((item, idx) => {
11876
+ var _a3, _b2, _c2, _d2, _e2;
11877
+ return /* @__PURE__ */ jsxs("div", { children: [
11878
+ /* @__PURE__ */ jsxs(
11879
+ "div",
11880
+ {
11881
+ className: "px-3 flex items-center gap-x-3",
11882
+ children: [
11883
+ /* @__PURE__ */ jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsx(
11884
+ Divider,
11885
+ {
11886
+ variant: "dashed",
11887
+ orientation: "vertical"
11888
+ }
11889
+ ) }),
11890
+ /* @__PURE__ */ jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11891
+ /* @__PURE__ */ jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxs(
11892
+ Text,
11893
+ {
11894
+ size: "small",
11895
+ leading: "compact",
11896
+ className: "text-ui-fg-subtle",
11897
+ children: [
11898
+ item.quantity,
11899
+ "x"
11900
+ ]
11901
+ }
11902
+ ) }),
11903
+ /* @__PURE__ */ jsx(Thumbnail, { thumbnail: item.thumbnail }),
11904
+ /* @__PURE__ */ jsxs("div", { children: [
11905
+ /* @__PURE__ */ jsxs(
11906
+ Text,
11907
+ {
11908
+ size: "small",
11909
+ leading: "compact",
11910
+ weight: "plus",
11911
+ children: [
11912
+ (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
11913
+ " (",
11914
+ (_c2 = item.variant) == null ? void 0 : _c2.title,
11915
+ ")"
11916
+ ]
11917
+ }
11918
+ ),
11919
+ /* @__PURE__ */ jsx(
11920
+ Text,
11921
+ {
11922
+ size: "small",
11923
+ leading: "compact",
11924
+ className: "text-ui-fg-subtle",
11925
+ children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
11926
+ }
11927
+ )
11928
+ ] })
11929
+ ] })
11930
+ ]
11931
+ },
11932
+ item.id
11933
+ ),
11934
+ idx !== items.length - 1 && /* @__PURE__ */ jsx(Divider, { variant: "dashed" })
11935
+ ] }, item.id);
11936
+ })
11937
+ ] })
11938
+ ]
11939
+ },
11940
+ profile.id
11941
+ );
11942
+ }) })
11943
+ ] }) })
11944
+ ] }) }),
11945
+ /* @__PURE__ */ jsx(
11946
+ StackedFocusModal,
11947
+ {
11948
+ id: STACKED_FOCUS_MODAL_ID,
11949
+ onOpenChangeCallback: (open) => {
11950
+ if (!open) {
11951
+ setData(null);
12623
11952
  }
12624
- ) }),
12625
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12626
- "rect",
11953
+ return open;
11954
+ },
11955
+ children: data && /* @__PURE__ */ jsx(ShippingProfileForm, { data, order, preview })
11956
+ }
11957
+ )
11958
+ ] }),
11959
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
11960
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11961
+ /* @__PURE__ */ jsx(
11962
+ Button,
11963
+ {
11964
+ size: "small",
11965
+ type: "button",
11966
+ isLoading: isSubmitting,
11967
+ onClick: onSubmit,
11968
+ children: "Save"
11969
+ }
11970
+ )
11971
+ ] }) })
11972
+ ] });
11973
+ };
11974
+ const StackedModalTrigger = ({
11975
+ shippingProfileId,
11976
+ shippingOption,
11977
+ shippingMethod,
11978
+ setData,
11979
+ children
11980
+ }) => {
11981
+ const { setIsOpen, getIsOpen } = useStackedModal();
11982
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11983
+ const onToggle = () => {
11984
+ if (isOpen) {
11985
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11986
+ setData(null);
11987
+ } else {
11988
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11989
+ setData({
11990
+ shippingProfileId,
11991
+ shippingOption,
11992
+ shippingMethod
11993
+ });
11994
+ }
11995
+ };
11996
+ return /* @__PURE__ */ jsx(
11997
+ Button,
11998
+ {
11999
+ size: "small",
12000
+ variant: "secondary",
12001
+ onClick: onToggle,
12002
+ className: "text-ui-fg-primary shrink-0",
12003
+ children
12004
+ }
12005
+ );
12006
+ };
12007
+ const ShippingProfileForm = ({
12008
+ data,
12009
+ order,
12010
+ preview
12011
+ }) => {
12012
+ var _a, _b, _c, _d, _e, _f;
12013
+ const { setIsOpen } = useStackedModal();
12014
+ const form = useForm({
12015
+ resolver: zodResolver(shippingMethodSchema),
12016
+ defaultValues: {
12017
+ 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,
12018
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12019
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12020
+ }
12021
+ });
12022
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12023
+ const {
12024
+ mutateAsync: updateShippingMethod,
12025
+ isPending: isUpdatingShippingMethod
12026
+ } = useDraftOrderUpdateShippingMethod(order.id);
12027
+ const onSubmit = form.handleSubmit(async (values) => {
12028
+ if (isEqual(values, form.formState.defaultValues)) {
12029
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12030
+ return;
12031
+ }
12032
+ if (data.shippingMethod) {
12033
+ await updateShippingMethod(
12034
+ {
12035
+ method_id: data.shippingMethod.id,
12036
+ shipping_option_id: values.shipping_option_id,
12037
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12038
+ },
12039
+ {
12040
+ onError: (e) => {
12041
+ toast.error(e.message);
12042
+ },
12043
+ onSuccess: () => {
12044
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12045
+ }
12046
+ }
12047
+ );
12048
+ return;
12049
+ }
12050
+ await addShippingMethod(
12051
+ {
12052
+ shipping_option_id: values.shipping_option_id,
12053
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12054
+ },
12055
+ {
12056
+ onError: (e) => {
12057
+ toast.error(e.message);
12058
+ },
12059
+ onSuccess: () => {
12060
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12061
+ }
12062
+ }
12063
+ );
12064
+ });
12065
+ return /* @__PURE__ */ jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxs(
12066
+ KeyboundForm,
12067
+ {
12068
+ className: "flex h-full flex-col overflow-hidden",
12069
+ onSubmit,
12070
+ children: [
12071
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12072
+ /* @__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: [
12073
+ /* @__PURE__ */ jsxs("div", { children: [
12074
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12075
+ /* @__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." }) })
12076
+ ] }),
12077
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12078
+ /* @__PURE__ */ jsx(
12079
+ LocationField,
12627
12080
  {
12628
- width: "12",
12629
- height: "12",
12630
- fill: "white",
12631
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12081
+ control: form.control,
12082
+ setValue: form.setValue
12632
12083
  }
12633
- ) }),
12634
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12635
- "rect",
12084
+ ),
12085
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12086
+ /* @__PURE__ */ jsx(
12087
+ ShippingOptionField,
12636
12088
  {
12637
- width: "12",
12638
- height: "12",
12639
- fill: "white",
12640
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12089
+ shippingProfileId: data.shippingProfileId,
12090
+ preview,
12091
+ control: form.control
12641
12092
  }
12642
- ) }),
12643
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12644
- "rect",
12093
+ ),
12094
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12095
+ /* @__PURE__ */ jsx(
12096
+ CustomAmountField,
12645
12097
  {
12646
- width: "12",
12647
- height: "12",
12648
- fill: "white",
12649
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12098
+ control: form.control,
12099
+ currencyCode: order.currency_code
12650
12100
  }
12651
- ) }),
12652
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12653
- "rect",
12101
+ ),
12102
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12103
+ /* @__PURE__ */ jsx(
12104
+ ItemsPreview,
12654
12105
  {
12655
- width: "12",
12656
- height: "12",
12657
- fill: "white",
12658
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12106
+ order,
12107
+ shippingProfileId: data.shippingProfileId
12659
12108
  }
12660
- ) }),
12661
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
12662
- "rect",
12109
+ )
12110
+ ] }) }) }),
12111
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
12112
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12113
+ /* @__PURE__ */ jsx(
12114
+ Button,
12663
12115
  {
12664
- width: "12",
12665
- height: "12",
12666
- fill: "white",
12667
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12116
+ size: "small",
12117
+ type: "submit",
12118
+ isLoading: isPending || isUpdatingShippingMethod,
12119
+ children: data.shippingMethod ? "Update" : "Add"
12668
12120
  }
12669
- ) })
12121
+ )
12122
+ ] }) })
12123
+ ]
12124
+ }
12125
+ ) }) });
12126
+ };
12127
+ const shippingMethodSchema = objectType({
12128
+ location_id: stringType(),
12129
+ shipping_option_id: stringType(),
12130
+ custom_amount: unionType([numberType(), stringType()]).optional()
12131
+ });
12132
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12133
+ const matches = order.items.filter(
12134
+ (item) => {
12135
+ var _a, _b, _c;
12136
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12137
+ }
12138
+ );
12139
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
12140
+ /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12141
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12142
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12143
+ ] }) }),
12144
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12145
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12146
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
12147
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
12148
+ ] }),
12149
+ /* @__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(
12150
+ "div",
12151
+ {
12152
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12153
+ children: [
12154
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12155
+ /* @__PURE__ */ jsx(
12156
+ Thumbnail,
12157
+ {
12158
+ thumbnail: item.thumbnail,
12159
+ alt: item.product_title ?? void 0
12160
+ }
12161
+ ),
12162
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12163
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
12164
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12165
+ /* @__PURE__ */ jsxs(
12166
+ Text,
12167
+ {
12168
+ size: "small",
12169
+ leading: "compact",
12170
+ className: "text-ui-fg-subtle",
12171
+ children: [
12172
+ "(",
12173
+ item.variant_title,
12174
+ ")"
12175
+ ]
12176
+ }
12177
+ )
12178
+ ] }),
12179
+ /* @__PURE__ */ jsx(
12180
+ Text,
12181
+ {
12182
+ size: "small",
12183
+ leading: "compact",
12184
+ className: "text-ui-fg-subtle",
12185
+ children: item.variant_sku
12186
+ }
12187
+ )
12188
+ ] })
12189
+ ] }),
12190
+ /* @__PURE__ */ jsxs(
12191
+ Text,
12192
+ {
12193
+ size: "small",
12194
+ leading: "compact",
12195
+ className: "text-ui-fg-subtle",
12196
+ children: [
12197
+ item.quantity,
12198
+ "x"
12199
+ ]
12200
+ }
12201
+ )
12202
+ ]
12203
+ },
12204
+ item.id
12205
+ )) : /* @__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: [
12206
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12207
+ /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12208
+ 'No items found for "',
12209
+ query,
12210
+ '".'
12670
12211
  ] })
12671
- ]
12672
- }
12673
- );
12674
- };
12675
- const schema$3 = objectType({
12676
- customer_id: stringType().min(1)
12677
- });
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
12687
- }
12688
- );
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 })
12212
+ ] }) })
12213
+ ] })
12699
12214
  ] });
12700
12215
  };
12701
- const SalesChannelForm = ({ order }) => {
12702
- const form = useForm({
12703
- defaultValues: {
12704
- sales_channel_id: order.sales_channel_id || ""
12216
+ const LocationField = ({ control, setValue }) => {
12217
+ const locations = useComboboxData({
12218
+ queryKey: ["locations"],
12219
+ queryFn: async (params) => {
12220
+ return await sdk.admin.stockLocation.list(params);
12705
12221
  },
12706
- resolver: zodResolver(schema$2)
12707
- });
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
- }
12723
- }
12724
- );
12222
+ getOptions: (data) => {
12223
+ return data.stock_locations.map((location) => ({
12224
+ label: location.name,
12225
+ value: location.id
12226
+ }));
12227
+ }
12725
12228
  });
12726
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12727
- KeyboundForm,
12229
+ return /* @__PURE__ */ jsx(
12230
+ Form$2.Field,
12728
12231
  {
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
- ]
12232
+ control,
12233
+ name: "location_id",
12234
+ render: ({ field: { onChange, ...field } }) => {
12235
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12236
+ /* @__PURE__ */ jsxs("div", { children: [
12237
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
12238
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12239
+ ] }),
12240
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12241
+ Combobox,
12242
+ {
12243
+ options: locations.options,
12244
+ fetchNextPage: locations.fetchNextPage,
12245
+ isFetchingNextPage: locations.isFetchingNextPage,
12246
+ searchValue: locations.searchValue,
12247
+ onSearchValueChange: locations.onSearchValueChange,
12248
+ placeholder: "Select location",
12249
+ onChange: (value) => {
12250
+ setValue("shipping_option_id", "", {
12251
+ shouldDirty: true,
12252
+ shouldTouch: true
12253
+ });
12254
+ onChange(value);
12255
+ },
12256
+ ...field
12257
+ }
12258
+ ) })
12259
+ ] }) });
12260
+ }
12738
12261
  }
12739
- ) });
12262
+ );
12740
12263
  };
12741
- const SalesChannelField = ({ control, order }) => {
12742
- const salesChannels = useComboboxData({
12264
+ const ShippingOptionField = ({
12265
+ shippingProfileId,
12266
+ preview,
12267
+ control
12268
+ }) => {
12269
+ var _a;
12270
+ const locationId = useWatch({ control, name: "location_id" });
12271
+ const shippingOptions = useComboboxData({
12272
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12743
12273
  queryFn: async (params) => {
12744
- return await sdk.admin.salesChannel.list(params);
12274
+ return await sdk.admin.shippingOption.list({
12275
+ ...params,
12276
+ stock_location_id: locationId,
12277
+ shipping_profile_id: shippingProfileId
12278
+ });
12745
12279
  },
12746
- queryKey: ["sales-channels"],
12747
12280
  getOptions: (data) => {
12748
- return data.sales_channels.map((salesChannel) => ({
12749
- label: salesChannel.name,
12750
- value: salesChannel.id
12751
- }));
12281
+ return data.shipping_options.map((option) => {
12282
+ var _a2;
12283
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12284
+ (r) => r.attribute === "is_return" && r.value === "true"
12285
+ )) {
12286
+ return void 0;
12287
+ }
12288
+ return {
12289
+ label: option.name,
12290
+ value: option.id
12291
+ };
12292
+ }).filter(Boolean);
12752
12293
  },
12753
- defaultValue: order.sales_channel_id || void 0
12294
+ enabled: !!locationId && !!shippingProfileId,
12295
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12754
12296
  });
12297
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12755
12298
  return /* @__PURE__ */ jsx(
12756
12299
  Form$2.Field,
12757
12300
  {
12758
12301
  control,
12759
- name: "sales_channel_id",
12302
+ name: "shipping_option_id",
12760
12303
  render: ({ field }) => {
12761
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12762
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
12304
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12305
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12306
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12307
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12308
+ ] }),
12309
+ /* @__PURE__ */ jsx(
12310
+ ConditionalTooltip,
12311
+ {
12312
+ content: tooltipContent,
12313
+ showTooltip: !locationId || !shippingProfileId,
12314
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12315
+ Combobox,
12316
+ {
12317
+ options: shippingOptions.options,
12318
+ fetchNextPage: shippingOptions.fetchNextPage,
12319
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12320
+ searchValue: shippingOptions.searchValue,
12321
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12322
+ placeholder: "Select shipping option",
12323
+ ...field,
12324
+ disabled: !locationId || !shippingProfileId
12325
+ }
12326
+ ) }) })
12327
+ }
12328
+ )
12329
+ ] }) });
12330
+ }
12331
+ }
12332
+ );
12333
+ };
12334
+ const CustomAmountField = ({
12335
+ control,
12336
+ currencyCode
12337
+ }) => {
12338
+ return /* @__PURE__ */ jsx(
12339
+ Form$2.Field,
12340
+ {
12341
+ control,
12342
+ name: "custom_amount",
12343
+ render: ({ field: { onChange, ...field } }) => {
12344
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12345
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12346
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12347
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12348
+ ] }),
12763
12349
  /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12764
- Combobox,
12350
+ CurrencyInput,
12765
12351
  {
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
12352
+ ...field,
12353
+ onValueChange: (value) => onChange(value),
12354
+ symbol: getNativeSymbol(currencyCode),
12355
+ code: currencyCode
12773
12356
  }
12774
- ) }),
12775
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12357
+ ) })
12776
12358
  ] });
12777
12359
  }
12778
12360
  }
12779
12361
  );
12780
12362
  };
12781
- const schema$2 = objectType({
12782
- sales_channel_id: stringType().min(1)
12783
- });
12784
- const Email = () => {
12363
+ const ShippingAddress = () => {
12785
12364
  const { id } = useParams();
12786
12365
  const { order, isPending, isError, error } = useOrder(id, {
12787
- fields: "+email"
12366
+ fields: "+shipping_address"
12788
12367
  });
12789
12368
  if (isError) {
12790
12369
  throw error;
@@ -12792,16 +12371,26 @@ const Email = () => {
12792
12371
  const isReady = !isPending && !!order;
12793
12372
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12794
12373
  /* @__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" }) })
12374
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12375
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12797
12376
  ] }),
12798
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
12377
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12799
12378
  ] });
12800
12379
  };
12801
- const EmailForm = ({ order }) => {
12380
+ const ShippingAddressForm = ({ order }) => {
12381
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12802
12382
  const form = useForm({
12803
12383
  defaultValues: {
12804
- email: order.email ?? ""
12384
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12385
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12386
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12387
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12388
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12389
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12390
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12391
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12392
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12393
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12805
12394
  },
12806
12395
  resolver: zodResolver(schema$1)
12807
12396
  });
@@ -12809,7 +12398,20 @@ const EmailForm = ({ order }) => {
12809
12398
  const { handleSuccess } = useRouteModal();
12810
12399
  const onSubmit = form.handleSubmit(async (data) => {
12811
12400
  await mutateAsync(
12812
- { email: data.email },
12401
+ {
12402
+ shipping_address: {
12403
+ first_name: data.first_name,
12404
+ last_name: data.last_name,
12405
+ company: data.company,
12406
+ address_1: data.address_1,
12407
+ address_2: data.address_2,
12408
+ city: data.city,
12409
+ province: data.province,
12410
+ country_code: data.country_code,
12411
+ postal_code: data.postal_code,
12412
+ phone: data.phone
12413
+ }
12414
+ },
12813
12415
  {
12814
12416
  onSuccess: () => {
12815
12417
  handleSuccess();
@@ -12826,18 +12428,132 @@ const EmailForm = ({ order }) => {
12826
12428
  className: "flex flex-1 flex-col overflow-hidden",
12827
12429
  onSubmit,
12828
12430
  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, {})
12838
- ] })
12839
- }
12840
- ) }),
12431
+ /* @__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: [
12432
+ /* @__PURE__ */ jsx(
12433
+ Form$2.Field,
12434
+ {
12435
+ control: form.control,
12436
+ name: "country_code",
12437
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12438
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12439
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12440
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12441
+ ] })
12442
+ }
12443
+ ),
12444
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12445
+ /* @__PURE__ */ jsx(
12446
+ Form$2.Field,
12447
+ {
12448
+ control: form.control,
12449
+ name: "first_name",
12450
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12451
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12452
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12453
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12454
+ ] })
12455
+ }
12456
+ ),
12457
+ /* @__PURE__ */ jsx(
12458
+ Form$2.Field,
12459
+ {
12460
+ control: form.control,
12461
+ name: "last_name",
12462
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12463
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12464
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12465
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12466
+ ] })
12467
+ }
12468
+ )
12469
+ ] }),
12470
+ /* @__PURE__ */ jsx(
12471
+ Form$2.Field,
12472
+ {
12473
+ control: form.control,
12474
+ name: "company",
12475
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12476
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12477
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12478
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12479
+ ] })
12480
+ }
12481
+ ),
12482
+ /* @__PURE__ */ jsx(
12483
+ Form$2.Field,
12484
+ {
12485
+ control: form.control,
12486
+ name: "address_1",
12487
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12488
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12489
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12490
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12491
+ ] })
12492
+ }
12493
+ ),
12494
+ /* @__PURE__ */ jsx(
12495
+ Form$2.Field,
12496
+ {
12497
+ control: form.control,
12498
+ name: "address_2",
12499
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12500
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12501
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12502
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12503
+ ] })
12504
+ }
12505
+ ),
12506
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12507
+ /* @__PURE__ */ jsx(
12508
+ Form$2.Field,
12509
+ {
12510
+ control: form.control,
12511
+ name: "postal_code",
12512
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12513
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12514
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12515
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12516
+ ] })
12517
+ }
12518
+ ),
12519
+ /* @__PURE__ */ jsx(
12520
+ Form$2.Field,
12521
+ {
12522
+ control: form.control,
12523
+ name: "city",
12524
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12525
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12526
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12527
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12528
+ ] })
12529
+ }
12530
+ )
12531
+ ] }),
12532
+ /* @__PURE__ */ jsx(
12533
+ Form$2.Field,
12534
+ {
12535
+ control: form.control,
12536
+ name: "province",
12537
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12538
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12539
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12540
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12541
+ ] })
12542
+ }
12543
+ ),
12544
+ /* @__PURE__ */ jsx(
12545
+ Form$2.Field,
12546
+ {
12547
+ control: form.control,
12548
+ name: "phone",
12549
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12550
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12551
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12552
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12553
+ ] })
12554
+ }
12555
+ )
12556
+ ] }) }),
12841
12557
  /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12842
12558
  /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12843
12559
  /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -12846,50 +12562,45 @@ const EmailForm = ({ order }) => {
12846
12562
  }
12847
12563
  ) });
12848
12564
  };
12849
- const schema$1 = objectType({
12850
- email: stringType().email()
12851
- });
12852
- const BillingAddress = () => {
12565
+ const schema$1 = addressSchema;
12566
+ const TransferOwnership = () => {
12853
12567
  const { id } = useParams();
12854
- const { order, isPending, isError, error } = useOrder(id, {
12855
- fields: "+billing_address"
12568
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12569
+ fields: "id,customer_id,customer.*"
12856
12570
  });
12857
12571
  if (isError) {
12858
12572
  throw error;
12859
12573
  }
12860
- const isReady = !isPending && !!order;
12574
+ const isReady = !isPending && !!draft_order;
12861
12575
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12862
12576
  /* @__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" }) })
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" }) })
12865
12579
  ] }),
12866
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12580
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12867
12581
  ] });
12868
12582
  };
12869
- const BillingAddressForm = ({ order }) => {
12870
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12583
+ const TransferOwnershipForm = ({ order }) => {
12584
+ var _a, _b;
12871
12585
  const form = useForm({
12872
12586
  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) ?? ""
12587
+ customer_id: order.customer_id || ""
12883
12588
  },
12884
12589
  resolver: zodResolver(schema)
12885
12590
  });
12886
12591
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12887
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;
12888
12598
  const onSubmit = form.handleSubmit(async (data) => {
12889
12599
  await mutateAsync(
12890
- { billing_address: data },
12600
+ { customer_id: data.customer_id },
12891
12601
  {
12892
12602
  onSuccess: () => {
12603
+ toast.success("Customer updated");
12893
12604
  handleSuccess();
12894
12605
  },
12895
12606
  onError: (error) => {
@@ -12898,147 +12609,436 @@ const BillingAddressForm = ({ order }) => {
12898
12609
  }
12899
12610
  );
12900
12611
  });
12901
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12902
- KeyboundForm,
12612
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12613
+ KeyboundForm,
12614
+ {
12615
+ className: "flex flex-1 flex-col overflow-hidden",
12616
+ onSubmit,
12617
+ children: [
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 }) })
12628
+ ] })
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" }) }),
12640
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12641
+ ] }) })
12642
+ ]
12643
+ }
12644
+ ) });
12645
+ };
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
+ });
12653
+ },
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
+ }
12664
+ });
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,21 +13059,33 @@ 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"
13069
13077
  },
13078
+ {
13079
+ Component: Promotions,
13080
+ path: "/draft-orders/:id/promotions"
13081
+ },
13070
13082
  {
13071
13083
  Component: Metadata,
13072
13084
  path: "/draft-orders/:id/metadata"
13073
13085
  },
13074
13086
  {
13075
- Component: Promotions,
13076
- path: "/draft-orders/:id/promotions"
13087
+ Component: SalesChannel,
13088
+ path: "/draft-orders/:id/sales-channel"
13077
13089
  },
13078
13090
  {
13079
13091
  Component: Shipping,
@@ -13086,18 +13098,6 @@ const routeModule = {
13086
13098
  {
13087
13099
  Component: TransferOwnership,
13088
13100
  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"
13097
- },
13098
- {
13099
- Component: BillingAddress,
13100
- path: "/draft-orders/:id/billing-address"
13101
13101
  }
13102
13102
  ]
13103
13103
  }