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