@medusajs/draft-order 2.10.0-snapshot-20250828141936 → 2.11.0-snapshot-20250828185926

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