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

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