@medusajs/draft-order 2.11.4-preview-20251129210134 → 2.11.4-preview-20251130000310
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.
- package/.medusa/server/src/admin/index.js +828 -828
- package/.medusa/server/src/admin/index.mjs +828 -828
- package/package.json +16 -16
|
@@ -10818,88 +10818,46 @@ const customItemSchema = objectType({
|
|
|
10818
10818
|
quantity: numberType(),
|
|
10819
10819
|
unit_price: unionType([numberType(), stringType()])
|
|
10820
10820
|
});
|
|
10821
|
-
const
|
|
10822
|
-
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
10823
|
-
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
10824
|
-
return /* @__PURE__ */ jsxs(
|
|
10825
|
-
"div",
|
|
10826
|
-
{
|
|
10827
|
-
ref,
|
|
10828
|
-
className: clx(
|
|
10829
|
-
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
10830
|
-
className
|
|
10831
|
-
),
|
|
10832
|
-
...props,
|
|
10833
|
-
children: [
|
|
10834
|
-
/* @__PURE__ */ jsx(
|
|
10835
|
-
"div",
|
|
10836
|
-
{
|
|
10837
|
-
role: "presentation",
|
|
10838
|
-
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
10839
|
-
"bg-ui-tag-orange-icon": variant === "warning"
|
|
10840
|
-
})
|
|
10841
|
-
}
|
|
10842
|
-
),
|
|
10843
|
-
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
10844
|
-
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
10845
|
-
labelValue,
|
|
10846
|
-
":"
|
|
10847
|
-
] }),
|
|
10848
|
-
" ",
|
|
10849
|
-
children
|
|
10850
|
-
] })
|
|
10851
|
-
]
|
|
10852
|
-
}
|
|
10853
|
-
);
|
|
10854
|
-
}
|
|
10855
|
-
);
|
|
10856
|
-
InlineTip.displayName = "InlineTip";
|
|
10857
|
-
const MetadataFieldSchema = objectType({
|
|
10858
|
-
key: stringType(),
|
|
10859
|
-
disabled: booleanType().optional(),
|
|
10860
|
-
value: anyType()
|
|
10861
|
-
});
|
|
10862
|
-
const MetadataSchema = objectType({
|
|
10863
|
-
metadata: arrayType(MetadataFieldSchema)
|
|
10864
|
-
});
|
|
10865
|
-
const Metadata = () => {
|
|
10821
|
+
const SalesChannel = () => {
|
|
10866
10822
|
const { id } = useParams();
|
|
10867
|
-
const {
|
|
10868
|
-
|
|
10869
|
-
|
|
10823
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
10824
|
+
id,
|
|
10825
|
+
{
|
|
10826
|
+
fields: "+sales_channel_id"
|
|
10827
|
+
},
|
|
10828
|
+
{
|
|
10829
|
+
enabled: !!id
|
|
10830
|
+
}
|
|
10831
|
+
);
|
|
10870
10832
|
if (isError) {
|
|
10871
10833
|
throw error;
|
|
10872
10834
|
}
|
|
10873
|
-
const
|
|
10835
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
10874
10836
|
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
10875
10837
|
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
10876
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "
|
|
10877
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "
|
|
10838
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
10839
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
10878
10840
|
] }),
|
|
10879
|
-
|
|
10841
|
+
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
10880
10842
|
] });
|
|
10881
10843
|
};
|
|
10882
|
-
const
|
|
10883
|
-
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
10884
|
-
const MetadataForm = ({ orderId, metadata }) => {
|
|
10885
|
-
const { handleSuccess } = useRouteModal();
|
|
10886
|
-
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
10887
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
10844
|
+
const SalesChannelForm = ({ order }) => {
|
|
10888
10845
|
const form = useForm({
|
|
10889
10846
|
defaultValues: {
|
|
10890
|
-
|
|
10847
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
10891
10848
|
},
|
|
10892
|
-
resolver: zodResolver(
|
|
10849
|
+
resolver: zodResolver(schema$2)
|
|
10893
10850
|
});
|
|
10894
|
-
const
|
|
10895
|
-
|
|
10851
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
10852
|
+
const { handleSuccess } = useRouteModal();
|
|
10853
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
10896
10854
|
await mutateAsync(
|
|
10897
10855
|
{
|
|
10898
|
-
|
|
10856
|
+
sales_channel_id: data.sales_channel_id
|
|
10899
10857
|
},
|
|
10900
10858
|
{
|
|
10901
10859
|
onSuccess: () => {
|
|
10902
|
-
toast.success("
|
|
10860
|
+
toast.success("Sales channel updated");
|
|
10903
10861
|
handleSuccess();
|
|
10904
10862
|
},
|
|
10905
10863
|
onError: (error) => {
|
|
@@ -10908,365 +10866,135 @@ const MetadataForm = ({ orderId, metadata }) => {
|
|
|
10908
10866
|
}
|
|
10909
10867
|
);
|
|
10910
10868
|
});
|
|
10911
|
-
const { fields, insert, remove } = useFieldArray({
|
|
10912
|
-
control: form.control,
|
|
10913
|
-
name: "metadata"
|
|
10914
|
-
});
|
|
10915
|
-
function deleteRow(index) {
|
|
10916
|
-
remove(index);
|
|
10917
|
-
if (fields.length === 1) {
|
|
10918
|
-
insert(0, {
|
|
10919
|
-
key: "",
|
|
10920
|
-
value: "",
|
|
10921
|
-
disabled: false
|
|
10922
|
-
});
|
|
10923
|
-
}
|
|
10924
|
-
}
|
|
10925
|
-
function insertRow(index, position) {
|
|
10926
|
-
insert(index + (position === "above" ? 0 : 1), {
|
|
10927
|
-
key: "",
|
|
10928
|
-
value: "",
|
|
10929
|
-
disabled: false
|
|
10930
|
-
});
|
|
10931
|
-
}
|
|
10932
10869
|
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
10933
10870
|
KeyboundForm,
|
|
10934
10871
|
{
|
|
10935
|
-
onSubmit: handleSubmit,
|
|
10936
10872
|
className: "flex flex-1 flex-col overflow-hidden",
|
|
10873
|
+
onSubmit,
|
|
10937
10874
|
children: [
|
|
10938
|
-
/* @__PURE__ */
|
|
10939
|
-
|
|
10940
|
-
|
|
10941
|
-
/* @__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" }) }),
|
|
10942
|
-
/* @__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" }) })
|
|
10943
|
-
] }),
|
|
10944
|
-
fields.map((field, index) => {
|
|
10945
|
-
const isDisabled = field.disabled || false;
|
|
10946
|
-
let placeholder = "-";
|
|
10947
|
-
if (typeof field.value === "object") {
|
|
10948
|
-
placeholder = "{ ... }";
|
|
10949
|
-
}
|
|
10950
|
-
if (Array.isArray(field.value)) {
|
|
10951
|
-
placeholder = "[ ... ]";
|
|
10952
|
-
}
|
|
10953
|
-
return /* @__PURE__ */ jsx(
|
|
10954
|
-
ConditionalTooltip,
|
|
10955
|
-
{
|
|
10956
|
-
showTooltip: isDisabled,
|
|
10957
|
-
content: "This row is disabled because it contains non-primitive data.",
|
|
10958
|
-
children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
|
|
10959
|
-
/* @__PURE__ */ jsxs(
|
|
10960
|
-
"div",
|
|
10961
|
-
{
|
|
10962
|
-
className: clx("grid grid-cols-2 divide-x", {
|
|
10963
|
-
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
10964
|
-
}),
|
|
10965
|
-
children: [
|
|
10966
|
-
/* @__PURE__ */ jsx(
|
|
10967
|
-
Form$2.Field,
|
|
10968
|
-
{
|
|
10969
|
-
control: form.control,
|
|
10970
|
-
name: `metadata.${index}.key`,
|
|
10971
|
-
render: ({ field: field2 }) => {
|
|
10972
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10973
|
-
GridInput,
|
|
10974
|
-
{
|
|
10975
|
-
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
10976
|
-
...field2,
|
|
10977
|
-
disabled: isDisabled,
|
|
10978
|
-
placeholder: "Key"
|
|
10979
|
-
}
|
|
10980
|
-
) }) });
|
|
10981
|
-
}
|
|
10982
|
-
}
|
|
10983
|
-
),
|
|
10984
|
-
/* @__PURE__ */ jsx(
|
|
10985
|
-
Form$2.Field,
|
|
10986
|
-
{
|
|
10987
|
-
control: form.control,
|
|
10988
|
-
name: `metadata.${index}.value`,
|
|
10989
|
-
render: ({ field: { value, ...field2 } }) => {
|
|
10990
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10991
|
-
GridInput,
|
|
10992
|
-
{
|
|
10993
|
-
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
10994
|
-
...field2,
|
|
10995
|
-
value: isDisabled ? placeholder : value,
|
|
10996
|
-
disabled: isDisabled,
|
|
10997
|
-
placeholder: "Value"
|
|
10998
|
-
}
|
|
10999
|
-
) }) });
|
|
11000
|
-
}
|
|
11001
|
-
}
|
|
11002
|
-
)
|
|
11003
|
-
]
|
|
11004
|
-
}
|
|
11005
|
-
),
|
|
11006
|
-
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
11007
|
-
/* @__PURE__ */ jsx(
|
|
11008
|
-
DropdownMenu.Trigger,
|
|
11009
|
-
{
|
|
11010
|
-
className: clx(
|
|
11011
|
-
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
11012
|
-
{
|
|
11013
|
-
hidden: isDisabled
|
|
11014
|
-
}
|
|
11015
|
-
),
|
|
11016
|
-
disabled: isDisabled,
|
|
11017
|
-
asChild: true,
|
|
11018
|
-
children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
|
|
11019
|
-
}
|
|
11020
|
-
),
|
|
11021
|
-
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
11022
|
-
/* @__PURE__ */ jsxs(
|
|
11023
|
-
DropdownMenu.Item,
|
|
11024
|
-
{
|
|
11025
|
-
className: "gap-x-2",
|
|
11026
|
-
onClick: () => insertRow(index, "above"),
|
|
11027
|
-
children: [
|
|
11028
|
-
/* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
11029
|
-
"Insert row above"
|
|
11030
|
-
]
|
|
11031
|
-
}
|
|
11032
|
-
),
|
|
11033
|
-
/* @__PURE__ */ jsxs(
|
|
11034
|
-
DropdownMenu.Item,
|
|
11035
|
-
{
|
|
11036
|
-
className: "gap-x-2",
|
|
11037
|
-
onClick: () => insertRow(index, "below"),
|
|
11038
|
-
children: [
|
|
11039
|
-
/* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
11040
|
-
"Insert row below"
|
|
11041
|
-
]
|
|
11042
|
-
}
|
|
11043
|
-
),
|
|
11044
|
-
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
11045
|
-
/* @__PURE__ */ jsxs(
|
|
11046
|
-
DropdownMenu.Item,
|
|
11047
|
-
{
|
|
11048
|
-
className: "gap-x-2",
|
|
11049
|
-
onClick: () => deleteRow(index),
|
|
11050
|
-
children: [
|
|
11051
|
-
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
11052
|
-
"Delete row"
|
|
11053
|
-
]
|
|
11054
|
-
}
|
|
11055
|
-
)
|
|
11056
|
-
] })
|
|
11057
|
-
] })
|
|
11058
|
-
] })
|
|
11059
|
-
},
|
|
11060
|
-
field.id
|
|
11061
|
-
);
|
|
11062
|
-
})
|
|
11063
|
-
] }),
|
|
11064
|
-
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." })
|
|
11065
|
-
] }),
|
|
11066
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11067
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10875
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
10876
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10877
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11068
10878
|
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11069
10879
|
] }) })
|
|
11070
10880
|
]
|
|
11071
10881
|
}
|
|
11072
10882
|
) });
|
|
11073
10883
|
};
|
|
11074
|
-
const
|
|
11075
|
-
|
|
11076
|
-
|
|
11077
|
-
|
|
11078
|
-
|
|
11079
|
-
|
|
11080
|
-
|
|
11081
|
-
|
|
11082
|
-
|
|
11083
|
-
|
|
11084
|
-
)
|
|
11085
|
-
}
|
|
11086
|
-
|
|
11087
|
-
});
|
|
11088
|
-
GridInput.displayName = "MetadataForm.GridInput";
|
|
11089
|
-
const PlaceholderInner = () => {
|
|
11090
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
11091
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
11092
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11093
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
11094
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
11095
|
-
] }) })
|
|
11096
|
-
] });
|
|
11097
|
-
};
|
|
11098
|
-
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
11099
|
-
function getDefaultValues(metadata) {
|
|
11100
|
-
if (!metadata || !Object.keys(metadata).length) {
|
|
11101
|
-
return [
|
|
11102
|
-
{
|
|
11103
|
-
key: "",
|
|
11104
|
-
value: "",
|
|
11105
|
-
disabled: false
|
|
11106
|
-
}
|
|
11107
|
-
];
|
|
11108
|
-
}
|
|
11109
|
-
return Object.entries(metadata).map(([key, value]) => {
|
|
11110
|
-
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
11111
|
-
return {
|
|
11112
|
-
key,
|
|
11113
|
-
value,
|
|
11114
|
-
disabled: true
|
|
11115
|
-
};
|
|
11116
|
-
}
|
|
11117
|
-
let stringValue = value;
|
|
11118
|
-
if (typeof value !== "string") {
|
|
11119
|
-
stringValue = JSON.stringify(value);
|
|
11120
|
-
}
|
|
11121
|
-
return {
|
|
11122
|
-
key,
|
|
11123
|
-
value: stringValue,
|
|
11124
|
-
original_key: key
|
|
11125
|
-
};
|
|
10884
|
+
const SalesChannelField = ({ control, order }) => {
|
|
10885
|
+
const salesChannels = useComboboxData({
|
|
10886
|
+
queryFn: async (params) => {
|
|
10887
|
+
return await sdk.admin.salesChannel.list(params);
|
|
10888
|
+
},
|
|
10889
|
+
queryKey: ["sales-channels"],
|
|
10890
|
+
getOptions: (data) => {
|
|
10891
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
10892
|
+
label: salesChannel.name,
|
|
10893
|
+
value: salesChannel.id
|
|
10894
|
+
}));
|
|
10895
|
+
},
|
|
10896
|
+
defaultValue: order.sales_channel_id || void 0
|
|
11126
10897
|
});
|
|
11127
|
-
|
|
11128
|
-
|
|
11129
|
-
|
|
11130
|
-
|
|
11131
|
-
|
|
11132
|
-
|
|
11133
|
-
|
|
11134
|
-
|
|
11135
|
-
|
|
11136
|
-
|
|
11137
|
-
|
|
11138
|
-
|
|
11139
|
-
|
|
11140
|
-
|
|
11141
|
-
|
|
11142
|
-
|
|
11143
|
-
|
|
11144
|
-
|
|
11145
|
-
|
|
11146
|
-
|
|
11147
|
-
|
|
11148
|
-
|
|
11149
|
-
update[key] = true;
|
|
11150
|
-
} else if (value === "false") {
|
|
11151
|
-
update[key] = false;
|
|
11152
|
-
} else {
|
|
11153
|
-
const parsedNumber = parseFloat(value);
|
|
11154
|
-
if (!isNaN(parsedNumber)) {
|
|
11155
|
-
update[key] = parsedNumber;
|
|
11156
|
-
} else {
|
|
11157
|
-
update[key] = value;
|
|
10898
|
+
return /* @__PURE__ */ jsx(
|
|
10899
|
+
Form$2.Field,
|
|
10900
|
+
{
|
|
10901
|
+
control,
|
|
10902
|
+
name: "sales_channel_id",
|
|
10903
|
+
render: ({ field }) => {
|
|
10904
|
+
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
10905
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
10906
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10907
|
+
Combobox,
|
|
10908
|
+
{
|
|
10909
|
+
options: salesChannels.options,
|
|
10910
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
10911
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
10912
|
+
searchValue: salesChannels.searchValue,
|
|
10913
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
10914
|
+
placeholder: "Select sales channel",
|
|
10915
|
+
...field
|
|
10916
|
+
}
|
|
10917
|
+
) }),
|
|
10918
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10919
|
+
] });
|
|
11158
10920
|
}
|
|
11159
10921
|
}
|
|
11160
|
-
});
|
|
11161
|
-
return update;
|
|
11162
|
-
}
|
|
11163
|
-
function getHasUneditableRows(metadata) {
|
|
11164
|
-
if (!metadata) {
|
|
11165
|
-
return false;
|
|
11166
|
-
}
|
|
11167
|
-
return Object.values(metadata).some(
|
|
11168
|
-
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11169
10922
|
);
|
|
11170
|
-
}
|
|
11171
|
-
const PROMOTION_QUERY_KEY = "promotions";
|
|
11172
|
-
const promotionsQueryKeys = {
|
|
11173
|
-
list: (query2) => [
|
|
11174
|
-
PROMOTION_QUERY_KEY,
|
|
11175
|
-
query2 ? query2 : void 0
|
|
11176
|
-
],
|
|
11177
|
-
detail: (id, query2) => [
|
|
11178
|
-
PROMOTION_QUERY_KEY,
|
|
11179
|
-
id,
|
|
11180
|
-
query2 ? query2 : void 0
|
|
11181
|
-
]
|
|
11182
|
-
};
|
|
11183
|
-
const usePromotions = (query2, options) => {
|
|
11184
|
-
const { data, ...rest } = useQuery({
|
|
11185
|
-
queryKey: promotionsQueryKeys.list(query2),
|
|
11186
|
-
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
11187
|
-
...options
|
|
11188
|
-
});
|
|
11189
|
-
return { ...data, ...rest };
|
|
11190
10923
|
};
|
|
11191
|
-
const
|
|
10924
|
+
const schema$2 = objectType({
|
|
10925
|
+
sales_channel_id: stringType().min(1)
|
|
10926
|
+
});
|
|
10927
|
+
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
10928
|
+
const Shipping = () => {
|
|
10929
|
+
var _a;
|
|
11192
10930
|
const { id } = useParams();
|
|
10931
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
10932
|
+
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
10933
|
+
});
|
|
11193
10934
|
const {
|
|
11194
10935
|
order: preview,
|
|
10936
|
+
isPending: isPreviewPending,
|
|
11195
10937
|
isError: isPreviewError,
|
|
11196
10938
|
error: previewError
|
|
11197
|
-
} = useOrderPreview(id
|
|
10939
|
+
} = useOrderPreview(id);
|
|
11198
10940
|
useInitiateOrderEdit({ preview });
|
|
11199
10941
|
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10942
|
+
if (isError) {
|
|
10943
|
+
throw error;
|
|
10944
|
+
}
|
|
11200
10945
|
if (isPreviewError) {
|
|
11201
10946
|
throw previewError;
|
|
11202
10947
|
}
|
|
11203
|
-
const
|
|
11204
|
-
|
|
11205
|
-
|
|
11206
|
-
|
|
11207
|
-
|
|
10948
|
+
const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
|
|
10949
|
+
const isReady = preview && !isPreviewPending && order && !isPending;
|
|
10950
|
+
return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
|
|
10951
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
10952
|
+
/* @__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 px-6 py-16", children: [
|
|
10953
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
|
|
10954
|
+
/* @__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." }) })
|
|
10955
|
+
] }) }) }),
|
|
10956
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
10957
|
+
] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
10958
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
10959
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
10960
|
+
] }) });
|
|
11208
10961
|
};
|
|
11209
|
-
const
|
|
11210
|
-
|
|
10962
|
+
const ShippingForm = ({ preview, order }) => {
|
|
10963
|
+
var _a;
|
|
10964
|
+
const { setIsOpen } = useStackedModal();
|
|
11211
10965
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
11212
|
-
const [
|
|
11213
|
-
const
|
|
11214
|
-
const {
|
|
11215
|
-
const promoIds = getPromotionIds(items, shipping_methods);
|
|
11216
|
-
const { promotions, isPending, isError, error } = usePromotions(
|
|
10966
|
+
const [data, setData] = useState(null);
|
|
10967
|
+
const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
|
|
10968
|
+
const { shipping_options } = useShippingOptions(
|
|
11217
10969
|
{
|
|
11218
|
-
id:
|
|
10970
|
+
id: appliedShippingOptionIds,
|
|
10971
|
+
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
11219
10972
|
},
|
|
11220
10973
|
{
|
|
11221
|
-
enabled:
|
|
10974
|
+
enabled: appliedShippingOptionIds.length > 0
|
|
11222
10975
|
}
|
|
11223
10976
|
);
|
|
11224
|
-
const
|
|
11225
|
-
|
|
11226
|
-
|
|
11227
|
-
|
|
11228
|
-
|
|
11229
|
-
|
|
11230
|
-
|
|
11231
|
-
|
|
11232
|
-
|
|
11233
|
-
|
|
11234
|
-
|
|
11235
|
-
return data.promotions.map((promotion) => ({
|
|
11236
|
-
label: promotion.code,
|
|
11237
|
-
value: promotion.code
|
|
11238
|
-
}));
|
|
11239
|
-
}
|
|
11240
|
-
});
|
|
11241
|
-
const add = async (value) => {
|
|
11242
|
-
if (!value) {
|
|
11243
|
-
return;
|
|
11244
|
-
}
|
|
11245
|
-
addPromotions(
|
|
11246
|
-
{
|
|
11247
|
-
promo_codes: [value]
|
|
11248
|
-
},
|
|
11249
|
-
{
|
|
11250
|
-
onError: (e) => {
|
|
11251
|
-
toast.error(e.message);
|
|
11252
|
-
comboboxData.onSearchValueChange("");
|
|
11253
|
-
setComboboxValue("");
|
|
11254
|
-
},
|
|
11255
|
-
onSuccess: () => {
|
|
11256
|
-
comboboxData.onSearchValueChange("");
|
|
11257
|
-
setComboboxValue("");
|
|
11258
|
-
}
|
|
11259
|
-
}
|
|
11260
|
-
);
|
|
11261
|
-
};
|
|
10977
|
+
const uniqueShippingProfiles = useMemo(() => {
|
|
10978
|
+
const profiles = /* @__PURE__ */ new Map();
|
|
10979
|
+
getUniqueShippingProfiles(order.items).forEach((profile) => {
|
|
10980
|
+
profiles.set(profile.id, profile);
|
|
10981
|
+
});
|
|
10982
|
+
shipping_options == null ? void 0 : shipping_options.forEach((option) => {
|
|
10983
|
+
profiles.set(option.shipping_profile_id, option.shipping_profile);
|
|
10984
|
+
});
|
|
10985
|
+
return Array.from(profiles.values());
|
|
10986
|
+
}, [order.items, shipping_options]);
|
|
10987
|
+
const { handleSuccess } = useRouteModal();
|
|
11262
10988
|
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11263
|
-
const { mutateAsync: requestOrderEdit } =
|
|
10989
|
+
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
10990
|
+
const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
|
|
10991
|
+
const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
|
|
11264
10992
|
const onSubmit = async () => {
|
|
11265
10993
|
setIsSubmitting(true);
|
|
11266
10994
|
let requestSucceeded = false;
|
|
11267
10995
|
await requestOrderEdit(void 0, {
|
|
11268
10996
|
onError: (e) => {
|
|
11269
|
-
toast.error(e.message);
|
|
10997
|
+
toast.error(`Failed to request order edit: ${e.message}`);
|
|
11270
10998
|
},
|
|
11271
10999
|
onSuccess: () => {
|
|
11272
11000
|
requestSucceeded = true;
|
|
@@ -11278,7 +11006,7 @@ const PromotionForm = ({ preview }) => {
|
|
|
11278
11006
|
}
|
|
11279
11007
|
await confirmOrderEdit(void 0, {
|
|
11280
11008
|
onError: (e) => {
|
|
11281
|
-
toast.error(e.message);
|
|
11009
|
+
toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
11282
11010
|
},
|
|
11283
11011
|
onSuccess: () => {
|
|
11284
11012
|
handleSuccess();
|
|
@@ -11288,371 +11016,16 @@ const PromotionForm = ({ preview }) => {
|
|
|
11288
11016
|
}
|
|
11289
11017
|
});
|
|
11290
11018
|
};
|
|
11291
|
-
|
|
11292
|
-
|
|
11293
|
-
|
|
11294
|
-
|
|
11295
|
-
|
|
11296
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
11297
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
11298
|
-
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
11299
|
-
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
11300
|
-
] }),
|
|
11301
|
-
/* @__PURE__ */ jsx(
|
|
11302
|
-
Combobox,
|
|
11303
|
-
{
|
|
11304
|
-
id: "promotion-combobox",
|
|
11305
|
-
"aria-describedby": "promotion-combobox-hint",
|
|
11306
|
-
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
11307
|
-
fetchNextPage: comboboxData.fetchNextPage,
|
|
11308
|
-
options: comboboxData.options,
|
|
11309
|
-
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
11310
|
-
searchValue: comboboxData.searchValue,
|
|
11311
|
-
disabled: comboboxData.disabled || isAddingPromotions,
|
|
11312
|
-
onChange: add,
|
|
11313
|
-
value: comboboxValue
|
|
11314
|
-
}
|
|
11315
|
-
)
|
|
11316
|
-
] }),
|
|
11317
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
11318
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
11319
|
-
PromotionItem,
|
|
11320
|
-
{
|
|
11321
|
-
promotion,
|
|
11322
|
-
orderId: preview.id,
|
|
11323
|
-
isLoading: isPending
|
|
11324
|
-
},
|
|
11325
|
-
promotion.id
|
|
11326
|
-
)) })
|
|
11327
|
-
] }) }),
|
|
11328
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11329
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11330
|
-
/* @__PURE__ */ jsx(
|
|
11331
|
-
Button,
|
|
11332
|
-
{
|
|
11333
|
-
size: "small",
|
|
11334
|
-
type: "submit",
|
|
11335
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
11336
|
-
children: "Save"
|
|
11337
|
-
}
|
|
11338
|
-
)
|
|
11339
|
-
] }) })
|
|
11340
|
-
] });
|
|
11341
|
-
};
|
|
11342
|
-
const PromotionItem = ({
|
|
11343
|
-
promotion,
|
|
11344
|
-
orderId,
|
|
11345
|
-
isLoading
|
|
11346
|
-
}) => {
|
|
11347
|
-
var _a;
|
|
11348
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11349
|
-
const onRemove = async () => {
|
|
11350
|
-
removePromotions(
|
|
11351
|
-
{
|
|
11352
|
-
promo_codes: [promotion.code]
|
|
11353
|
-
},
|
|
11354
|
-
{
|
|
11355
|
-
onError: (e) => {
|
|
11356
|
-
toast.error(e.message);
|
|
11357
|
-
}
|
|
11358
|
-
}
|
|
11359
|
-
);
|
|
11360
|
-
};
|
|
11361
|
-
const displayValue = getDisplayValue(promotion);
|
|
11362
|
-
return /* @__PURE__ */ jsxs(
|
|
11363
|
-
"div",
|
|
11364
|
-
{
|
|
11365
|
-
className: clx(
|
|
11366
|
-
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11367
|
-
{
|
|
11368
|
-
"animate-pulse": isLoading
|
|
11369
|
-
}
|
|
11370
|
-
),
|
|
11371
|
-
children: [
|
|
11372
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
11373
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11374
|
-
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11375
|
-
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11376
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11377
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
11378
|
-
] }),
|
|
11379
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11380
|
-
] })
|
|
11381
|
-
] }),
|
|
11382
|
-
/* @__PURE__ */ jsx(
|
|
11383
|
-
IconButton,
|
|
11384
|
-
{
|
|
11385
|
-
size: "small",
|
|
11386
|
-
type: "button",
|
|
11387
|
-
variant: "transparent",
|
|
11388
|
-
onClick: onRemove,
|
|
11389
|
-
isLoading: isPending || isLoading,
|
|
11390
|
-
children: /* @__PURE__ */ jsx(XMark, {})
|
|
11391
|
-
}
|
|
11392
|
-
)
|
|
11393
|
-
]
|
|
11394
|
-
},
|
|
11395
|
-
promotion.id
|
|
11396
|
-
);
|
|
11397
|
-
};
|
|
11398
|
-
function getDisplayValue(promotion) {
|
|
11399
|
-
var _a, _b, _c, _d;
|
|
11400
|
-
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11401
|
-
if (!value) {
|
|
11402
|
-
return null;
|
|
11403
|
-
}
|
|
11404
|
-
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11405
|
-
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11406
|
-
if (!currency) {
|
|
11407
|
-
return null;
|
|
11408
|
-
}
|
|
11409
|
-
return getLocaleAmount(value, currency);
|
|
11410
|
-
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11411
|
-
return formatPercentage(value);
|
|
11412
|
-
}
|
|
11413
|
-
return null;
|
|
11414
|
-
}
|
|
11415
|
-
const formatter = new Intl.NumberFormat([], {
|
|
11416
|
-
style: "percent",
|
|
11417
|
-
minimumFractionDigits: 2
|
|
11418
|
-
});
|
|
11419
|
-
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11420
|
-
let val = value || 0;
|
|
11421
|
-
if (!isPercentageValue) {
|
|
11422
|
-
val = val / 100;
|
|
11423
|
-
}
|
|
11424
|
-
return formatter.format(val);
|
|
11425
|
-
};
|
|
11426
|
-
function getPromotionIds(items, shippingMethods) {
|
|
11427
|
-
const promotionIds = /* @__PURE__ */ new Set();
|
|
11428
|
-
for (const item of items) {
|
|
11429
|
-
if (item.adjustments) {
|
|
11430
|
-
for (const adjustment of item.adjustments) {
|
|
11431
|
-
if (adjustment.promotion_id) {
|
|
11432
|
-
promotionIds.add(adjustment.promotion_id);
|
|
11433
|
-
}
|
|
11434
|
-
}
|
|
11435
|
-
}
|
|
11436
|
-
}
|
|
11437
|
-
for (const shippingMethod of shippingMethods) {
|
|
11438
|
-
if (shippingMethod.adjustments) {
|
|
11439
|
-
for (const adjustment of shippingMethod.adjustments) {
|
|
11440
|
-
if (adjustment.promotion_id) {
|
|
11441
|
-
promotionIds.add(adjustment.promotion_id);
|
|
11442
|
-
}
|
|
11443
|
-
}
|
|
11444
|
-
}
|
|
11445
|
-
}
|
|
11446
|
-
return Array.from(promotionIds);
|
|
11447
|
-
}
|
|
11448
|
-
const SalesChannel = () => {
|
|
11449
|
-
const { id } = useParams();
|
|
11450
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
11451
|
-
id,
|
|
11452
|
-
{
|
|
11453
|
-
fields: "+sales_channel_id"
|
|
11454
|
-
},
|
|
11455
|
-
{
|
|
11456
|
-
enabled: !!id
|
|
11457
|
-
}
|
|
11458
|
-
);
|
|
11459
|
-
if (isError) {
|
|
11460
|
-
throw error;
|
|
11461
|
-
}
|
|
11462
|
-
const ISrEADY = !!draft_order && !isPending;
|
|
11463
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11464
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
11465
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
11466
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
11467
|
-
] }),
|
|
11468
|
-
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
11469
|
-
] });
|
|
11470
|
-
};
|
|
11471
|
-
const SalesChannelForm = ({ order }) => {
|
|
11472
|
-
const form = useForm({
|
|
11473
|
-
defaultValues: {
|
|
11474
|
-
sales_channel_id: order.sales_channel_id || ""
|
|
11475
|
-
},
|
|
11476
|
-
resolver: zodResolver(schema$2)
|
|
11477
|
-
});
|
|
11478
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11479
|
-
const { handleSuccess } = useRouteModal();
|
|
11480
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
11481
|
-
await mutateAsync(
|
|
11482
|
-
{
|
|
11483
|
-
sales_channel_id: data.sales_channel_id
|
|
11484
|
-
},
|
|
11485
|
-
{
|
|
11486
|
-
onSuccess: () => {
|
|
11487
|
-
toast.success("Sales channel updated");
|
|
11488
|
-
handleSuccess();
|
|
11489
|
-
},
|
|
11490
|
-
onError: (error) => {
|
|
11491
|
-
toast.error(error.message);
|
|
11019
|
+
const onKeydown = useCallback(
|
|
11020
|
+
(e) => {
|
|
11021
|
+
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
11022
|
+
if (data || isSubmitting) {
|
|
11023
|
+
return;
|
|
11492
11024
|
}
|
|
11025
|
+
onSubmit();
|
|
11493
11026
|
}
|
|
11494
|
-
);
|
|
11495
|
-
});
|
|
11496
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
11497
|
-
KeyboundForm,
|
|
11498
|
-
{
|
|
11499
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
11500
|
-
onSubmit,
|
|
11501
|
-
children: [
|
|
11502
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
11503
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11504
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11505
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11506
|
-
] }) })
|
|
11507
|
-
]
|
|
11508
|
-
}
|
|
11509
|
-
) });
|
|
11510
|
-
};
|
|
11511
|
-
const SalesChannelField = ({ control, order }) => {
|
|
11512
|
-
const salesChannels = useComboboxData({
|
|
11513
|
-
queryFn: async (params) => {
|
|
11514
|
-
return await sdk.admin.salesChannel.list(params);
|
|
11515
|
-
},
|
|
11516
|
-
queryKey: ["sales-channels"],
|
|
11517
|
-
getOptions: (data) => {
|
|
11518
|
-
return data.sales_channels.map((salesChannel) => ({
|
|
11519
|
-
label: salesChannel.name,
|
|
11520
|
-
value: salesChannel.id
|
|
11521
|
-
}));
|
|
11522
11027
|
},
|
|
11523
|
-
|
|
11524
|
-
});
|
|
11525
|
-
return /* @__PURE__ */ jsx(
|
|
11526
|
-
Form$2.Field,
|
|
11527
|
-
{
|
|
11528
|
-
control,
|
|
11529
|
-
name: "sales_channel_id",
|
|
11530
|
-
render: ({ field }) => {
|
|
11531
|
-
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11532
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
11533
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11534
|
-
Combobox,
|
|
11535
|
-
{
|
|
11536
|
-
options: salesChannels.options,
|
|
11537
|
-
fetchNextPage: salesChannels.fetchNextPage,
|
|
11538
|
-
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
11539
|
-
searchValue: salesChannels.searchValue,
|
|
11540
|
-
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
11541
|
-
placeholder: "Select sales channel",
|
|
11542
|
-
...field
|
|
11543
|
-
}
|
|
11544
|
-
) }),
|
|
11545
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11546
|
-
] });
|
|
11547
|
-
}
|
|
11548
|
-
}
|
|
11549
|
-
);
|
|
11550
|
-
};
|
|
11551
|
-
const schema$2 = objectType({
|
|
11552
|
-
sales_channel_id: stringType().min(1)
|
|
11553
|
-
});
|
|
11554
|
-
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11555
|
-
const Shipping = () => {
|
|
11556
|
-
var _a;
|
|
11557
|
-
const { id } = useParams();
|
|
11558
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
11559
|
-
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
11560
|
-
});
|
|
11561
|
-
const {
|
|
11562
|
-
order: preview,
|
|
11563
|
-
isPending: isPreviewPending,
|
|
11564
|
-
isError: isPreviewError,
|
|
11565
|
-
error: previewError
|
|
11566
|
-
} = useOrderPreview(id);
|
|
11567
|
-
useInitiateOrderEdit({ preview });
|
|
11568
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11569
|
-
if (isError) {
|
|
11570
|
-
throw error;
|
|
11571
|
-
}
|
|
11572
|
-
if (isPreviewError) {
|
|
11573
|
-
throw previewError;
|
|
11574
|
-
}
|
|
11575
|
-
const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
|
|
11576
|
-
const isReady = preview && !isPreviewPending && order && !isPending;
|
|
11577
|
-
return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
|
|
11578
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
11579
|
-
/* @__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 px-6 py-16", children: [
|
|
11580
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
|
|
11581
|
-
/* @__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." }) })
|
|
11582
|
-
] }) }) }),
|
|
11583
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
11584
|
-
] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
11585
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
11586
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
11587
|
-
] }) });
|
|
11588
|
-
};
|
|
11589
|
-
const ShippingForm = ({ preview, order }) => {
|
|
11590
|
-
var _a;
|
|
11591
|
-
const { setIsOpen } = useStackedModal();
|
|
11592
|
-
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
11593
|
-
const [data, setData] = useState(null);
|
|
11594
|
-
const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
|
|
11595
|
-
const { shipping_options } = useShippingOptions(
|
|
11596
|
-
{
|
|
11597
|
-
id: appliedShippingOptionIds,
|
|
11598
|
-
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
11599
|
-
},
|
|
11600
|
-
{
|
|
11601
|
-
enabled: appliedShippingOptionIds.length > 0
|
|
11602
|
-
}
|
|
11603
|
-
);
|
|
11604
|
-
const uniqueShippingProfiles = useMemo(() => {
|
|
11605
|
-
const profiles = /* @__PURE__ */ new Map();
|
|
11606
|
-
getUniqueShippingProfiles(order.items).forEach((profile) => {
|
|
11607
|
-
profiles.set(profile.id, profile);
|
|
11608
|
-
});
|
|
11609
|
-
shipping_options == null ? void 0 : shipping_options.forEach((option) => {
|
|
11610
|
-
profiles.set(option.shipping_profile_id, option.shipping_profile);
|
|
11611
|
-
});
|
|
11612
|
-
return Array.from(profiles.values());
|
|
11613
|
-
}, [order.items, shipping_options]);
|
|
11614
|
-
const { handleSuccess } = useRouteModal();
|
|
11615
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11616
|
-
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
11617
|
-
const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
|
|
11618
|
-
const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
|
|
11619
|
-
const onSubmit = async () => {
|
|
11620
|
-
setIsSubmitting(true);
|
|
11621
|
-
let requestSucceeded = false;
|
|
11622
|
-
await requestOrderEdit(void 0, {
|
|
11623
|
-
onError: (e) => {
|
|
11624
|
-
toast.error(`Failed to request order edit: ${e.message}`);
|
|
11625
|
-
},
|
|
11626
|
-
onSuccess: () => {
|
|
11627
|
-
requestSucceeded = true;
|
|
11628
|
-
}
|
|
11629
|
-
});
|
|
11630
|
-
if (!requestSucceeded) {
|
|
11631
|
-
setIsSubmitting(false);
|
|
11632
|
-
return;
|
|
11633
|
-
}
|
|
11634
|
-
await confirmOrderEdit(void 0, {
|
|
11635
|
-
onError: (e) => {
|
|
11636
|
-
toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
11637
|
-
},
|
|
11638
|
-
onSuccess: () => {
|
|
11639
|
-
handleSuccess();
|
|
11640
|
-
},
|
|
11641
|
-
onSettled: () => {
|
|
11642
|
-
setIsSubmitting(false);
|
|
11643
|
-
}
|
|
11644
|
-
});
|
|
11645
|
-
};
|
|
11646
|
-
const onKeydown = useCallback(
|
|
11647
|
-
(e) => {
|
|
11648
|
-
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
11649
|
-
if (data || isSubmitting) {
|
|
11650
|
-
return;
|
|
11651
|
-
}
|
|
11652
|
-
onSubmit();
|
|
11653
|
-
}
|
|
11654
|
-
},
|
|
11655
|
-
[data, isSubmitting, onSubmit]
|
|
11028
|
+
[data, isSubmitting, onSubmit]
|
|
11656
11029
|
);
|
|
11657
11030
|
useEffect(() => {
|
|
11658
11031
|
document.addEventListener("keydown", onKeydown);
|
|
@@ -12957,86 +12330,713 @@ const Illustration = () => {
|
|
|
12957
12330
|
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12958
12331
|
"path",
|
|
12959
12332
|
{
|
|
12960
|
-
d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
|
|
12961
|
-
stroke: "#A1A1AA",
|
|
12962
|
-
strokeWidth: "1.5",
|
|
12963
|
-
strokeLinecap: "round",
|
|
12964
|
-
strokeLinejoin: "round"
|
|
12333
|
+
d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
|
|
12334
|
+
stroke: "#A1A1AA",
|
|
12335
|
+
strokeWidth: "1.5",
|
|
12336
|
+
strokeLinecap: "round",
|
|
12337
|
+
strokeLinejoin: "round"
|
|
12338
|
+
}
|
|
12339
|
+
) }),
|
|
12340
|
+
/* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
|
|
12341
|
+
"path",
|
|
12342
|
+
{
|
|
12343
|
+
d: "M146.894 101.198L139.51 101.155L139.486 105.365",
|
|
12344
|
+
stroke: "#A1A1AA",
|
|
12345
|
+
strokeWidth: "1.5",
|
|
12346
|
+
strokeLinecap: "round",
|
|
12347
|
+
strokeLinejoin: "round"
|
|
12348
|
+
}
|
|
12349
|
+
) }),
|
|
12350
|
+
/* @__PURE__ */ jsxs("defs", { children: [
|
|
12351
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12352
|
+
"rect",
|
|
12353
|
+
{
|
|
12354
|
+
width: "12",
|
|
12355
|
+
height: "12",
|
|
12356
|
+
fill: "white",
|
|
12357
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
|
|
12358
|
+
}
|
|
12359
|
+
) }),
|
|
12360
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12361
|
+
"rect",
|
|
12362
|
+
{
|
|
12363
|
+
width: "12",
|
|
12364
|
+
height: "12",
|
|
12365
|
+
fill: "white",
|
|
12366
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
|
|
12367
|
+
}
|
|
12368
|
+
) }),
|
|
12369
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12370
|
+
"rect",
|
|
12371
|
+
{
|
|
12372
|
+
width: "12",
|
|
12373
|
+
height: "12",
|
|
12374
|
+
fill: "white",
|
|
12375
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
|
|
12376
|
+
}
|
|
12377
|
+
) }),
|
|
12378
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12379
|
+
"rect",
|
|
12380
|
+
{
|
|
12381
|
+
width: "12",
|
|
12382
|
+
height: "12",
|
|
12383
|
+
fill: "white",
|
|
12384
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
|
|
12385
|
+
}
|
|
12386
|
+
) }),
|
|
12387
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12388
|
+
"rect",
|
|
12389
|
+
{
|
|
12390
|
+
width: "12",
|
|
12391
|
+
height: "12",
|
|
12392
|
+
fill: "white",
|
|
12393
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
|
|
12394
|
+
}
|
|
12395
|
+
) }),
|
|
12396
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12397
|
+
"rect",
|
|
12398
|
+
{
|
|
12399
|
+
width: "12",
|
|
12400
|
+
height: "12",
|
|
12401
|
+
fill: "white",
|
|
12402
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
|
|
12403
|
+
}
|
|
12404
|
+
) })
|
|
12405
|
+
] })
|
|
12406
|
+
]
|
|
12407
|
+
}
|
|
12408
|
+
);
|
|
12409
|
+
};
|
|
12410
|
+
const schema = objectType({
|
|
12411
|
+
customer_id: stringType().min(1)
|
|
12412
|
+
});
|
|
12413
|
+
const InlineTip = forwardRef(
|
|
12414
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
12415
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
12416
|
+
return /* @__PURE__ */ jsxs(
|
|
12417
|
+
"div",
|
|
12418
|
+
{
|
|
12419
|
+
ref,
|
|
12420
|
+
className: clx(
|
|
12421
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
12422
|
+
className
|
|
12423
|
+
),
|
|
12424
|
+
...props,
|
|
12425
|
+
children: [
|
|
12426
|
+
/* @__PURE__ */ jsx(
|
|
12427
|
+
"div",
|
|
12428
|
+
{
|
|
12429
|
+
role: "presentation",
|
|
12430
|
+
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
12431
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
12432
|
+
})
|
|
12433
|
+
}
|
|
12434
|
+
),
|
|
12435
|
+
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
12436
|
+
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
12437
|
+
labelValue,
|
|
12438
|
+
":"
|
|
12439
|
+
] }),
|
|
12440
|
+
" ",
|
|
12441
|
+
children
|
|
12442
|
+
] })
|
|
12443
|
+
]
|
|
12444
|
+
}
|
|
12445
|
+
);
|
|
12446
|
+
}
|
|
12447
|
+
);
|
|
12448
|
+
InlineTip.displayName = "InlineTip";
|
|
12449
|
+
const MetadataFieldSchema = objectType({
|
|
12450
|
+
key: stringType(),
|
|
12451
|
+
disabled: booleanType().optional(),
|
|
12452
|
+
value: anyType()
|
|
12453
|
+
});
|
|
12454
|
+
const MetadataSchema = objectType({
|
|
12455
|
+
metadata: arrayType(MetadataFieldSchema)
|
|
12456
|
+
});
|
|
12457
|
+
const Metadata = () => {
|
|
12458
|
+
const { id } = useParams();
|
|
12459
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
12460
|
+
fields: "metadata"
|
|
12461
|
+
});
|
|
12462
|
+
if (isError) {
|
|
12463
|
+
throw error;
|
|
12464
|
+
}
|
|
12465
|
+
const isReady = !isPending && !!order;
|
|
12466
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12467
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
12468
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
|
|
12469
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
12470
|
+
] }),
|
|
12471
|
+
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
12472
|
+
] });
|
|
12473
|
+
};
|
|
12474
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
12475
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
12476
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
12477
|
+
const { handleSuccess } = useRouteModal();
|
|
12478
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
12479
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
12480
|
+
const form = useForm({
|
|
12481
|
+
defaultValues: {
|
|
12482
|
+
metadata: getDefaultValues(metadata)
|
|
12483
|
+
},
|
|
12484
|
+
resolver: zodResolver(MetadataSchema)
|
|
12485
|
+
});
|
|
12486
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
12487
|
+
const parsedData = parseValues(data);
|
|
12488
|
+
await mutateAsync(
|
|
12489
|
+
{
|
|
12490
|
+
metadata: parsedData
|
|
12491
|
+
},
|
|
12492
|
+
{
|
|
12493
|
+
onSuccess: () => {
|
|
12494
|
+
toast.success("Metadata updated");
|
|
12495
|
+
handleSuccess();
|
|
12496
|
+
},
|
|
12497
|
+
onError: (error) => {
|
|
12498
|
+
toast.error(error.message);
|
|
12499
|
+
}
|
|
12500
|
+
}
|
|
12501
|
+
);
|
|
12502
|
+
});
|
|
12503
|
+
const { fields, insert, remove } = useFieldArray({
|
|
12504
|
+
control: form.control,
|
|
12505
|
+
name: "metadata"
|
|
12506
|
+
});
|
|
12507
|
+
function deleteRow(index) {
|
|
12508
|
+
remove(index);
|
|
12509
|
+
if (fields.length === 1) {
|
|
12510
|
+
insert(0, {
|
|
12511
|
+
key: "",
|
|
12512
|
+
value: "",
|
|
12513
|
+
disabled: false
|
|
12514
|
+
});
|
|
12515
|
+
}
|
|
12516
|
+
}
|
|
12517
|
+
function insertRow(index, position) {
|
|
12518
|
+
insert(index + (position === "above" ? 0 : 1), {
|
|
12519
|
+
key: "",
|
|
12520
|
+
value: "",
|
|
12521
|
+
disabled: false
|
|
12522
|
+
});
|
|
12523
|
+
}
|
|
12524
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
12525
|
+
KeyboundForm,
|
|
12526
|
+
{
|
|
12527
|
+
onSubmit: handleSubmit,
|
|
12528
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
12529
|
+
children: [
|
|
12530
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
12531
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
12532
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
12533
|
+
/* @__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" }) }),
|
|
12534
|
+
/* @__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" }) })
|
|
12535
|
+
] }),
|
|
12536
|
+
fields.map((field, index) => {
|
|
12537
|
+
const isDisabled = field.disabled || false;
|
|
12538
|
+
let placeholder = "-";
|
|
12539
|
+
if (typeof field.value === "object") {
|
|
12540
|
+
placeholder = "{ ... }";
|
|
12541
|
+
}
|
|
12542
|
+
if (Array.isArray(field.value)) {
|
|
12543
|
+
placeholder = "[ ... ]";
|
|
12544
|
+
}
|
|
12545
|
+
return /* @__PURE__ */ jsx(
|
|
12546
|
+
ConditionalTooltip,
|
|
12547
|
+
{
|
|
12548
|
+
showTooltip: isDisabled,
|
|
12549
|
+
content: "This row is disabled because it contains non-primitive data.",
|
|
12550
|
+
children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
|
|
12551
|
+
/* @__PURE__ */ jsxs(
|
|
12552
|
+
"div",
|
|
12553
|
+
{
|
|
12554
|
+
className: clx("grid grid-cols-2 divide-x", {
|
|
12555
|
+
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
12556
|
+
}),
|
|
12557
|
+
children: [
|
|
12558
|
+
/* @__PURE__ */ jsx(
|
|
12559
|
+
Form$2.Field,
|
|
12560
|
+
{
|
|
12561
|
+
control: form.control,
|
|
12562
|
+
name: `metadata.${index}.key`,
|
|
12563
|
+
render: ({ field: field2 }) => {
|
|
12564
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
12565
|
+
GridInput,
|
|
12566
|
+
{
|
|
12567
|
+
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
12568
|
+
...field2,
|
|
12569
|
+
disabled: isDisabled,
|
|
12570
|
+
placeholder: "Key"
|
|
12571
|
+
}
|
|
12572
|
+
) }) });
|
|
12573
|
+
}
|
|
12574
|
+
}
|
|
12575
|
+
),
|
|
12576
|
+
/* @__PURE__ */ jsx(
|
|
12577
|
+
Form$2.Field,
|
|
12578
|
+
{
|
|
12579
|
+
control: form.control,
|
|
12580
|
+
name: `metadata.${index}.value`,
|
|
12581
|
+
render: ({ field: { value, ...field2 } }) => {
|
|
12582
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
12583
|
+
GridInput,
|
|
12584
|
+
{
|
|
12585
|
+
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
12586
|
+
...field2,
|
|
12587
|
+
value: isDisabled ? placeholder : value,
|
|
12588
|
+
disabled: isDisabled,
|
|
12589
|
+
placeholder: "Value"
|
|
12590
|
+
}
|
|
12591
|
+
) }) });
|
|
12592
|
+
}
|
|
12593
|
+
}
|
|
12594
|
+
)
|
|
12595
|
+
]
|
|
12596
|
+
}
|
|
12597
|
+
),
|
|
12598
|
+
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
12599
|
+
/* @__PURE__ */ jsx(
|
|
12600
|
+
DropdownMenu.Trigger,
|
|
12601
|
+
{
|
|
12602
|
+
className: clx(
|
|
12603
|
+
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
12604
|
+
{
|
|
12605
|
+
hidden: isDisabled
|
|
12606
|
+
}
|
|
12607
|
+
),
|
|
12608
|
+
disabled: isDisabled,
|
|
12609
|
+
asChild: true,
|
|
12610
|
+
children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
|
|
12611
|
+
}
|
|
12612
|
+
),
|
|
12613
|
+
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
12614
|
+
/* @__PURE__ */ jsxs(
|
|
12615
|
+
DropdownMenu.Item,
|
|
12616
|
+
{
|
|
12617
|
+
className: "gap-x-2",
|
|
12618
|
+
onClick: () => insertRow(index, "above"),
|
|
12619
|
+
children: [
|
|
12620
|
+
/* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
12621
|
+
"Insert row above"
|
|
12622
|
+
]
|
|
12623
|
+
}
|
|
12624
|
+
),
|
|
12625
|
+
/* @__PURE__ */ jsxs(
|
|
12626
|
+
DropdownMenu.Item,
|
|
12627
|
+
{
|
|
12628
|
+
className: "gap-x-2",
|
|
12629
|
+
onClick: () => insertRow(index, "below"),
|
|
12630
|
+
children: [
|
|
12631
|
+
/* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
12632
|
+
"Insert row below"
|
|
12633
|
+
]
|
|
12634
|
+
}
|
|
12635
|
+
),
|
|
12636
|
+
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
12637
|
+
/* @__PURE__ */ jsxs(
|
|
12638
|
+
DropdownMenu.Item,
|
|
12639
|
+
{
|
|
12640
|
+
className: "gap-x-2",
|
|
12641
|
+
onClick: () => deleteRow(index),
|
|
12642
|
+
children: [
|
|
12643
|
+
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
12644
|
+
"Delete row"
|
|
12645
|
+
]
|
|
12646
|
+
}
|
|
12647
|
+
)
|
|
12648
|
+
] })
|
|
12649
|
+
] })
|
|
12650
|
+
] })
|
|
12651
|
+
},
|
|
12652
|
+
field.id
|
|
12653
|
+
);
|
|
12654
|
+
})
|
|
12655
|
+
] }),
|
|
12656
|
+
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." })
|
|
12657
|
+
] }),
|
|
12658
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
12659
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
12660
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12661
|
+
] }) })
|
|
12662
|
+
]
|
|
12663
|
+
}
|
|
12664
|
+
) });
|
|
12665
|
+
};
|
|
12666
|
+
const GridInput = forwardRef(({ className, ...props }, ref) => {
|
|
12667
|
+
return /* @__PURE__ */ jsx(
|
|
12668
|
+
"input",
|
|
12669
|
+
{
|
|
12670
|
+
ref,
|
|
12671
|
+
...props,
|
|
12672
|
+
autoComplete: "off",
|
|
12673
|
+
className: clx(
|
|
12674
|
+
"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",
|
|
12675
|
+
className
|
|
12676
|
+
)
|
|
12677
|
+
}
|
|
12678
|
+
);
|
|
12679
|
+
});
|
|
12680
|
+
GridInput.displayName = "MetadataForm.GridInput";
|
|
12681
|
+
const PlaceholderInner = () => {
|
|
12682
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
12683
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
12684
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
12685
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
12686
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
12687
|
+
] }) })
|
|
12688
|
+
] });
|
|
12689
|
+
};
|
|
12690
|
+
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
12691
|
+
function getDefaultValues(metadata) {
|
|
12692
|
+
if (!metadata || !Object.keys(metadata).length) {
|
|
12693
|
+
return [
|
|
12694
|
+
{
|
|
12695
|
+
key: "",
|
|
12696
|
+
value: "",
|
|
12697
|
+
disabled: false
|
|
12698
|
+
}
|
|
12699
|
+
];
|
|
12700
|
+
}
|
|
12701
|
+
return Object.entries(metadata).map(([key, value]) => {
|
|
12702
|
+
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
12703
|
+
return {
|
|
12704
|
+
key,
|
|
12705
|
+
value,
|
|
12706
|
+
disabled: true
|
|
12707
|
+
};
|
|
12708
|
+
}
|
|
12709
|
+
let stringValue = value;
|
|
12710
|
+
if (typeof value !== "string") {
|
|
12711
|
+
stringValue = JSON.stringify(value);
|
|
12712
|
+
}
|
|
12713
|
+
return {
|
|
12714
|
+
key,
|
|
12715
|
+
value: stringValue,
|
|
12716
|
+
original_key: key
|
|
12717
|
+
};
|
|
12718
|
+
});
|
|
12719
|
+
}
|
|
12720
|
+
function parseValues(values) {
|
|
12721
|
+
const metadata = values.metadata;
|
|
12722
|
+
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
12723
|
+
if (isEmpty) {
|
|
12724
|
+
return null;
|
|
12725
|
+
}
|
|
12726
|
+
const update = {};
|
|
12727
|
+
metadata.forEach((field) => {
|
|
12728
|
+
let key = field.key;
|
|
12729
|
+
let value = field.value;
|
|
12730
|
+
const disabled = field.disabled;
|
|
12731
|
+
if (!key || !value) {
|
|
12732
|
+
return;
|
|
12733
|
+
}
|
|
12734
|
+
if (disabled) {
|
|
12735
|
+
update[key] = value;
|
|
12736
|
+
return;
|
|
12737
|
+
}
|
|
12738
|
+
key = key.trim();
|
|
12739
|
+
value = value.trim();
|
|
12740
|
+
if (value === "true") {
|
|
12741
|
+
update[key] = true;
|
|
12742
|
+
} else if (value === "false") {
|
|
12743
|
+
update[key] = false;
|
|
12744
|
+
} else {
|
|
12745
|
+
const parsedNumber = parseFloat(value);
|
|
12746
|
+
if (!isNaN(parsedNumber)) {
|
|
12747
|
+
update[key] = parsedNumber;
|
|
12748
|
+
} else {
|
|
12749
|
+
update[key] = value;
|
|
12750
|
+
}
|
|
12751
|
+
}
|
|
12752
|
+
});
|
|
12753
|
+
return update;
|
|
12754
|
+
}
|
|
12755
|
+
function getHasUneditableRows(metadata) {
|
|
12756
|
+
if (!metadata) {
|
|
12757
|
+
return false;
|
|
12758
|
+
}
|
|
12759
|
+
return Object.values(metadata).some(
|
|
12760
|
+
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
12761
|
+
);
|
|
12762
|
+
}
|
|
12763
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
12764
|
+
const promotionsQueryKeys = {
|
|
12765
|
+
list: (query2) => [
|
|
12766
|
+
PROMOTION_QUERY_KEY,
|
|
12767
|
+
query2 ? query2 : void 0
|
|
12768
|
+
],
|
|
12769
|
+
detail: (id, query2) => [
|
|
12770
|
+
PROMOTION_QUERY_KEY,
|
|
12771
|
+
id,
|
|
12772
|
+
query2 ? query2 : void 0
|
|
12773
|
+
]
|
|
12774
|
+
};
|
|
12775
|
+
const usePromotions = (query2, options) => {
|
|
12776
|
+
const { data, ...rest } = useQuery({
|
|
12777
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
12778
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
12779
|
+
...options
|
|
12780
|
+
});
|
|
12781
|
+
return { ...data, ...rest };
|
|
12782
|
+
};
|
|
12783
|
+
const Promotions = () => {
|
|
12784
|
+
const { id } = useParams();
|
|
12785
|
+
const {
|
|
12786
|
+
order: preview,
|
|
12787
|
+
isError: isPreviewError,
|
|
12788
|
+
error: previewError
|
|
12789
|
+
} = useOrderPreview(id, void 0);
|
|
12790
|
+
useInitiateOrderEdit({ preview });
|
|
12791
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
12792
|
+
if (isPreviewError) {
|
|
12793
|
+
throw previewError;
|
|
12794
|
+
}
|
|
12795
|
+
const isReady = !!preview;
|
|
12796
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
12797
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
|
|
12798
|
+
isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
|
|
12799
|
+
] });
|
|
12800
|
+
};
|
|
12801
|
+
const PromotionForm = ({ preview }) => {
|
|
12802
|
+
const { items, shipping_methods } = preview;
|
|
12803
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
12804
|
+
const [comboboxValue, setComboboxValue] = useState("");
|
|
12805
|
+
const { handleSuccess } = useRouteModal();
|
|
12806
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
12807
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
12808
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
12809
|
+
{
|
|
12810
|
+
id: promoIds
|
|
12811
|
+
},
|
|
12812
|
+
{
|
|
12813
|
+
enabled: !!promoIds.length
|
|
12814
|
+
}
|
|
12815
|
+
);
|
|
12816
|
+
const comboboxData = useComboboxData({
|
|
12817
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
12818
|
+
queryFn: async (params) => {
|
|
12819
|
+
return await sdk.admin.promotion.list({
|
|
12820
|
+
...params,
|
|
12821
|
+
id: {
|
|
12822
|
+
$nin: promoIds
|
|
12823
|
+
}
|
|
12824
|
+
});
|
|
12825
|
+
},
|
|
12826
|
+
getOptions: (data) => {
|
|
12827
|
+
return data.promotions.map((promotion) => ({
|
|
12828
|
+
label: promotion.code,
|
|
12829
|
+
value: promotion.code
|
|
12830
|
+
}));
|
|
12831
|
+
}
|
|
12832
|
+
});
|
|
12833
|
+
const add = async (value) => {
|
|
12834
|
+
if (!value) {
|
|
12835
|
+
return;
|
|
12836
|
+
}
|
|
12837
|
+
addPromotions(
|
|
12838
|
+
{
|
|
12839
|
+
promo_codes: [value]
|
|
12840
|
+
},
|
|
12841
|
+
{
|
|
12842
|
+
onError: (e) => {
|
|
12843
|
+
toast.error(e.message);
|
|
12844
|
+
comboboxData.onSearchValueChange("");
|
|
12845
|
+
setComboboxValue("");
|
|
12846
|
+
},
|
|
12847
|
+
onSuccess: () => {
|
|
12848
|
+
comboboxData.onSearchValueChange("");
|
|
12849
|
+
setComboboxValue("");
|
|
12850
|
+
}
|
|
12851
|
+
}
|
|
12852
|
+
);
|
|
12853
|
+
};
|
|
12854
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
12855
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
12856
|
+
const onSubmit = async () => {
|
|
12857
|
+
setIsSubmitting(true);
|
|
12858
|
+
let requestSucceeded = false;
|
|
12859
|
+
await requestOrderEdit(void 0, {
|
|
12860
|
+
onError: (e) => {
|
|
12861
|
+
toast.error(e.message);
|
|
12862
|
+
},
|
|
12863
|
+
onSuccess: () => {
|
|
12864
|
+
requestSucceeded = true;
|
|
12865
|
+
}
|
|
12866
|
+
});
|
|
12867
|
+
if (!requestSucceeded) {
|
|
12868
|
+
setIsSubmitting(false);
|
|
12869
|
+
return;
|
|
12870
|
+
}
|
|
12871
|
+
await confirmOrderEdit(void 0, {
|
|
12872
|
+
onError: (e) => {
|
|
12873
|
+
toast.error(e.message);
|
|
12874
|
+
},
|
|
12875
|
+
onSuccess: () => {
|
|
12876
|
+
handleSuccess();
|
|
12877
|
+
},
|
|
12878
|
+
onSettled: () => {
|
|
12879
|
+
setIsSubmitting(false);
|
|
12880
|
+
}
|
|
12881
|
+
});
|
|
12882
|
+
};
|
|
12883
|
+
if (isError) {
|
|
12884
|
+
throw error;
|
|
12885
|
+
}
|
|
12886
|
+
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
12887
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
12888
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
12889
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
12890
|
+
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
12891
|
+
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
12892
|
+
] }),
|
|
12893
|
+
/* @__PURE__ */ jsx(
|
|
12894
|
+
Combobox,
|
|
12895
|
+
{
|
|
12896
|
+
id: "promotion-combobox",
|
|
12897
|
+
"aria-describedby": "promotion-combobox-hint",
|
|
12898
|
+
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
12899
|
+
fetchNextPage: comboboxData.fetchNextPage,
|
|
12900
|
+
options: comboboxData.options,
|
|
12901
|
+
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
12902
|
+
searchValue: comboboxData.searchValue,
|
|
12903
|
+
disabled: comboboxData.disabled || isAddingPromotions,
|
|
12904
|
+
onChange: add,
|
|
12905
|
+
value: comboboxValue
|
|
12965
12906
|
}
|
|
12966
|
-
)
|
|
12967
|
-
|
|
12968
|
-
|
|
12907
|
+
)
|
|
12908
|
+
] }),
|
|
12909
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
12910
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
12911
|
+
PromotionItem,
|
|
12912
|
+
{
|
|
12913
|
+
promotion,
|
|
12914
|
+
orderId: preview.id,
|
|
12915
|
+
isLoading: isPending
|
|
12916
|
+
},
|
|
12917
|
+
promotion.id
|
|
12918
|
+
)) })
|
|
12919
|
+
] }) }),
|
|
12920
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12921
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12922
|
+
/* @__PURE__ */ jsx(
|
|
12923
|
+
Button,
|
|
12924
|
+
{
|
|
12925
|
+
size: "small",
|
|
12926
|
+
type: "submit",
|
|
12927
|
+
isLoading: isSubmitting || isAddingPromotions,
|
|
12928
|
+
children: "Save"
|
|
12929
|
+
}
|
|
12930
|
+
)
|
|
12931
|
+
] }) })
|
|
12932
|
+
] });
|
|
12933
|
+
};
|
|
12934
|
+
const PromotionItem = ({
|
|
12935
|
+
promotion,
|
|
12936
|
+
orderId,
|
|
12937
|
+
isLoading
|
|
12938
|
+
}) => {
|
|
12939
|
+
var _a;
|
|
12940
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
12941
|
+
const onRemove = async () => {
|
|
12942
|
+
removePromotions(
|
|
12943
|
+
{
|
|
12944
|
+
promo_codes: [promotion.code]
|
|
12945
|
+
},
|
|
12946
|
+
{
|
|
12947
|
+
onError: (e) => {
|
|
12948
|
+
toast.error(e.message);
|
|
12949
|
+
}
|
|
12950
|
+
}
|
|
12951
|
+
);
|
|
12952
|
+
};
|
|
12953
|
+
const displayValue = getDisplayValue(promotion);
|
|
12954
|
+
return /* @__PURE__ */ jsxs(
|
|
12955
|
+
"div",
|
|
12956
|
+
{
|
|
12957
|
+
className: clx(
|
|
12958
|
+
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
12959
|
+
{
|
|
12960
|
+
"animate-pulse": isLoading
|
|
12961
|
+
}
|
|
12962
|
+
),
|
|
12963
|
+
children: [
|
|
12964
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
12965
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
12966
|
+
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
12967
|
+
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
12968
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
12969
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
12970
|
+
] }),
|
|
12971
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
12972
|
+
] })
|
|
12973
|
+
] }),
|
|
12974
|
+
/* @__PURE__ */ jsx(
|
|
12975
|
+
IconButton,
|
|
12969
12976
|
{
|
|
12970
|
-
|
|
12971
|
-
|
|
12972
|
-
|
|
12973
|
-
|
|
12974
|
-
|
|
12977
|
+
size: "small",
|
|
12978
|
+
type: "button",
|
|
12979
|
+
variant: "transparent",
|
|
12980
|
+
onClick: onRemove,
|
|
12981
|
+
isLoading: isPending || isLoading,
|
|
12982
|
+
children: /* @__PURE__ */ jsx(XMark, {})
|
|
12975
12983
|
}
|
|
12976
|
-
)
|
|
12977
|
-
/* @__PURE__ */ jsxs("defs", { children: [
|
|
12978
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12979
|
-
"rect",
|
|
12980
|
-
{
|
|
12981
|
-
width: "12",
|
|
12982
|
-
height: "12",
|
|
12983
|
-
fill: "white",
|
|
12984
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
|
|
12985
|
-
}
|
|
12986
|
-
) }),
|
|
12987
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12988
|
-
"rect",
|
|
12989
|
-
{
|
|
12990
|
-
width: "12",
|
|
12991
|
-
height: "12",
|
|
12992
|
-
fill: "white",
|
|
12993
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
|
|
12994
|
-
}
|
|
12995
|
-
) }),
|
|
12996
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12997
|
-
"rect",
|
|
12998
|
-
{
|
|
12999
|
-
width: "12",
|
|
13000
|
-
height: "12",
|
|
13001
|
-
fill: "white",
|
|
13002
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
|
|
13003
|
-
}
|
|
13004
|
-
) }),
|
|
13005
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
|
|
13006
|
-
"rect",
|
|
13007
|
-
{
|
|
13008
|
-
width: "12",
|
|
13009
|
-
height: "12",
|
|
13010
|
-
fill: "white",
|
|
13011
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
|
|
13012
|
-
}
|
|
13013
|
-
) }),
|
|
13014
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
|
|
13015
|
-
"rect",
|
|
13016
|
-
{
|
|
13017
|
-
width: "12",
|
|
13018
|
-
height: "12",
|
|
13019
|
-
fill: "white",
|
|
13020
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
|
|
13021
|
-
}
|
|
13022
|
-
) }),
|
|
13023
|
-
/* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
|
|
13024
|
-
"rect",
|
|
13025
|
-
{
|
|
13026
|
-
width: "12",
|
|
13027
|
-
height: "12",
|
|
13028
|
-
fill: "white",
|
|
13029
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
|
|
13030
|
-
}
|
|
13031
|
-
) })
|
|
13032
|
-
] })
|
|
12984
|
+
)
|
|
13033
12985
|
]
|
|
13034
|
-
}
|
|
12986
|
+
},
|
|
12987
|
+
promotion.id
|
|
13035
12988
|
);
|
|
13036
12989
|
};
|
|
13037
|
-
|
|
13038
|
-
|
|
12990
|
+
function getDisplayValue(promotion) {
|
|
12991
|
+
var _a, _b, _c, _d;
|
|
12992
|
+
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
12993
|
+
if (!value) {
|
|
12994
|
+
return null;
|
|
12995
|
+
}
|
|
12996
|
+
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
12997
|
+
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
12998
|
+
if (!currency) {
|
|
12999
|
+
return null;
|
|
13000
|
+
}
|
|
13001
|
+
return getLocaleAmount(value, currency);
|
|
13002
|
+
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
13003
|
+
return formatPercentage(value);
|
|
13004
|
+
}
|
|
13005
|
+
return null;
|
|
13006
|
+
}
|
|
13007
|
+
const formatter = new Intl.NumberFormat([], {
|
|
13008
|
+
style: "percent",
|
|
13009
|
+
minimumFractionDigits: 2
|
|
13039
13010
|
});
|
|
13011
|
+
const formatPercentage = (value, isPercentageValue = false) => {
|
|
13012
|
+
let val = value || 0;
|
|
13013
|
+
if (!isPercentageValue) {
|
|
13014
|
+
val = val / 100;
|
|
13015
|
+
}
|
|
13016
|
+
return formatter.format(val);
|
|
13017
|
+
};
|
|
13018
|
+
function getPromotionIds(items, shippingMethods) {
|
|
13019
|
+
const promotionIds = /* @__PURE__ */ new Set();
|
|
13020
|
+
for (const item of items) {
|
|
13021
|
+
if (item.adjustments) {
|
|
13022
|
+
for (const adjustment of item.adjustments) {
|
|
13023
|
+
if (adjustment.promotion_id) {
|
|
13024
|
+
promotionIds.add(adjustment.promotion_id);
|
|
13025
|
+
}
|
|
13026
|
+
}
|
|
13027
|
+
}
|
|
13028
|
+
}
|
|
13029
|
+
for (const shippingMethod of shippingMethods) {
|
|
13030
|
+
if (shippingMethod.adjustments) {
|
|
13031
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
13032
|
+
if (adjustment.promotion_id) {
|
|
13033
|
+
promotionIds.add(adjustment.promotion_id);
|
|
13034
|
+
}
|
|
13035
|
+
}
|
|
13036
|
+
}
|
|
13037
|
+
}
|
|
13038
|
+
return Array.from(promotionIds);
|
|
13039
|
+
}
|
|
13040
13040
|
const widgetModule = { widgets: [] };
|
|
13041
13041
|
const routeModule = {
|
|
13042
13042
|
routes: [
|
|
@@ -13073,14 +13073,6 @@ const routeModule = {
|
|
|
13073
13073
|
Component: Items,
|
|
13074
13074
|
path: "/draft-orders/:id/items"
|
|
13075
13075
|
},
|
|
13076
|
-
{
|
|
13077
|
-
Component: Metadata,
|
|
13078
|
-
path: "/draft-orders/:id/metadata"
|
|
13079
|
-
},
|
|
13080
|
-
{
|
|
13081
|
-
Component: Promotions,
|
|
13082
|
-
path: "/draft-orders/:id/promotions"
|
|
13083
|
-
},
|
|
13084
13076
|
{
|
|
13085
13077
|
Component: SalesChannel,
|
|
13086
13078
|
path: "/draft-orders/:id/sales-channel"
|
|
@@ -13096,6 +13088,14 @@ const routeModule = {
|
|
|
13096
13088
|
{
|
|
13097
13089
|
Component: TransferOwnership,
|
|
13098
13090
|
path: "/draft-orders/:id/transfer-ownership"
|
|
13091
|
+
},
|
|
13092
|
+
{
|
|
13093
|
+
Component: Metadata,
|
|
13094
|
+
path: "/draft-orders/:id/metadata"
|
|
13095
|
+
},
|
|
13096
|
+
{
|
|
13097
|
+
Component: Promotions,
|
|
13098
|
+
path: "/draft-orders/:id/promotions"
|
|
13099
13099
|
}
|
|
13100
13100
|
]
|
|
13101
13101
|
}
|