@medusajs/draft-order 2.10.4-preview-20251006060203 → 2.10.4-preview-20251006090200

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