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

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