@medusajs/draft-order 2.11.1-preview-20251025060207 → 2.11.1-preview-20251025090157

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