@medusajs/draft-order 2.11.3-preview-20251031120214 → 2.11.3-preview-20251031150158

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.
@@ -9592,6 +9592,74 @@ const CustomItemsForm = () => {
9592
9592
  const schema$5 = objectType({
9593
9593
  email: stringType().email()
9594
9594
  });
9595
+ const Email = () => {
9596
+ const { id } = reactRouterDom.useParams();
9597
+ const { order, isPending, isError, error } = useOrder(id, {
9598
+ fields: "+email"
9599
+ });
9600
+ if (isError) {
9601
+ throw error;
9602
+ }
9603
+ const isReady = !isPending && !!order;
9604
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9605
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9606
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9607
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9608
+ ] }),
9609
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9610
+ ] });
9611
+ };
9612
+ const EmailForm = ({ order }) => {
9613
+ const form = reactHookForm.useForm({
9614
+ defaultValues: {
9615
+ email: order.email ?? ""
9616
+ },
9617
+ resolver: zod.zodResolver(schema$4)
9618
+ });
9619
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9620
+ const { handleSuccess } = useRouteModal();
9621
+ const onSubmit = form.handleSubmit(async (data) => {
9622
+ await mutateAsync(
9623
+ { email: data.email },
9624
+ {
9625
+ onSuccess: () => {
9626
+ handleSuccess();
9627
+ },
9628
+ onError: (error) => {
9629
+ ui.toast.error(error.message);
9630
+ }
9631
+ }
9632
+ );
9633
+ });
9634
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9635
+ KeyboundForm,
9636
+ {
9637
+ className: "flex flex-1 flex-col overflow-hidden",
9638
+ onSubmit,
9639
+ children: [
9640
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9641
+ Form$2.Field,
9642
+ {
9643
+ control: form.control,
9644
+ name: "email",
9645
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9646
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9647
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9648
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9649
+ ] })
9650
+ }
9651
+ ) }),
9652
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9653
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9654
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9655
+ ] }) })
9656
+ ]
9657
+ }
9658
+ ) });
9659
+ };
9660
+ const schema$4 = objectType({
9661
+ email: stringType().email()
9662
+ });
9595
9663
  const NumberInput = React.forwardRef(
9596
9664
  ({
9597
9665
  value,
@@ -10566,632 +10634,632 @@ const customItemSchema = objectType({
10566
10634
  quantity: numberType(),
10567
10635
  unit_price: unionType([numberType(), stringType()])
10568
10636
  });
10569
- const PROMOTION_QUERY_KEY = "promotions";
10570
- const promotionsQueryKeys = {
10571
- list: (query2) => [
10572
- PROMOTION_QUERY_KEY,
10573
- query2 ? query2 : void 0
10574
- ],
10575
- detail: (id, query2) => [
10576
- PROMOTION_QUERY_KEY,
10577
- id,
10578
- query2 ? query2 : void 0
10579
- ]
10580
- };
10581
- const usePromotions = (query2, options) => {
10582
- const { data, ...rest } = reactQuery.useQuery({
10583
- queryKey: promotionsQueryKeys.list(query2),
10584
- queryFn: async () => sdk.admin.promotion.list(query2),
10585
- ...options
10586
- });
10587
- return { ...data, ...rest };
10588
- };
10589
- const Promotions = () => {
10637
+ const InlineTip = React.forwardRef(
10638
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
10639
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10640
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10641
+ "div",
10642
+ {
10643
+ ref,
10644
+ className: ui.clx(
10645
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10646
+ className
10647
+ ),
10648
+ ...props,
10649
+ children: [
10650
+ /* @__PURE__ */ jsxRuntime.jsx(
10651
+ "div",
10652
+ {
10653
+ role: "presentation",
10654
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10655
+ "bg-ui-tag-orange-icon": variant === "warning"
10656
+ })
10657
+ }
10658
+ ),
10659
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
10660
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10661
+ labelValue,
10662
+ ":"
10663
+ ] }),
10664
+ " ",
10665
+ children
10666
+ ] })
10667
+ ]
10668
+ }
10669
+ );
10670
+ }
10671
+ );
10672
+ InlineTip.displayName = "InlineTip";
10673
+ const MetadataFieldSchema = objectType({
10674
+ key: stringType(),
10675
+ disabled: booleanType().optional(),
10676
+ value: anyType()
10677
+ });
10678
+ const MetadataSchema = objectType({
10679
+ metadata: arrayType(MetadataFieldSchema)
10680
+ });
10681
+ const Metadata = () => {
10590
10682
  const { id } = reactRouterDom.useParams();
10591
- const {
10592
- order: preview,
10593
- isError: isPreviewError,
10594
- error: previewError
10595
- } = useOrderPreview(id, void 0);
10596
- useInitiateOrderEdit({ preview });
10597
- const { onCancel } = useCancelOrderEdit({ preview });
10598
- if (isPreviewError) {
10599
- throw previewError;
10683
+ const { order, isPending, isError, error } = useOrder(id, {
10684
+ fields: "metadata"
10685
+ });
10686
+ if (isError) {
10687
+ throw error;
10600
10688
  }
10601
- const isReady = !!preview;
10602
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
10603
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
10604
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
10689
+ const isReady = !isPending && !!order;
10690
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10691
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10692
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
10693
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10694
+ ] }),
10695
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10605
10696
  ] });
10606
10697
  };
10607
- const PromotionForm = ({ preview }) => {
10608
- const { items, shipping_methods } = preview;
10609
- const [isSubmitting, setIsSubmitting] = React.useState(false);
10610
- const [comboboxValue, setComboboxValue] = React.useState("");
10698
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10699
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10700
+ const MetadataForm = ({ orderId, metadata }) => {
10611
10701
  const { handleSuccess } = useRouteModal();
10612
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10613
- const promoIds = getPromotionIds(items, shipping_methods);
10614
- const { promotions, isPending, isError, error } = usePromotions(
10615
- {
10616
- id: promoIds
10617
- },
10618
- {
10619
- enabled: !!promoIds.length
10620
- }
10621
- );
10622
- const comboboxData = useComboboxData({
10623
- queryKey: ["promotions", "combobox", promoIds],
10624
- queryFn: async (params) => {
10625
- return await sdk.admin.promotion.list({
10626
- ...params,
10627
- id: {
10628
- $nin: promoIds
10629
- }
10630
- });
10702
+ const hasUneditableRows = getHasUneditableRows(metadata);
10703
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10704
+ const form = reactHookForm.useForm({
10705
+ defaultValues: {
10706
+ metadata: getDefaultValues(metadata)
10631
10707
  },
10632
- getOptions: (data) => {
10633
- return data.promotions.map((promotion) => ({
10634
- label: promotion.code,
10635
- value: promotion.code
10636
- }));
10637
- }
10708
+ resolver: zod.zodResolver(MetadataSchema)
10638
10709
  });
10639
- const add = async (value) => {
10640
- if (!value) {
10641
- return;
10642
- }
10643
- addPromotions(
10710
+ const handleSubmit = form.handleSubmit(async (data) => {
10711
+ const parsedData = parseValues(data);
10712
+ await mutateAsync(
10644
10713
  {
10645
- promo_codes: [value]
10714
+ metadata: parsedData
10646
10715
  },
10647
10716
  {
10648
- onError: (e) => {
10649
- ui.toast.error(e.message);
10650
- comboboxData.onSearchValueChange("");
10651
- setComboboxValue("");
10652
- },
10653
10717
  onSuccess: () => {
10654
- comboboxData.onSearchValueChange("");
10655
- setComboboxValue("");
10718
+ ui.toast.success("Metadata updated");
10719
+ handleSuccess();
10720
+ },
10721
+ onError: (error) => {
10722
+ ui.toast.error(error.message);
10656
10723
  }
10657
10724
  }
10658
10725
  );
10659
- };
10660
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10661
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
10662
- const onSubmit = async () => {
10663
- setIsSubmitting(true);
10664
- let requestSucceeded = false;
10665
- await requestOrderEdit(void 0, {
10666
- onError: (e) => {
10667
- ui.toast.error(e.message);
10668
- },
10669
- onSuccess: () => {
10670
- requestSucceeded = true;
10671
- }
10672
- });
10673
- if (!requestSucceeded) {
10674
- setIsSubmitting(false);
10675
- return;
10726
+ });
10727
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
10728
+ control: form.control,
10729
+ name: "metadata"
10730
+ });
10731
+ function deleteRow(index) {
10732
+ remove(index);
10733
+ if (fields.length === 1) {
10734
+ insert(0, {
10735
+ key: "",
10736
+ value: "",
10737
+ disabled: false
10738
+ });
10676
10739
  }
10677
- await confirmOrderEdit(void 0, {
10678
- onError: (e) => {
10679
- ui.toast.error(e.message);
10680
- },
10681
- onSuccess: () => {
10682
- handleSuccess();
10683
- },
10684
- onSettled: () => {
10685
- setIsSubmitting(false);
10686
- }
10740
+ }
10741
+ function insertRow(index, position) {
10742
+ insert(index + (position === "above" ? 0 : 1), {
10743
+ key: "",
10744
+ value: "",
10745
+ disabled: false
10687
10746
  });
10688
- };
10689
- if (isError) {
10690
- throw error;
10691
10747
  }
10692
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
10693
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
10694
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
10695
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10696
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
10697
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
10748
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10749
+ KeyboundForm,
10750
+ {
10751
+ onSubmit: handleSubmit,
10752
+ className: "flex flex-1 flex-col overflow-hidden",
10753
+ children: [
10754
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10755
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10756
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10757
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10758
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
10759
+ ] }),
10760
+ fields.map((field, index) => {
10761
+ const isDisabled = field.disabled || false;
10762
+ let placeholder = "-";
10763
+ if (typeof field.value === "object") {
10764
+ placeholder = "{ ... }";
10765
+ }
10766
+ if (Array.isArray(field.value)) {
10767
+ placeholder = "[ ... ]";
10768
+ }
10769
+ return /* @__PURE__ */ jsxRuntime.jsx(
10770
+ ConditionalTooltip,
10771
+ {
10772
+ showTooltip: isDisabled,
10773
+ content: "This row is disabled because it contains non-primitive data.",
10774
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
10775
+ /* @__PURE__ */ jsxRuntime.jsxs(
10776
+ "div",
10777
+ {
10778
+ className: ui.clx("grid grid-cols-2 divide-x", {
10779
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
10780
+ }),
10781
+ children: [
10782
+ /* @__PURE__ */ jsxRuntime.jsx(
10783
+ Form$2.Field,
10784
+ {
10785
+ control: form.control,
10786
+ name: `metadata.${index}.key`,
10787
+ render: ({ field: field2 }) => {
10788
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10789
+ GridInput,
10790
+ {
10791
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10792
+ ...field2,
10793
+ disabled: isDisabled,
10794
+ placeholder: "Key"
10795
+ }
10796
+ ) }) });
10797
+ }
10798
+ }
10799
+ ),
10800
+ /* @__PURE__ */ jsxRuntime.jsx(
10801
+ Form$2.Field,
10802
+ {
10803
+ control: form.control,
10804
+ name: `metadata.${index}.value`,
10805
+ render: ({ field: { value, ...field2 } }) => {
10806
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10807
+ GridInput,
10808
+ {
10809
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
10810
+ ...field2,
10811
+ value: isDisabled ? placeholder : value,
10812
+ disabled: isDisabled,
10813
+ placeholder: "Value"
10814
+ }
10815
+ ) }) });
10816
+ }
10817
+ }
10818
+ )
10819
+ ]
10820
+ }
10821
+ ),
10822
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10823
+ /* @__PURE__ */ jsxRuntime.jsx(
10824
+ ui.DropdownMenu.Trigger,
10825
+ {
10826
+ className: ui.clx(
10827
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10828
+ {
10829
+ hidden: isDisabled
10830
+ }
10831
+ ),
10832
+ disabled: isDisabled,
10833
+ asChild: true,
10834
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
10835
+ }
10836
+ ),
10837
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10838
+ /* @__PURE__ */ jsxRuntime.jsxs(
10839
+ ui.DropdownMenu.Item,
10840
+ {
10841
+ className: "gap-x-2",
10842
+ onClick: () => insertRow(index, "above"),
10843
+ children: [
10844
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
10845
+ "Insert row above"
10846
+ ]
10847
+ }
10848
+ ),
10849
+ /* @__PURE__ */ jsxRuntime.jsxs(
10850
+ ui.DropdownMenu.Item,
10851
+ {
10852
+ className: "gap-x-2",
10853
+ onClick: () => insertRow(index, "below"),
10854
+ children: [
10855
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
10856
+ "Insert row below"
10857
+ ]
10858
+ }
10859
+ ),
10860
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
10861
+ /* @__PURE__ */ jsxRuntime.jsxs(
10862
+ ui.DropdownMenu.Item,
10863
+ {
10864
+ className: "gap-x-2",
10865
+ onClick: () => deleteRow(index),
10866
+ children: [
10867
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
10868
+ "Delete row"
10869
+ ]
10870
+ }
10871
+ )
10872
+ ] })
10873
+ ] })
10874
+ ] })
10875
+ },
10876
+ field.id
10877
+ );
10878
+ })
10879
+ ] }),
10880
+ hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
10698
10881
  ] }),
10699
- /* @__PURE__ */ jsxRuntime.jsx(
10700
- Combobox,
10701
- {
10702
- id: "promotion-combobox",
10703
- "aria-describedby": "promotion-combobox-hint",
10704
- isFetchingNextPage: comboboxData.isFetchingNextPage,
10705
- fetchNextPage: comboboxData.fetchNextPage,
10706
- options: comboboxData.options,
10707
- onSearchValueChange: comboboxData.onSearchValueChange,
10708
- searchValue: comboboxData.searchValue,
10709
- disabled: comboboxData.disabled || isAddingPromotions,
10710
- onChange: add,
10711
- value: comboboxValue
10712
- }
10713
- )
10714
- ] }),
10715
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10716
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
10717
- PromotionItem,
10718
- {
10719
- promotion,
10720
- orderId: preview.id,
10721
- isLoading: isPending
10722
- },
10723
- promotion.id
10724
- )) })
10725
- ] }) }),
10726
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10727
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10728
- /* @__PURE__ */ jsxRuntime.jsx(
10729
- ui.Button,
10730
- {
10731
- size: "small",
10732
- type: "submit",
10733
- isLoading: isSubmitting || isAddingPromotions,
10734
- children: "Save"
10735
- }
10882
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10883
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10884
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10885
+ ] }) })
10886
+ ]
10887
+ }
10888
+ ) });
10889
+ };
10890
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
10891
+ return /* @__PURE__ */ jsxRuntime.jsx(
10892
+ "input",
10893
+ {
10894
+ ref,
10895
+ ...props,
10896
+ autoComplete: "off",
10897
+ className: ui.clx(
10898
+ "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
10899
+ className
10736
10900
  )
10901
+ }
10902
+ );
10903
+ });
10904
+ GridInput.displayName = "MetadataForm.GridInput";
10905
+ const PlaceholderInner = () => {
10906
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10907
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10908
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10909
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
10910
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
10737
10911
  ] }) })
10738
10912
  ] });
10739
10913
  };
10740
- const PromotionItem = ({
10741
- promotion,
10742
- orderId,
10743
- isLoading
10744
- }) => {
10745
- var _a;
10746
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
10747
- const onRemove = async () => {
10748
- removePromotions(
10749
- {
10750
- promo_codes: [promotion.code]
10751
- },
10914
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
10915
+ function getDefaultValues(metadata) {
10916
+ if (!metadata || !Object.keys(metadata).length) {
10917
+ return [
10752
10918
  {
10753
- onError: (e) => {
10754
- ui.toast.error(e.message);
10755
- }
10919
+ key: "",
10920
+ value: "",
10921
+ disabled: false
10756
10922
  }
10757
- );
10758
- };
10759
- const displayValue = getDisplayValue(promotion);
10760
- return /* @__PURE__ */ jsxRuntime.jsxs(
10761
- "div",
10762
- {
10763
- className: ui.clx(
10764
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
10765
- {
10766
- "animate-pulse": isLoading
10767
- }
10768
- ),
10769
- children: [
10770
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10771
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
10772
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
10773
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
10774
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
10775
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
10776
- ] }),
10777
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
10778
- ] })
10779
- ] }),
10780
- /* @__PURE__ */ jsxRuntime.jsx(
10781
- ui.IconButton,
10782
- {
10783
- size: "small",
10784
- type: "button",
10785
- variant: "transparent",
10786
- onClick: onRemove,
10787
- isLoading: isPending || isLoading,
10788
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
10789
- }
10790
- )
10791
- ]
10792
- },
10793
- promotion.id
10794
- );
10795
- };
10796
- function getDisplayValue(promotion) {
10797
- var _a, _b, _c, _d;
10798
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
10799
- if (!value) {
10800
- return null;
10923
+ ];
10801
10924
  }
10802
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
10803
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
10804
- if (!currency) {
10805
- return null;
10925
+ return Object.entries(metadata).map(([key, value]) => {
10926
+ if (!EDITABLE_TYPES.includes(typeof value)) {
10927
+ return {
10928
+ key,
10929
+ value,
10930
+ disabled: true
10931
+ };
10806
10932
  }
10807
- return getLocaleAmount(value, currency);
10808
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
10809
- return formatPercentage(value);
10810
- }
10811
- return null;
10933
+ let stringValue = value;
10934
+ if (typeof value !== "string") {
10935
+ stringValue = JSON.stringify(value);
10936
+ }
10937
+ return {
10938
+ key,
10939
+ value: stringValue,
10940
+ original_key: key
10941
+ };
10942
+ });
10812
10943
  }
10813
- const formatter = new Intl.NumberFormat([], {
10814
- style: "percent",
10815
- minimumFractionDigits: 2
10816
- });
10817
- const formatPercentage = (value, isPercentageValue = false) => {
10818
- let val = value || 0;
10819
- if (!isPercentageValue) {
10820
- val = val / 100;
10944
+ function parseValues(values) {
10945
+ const metadata = values.metadata;
10946
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10947
+ if (isEmpty) {
10948
+ return null;
10821
10949
  }
10822
- return formatter.format(val);
10823
- };
10824
- function getPromotionIds(items, shippingMethods) {
10825
- const promotionIds = /* @__PURE__ */ new Set();
10826
- for (const item of items) {
10827
- if (item.adjustments) {
10828
- for (const adjustment of item.adjustments) {
10829
- if (adjustment.promotion_id) {
10830
- promotionIds.add(adjustment.promotion_id);
10831
- }
10832
- }
10950
+ const update = {};
10951
+ metadata.forEach((field) => {
10952
+ let key = field.key;
10953
+ let value = field.value;
10954
+ const disabled = field.disabled;
10955
+ if (!key || !value) {
10956
+ return;
10833
10957
  }
10834
- }
10835
- for (const shippingMethod of shippingMethods) {
10836
- if (shippingMethod.adjustments) {
10837
- for (const adjustment of shippingMethod.adjustments) {
10838
- if (adjustment.promotion_id) {
10839
- promotionIds.add(adjustment.promotion_id);
10840
- }
10958
+ if (disabled) {
10959
+ update[key] = value;
10960
+ return;
10961
+ }
10962
+ key = key.trim();
10963
+ value = value.trim();
10964
+ if (value === "true") {
10965
+ update[key] = true;
10966
+ } else if (value === "false") {
10967
+ update[key] = false;
10968
+ } else {
10969
+ const parsedNumber = parseFloat(value);
10970
+ if (!isNaN(parsedNumber)) {
10971
+ update[key] = parsedNumber;
10972
+ } else {
10973
+ update[key] = value;
10841
10974
  }
10842
10975
  }
10843
- }
10844
- return Array.from(promotionIds);
10976
+ });
10977
+ return update;
10845
10978
  }
10846
- const InlineTip = React.forwardRef(
10847
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10848
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10849
- return /* @__PURE__ */ jsxRuntime.jsxs(
10850
- "div",
10851
- {
10852
- ref,
10853
- className: ui.clx(
10854
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10855
- className
10856
- ),
10857
- ...props,
10858
- children: [
10859
- /* @__PURE__ */ jsxRuntime.jsx(
10860
- "div",
10861
- {
10862
- role: "presentation",
10863
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10864
- "bg-ui-tag-orange-icon": variant === "warning"
10865
- })
10866
- }
10867
- ),
10868
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
10869
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10870
- labelValue,
10871
- ":"
10872
- ] }),
10873
- " ",
10874
- children
10875
- ] })
10876
- ]
10877
- }
10878
- );
10979
+ function getHasUneditableRows(metadata) {
10980
+ if (!metadata) {
10981
+ return false;
10879
10982
  }
10880
- );
10881
- InlineTip.displayName = "InlineTip";
10882
- const MetadataFieldSchema = objectType({
10883
- key: stringType(),
10884
- disabled: booleanType().optional(),
10885
- value: anyType()
10886
- });
10887
- const MetadataSchema = objectType({
10888
- metadata: arrayType(MetadataFieldSchema)
10889
- });
10890
- const Metadata = () => {
10891
- const { id } = reactRouterDom.useParams();
10892
- const { order, isPending, isError, error } = useOrder(id, {
10893
- fields: "metadata"
10983
+ return Object.values(metadata).some(
10984
+ (value) => !EDITABLE_TYPES.includes(typeof value)
10985
+ );
10986
+ }
10987
+ const PROMOTION_QUERY_KEY = "promotions";
10988
+ const promotionsQueryKeys = {
10989
+ list: (query2) => [
10990
+ PROMOTION_QUERY_KEY,
10991
+ query2 ? query2 : void 0
10992
+ ],
10993
+ detail: (id, query2) => [
10994
+ PROMOTION_QUERY_KEY,
10995
+ id,
10996
+ query2 ? query2 : void 0
10997
+ ]
10998
+ };
10999
+ const usePromotions = (query2, options) => {
11000
+ const { data, ...rest } = reactQuery.useQuery({
11001
+ queryKey: promotionsQueryKeys.list(query2),
11002
+ queryFn: async () => sdk.admin.promotion.list(query2),
11003
+ ...options
10894
11004
  });
10895
- if (isError) {
10896
- throw error;
11005
+ return { ...data, ...rest };
11006
+ };
11007
+ const Promotions = () => {
11008
+ const { id } = reactRouterDom.useParams();
11009
+ const {
11010
+ order: preview,
11011
+ isError: isPreviewError,
11012
+ error: previewError
11013
+ } = useOrderPreview(id, void 0);
11014
+ useInitiateOrderEdit({ preview });
11015
+ const { onCancel } = useCancelOrderEdit({ preview });
11016
+ if (isPreviewError) {
11017
+ throw previewError;
10897
11018
  }
10898
- const isReady = !isPending && !!order;
10899
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10900
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10901
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
10902
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10903
- ] }),
10904
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11019
+ const isReady = !!preview;
11020
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11021
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11022
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
10905
11023
  ] });
10906
11024
  };
10907
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10908
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10909
- const MetadataForm = ({ orderId, metadata }) => {
11025
+ const PromotionForm = ({ preview }) => {
11026
+ const { items, shipping_methods } = preview;
11027
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11028
+ const [comboboxValue, setComboboxValue] = React.useState("");
10910
11029
  const { handleSuccess } = useRouteModal();
10911
- const hasUneditableRows = getHasUneditableRows(metadata);
10912
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10913
- const form = reactHookForm.useForm({
10914
- defaultValues: {
10915
- metadata: getDefaultValues(metadata)
11030
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11031
+ const promoIds = getPromotionIds(items, shipping_methods);
11032
+ const { promotions, isPending, isError, error } = usePromotions(
11033
+ {
11034
+ id: promoIds
10916
11035
  },
10917
- resolver: zod.zodResolver(MetadataSchema)
11036
+ {
11037
+ enabled: !!promoIds.length
11038
+ }
11039
+ );
11040
+ const comboboxData = useComboboxData({
11041
+ queryKey: ["promotions", "combobox", promoIds],
11042
+ queryFn: async (params) => {
11043
+ return await sdk.admin.promotion.list({
11044
+ ...params,
11045
+ id: {
11046
+ $nin: promoIds
11047
+ }
11048
+ });
11049
+ },
11050
+ getOptions: (data) => {
11051
+ return data.promotions.map((promotion) => ({
11052
+ label: promotion.code,
11053
+ value: promotion.code
11054
+ }));
11055
+ }
10918
11056
  });
10919
- const handleSubmit = form.handleSubmit(async (data) => {
10920
- const parsedData = parseValues(data);
10921
- await mutateAsync(
11057
+ const add = async (value) => {
11058
+ if (!value) {
11059
+ return;
11060
+ }
11061
+ addPromotions(
10922
11062
  {
10923
- metadata: parsedData
11063
+ promo_codes: [value]
10924
11064
  },
10925
11065
  {
10926
- onSuccess: () => {
10927
- ui.toast.success("Metadata updated");
10928
- handleSuccess();
11066
+ onError: (e) => {
11067
+ ui.toast.error(e.message);
11068
+ comboboxData.onSearchValueChange("");
11069
+ setComboboxValue("");
10929
11070
  },
10930
- onError: (error) => {
10931
- ui.toast.error(error.message);
11071
+ onSuccess: () => {
11072
+ comboboxData.onSearchValueChange("");
11073
+ setComboboxValue("");
10932
11074
  }
10933
11075
  }
10934
11076
  );
10935
- });
10936
- const { fields, insert, remove } = reactHookForm.useFieldArray({
10937
- control: form.control,
10938
- name: "metadata"
10939
- });
10940
- function deleteRow(index) {
10941
- remove(index);
10942
- if (fields.length === 1) {
10943
- insert(0, {
10944
- key: "",
10945
- value: "",
10946
- disabled: false
10947
- });
11077
+ };
11078
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11079
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11080
+ const onSubmit = async () => {
11081
+ setIsSubmitting(true);
11082
+ let requestSucceeded = false;
11083
+ await requestOrderEdit(void 0, {
11084
+ onError: (e) => {
11085
+ ui.toast.error(e.message);
11086
+ },
11087
+ onSuccess: () => {
11088
+ requestSucceeded = true;
11089
+ }
11090
+ });
11091
+ if (!requestSucceeded) {
11092
+ setIsSubmitting(false);
11093
+ return;
10948
11094
  }
10949
- }
10950
- function insertRow(index, position) {
10951
- insert(index + (position === "above" ? 0 : 1), {
10952
- key: "",
10953
- value: "",
10954
- disabled: false
11095
+ await confirmOrderEdit(void 0, {
11096
+ onError: (e) => {
11097
+ ui.toast.error(e.message);
11098
+ },
11099
+ onSuccess: () => {
11100
+ handleSuccess();
11101
+ },
11102
+ onSettled: () => {
11103
+ setIsSubmitting(false);
11104
+ }
10955
11105
  });
11106
+ };
11107
+ if (isError) {
11108
+ throw error;
10956
11109
  }
10957
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10958
- KeyboundForm,
11110
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11111
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11112
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11113
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11114
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11115
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11116
+ ] }),
11117
+ /* @__PURE__ */ jsxRuntime.jsx(
11118
+ Combobox,
11119
+ {
11120
+ id: "promotion-combobox",
11121
+ "aria-describedby": "promotion-combobox-hint",
11122
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11123
+ fetchNextPage: comboboxData.fetchNextPage,
11124
+ options: comboboxData.options,
11125
+ onSearchValueChange: comboboxData.onSearchValueChange,
11126
+ searchValue: comboboxData.searchValue,
11127
+ disabled: comboboxData.disabled || isAddingPromotions,
11128
+ onChange: add,
11129
+ value: comboboxValue
11130
+ }
11131
+ )
11132
+ ] }),
11133
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11134
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11135
+ PromotionItem,
11136
+ {
11137
+ promotion,
11138
+ orderId: preview.id,
11139
+ isLoading: isPending
11140
+ },
11141
+ promotion.id
11142
+ )) })
11143
+ ] }) }),
11144
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11145
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11146
+ /* @__PURE__ */ jsxRuntime.jsx(
11147
+ ui.Button,
11148
+ {
11149
+ size: "small",
11150
+ type: "submit",
11151
+ isLoading: isSubmitting || isAddingPromotions,
11152
+ children: "Save"
11153
+ }
11154
+ )
11155
+ ] }) })
11156
+ ] });
11157
+ };
11158
+ const PromotionItem = ({
11159
+ promotion,
11160
+ orderId,
11161
+ isLoading
11162
+ }) => {
11163
+ var _a;
11164
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11165
+ const onRemove = async () => {
11166
+ removePromotions(
11167
+ {
11168
+ promo_codes: [promotion.code]
11169
+ },
11170
+ {
11171
+ onError: (e) => {
11172
+ ui.toast.error(e.message);
11173
+ }
11174
+ }
11175
+ );
11176
+ };
11177
+ const displayValue = getDisplayValue(promotion);
11178
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11179
+ "div",
10959
11180
  {
10960
- onSubmit: handleSubmit,
10961
- className: "flex flex-1 flex-col overflow-hidden",
11181
+ className: ui.clx(
11182
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11183
+ {
11184
+ "animate-pulse": isLoading
11185
+ }
11186
+ ),
10962
11187
  children: [
10963
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10964
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10965
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10966
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10967
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
11188
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11189
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11190
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11191
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11192
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11193
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
10968
11194
  ] }),
10969
- fields.map((field, index) => {
10970
- const isDisabled = field.disabled || false;
10971
- let placeholder = "-";
10972
- if (typeof field.value === "object") {
10973
- placeholder = "{ ... }";
10974
- }
10975
- if (Array.isArray(field.value)) {
10976
- placeholder = "[ ... ]";
10977
- }
10978
- return /* @__PURE__ */ jsxRuntime.jsx(
10979
- ConditionalTooltip,
10980
- {
10981
- showTooltip: isDisabled,
10982
- content: "This row is disabled because it contains non-primitive data.",
10983
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
10984
- /* @__PURE__ */ jsxRuntime.jsxs(
10985
- "div",
10986
- {
10987
- className: ui.clx("grid grid-cols-2 divide-x", {
10988
- "overflow-hidden rounded-b-lg": index === fields.length - 1
10989
- }),
10990
- children: [
10991
- /* @__PURE__ */ jsxRuntime.jsx(
10992
- Form$2.Field,
10993
- {
10994
- control: form.control,
10995
- name: `metadata.${index}.key`,
10996
- render: ({ field: field2 }) => {
10997
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10998
- GridInput,
10999
- {
11000
- "aria-labelledby": METADATA_KEY_LABEL_ID,
11001
- ...field2,
11002
- disabled: isDisabled,
11003
- placeholder: "Key"
11004
- }
11005
- ) }) });
11006
- }
11007
- }
11008
- ),
11009
- /* @__PURE__ */ jsxRuntime.jsx(
11010
- Form$2.Field,
11011
- {
11012
- control: form.control,
11013
- name: `metadata.${index}.value`,
11014
- render: ({ field: { value, ...field2 } }) => {
11015
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11016
- GridInput,
11017
- {
11018
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
11019
- ...field2,
11020
- value: isDisabled ? placeholder : value,
11021
- disabled: isDisabled,
11022
- placeholder: "Value"
11023
- }
11024
- ) }) });
11025
- }
11026
- }
11027
- )
11028
- ]
11029
- }
11030
- ),
11031
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11032
- /* @__PURE__ */ jsxRuntime.jsx(
11033
- ui.DropdownMenu.Trigger,
11034
- {
11035
- className: ui.clx(
11036
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11037
- {
11038
- hidden: isDisabled
11039
- }
11040
- ),
11041
- disabled: isDisabled,
11042
- asChild: true,
11043
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11044
- }
11045
- ),
11046
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11047
- /* @__PURE__ */ jsxRuntime.jsxs(
11048
- ui.DropdownMenu.Item,
11049
- {
11050
- className: "gap-x-2",
11051
- onClick: () => insertRow(index, "above"),
11052
- children: [
11053
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11054
- "Insert row above"
11055
- ]
11056
- }
11057
- ),
11058
- /* @__PURE__ */ jsxRuntime.jsxs(
11059
- ui.DropdownMenu.Item,
11060
- {
11061
- className: "gap-x-2",
11062
- onClick: () => insertRow(index, "below"),
11063
- children: [
11064
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11065
- "Insert row below"
11066
- ]
11067
- }
11068
- ),
11069
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11070
- /* @__PURE__ */ jsxRuntime.jsxs(
11071
- ui.DropdownMenu.Item,
11072
- {
11073
- className: "gap-x-2",
11074
- onClick: () => deleteRow(index),
11075
- children: [
11076
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11077
- "Delete row"
11078
- ]
11079
- }
11080
- )
11081
- ] })
11082
- ] })
11083
- ] })
11084
- },
11085
- field.id
11086
- );
11087
- })
11088
- ] }),
11089
- hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
11195
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11196
+ ] })
11090
11197
  ] }),
11091
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11092
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11093
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11094
- ] }) })
11198
+ /* @__PURE__ */ jsxRuntime.jsx(
11199
+ ui.IconButton,
11200
+ {
11201
+ size: "small",
11202
+ type: "button",
11203
+ variant: "transparent",
11204
+ onClick: onRemove,
11205
+ isLoading: isPending || isLoading,
11206
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11207
+ }
11208
+ )
11095
11209
  ]
11096
- }
11097
- ) });
11098
- };
11099
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11100
- return /* @__PURE__ */ jsxRuntime.jsx(
11101
- "input",
11102
- {
11103
- ref,
11104
- ...props,
11105
- autoComplete: "off",
11106
- className: ui.clx(
11107
- "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",
11108
- className
11109
- )
11110
- }
11210
+ },
11211
+ promotion.id
11111
11212
  );
11112
- });
11113
- GridInput.displayName = "MetadataForm.GridInput";
11114
- const PlaceholderInner = () => {
11115
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11116
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11117
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11118
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11119
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11120
- ] }) })
11121
- ] });
11122
11213
  };
11123
- const EDITABLE_TYPES = ["string", "number", "boolean"];
11124
- function getDefaultValues(metadata) {
11125
- if (!metadata || !Object.keys(metadata).length) {
11126
- return [
11127
- {
11128
- key: "",
11129
- value: "",
11130
- disabled: false
11131
- }
11132
- ];
11214
+ function getDisplayValue(promotion) {
11215
+ var _a, _b, _c, _d;
11216
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11217
+ if (!value) {
11218
+ return null;
11133
11219
  }
11134
- return Object.entries(metadata).map(([key, value]) => {
11135
- if (!EDITABLE_TYPES.includes(typeof value)) {
11136
- return {
11137
- key,
11138
- value,
11139
- disabled: true
11140
- };
11141
- }
11142
- let stringValue = value;
11143
- if (typeof value !== "string") {
11144
- stringValue = JSON.stringify(value);
11220
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11221
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11222
+ if (!currency) {
11223
+ return null;
11145
11224
  }
11146
- return {
11147
- key,
11148
- value: stringValue,
11149
- original_key: key
11150
- };
11151
- });
11225
+ return getLocaleAmount(value, currency);
11226
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11227
+ return formatPercentage(value);
11228
+ }
11229
+ return null;
11152
11230
  }
11153
- function parseValues(values) {
11154
- const metadata = values.metadata;
11155
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11156
- if (isEmpty) {
11157
- return null;
11231
+ const formatter = new Intl.NumberFormat([], {
11232
+ style: "percent",
11233
+ minimumFractionDigits: 2
11234
+ });
11235
+ const formatPercentage = (value, isPercentageValue = false) => {
11236
+ let val = value || 0;
11237
+ if (!isPercentageValue) {
11238
+ val = val / 100;
11158
11239
  }
11159
- const update = {};
11160
- metadata.forEach((field) => {
11161
- let key = field.key;
11162
- let value = field.value;
11163
- const disabled = field.disabled;
11164
- if (!key || !value) {
11165
- return;
11166
- }
11167
- if (disabled) {
11168
- update[key] = value;
11169
- return;
11240
+ return formatter.format(val);
11241
+ };
11242
+ function getPromotionIds(items, shippingMethods) {
11243
+ const promotionIds = /* @__PURE__ */ new Set();
11244
+ for (const item of items) {
11245
+ if (item.adjustments) {
11246
+ for (const adjustment of item.adjustments) {
11247
+ if (adjustment.promotion_id) {
11248
+ promotionIds.add(adjustment.promotion_id);
11249
+ }
11250
+ }
11170
11251
  }
11171
- key = key.trim();
11172
- value = value.trim();
11173
- if (value === "true") {
11174
- update[key] = true;
11175
- } else if (value === "false") {
11176
- update[key] = false;
11177
- } else {
11178
- const parsedNumber = parseFloat(value);
11179
- if (!isNaN(parsedNumber)) {
11180
- update[key] = parsedNumber;
11181
- } else {
11182
- update[key] = value;
11252
+ }
11253
+ for (const shippingMethod of shippingMethods) {
11254
+ if (shippingMethod.adjustments) {
11255
+ for (const adjustment of shippingMethod.adjustments) {
11256
+ if (adjustment.promotion_id) {
11257
+ promotionIds.add(adjustment.promotion_id);
11258
+ }
11183
11259
  }
11184
11260
  }
11185
- });
11186
- return update;
11187
- }
11188
- function getHasUneditableRows(metadata) {
11189
- if (!metadata) {
11190
- return false;
11191
11261
  }
11192
- return Object.values(metadata).some(
11193
- (value) => !EDITABLE_TYPES.includes(typeof value)
11194
- );
11262
+ return Array.from(promotionIds);
11195
11263
  }
11196
11264
  const SalesChannel = () => {
11197
11265
  const { id } = reactRouterDom.useParams();
@@ -11221,7 +11289,7 @@ const SalesChannelForm = ({ order }) => {
11221
11289
  defaultValues: {
11222
11290
  sales_channel_id: order.sales_channel_id || ""
11223
11291
  },
11224
- resolver: zod.zodResolver(schema$4)
11292
+ resolver: zod.zodResolver(schema$3)
11225
11293
  });
11226
11294
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11227
11295
  const { handleSuccess } = useRouteModal();
@@ -11296,78 +11364,281 @@ const SalesChannelField = ({ control, order }) => {
11296
11364
  }
11297
11365
  );
11298
11366
  };
11299
- const schema$4 = objectType({
11367
+ const schema$3 = objectType({
11300
11368
  sales_channel_id: stringType().min(1)
11301
11369
  });
11302
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11303
- const Shipping = () => {
11304
- var _a;
11370
+ const ShippingAddress = () => {
11305
11371
  const { id } = reactRouterDom.useParams();
11306
11372
  const { order, isPending, isError, error } = useOrder(id, {
11307
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11373
+ fields: "+shipping_address"
11308
11374
  });
11309
- const {
11310
- order: preview,
11311
- isPending: isPreviewPending,
11312
- isError: isPreviewError,
11313
- error: previewError
11314
- } = useOrderPreview(id);
11315
- useInitiateOrderEdit({ preview });
11316
- const { onCancel } = useCancelOrderEdit({ preview });
11317
11375
  if (isError) {
11318
11376
  throw error;
11319
11377
  }
11320
- if (isPreviewError) {
11321
- throw previewError;
11322
- }
11323
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11324
- const isReady = preview && !isPreviewPending && order && !isPending;
11325
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11326
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11327
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11328
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11329
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11330
- ] }) }) }),
11331
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11332
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11333
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11334
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11335
- ] }) });
11378
+ const isReady = !isPending && !!order;
11379
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11380
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11381
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11382
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11383
+ ] }),
11384
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11385
+ ] });
11336
11386
  };
11337
- const ShippingForm = ({ preview, order }) => {
11338
- var _a;
11339
- const { setIsOpen } = useStackedModal();
11340
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11341
- const [data, setData] = React.useState(null);
11342
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11343
- const { shipping_options } = useShippingOptions(
11344
- {
11345
- id: appliedShippingOptionIds,
11346
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11387
+ const ShippingAddressForm = ({ order }) => {
11388
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11389
+ const form = reactHookForm.useForm({
11390
+ defaultValues: {
11391
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11392
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11393
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11394
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11395
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11396
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11397
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11398
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11399
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11400
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11347
11401
  },
11348
- {
11349
- enabled: appliedShippingOptionIds.length > 0
11350
- }
11351
- );
11352
- const uniqueShippingProfiles = React.useMemo(() => {
11353
- const profiles = /* @__PURE__ */ new Map();
11354
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11355
- profiles.set(profile.id, profile);
11356
- });
11357
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11358
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11359
- });
11360
- return Array.from(profiles.values());
11361
- }, [order.items, shipping_options]);
11402
+ resolver: zod.zodResolver(schema$2)
11403
+ });
11404
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11362
11405
  const { handleSuccess } = useRouteModal();
11363
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11364
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11365
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11366
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11367
- const onSubmit = async () => {
11368
- setIsSubmitting(true);
11369
- let requestSucceeded = false;
11370
- await requestOrderEdit(void 0, {
11406
+ const onSubmit = form.handleSubmit(async (data) => {
11407
+ await mutateAsync(
11408
+ {
11409
+ shipping_address: {
11410
+ first_name: data.first_name,
11411
+ last_name: data.last_name,
11412
+ company: data.company,
11413
+ address_1: data.address_1,
11414
+ address_2: data.address_2,
11415
+ city: data.city,
11416
+ province: data.province,
11417
+ country_code: data.country_code,
11418
+ postal_code: data.postal_code,
11419
+ phone: data.phone
11420
+ }
11421
+ },
11422
+ {
11423
+ onSuccess: () => {
11424
+ handleSuccess();
11425
+ },
11426
+ onError: (error) => {
11427
+ ui.toast.error(error.message);
11428
+ }
11429
+ }
11430
+ );
11431
+ });
11432
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11433
+ KeyboundForm,
11434
+ {
11435
+ className: "flex flex-1 flex-col overflow-hidden",
11436
+ onSubmit,
11437
+ children: [
11438
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
11439
+ /* @__PURE__ */ jsxRuntime.jsx(
11440
+ Form$2.Field,
11441
+ {
11442
+ control: form.control,
11443
+ name: "country_code",
11444
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11445
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11446
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11447
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11448
+ ] })
11449
+ }
11450
+ ),
11451
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11452
+ /* @__PURE__ */ jsxRuntime.jsx(
11453
+ Form$2.Field,
11454
+ {
11455
+ control: form.control,
11456
+ name: "first_name",
11457
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11458
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11459
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11460
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11461
+ ] })
11462
+ }
11463
+ ),
11464
+ /* @__PURE__ */ jsxRuntime.jsx(
11465
+ Form$2.Field,
11466
+ {
11467
+ control: form.control,
11468
+ name: "last_name",
11469
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11470
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11471
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11472
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11473
+ ] })
11474
+ }
11475
+ )
11476
+ ] }),
11477
+ /* @__PURE__ */ jsxRuntime.jsx(
11478
+ Form$2.Field,
11479
+ {
11480
+ control: form.control,
11481
+ name: "company",
11482
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11483
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11484
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11485
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11486
+ ] })
11487
+ }
11488
+ ),
11489
+ /* @__PURE__ */ jsxRuntime.jsx(
11490
+ Form$2.Field,
11491
+ {
11492
+ control: form.control,
11493
+ name: "address_1",
11494
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11495
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11496
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11497
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11498
+ ] })
11499
+ }
11500
+ ),
11501
+ /* @__PURE__ */ jsxRuntime.jsx(
11502
+ Form$2.Field,
11503
+ {
11504
+ control: form.control,
11505
+ name: "address_2",
11506
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11507
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11508
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11509
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11510
+ ] })
11511
+ }
11512
+ ),
11513
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11514
+ /* @__PURE__ */ jsxRuntime.jsx(
11515
+ Form$2.Field,
11516
+ {
11517
+ control: form.control,
11518
+ name: "postal_code",
11519
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11520
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11521
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11522
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11523
+ ] })
11524
+ }
11525
+ ),
11526
+ /* @__PURE__ */ jsxRuntime.jsx(
11527
+ Form$2.Field,
11528
+ {
11529
+ control: form.control,
11530
+ name: "city",
11531
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11532
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11533
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11534
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11535
+ ] })
11536
+ }
11537
+ )
11538
+ ] }),
11539
+ /* @__PURE__ */ jsxRuntime.jsx(
11540
+ Form$2.Field,
11541
+ {
11542
+ control: form.control,
11543
+ name: "province",
11544
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11545
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11546
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11547
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11548
+ ] })
11549
+ }
11550
+ ),
11551
+ /* @__PURE__ */ jsxRuntime.jsx(
11552
+ Form$2.Field,
11553
+ {
11554
+ control: form.control,
11555
+ name: "phone",
11556
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11557
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11558
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11559
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11560
+ ] })
11561
+ }
11562
+ )
11563
+ ] }) }),
11564
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11565
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11566
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11567
+ ] }) })
11568
+ ]
11569
+ }
11570
+ ) });
11571
+ };
11572
+ const schema$2 = addressSchema;
11573
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11574
+ const Shipping = () => {
11575
+ var _a;
11576
+ const { id } = reactRouterDom.useParams();
11577
+ const { order, isPending, isError, error } = useOrder(id, {
11578
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11579
+ });
11580
+ const {
11581
+ order: preview,
11582
+ isPending: isPreviewPending,
11583
+ isError: isPreviewError,
11584
+ error: previewError
11585
+ } = useOrderPreview(id);
11586
+ useInitiateOrderEdit({ preview });
11587
+ const { onCancel } = useCancelOrderEdit({ preview });
11588
+ if (isError) {
11589
+ throw error;
11590
+ }
11591
+ if (isPreviewError) {
11592
+ throw previewError;
11593
+ }
11594
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11595
+ const isReady = preview && !isPreviewPending && order && !isPending;
11596
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11597
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11598
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11599
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11600
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11601
+ ] }) }) }),
11602
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11603
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11604
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11605
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11606
+ ] }) });
11607
+ };
11608
+ const ShippingForm = ({ preview, order }) => {
11609
+ var _a;
11610
+ const { setIsOpen } = useStackedModal();
11611
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11612
+ const [data, setData] = React.useState(null);
11613
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11614
+ const { shipping_options } = useShippingOptions(
11615
+ {
11616
+ id: appliedShippingOptionIds,
11617
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11618
+ },
11619
+ {
11620
+ enabled: appliedShippingOptionIds.length > 0
11621
+ }
11622
+ );
11623
+ const uniqueShippingProfiles = React.useMemo(() => {
11624
+ const profiles = /* @__PURE__ */ new Map();
11625
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11626
+ profiles.set(profile.id, profile);
11627
+ });
11628
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11629
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11630
+ });
11631
+ return Array.from(profiles.values());
11632
+ }, [order.items, shipping_options]);
11633
+ const { handleSuccess } = useRouteModal();
11634
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11635
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11636
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11637
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11638
+ const onSubmit = async () => {
11639
+ setIsSubmitting(true);
11640
+ let requestSucceeded = false;
11641
+ await requestOrderEdit(void 0, {
11371
11642
  onError: (e) => {
11372
11643
  ui.toast.error(`Failed to request order edit: ${e.message}`);
11373
11644
  },
@@ -11635,680 +11906,477 @@ const ShippingForm = ({ preview, order }) => {
11635
11906
  ) }),
11636
11907
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11637
11908
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
11638
- ui.Text,
11639
- {
11640
- size: "small",
11641
- leading: "compact",
11642
- className: "text-ui-fg-subtle",
11643
- children: [
11644
- item.quantity,
11645
- "x"
11646
- ]
11647
- }
11648
- ) }),
11649
- /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
11650
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11651
- /* @__PURE__ */ jsxRuntime.jsxs(
11652
- ui.Text,
11653
- {
11654
- size: "small",
11655
- leading: "compact",
11656
- weight: "plus",
11657
- children: [
11658
- (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
11659
- " (",
11660
- (_c2 = item.variant) == null ? void 0 : _c2.title,
11661
- ")"
11662
- ]
11663
- }
11664
- ),
11665
- /* @__PURE__ */ jsxRuntime.jsx(
11666
- ui.Text,
11667
- {
11668
- size: "small",
11669
- leading: "compact",
11670
- className: "text-ui-fg-subtle",
11671
- children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
11672
- }
11673
- )
11674
- ] })
11675
- ] })
11676
- ]
11677
- },
11678
- item.id
11679
- ),
11680
- idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
11681
- ] }, item.id);
11682
- })
11683
- ] })
11684
- ]
11685
- },
11686
- profile.id
11687
- );
11688
- }) })
11689
- ] }) })
11690
- ] }) }),
11691
- /* @__PURE__ */ jsxRuntime.jsx(
11692
- StackedFocusModal,
11693
- {
11694
- id: STACKED_FOCUS_MODAL_ID,
11695
- onOpenChangeCallback: (open) => {
11696
- if (!open) {
11697
- setData(null);
11698
- }
11699
- return open;
11700
- },
11701
- children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
11702
- }
11703
- )
11704
- ] }),
11705
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11706
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11707
- /* @__PURE__ */ jsxRuntime.jsx(
11708
- ui.Button,
11709
- {
11710
- size: "small",
11711
- type: "button",
11712
- isLoading: isSubmitting,
11713
- onClick: onSubmit,
11714
- children: "Save"
11715
- }
11716
- )
11717
- ] }) })
11718
- ] });
11719
- };
11720
- const StackedModalTrigger = ({
11721
- shippingProfileId,
11722
- shippingOption,
11723
- shippingMethod,
11724
- setData,
11725
- children
11726
- }) => {
11727
- const { setIsOpen, getIsOpen } = useStackedModal();
11728
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11729
- const onToggle = () => {
11730
- if (isOpen) {
11731
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11732
- setData(null);
11733
- } else {
11734
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11735
- setData({
11736
- shippingProfileId,
11737
- shippingOption,
11738
- shippingMethod
11739
- });
11740
- }
11741
- };
11742
- return /* @__PURE__ */ jsxRuntime.jsx(
11743
- ui.Button,
11744
- {
11745
- size: "small",
11746
- variant: "secondary",
11747
- onClick: onToggle,
11748
- className: "text-ui-fg-primary shrink-0",
11749
- children
11750
- }
11751
- );
11752
- };
11753
- const ShippingProfileForm = ({
11754
- data,
11755
- order,
11756
- preview
11757
- }) => {
11758
- var _a, _b, _c, _d, _e, _f;
11759
- const { setIsOpen } = useStackedModal();
11760
- const form = reactHookForm.useForm({
11761
- resolver: zod.zodResolver(shippingMethodSchema),
11762
- defaultValues: {
11763
- 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,
11764
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
11765
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
11766
- }
11767
- });
11768
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
11769
- const {
11770
- mutateAsync: updateShippingMethod,
11771
- isPending: isUpdatingShippingMethod
11772
- } = useDraftOrderUpdateShippingMethod(order.id);
11773
- const onSubmit = form.handleSubmit(async (values) => {
11774
- if (lodash.isEqual(values, form.formState.defaultValues)) {
11775
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11776
- return;
11777
- }
11778
- if (data.shippingMethod) {
11779
- await updateShippingMethod(
11780
- {
11781
- method_id: data.shippingMethod.id,
11782
- shipping_option_id: values.shipping_option_id,
11783
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11784
- },
11785
- {
11786
- onError: (e) => {
11787
- ui.toast.error(e.message);
11788
- },
11789
- onSuccess: () => {
11790
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11791
- }
11792
- }
11793
- );
11794
- return;
11795
- }
11796
- await addShippingMethod(
11797
- {
11798
- shipping_option_id: values.shipping_option_id,
11799
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11800
- },
11801
- {
11802
- onError: (e) => {
11803
- ui.toast.error(e.message);
11804
- },
11805
- onSuccess: () => {
11806
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11807
- }
11808
- }
11809
- );
11810
- });
11811
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11812
- KeyboundForm,
11813
- {
11814
- className: "flex h-full flex-col overflow-hidden",
11815
- onSubmit,
11816
- children: [
11817
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
11818
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11819
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11820
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11821
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
11822
- ] }),
11823
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11824
- /* @__PURE__ */ jsxRuntime.jsx(
11825
- LocationField,
11826
- {
11827
- control: form.control,
11828
- setValue: form.setValue
11829
- }
11830
- ),
11831
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11832
- /* @__PURE__ */ jsxRuntime.jsx(
11833
- ShippingOptionField,
11834
- {
11835
- shippingProfileId: data.shippingProfileId,
11836
- preview,
11837
- control: form.control
11838
- }
11839
- ),
11840
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11841
- /* @__PURE__ */ jsxRuntime.jsx(
11842
- CustomAmountField,
11843
- {
11844
- control: form.control,
11845
- currencyCode: order.currency_code
11846
- }
11847
- ),
11848
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11849
- /* @__PURE__ */ jsxRuntime.jsx(
11850
- ItemsPreview,
11851
- {
11852
- order,
11853
- shippingProfileId: data.shippingProfileId
11854
- }
11855
- )
11856
- ] }) }) }),
11857
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11858
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11859
- /* @__PURE__ */ jsxRuntime.jsx(
11860
- ui.Button,
11861
- {
11862
- size: "small",
11863
- type: "submit",
11864
- isLoading: isPending || isUpdatingShippingMethod,
11865
- children: data.shippingMethod ? "Update" : "Add"
11866
- }
11867
- )
11868
- ] }) })
11869
- ]
11870
- }
11871
- ) }) });
11872
- };
11873
- const shippingMethodSchema = objectType({
11874
- location_id: stringType(),
11875
- shipping_option_id: stringType(),
11876
- custom_amount: unionType([numberType(), stringType()]).optional()
11877
- });
11878
- const ItemsPreview = ({ order, shippingProfileId }) => {
11879
- const matches = order.items.filter(
11880
- (item) => {
11881
- var _a, _b, _c;
11882
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
11883
- }
11884
- );
11885
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
11886
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11887
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
11888
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
11889
- ] }) }),
11890
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11891
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
11892
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
11893
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
11894
- ] }),
11895
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
11896
- "div",
11897
- {
11898
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
11899
- children: [
11900
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11901
- /* @__PURE__ */ jsxRuntime.jsx(
11902
- Thumbnail,
11903
- {
11904
- thumbnail: item.thumbnail,
11905
- alt: item.product_title ?? void 0
11906
- }
11907
- ),
11908
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11909
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
11910
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
11911
- /* @__PURE__ */ jsxRuntime.jsxs(
11912
- ui.Text,
11913
- {
11914
- size: "small",
11915
- leading: "compact",
11916
- className: "text-ui-fg-subtle",
11917
- children: [
11918
- "(",
11919
- item.variant_title,
11920
- ")"
11921
- ]
11922
- }
11923
- )
11924
- ] }),
11925
- /* @__PURE__ */ jsxRuntime.jsx(
11926
- ui.Text,
11927
- {
11928
- size: "small",
11929
- leading: "compact",
11930
- className: "text-ui-fg-subtle",
11931
- children: item.variant_sku
11932
- }
11933
- )
11934
- ] })
11935
- ] }),
11936
- /* @__PURE__ */ jsxRuntime.jsxs(
11937
- ui.Text,
11938
- {
11939
- size: "small",
11940
- leading: "compact",
11941
- className: "text-ui-fg-subtle",
11942
- children: [
11943
- item.quantity,
11944
- "x"
11945
- ]
11946
- }
11947
- )
11948
- ]
11949
- },
11950
- item.id
11951
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
11952
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
11953
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
11954
- 'No items found for "',
11955
- query,
11956
- '".'
11957
- ] })
11958
- ] }) })
11959
- ] })
11960
- ] });
11961
- };
11962
- const LocationField = ({ control, setValue }) => {
11963
- const locations = useComboboxData({
11964
- queryKey: ["locations"],
11965
- queryFn: async (params) => {
11966
- return await sdk.admin.stockLocation.list(params);
11967
- },
11968
- getOptions: (data) => {
11969
- return data.stock_locations.map((location) => ({
11970
- label: location.name,
11971
- value: location.id
11972
- }));
11973
- }
11974
- });
11975
- return /* @__PURE__ */ jsxRuntime.jsx(
11976
- Form$2.Field,
11977
- {
11978
- control,
11979
- name: "location_id",
11980
- render: ({ field: { onChange, ...field } }) => {
11981
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11982
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11983
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
11984
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
11985
- ] }),
11986
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11987
- Combobox,
11988
- {
11989
- options: locations.options,
11990
- fetchNextPage: locations.fetchNextPage,
11991
- isFetchingNextPage: locations.isFetchingNextPage,
11992
- searchValue: locations.searchValue,
11993
- onSearchValueChange: locations.onSearchValueChange,
11994
- placeholder: "Select location",
11995
- onChange: (value) => {
11996
- setValue("shipping_option_id", "", {
11997
- shouldDirty: true,
11998
- shouldTouch: true
11999
- });
12000
- onChange(value);
11909
+ ui.Text,
11910
+ {
11911
+ size: "small",
11912
+ leading: "compact",
11913
+ className: "text-ui-fg-subtle",
11914
+ children: [
11915
+ item.quantity,
11916
+ "x"
11917
+ ]
11918
+ }
11919
+ ) }),
11920
+ /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
11921
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11922
+ /* @__PURE__ */ jsxRuntime.jsxs(
11923
+ ui.Text,
11924
+ {
11925
+ size: "small",
11926
+ leading: "compact",
11927
+ weight: "plus",
11928
+ children: [
11929
+ (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
11930
+ " (",
11931
+ (_c2 = item.variant) == null ? void 0 : _c2.title,
11932
+ ")"
11933
+ ]
11934
+ }
11935
+ ),
11936
+ /* @__PURE__ */ jsxRuntime.jsx(
11937
+ ui.Text,
11938
+ {
11939
+ size: "small",
11940
+ leading: "compact",
11941
+ className: "text-ui-fg-subtle",
11942
+ children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
11943
+ }
11944
+ )
11945
+ ] })
11946
+ ] })
11947
+ ]
11948
+ },
11949
+ item.id
11950
+ ),
11951
+ idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
11952
+ ] }, item.id);
11953
+ })
11954
+ ] })
11955
+ ]
12001
11956
  },
12002
- ...field
11957
+ profile.id
11958
+ );
11959
+ }) })
11960
+ ] }) })
11961
+ ] }) }),
11962
+ /* @__PURE__ */ jsxRuntime.jsx(
11963
+ StackedFocusModal,
11964
+ {
11965
+ id: STACKED_FOCUS_MODAL_ID,
11966
+ onOpenChangeCallback: (open) => {
11967
+ if (!open) {
11968
+ setData(null);
12003
11969
  }
12004
- ) })
12005
- ] }) });
12006
- }
12007
- }
12008
- );
11970
+ return open;
11971
+ },
11972
+ children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
11973
+ }
11974
+ )
11975
+ ] }),
11976
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11977
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11978
+ /* @__PURE__ */ jsxRuntime.jsx(
11979
+ ui.Button,
11980
+ {
11981
+ size: "small",
11982
+ type: "button",
11983
+ isLoading: isSubmitting,
11984
+ onClick: onSubmit,
11985
+ children: "Save"
11986
+ }
11987
+ )
11988
+ ] }) })
11989
+ ] });
12009
11990
  };
12010
- const ShippingOptionField = ({
11991
+ const StackedModalTrigger = ({
12011
11992
  shippingProfileId,
12012
- preview,
12013
- control
11993
+ shippingOption,
11994
+ shippingMethod,
11995
+ setData,
11996
+ children
12014
11997
  }) => {
12015
- var _a;
12016
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12017
- const shippingOptions = useComboboxData({
12018
- queryKey: ["shipping_options", locationId, shippingProfileId],
12019
- queryFn: async (params) => {
12020
- return await sdk.admin.shippingOption.list({
12021
- ...params,
12022
- stock_location_id: locationId,
12023
- shipping_profile_id: shippingProfileId
11998
+ const { setIsOpen, getIsOpen } = useStackedModal();
11999
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12000
+ const onToggle = () => {
12001
+ if (isOpen) {
12002
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12003
+ setData(null);
12004
+ } else {
12005
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12006
+ setData({
12007
+ shippingProfileId,
12008
+ shippingOption,
12009
+ shippingMethod
12024
12010
  });
12025
- },
12026
- getOptions: (data) => {
12027
- return data.shipping_options.map((option) => {
12028
- var _a2;
12029
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12030
- (r) => r.attribute === "is_return" && r.value === "true"
12031
- )) {
12032
- return void 0;
12033
- }
12034
- return {
12035
- label: option.name,
12036
- value: option.id
12037
- };
12038
- }).filter(Boolean);
12039
- },
12040
- enabled: !!locationId && !!shippingProfileId,
12041
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12042
- });
12043
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12044
- return /* @__PURE__ */ jsxRuntime.jsx(
12045
- Form$2.Field,
12046
- {
12047
- control,
12048
- name: "shipping_option_id",
12049
- render: ({ field }) => {
12050
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12051
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12052
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12053
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12054
- ] }),
12055
- /* @__PURE__ */ jsxRuntime.jsx(
12056
- ConditionalTooltip,
12057
- {
12058
- content: tooltipContent,
12059
- showTooltip: !locationId || !shippingProfileId,
12060
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12061
- Combobox,
12062
- {
12063
- options: shippingOptions.options,
12064
- fetchNextPage: shippingOptions.fetchNextPage,
12065
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12066
- searchValue: shippingOptions.searchValue,
12067
- onSearchValueChange: shippingOptions.onSearchValueChange,
12068
- placeholder: "Select shipping option",
12069
- ...field,
12070
- disabled: !locationId || !shippingProfileId
12071
- }
12072
- ) }) })
12073
- }
12074
- )
12075
- ] }) });
12076
- }
12077
12011
  }
12078
- );
12079
- };
12080
- const CustomAmountField = ({
12081
- control,
12082
- currencyCode
12083
- }) => {
12012
+ };
12084
12013
  return /* @__PURE__ */ jsxRuntime.jsx(
12085
- Form$2.Field,
12014
+ ui.Button,
12086
12015
  {
12087
- control,
12088
- name: "custom_amount",
12089
- render: ({ field: { onChange, ...field } }) => {
12090
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12091
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12092
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12093
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12094
- ] }),
12095
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12096
- ui.CurrencyInput,
12097
- {
12098
- ...field,
12099
- onValueChange: (value) => onChange(value),
12100
- symbol: getNativeSymbol(currencyCode),
12101
- code: currencyCode
12102
- }
12103
- ) })
12104
- ] });
12105
- }
12016
+ size: "small",
12017
+ variant: "secondary",
12018
+ onClick: onToggle,
12019
+ className: "text-ui-fg-primary shrink-0",
12020
+ children
12106
12021
  }
12107
12022
  );
12108
12023
  };
12109
- const ShippingAddress = () => {
12110
- const { id } = reactRouterDom.useParams();
12111
- const { order, isPending, isError, error } = useOrder(id, {
12112
- fields: "+shipping_address"
12113
- });
12114
- if (isError) {
12115
- throw error;
12116
- }
12117
- const isReady = !isPending && !!order;
12118
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12119
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12120
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12121
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12122
- ] }),
12123
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12124
- ] });
12125
- };
12126
- const ShippingAddressForm = ({ order }) => {
12127
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12024
+ const ShippingProfileForm = ({
12025
+ data,
12026
+ order,
12027
+ preview
12028
+ }) => {
12029
+ var _a, _b, _c, _d, _e, _f;
12030
+ const { setIsOpen } = useStackedModal();
12128
12031
  const form = reactHookForm.useForm({
12129
- defaultValues: {
12130
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12131
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12132
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12133
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12134
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12135
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12136
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12137
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12138
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12139
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12140
- },
12141
- resolver: zod.zodResolver(schema$3)
12142
- });
12143
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12144
- const { handleSuccess } = useRouteModal();
12145
- const onSubmit = form.handleSubmit(async (data) => {
12146
- await mutateAsync(
12147
- {
12148
- shipping_address: {
12149
- first_name: data.first_name,
12150
- last_name: data.last_name,
12151
- company: data.company,
12152
- address_1: data.address_1,
12153
- address_2: data.address_2,
12154
- city: data.city,
12155
- province: data.province,
12156
- country_code: data.country_code,
12157
- postal_code: data.postal_code,
12158
- phone: data.phone
12032
+ resolver: zod.zodResolver(shippingMethodSchema),
12033
+ defaultValues: {
12034
+ 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,
12035
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12036
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12037
+ }
12038
+ });
12039
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12040
+ const {
12041
+ mutateAsync: updateShippingMethod,
12042
+ isPending: isUpdatingShippingMethod
12043
+ } = useDraftOrderUpdateShippingMethod(order.id);
12044
+ const onSubmit = form.handleSubmit(async (values) => {
12045
+ if (lodash.isEqual(values, form.formState.defaultValues)) {
12046
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12047
+ return;
12048
+ }
12049
+ if (data.shippingMethod) {
12050
+ await updateShippingMethod(
12051
+ {
12052
+ method_id: data.shippingMethod.id,
12053
+ shipping_option_id: values.shipping_option_id,
12054
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12055
+ },
12056
+ {
12057
+ onError: (e) => {
12058
+ ui.toast.error(e.message);
12059
+ },
12060
+ onSuccess: () => {
12061
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12062
+ }
12159
12063
  }
12064
+ );
12065
+ return;
12066
+ }
12067
+ await addShippingMethod(
12068
+ {
12069
+ shipping_option_id: values.shipping_option_id,
12070
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12160
12071
  },
12161
12072
  {
12162
- onSuccess: () => {
12163
- handleSuccess();
12073
+ onError: (e) => {
12074
+ ui.toast.error(e.message);
12164
12075
  },
12165
- onError: (error) => {
12166
- ui.toast.error(error.message);
12076
+ onSuccess: () => {
12077
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12167
12078
  }
12168
12079
  }
12169
12080
  );
12170
12081
  });
12171
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12082
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12172
12083
  KeyboundForm,
12173
12084
  {
12174
- className: "flex flex-1 flex-col overflow-hidden",
12085
+ className: "flex h-full flex-col overflow-hidden",
12175
12086
  onSubmit,
12176
12087
  children: [
12177
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12088
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12089
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12090
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12091
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12092
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12093
+ ] }),
12094
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12178
12095
  /* @__PURE__ */ jsxRuntime.jsx(
12179
- Form$2.Field,
12096
+ LocationField,
12180
12097
  {
12181
12098
  control: form.control,
12182
- name: "country_code",
12183
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12184
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12185
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12186
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12187
- ] })
12099
+ setValue: form.setValue
12188
12100
  }
12189
12101
  ),
12190
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12191
- /* @__PURE__ */ jsxRuntime.jsx(
12192
- Form$2.Field,
12193
- {
12194
- control: form.control,
12195
- name: "first_name",
12196
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12197
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12198
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12199
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12200
- ] })
12201
- }
12202
- ),
12203
- /* @__PURE__ */ jsxRuntime.jsx(
12204
- Form$2.Field,
12205
- {
12206
- control: form.control,
12207
- name: "last_name",
12208
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12209
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12210
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12211
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12212
- ] })
12213
- }
12214
- )
12215
- ] }),
12102
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12216
12103
  /* @__PURE__ */ jsxRuntime.jsx(
12217
- Form$2.Field,
12104
+ ShippingOptionField,
12218
12105
  {
12219
- control: form.control,
12220
- name: "company",
12221
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12222
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12223
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12224
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12225
- ] })
12106
+ shippingProfileId: data.shippingProfileId,
12107
+ preview,
12108
+ control: form.control
12226
12109
  }
12227
12110
  ),
12111
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12228
12112
  /* @__PURE__ */ jsxRuntime.jsx(
12229
- Form$2.Field,
12113
+ CustomAmountField,
12230
12114
  {
12231
12115
  control: form.control,
12232
- name: "address_1",
12233
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12234
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12235
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12236
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12237
- ] })
12116
+ currencyCode: order.currency_code
12238
12117
  }
12239
12118
  ),
12119
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12240
12120
  /* @__PURE__ */ jsxRuntime.jsx(
12241
- Form$2.Field,
12121
+ ItemsPreview,
12242
12122
  {
12243
- control: form.control,
12244
- name: "address_2",
12245
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12246
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12247
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12248
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12249
- ] })
12123
+ order,
12124
+ shippingProfileId: data.shippingProfileId
12250
12125
  }
12251
- ),
12252
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12253
- /* @__PURE__ */ jsxRuntime.jsx(
12254
- Form$2.Field,
12255
- {
12256
- control: form.control,
12257
- name: "postal_code",
12258
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12259
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12260
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12261
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12262
- ] })
12263
- }
12264
- ),
12265
- /* @__PURE__ */ jsxRuntime.jsx(
12266
- Form$2.Field,
12126
+ )
12127
+ ] }) }) }),
12128
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12129
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12130
+ /* @__PURE__ */ jsxRuntime.jsx(
12131
+ ui.Button,
12132
+ {
12133
+ size: "small",
12134
+ type: "submit",
12135
+ isLoading: isPending || isUpdatingShippingMethod,
12136
+ children: data.shippingMethod ? "Update" : "Add"
12137
+ }
12138
+ )
12139
+ ] }) })
12140
+ ]
12141
+ }
12142
+ ) }) });
12143
+ };
12144
+ const shippingMethodSchema = objectType({
12145
+ location_id: stringType(),
12146
+ shipping_option_id: stringType(),
12147
+ custom_amount: unionType([numberType(), stringType()]).optional()
12148
+ });
12149
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12150
+ const matches = order.items.filter(
12151
+ (item) => {
12152
+ var _a, _b, _c;
12153
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12154
+ }
12155
+ );
12156
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12157
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12158
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12159
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12160
+ ] }) }),
12161
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12162
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12163
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12164
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12165
+ ] }),
12166
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
12167
+ "div",
12168
+ {
12169
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12170
+ children: [
12171
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12172
+ /* @__PURE__ */ jsxRuntime.jsx(
12173
+ Thumbnail,
12174
+ {
12175
+ thumbnail: item.thumbnail,
12176
+ alt: item.product_title ?? void 0
12177
+ }
12178
+ ),
12179
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12180
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12181
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12182
+ /* @__PURE__ */ jsxRuntime.jsxs(
12183
+ ui.Text,
12184
+ {
12185
+ size: "small",
12186
+ leading: "compact",
12187
+ className: "text-ui-fg-subtle",
12188
+ children: [
12189
+ "(",
12190
+ item.variant_title,
12191
+ ")"
12192
+ ]
12193
+ }
12194
+ )
12195
+ ] }),
12196
+ /* @__PURE__ */ jsxRuntime.jsx(
12197
+ ui.Text,
12198
+ {
12199
+ size: "small",
12200
+ leading: "compact",
12201
+ className: "text-ui-fg-subtle",
12202
+ children: item.variant_sku
12203
+ }
12204
+ )
12205
+ ] })
12206
+ ] }),
12207
+ /* @__PURE__ */ jsxRuntime.jsxs(
12208
+ ui.Text,
12267
12209
  {
12268
- control: form.control,
12269
- name: "city",
12270
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12271
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12272
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12273
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12274
- ] })
12210
+ size: "small",
12211
+ leading: "compact",
12212
+ className: "text-ui-fg-subtle",
12213
+ children: [
12214
+ item.quantity,
12215
+ "x"
12216
+ ]
12275
12217
  }
12276
12218
  )
12219
+ ]
12220
+ },
12221
+ item.id
12222
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12223
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12224
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12225
+ 'No items found for "',
12226
+ query,
12227
+ '".'
12228
+ ] })
12229
+ ] }) })
12230
+ ] })
12231
+ ] });
12232
+ };
12233
+ const LocationField = ({ control, setValue }) => {
12234
+ const locations = useComboboxData({
12235
+ queryKey: ["locations"],
12236
+ queryFn: async (params) => {
12237
+ return await sdk.admin.stockLocation.list(params);
12238
+ },
12239
+ getOptions: (data) => {
12240
+ return data.stock_locations.map((location) => ({
12241
+ label: location.name,
12242
+ value: location.id
12243
+ }));
12244
+ }
12245
+ });
12246
+ return /* @__PURE__ */ jsxRuntime.jsx(
12247
+ Form$2.Field,
12248
+ {
12249
+ control,
12250
+ name: "location_id",
12251
+ render: ({ field: { onChange, ...field } }) => {
12252
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12253
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12254
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12255
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12277
12256
  ] }),
12278
- /* @__PURE__ */ jsxRuntime.jsx(
12279
- Form$2.Field,
12257
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12258
+ Combobox,
12280
12259
  {
12281
- control: form.control,
12282
- name: "province",
12283
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12284
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12285
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12286
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12287
- ] })
12260
+ options: locations.options,
12261
+ fetchNextPage: locations.fetchNextPage,
12262
+ isFetchingNextPage: locations.isFetchingNextPage,
12263
+ searchValue: locations.searchValue,
12264
+ onSearchValueChange: locations.onSearchValueChange,
12265
+ placeholder: "Select location",
12266
+ onChange: (value) => {
12267
+ setValue("shipping_option_id", "", {
12268
+ shouldDirty: true,
12269
+ shouldTouch: true
12270
+ });
12271
+ onChange(value);
12272
+ },
12273
+ ...field
12288
12274
  }
12289
- ),
12275
+ ) })
12276
+ ] }) });
12277
+ }
12278
+ }
12279
+ );
12280
+ };
12281
+ const ShippingOptionField = ({
12282
+ shippingProfileId,
12283
+ preview,
12284
+ control
12285
+ }) => {
12286
+ var _a;
12287
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12288
+ const shippingOptions = useComboboxData({
12289
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12290
+ queryFn: async (params) => {
12291
+ return await sdk.admin.shippingOption.list({
12292
+ ...params,
12293
+ stock_location_id: locationId,
12294
+ shipping_profile_id: shippingProfileId
12295
+ });
12296
+ },
12297
+ getOptions: (data) => {
12298
+ return data.shipping_options.map((option) => {
12299
+ var _a2;
12300
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12301
+ (r) => r.attribute === "is_return" && r.value === "true"
12302
+ )) {
12303
+ return void 0;
12304
+ }
12305
+ return {
12306
+ label: option.name,
12307
+ value: option.id
12308
+ };
12309
+ }).filter(Boolean);
12310
+ },
12311
+ enabled: !!locationId && !!shippingProfileId,
12312
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12313
+ });
12314
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12315
+ return /* @__PURE__ */ jsxRuntime.jsx(
12316
+ Form$2.Field,
12317
+ {
12318
+ control,
12319
+ name: "shipping_option_id",
12320
+ render: ({ field }) => {
12321
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12322
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12323
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12324
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12325
+ ] }),
12290
12326
  /* @__PURE__ */ jsxRuntime.jsx(
12291
- Form$2.Field,
12327
+ ConditionalTooltip,
12292
12328
  {
12293
- control: form.control,
12294
- name: "phone",
12295
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12296
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12297
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12298
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12299
- ] })
12329
+ content: tooltipContent,
12330
+ showTooltip: !locationId || !shippingProfileId,
12331
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12332
+ Combobox,
12333
+ {
12334
+ options: shippingOptions.options,
12335
+ fetchNextPage: shippingOptions.fetchNextPage,
12336
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12337
+ searchValue: shippingOptions.searchValue,
12338
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12339
+ placeholder: "Select shipping option",
12340
+ ...field,
12341
+ disabled: !locationId || !shippingProfileId
12342
+ }
12343
+ ) }) })
12300
12344
  }
12301
12345
  )
12302
- ] }) }),
12303
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12304
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12305
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12306
- ] }) })
12307
- ]
12346
+ ] }) });
12347
+ }
12308
12348
  }
12309
- ) });
12349
+ );
12350
+ };
12351
+ const CustomAmountField = ({
12352
+ control,
12353
+ currencyCode
12354
+ }) => {
12355
+ return /* @__PURE__ */ jsxRuntime.jsx(
12356
+ Form$2.Field,
12357
+ {
12358
+ control,
12359
+ name: "custom_amount",
12360
+ render: ({ field: { onChange, ...field } }) => {
12361
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12362
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12363
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12364
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12365
+ ] }),
12366
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12367
+ ui.CurrencyInput,
12368
+ {
12369
+ ...field,
12370
+ onValueChange: (value) => onChange(value),
12371
+ symbol: getNativeSymbol(currencyCode),
12372
+ code: currencyCode
12373
+ }
12374
+ ) })
12375
+ ] });
12376
+ }
12377
+ }
12378
+ );
12310
12379
  };
12311
- const schema$3 = addressSchema;
12312
12380
  const TransferOwnership = () => {
12313
12381
  const { id } = reactRouterDom.useParams();
12314
12382
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12332,7 +12400,7 @@ const TransferOwnershipForm = ({ order }) => {
12332
12400
  defaultValues: {
12333
12401
  customer_id: order.customer_id || ""
12334
12402
  },
12335
- resolver: zod.zodResolver(schema$2)
12403
+ resolver: zod.zodResolver(schema$1)
12336
12404
  });
12337
12405
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12338
12406
  const { handleSuccess } = useRouteModal();
@@ -12782,76 +12850,8 @@ const Illustration = () => {
12782
12850
  }
12783
12851
  );
12784
12852
  };
12785
- const schema$2 = objectType({
12786
- customer_id: stringType().min(1)
12787
- });
12788
- const Email = () => {
12789
- const { id } = reactRouterDom.useParams();
12790
- const { order, isPending, isError, error } = useOrder(id, {
12791
- fields: "+email"
12792
- });
12793
- if (isError) {
12794
- throw error;
12795
- }
12796
- const isReady = !isPending && !!order;
12797
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12798
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12799
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
12800
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
12801
- ] }),
12802
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
12803
- ] });
12804
- };
12805
- const EmailForm = ({ order }) => {
12806
- const form = reactHookForm.useForm({
12807
- defaultValues: {
12808
- email: order.email ?? ""
12809
- },
12810
- resolver: zod.zodResolver(schema$1)
12811
- });
12812
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12813
- const { handleSuccess } = useRouteModal();
12814
- const onSubmit = form.handleSubmit(async (data) => {
12815
- await mutateAsync(
12816
- { email: data.email },
12817
- {
12818
- onSuccess: () => {
12819
- handleSuccess();
12820
- },
12821
- onError: (error) => {
12822
- ui.toast.error(error.message);
12823
- }
12824
- }
12825
- );
12826
- });
12827
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12828
- KeyboundForm,
12829
- {
12830
- className: "flex flex-1 flex-col overflow-hidden",
12831
- onSubmit,
12832
- children: [
12833
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
12834
- Form$2.Field,
12835
- {
12836
- control: form.control,
12837
- name: "email",
12838
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12839
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
12840
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12841
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12842
- ] })
12843
- }
12844
- ) }),
12845
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12846
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12847
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12848
- ] }) })
12849
- ]
12850
- }
12851
- ) });
12852
- };
12853
12853
  const schema$1 = objectType({
12854
- email: stringType().email()
12854
+ customer_id: stringType().min(1)
12855
12855
  });
12856
12856
  const BillingAddress = () => {
12857
12857
  const { id } = reactRouterDom.useParams();
@@ -13068,36 +13068,36 @@ const routeModule = {
13068
13068
  path: "/draft-orders/:id/custom-items"
13069
13069
  },
13070
13070
  {
13071
- Component: Items,
13072
- path: "/draft-orders/:id/items"
13071
+ Component: Email,
13072
+ path: "/draft-orders/:id/email"
13073
13073
  },
13074
13074
  {
13075
- Component: Promotions,
13076
- path: "/draft-orders/:id/promotions"
13075
+ Component: Items,
13076
+ path: "/draft-orders/:id/items"
13077
13077
  },
13078
13078
  {
13079
13079
  Component: Metadata,
13080
13080
  path: "/draft-orders/:id/metadata"
13081
13081
  },
13082
13082
  {
13083
- Component: SalesChannel,
13084
- path: "/draft-orders/:id/sales-channel"
13083
+ Component: Promotions,
13084
+ path: "/draft-orders/:id/promotions"
13085
13085
  },
13086
13086
  {
13087
- Component: Shipping,
13088
- path: "/draft-orders/:id/shipping"
13087
+ Component: SalesChannel,
13088
+ path: "/draft-orders/:id/sales-channel"
13089
13089
  },
13090
13090
  {
13091
13091
  Component: ShippingAddress,
13092
13092
  path: "/draft-orders/:id/shipping-address"
13093
13093
  },
13094
13094
  {
13095
- Component: TransferOwnership,
13096
- path: "/draft-orders/:id/transfer-ownership"
13095
+ Component: Shipping,
13096
+ path: "/draft-orders/:id/shipping"
13097
13097
  },
13098
13098
  {
13099
- Component: Email,
13100
- path: "/draft-orders/:id/email"
13099
+ Component: TransferOwnership,
13100
+ path: "/draft-orders/:id/transfer-ownership"
13101
13101
  },
13102
13102
  {
13103
13103
  Component: BillingAddress,