@medusajs/draft-order 2.11.4-preview-20251118000304 → 2.11.4-preview-20251118032059
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 +876 -876
- package/.medusa/server/src/admin/index.mjs +876 -876
- package/package.json +16 -16
|
@@ -9755,6 +9755,27 @@ const BillingAddressForm = ({ order }) => {
|
|
|
9755
9755
|
) });
|
|
9756
9756
|
};
|
|
9757
9757
|
const schema$5 = addressSchema;
|
|
9758
|
+
const CustomItems = () => {
|
|
9759
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9760
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
|
|
9761
|
+
/* @__PURE__ */ jsx(CustomItemsForm, {})
|
|
9762
|
+
] });
|
|
9763
|
+
};
|
|
9764
|
+
const CustomItemsForm = () => {
|
|
9765
|
+
const form = useForm({
|
|
9766
|
+
resolver: zodResolver(schema$4)
|
|
9767
|
+
});
|
|
9768
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
9769
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, {}),
|
|
9770
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9771
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9772
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
|
|
9773
|
+
] }) })
|
|
9774
|
+
] }) });
|
|
9775
|
+
};
|
|
9776
|
+
const schema$4 = objectType({
|
|
9777
|
+
email: stringType().email()
|
|
9778
|
+
});
|
|
9758
9779
|
const Email = () => {
|
|
9759
9780
|
const { id } = useParams();
|
|
9760
9781
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
@@ -9777,7 +9798,7 @@ const EmailForm = ({ order }) => {
|
|
|
9777
9798
|
defaultValues: {
|
|
9778
9799
|
email: order.email ?? ""
|
|
9779
9800
|
},
|
|
9780
|
-
resolver: zodResolver(schema$
|
|
9801
|
+
resolver: zodResolver(schema$3)
|
|
9781
9802
|
});
|
|
9782
9803
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9783
9804
|
const { handleSuccess } = useRouteModal();
|
|
@@ -9820,7 +9841,7 @@ const EmailForm = ({ order }) => {
|
|
|
9820
9841
|
}
|
|
9821
9842
|
) });
|
|
9822
9843
|
};
|
|
9823
|
-
const schema$
|
|
9844
|
+
const schema$3 = objectType({
|
|
9824
9845
|
email: stringType().email()
|
|
9825
9846
|
});
|
|
9826
9847
|
const NumberInput = forwardRef(
|
|
@@ -10797,413 +10818,115 @@ const customItemSchema = objectType({
|
|
|
10797
10818
|
quantity: numberType(),
|
|
10798
10819
|
unit_price: unionType([numberType(), stringType()])
|
|
10799
10820
|
});
|
|
10800
|
-
const
|
|
10801
|
-
|
|
10802
|
-
|
|
10803
|
-
/* @__PURE__ */
|
|
10804
|
-
|
|
10805
|
-
|
|
10806
|
-
|
|
10807
|
-
|
|
10808
|
-
|
|
10809
|
-
|
|
10810
|
-
|
|
10811
|
-
|
|
10812
|
-
|
|
10813
|
-
|
|
10814
|
-
|
|
10815
|
-
|
|
10816
|
-
|
|
10817
|
-
|
|
10818
|
-
|
|
10819
|
-
|
|
10821
|
+
const InlineTip = forwardRef(
|
|
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()
|
|
10820
10861
|
});
|
|
10821
|
-
const
|
|
10822
|
-
|
|
10823
|
-
|
|
10824
|
-
|
|
10825
|
-
query2 ? query2 : void 0
|
|
10826
|
-
],
|
|
10827
|
-
detail: (id, query2) => [
|
|
10828
|
-
PROMOTION_QUERY_KEY,
|
|
10829
|
-
id,
|
|
10830
|
-
query2 ? query2 : void 0
|
|
10831
|
-
]
|
|
10832
|
-
};
|
|
10833
|
-
const usePromotions = (query2, options) => {
|
|
10834
|
-
const { data, ...rest } = useQuery({
|
|
10835
|
-
queryKey: promotionsQueryKeys.list(query2),
|
|
10836
|
-
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
10837
|
-
...options
|
|
10838
|
-
});
|
|
10839
|
-
return { ...data, ...rest };
|
|
10840
|
-
};
|
|
10841
|
-
const Promotions = () => {
|
|
10862
|
+
const MetadataSchema = objectType({
|
|
10863
|
+
metadata: arrayType(MetadataFieldSchema)
|
|
10864
|
+
});
|
|
10865
|
+
const Metadata = () => {
|
|
10842
10866
|
const { id } = useParams();
|
|
10843
|
-
const {
|
|
10844
|
-
|
|
10845
|
-
|
|
10846
|
-
|
|
10847
|
-
|
|
10848
|
-
useInitiateOrderEdit({ preview });
|
|
10849
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10850
|
-
if (isPreviewError) {
|
|
10851
|
-
throw previewError;
|
|
10867
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
10868
|
+
fields: "metadata"
|
|
10869
|
+
});
|
|
10870
|
+
if (isError) {
|
|
10871
|
+
throw error;
|
|
10852
10872
|
}
|
|
10853
|
-
const isReady = !!
|
|
10854
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, {
|
|
10855
|
-
/* @__PURE__ */
|
|
10856
|
-
|
|
10873
|
+
const isReady = !isPending && !!order;
|
|
10874
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
10875
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
10876
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
|
|
10877
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
10878
|
+
] }),
|
|
10879
|
+
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
10857
10880
|
] });
|
|
10858
10881
|
};
|
|
10859
|
-
const
|
|
10860
|
-
|
|
10861
|
-
|
|
10862
|
-
const [comboboxValue, setComboboxValue] = useState("");
|
|
10882
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
10883
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
10884
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
10863
10885
|
const { handleSuccess } = useRouteModal();
|
|
10864
|
-
const
|
|
10865
|
-
const
|
|
10866
|
-
const
|
|
10867
|
-
{
|
|
10868
|
-
|
|
10869
|
-
},
|
|
10870
|
-
{
|
|
10871
|
-
enabled: !!promoIds.length
|
|
10872
|
-
}
|
|
10873
|
-
);
|
|
10874
|
-
const comboboxData = useComboboxData({
|
|
10875
|
-
queryKey: ["promotions", "combobox", promoIds],
|
|
10876
|
-
queryFn: async (params) => {
|
|
10877
|
-
return await sdk.admin.promotion.list({
|
|
10878
|
-
...params,
|
|
10879
|
-
id: {
|
|
10880
|
-
$nin: promoIds
|
|
10881
|
-
}
|
|
10882
|
-
});
|
|
10886
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
10887
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
10888
|
+
const form = useForm({
|
|
10889
|
+
defaultValues: {
|
|
10890
|
+
metadata: getDefaultValues(metadata)
|
|
10883
10891
|
},
|
|
10884
|
-
|
|
10885
|
-
return data.promotions.map((promotion) => ({
|
|
10886
|
-
label: promotion.code,
|
|
10887
|
-
value: promotion.code
|
|
10888
|
-
}));
|
|
10889
|
-
}
|
|
10892
|
+
resolver: zodResolver(MetadataSchema)
|
|
10890
10893
|
});
|
|
10891
|
-
const
|
|
10892
|
-
|
|
10893
|
-
|
|
10894
|
-
}
|
|
10895
|
-
addPromotions(
|
|
10894
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
10895
|
+
const parsedData = parseValues(data);
|
|
10896
|
+
await mutateAsync(
|
|
10896
10897
|
{
|
|
10897
|
-
|
|
10898
|
+
metadata: parsedData
|
|
10898
10899
|
},
|
|
10899
10900
|
{
|
|
10900
|
-
onError: (e) => {
|
|
10901
|
-
toast.error(e.message);
|
|
10902
|
-
comboboxData.onSearchValueChange("");
|
|
10903
|
-
setComboboxValue("");
|
|
10904
|
-
},
|
|
10905
10901
|
onSuccess: () => {
|
|
10906
|
-
|
|
10907
|
-
|
|
10902
|
+
toast.success("Metadata updated");
|
|
10903
|
+
handleSuccess();
|
|
10904
|
+
},
|
|
10905
|
+
onError: (error) => {
|
|
10906
|
+
toast.error(error.message);
|
|
10908
10907
|
}
|
|
10909
10908
|
}
|
|
10910
10909
|
);
|
|
10911
|
-
};
|
|
10912
|
-
const {
|
|
10913
|
-
|
|
10914
|
-
|
|
10915
|
-
|
|
10916
|
-
|
|
10917
|
-
|
|
10918
|
-
|
|
10919
|
-
|
|
10920
|
-
|
|
10921
|
-
|
|
10922
|
-
|
|
10923
|
-
}
|
|
10924
|
-
});
|
|
10925
|
-
if (!requestSucceeded) {
|
|
10926
|
-
setIsSubmitting(false);
|
|
10927
|
-
return;
|
|
10910
|
+
});
|
|
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
|
+
});
|
|
10928
10923
|
}
|
|
10929
|
-
|
|
10930
|
-
|
|
10931
|
-
|
|
10932
|
-
|
|
10933
|
-
|
|
10934
|
-
|
|
10935
|
-
},
|
|
10936
|
-
onSettled: () => {
|
|
10937
|
-
setIsSubmitting(false);
|
|
10938
|
-
}
|
|
10939
|
-
});
|
|
10940
|
-
};
|
|
10941
|
-
if (isError) {
|
|
10942
|
-
throw error;
|
|
10943
|
-
}
|
|
10944
|
-
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
10945
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
10946
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
10947
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
10948
|
-
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
10949
|
-
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
10950
|
-
] }),
|
|
10951
|
-
/* @__PURE__ */ jsx(
|
|
10952
|
-
Combobox,
|
|
10953
|
-
{
|
|
10954
|
-
id: "promotion-combobox",
|
|
10955
|
-
"aria-describedby": "promotion-combobox-hint",
|
|
10956
|
-
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
10957
|
-
fetchNextPage: comboboxData.fetchNextPage,
|
|
10958
|
-
options: comboboxData.options,
|
|
10959
|
-
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
10960
|
-
searchValue: comboboxData.searchValue,
|
|
10961
|
-
disabled: comboboxData.disabled || isAddingPromotions,
|
|
10962
|
-
onChange: add,
|
|
10963
|
-
value: comboboxValue
|
|
10964
|
-
}
|
|
10965
|
-
)
|
|
10966
|
-
] }),
|
|
10967
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10968
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
10969
|
-
PromotionItem,
|
|
10970
|
-
{
|
|
10971
|
-
promotion,
|
|
10972
|
-
orderId: preview.id,
|
|
10973
|
-
isLoading: isPending
|
|
10974
|
-
},
|
|
10975
|
-
promotion.id
|
|
10976
|
-
)) })
|
|
10977
|
-
] }) }),
|
|
10978
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10979
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10980
|
-
/* @__PURE__ */ jsx(
|
|
10981
|
-
Button,
|
|
10982
|
-
{
|
|
10983
|
-
size: "small",
|
|
10984
|
-
type: "submit",
|
|
10985
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
10986
|
-
children: "Save"
|
|
10987
|
-
}
|
|
10988
|
-
)
|
|
10989
|
-
] }) })
|
|
10990
|
-
] });
|
|
10991
|
-
};
|
|
10992
|
-
const PromotionItem = ({
|
|
10993
|
-
promotion,
|
|
10994
|
-
orderId,
|
|
10995
|
-
isLoading
|
|
10996
|
-
}) => {
|
|
10997
|
-
var _a;
|
|
10998
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
10999
|
-
const onRemove = async () => {
|
|
11000
|
-
removePromotions(
|
|
11001
|
-
{
|
|
11002
|
-
promo_codes: [promotion.code]
|
|
11003
|
-
},
|
|
11004
|
-
{
|
|
11005
|
-
onError: (e) => {
|
|
11006
|
-
toast.error(e.message);
|
|
11007
|
-
}
|
|
11008
|
-
}
|
|
11009
|
-
);
|
|
11010
|
-
};
|
|
11011
|
-
const displayValue = getDisplayValue(promotion);
|
|
11012
|
-
return /* @__PURE__ */ jsxs(
|
|
11013
|
-
"div",
|
|
11014
|
-
{
|
|
11015
|
-
className: clx(
|
|
11016
|
-
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11017
|
-
{
|
|
11018
|
-
"animate-pulse": isLoading
|
|
11019
|
-
}
|
|
11020
|
-
),
|
|
11021
|
-
children: [
|
|
11022
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
11023
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11024
|
-
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11025
|
-
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11026
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11027
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
11028
|
-
] }),
|
|
11029
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11030
|
-
] })
|
|
11031
|
-
] }),
|
|
11032
|
-
/* @__PURE__ */ jsx(
|
|
11033
|
-
IconButton,
|
|
11034
|
-
{
|
|
11035
|
-
size: "small",
|
|
11036
|
-
type: "button",
|
|
11037
|
-
variant: "transparent",
|
|
11038
|
-
onClick: onRemove,
|
|
11039
|
-
isLoading: isPending || isLoading,
|
|
11040
|
-
children: /* @__PURE__ */ jsx(XMark, {})
|
|
11041
|
-
}
|
|
11042
|
-
)
|
|
11043
|
-
]
|
|
11044
|
-
},
|
|
11045
|
-
promotion.id
|
|
11046
|
-
);
|
|
11047
|
-
};
|
|
11048
|
-
function getDisplayValue(promotion) {
|
|
11049
|
-
var _a, _b, _c, _d;
|
|
11050
|
-
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11051
|
-
if (!value) {
|
|
11052
|
-
return null;
|
|
11053
|
-
}
|
|
11054
|
-
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11055
|
-
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11056
|
-
if (!currency) {
|
|
11057
|
-
return null;
|
|
11058
|
-
}
|
|
11059
|
-
return getLocaleAmount(value, currency);
|
|
11060
|
-
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11061
|
-
return formatPercentage(value);
|
|
11062
|
-
}
|
|
11063
|
-
return null;
|
|
11064
|
-
}
|
|
11065
|
-
const formatter = new Intl.NumberFormat([], {
|
|
11066
|
-
style: "percent",
|
|
11067
|
-
minimumFractionDigits: 2
|
|
11068
|
-
});
|
|
11069
|
-
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11070
|
-
let val = value || 0;
|
|
11071
|
-
if (!isPercentageValue) {
|
|
11072
|
-
val = val / 100;
|
|
11073
|
-
}
|
|
11074
|
-
return formatter.format(val);
|
|
11075
|
-
};
|
|
11076
|
-
function getPromotionIds(items, shippingMethods) {
|
|
11077
|
-
const promotionIds = /* @__PURE__ */ new Set();
|
|
11078
|
-
for (const item of items) {
|
|
11079
|
-
if (item.adjustments) {
|
|
11080
|
-
for (const adjustment of item.adjustments) {
|
|
11081
|
-
if (adjustment.promotion_id) {
|
|
11082
|
-
promotionIds.add(adjustment.promotion_id);
|
|
11083
|
-
}
|
|
11084
|
-
}
|
|
11085
|
-
}
|
|
11086
|
-
}
|
|
11087
|
-
for (const shippingMethod of shippingMethods) {
|
|
11088
|
-
if (shippingMethod.adjustments) {
|
|
11089
|
-
for (const adjustment of shippingMethod.adjustments) {
|
|
11090
|
-
if (adjustment.promotion_id) {
|
|
11091
|
-
promotionIds.add(adjustment.promotion_id);
|
|
11092
|
-
}
|
|
11093
|
-
}
|
|
11094
|
-
}
|
|
11095
|
-
}
|
|
11096
|
-
return Array.from(promotionIds);
|
|
11097
|
-
}
|
|
11098
|
-
const InlineTip = forwardRef(
|
|
11099
|
-
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
11100
|
-
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
11101
|
-
return /* @__PURE__ */ jsxs(
|
|
11102
|
-
"div",
|
|
11103
|
-
{
|
|
11104
|
-
ref,
|
|
11105
|
-
className: clx(
|
|
11106
|
-
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
11107
|
-
className
|
|
11108
|
-
),
|
|
11109
|
-
...props,
|
|
11110
|
-
children: [
|
|
11111
|
-
/* @__PURE__ */ jsx(
|
|
11112
|
-
"div",
|
|
11113
|
-
{
|
|
11114
|
-
role: "presentation",
|
|
11115
|
-
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
11116
|
-
"bg-ui-tag-orange-icon": variant === "warning"
|
|
11117
|
-
})
|
|
11118
|
-
}
|
|
11119
|
-
),
|
|
11120
|
-
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
11121
|
-
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
11122
|
-
labelValue,
|
|
11123
|
-
":"
|
|
11124
|
-
] }),
|
|
11125
|
-
" ",
|
|
11126
|
-
children
|
|
11127
|
-
] })
|
|
11128
|
-
]
|
|
11129
|
-
}
|
|
11130
|
-
);
|
|
11131
|
-
}
|
|
11132
|
-
);
|
|
11133
|
-
InlineTip.displayName = "InlineTip";
|
|
11134
|
-
const MetadataFieldSchema = objectType({
|
|
11135
|
-
key: stringType(),
|
|
11136
|
-
disabled: booleanType().optional(),
|
|
11137
|
-
value: anyType()
|
|
11138
|
-
});
|
|
11139
|
-
const MetadataSchema = objectType({
|
|
11140
|
-
metadata: arrayType(MetadataFieldSchema)
|
|
11141
|
-
});
|
|
11142
|
-
const Metadata = () => {
|
|
11143
|
-
const { id } = useParams();
|
|
11144
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
11145
|
-
fields: "metadata"
|
|
11146
|
-
});
|
|
11147
|
-
if (isError) {
|
|
11148
|
-
throw error;
|
|
11149
|
-
}
|
|
11150
|
-
const isReady = !isPending && !!order;
|
|
11151
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11152
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
11153
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
|
|
11154
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
11155
|
-
] }),
|
|
11156
|
-
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
11157
|
-
] });
|
|
11158
|
-
};
|
|
11159
|
-
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
11160
|
-
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
11161
|
-
const MetadataForm = ({ orderId, metadata }) => {
|
|
11162
|
-
const { handleSuccess } = useRouteModal();
|
|
11163
|
-
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
11164
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
11165
|
-
const form = useForm({
|
|
11166
|
-
defaultValues: {
|
|
11167
|
-
metadata: getDefaultValues(metadata)
|
|
11168
|
-
},
|
|
11169
|
-
resolver: zodResolver(MetadataSchema)
|
|
11170
|
-
});
|
|
11171
|
-
const handleSubmit = form.handleSubmit(async (data) => {
|
|
11172
|
-
const parsedData = parseValues(data);
|
|
11173
|
-
await mutateAsync(
|
|
11174
|
-
{
|
|
11175
|
-
metadata: parsedData
|
|
11176
|
-
},
|
|
11177
|
-
{
|
|
11178
|
-
onSuccess: () => {
|
|
11179
|
-
toast.success("Metadata updated");
|
|
11180
|
-
handleSuccess();
|
|
11181
|
-
},
|
|
11182
|
-
onError: (error) => {
|
|
11183
|
-
toast.error(error.message);
|
|
11184
|
-
}
|
|
11185
|
-
}
|
|
11186
|
-
);
|
|
11187
|
-
});
|
|
11188
|
-
const { fields, insert, remove } = useFieldArray({
|
|
11189
|
-
control: form.control,
|
|
11190
|
-
name: "metadata"
|
|
11191
|
-
});
|
|
11192
|
-
function deleteRow(index) {
|
|
11193
|
-
remove(index);
|
|
11194
|
-
if (fields.length === 1) {
|
|
11195
|
-
insert(0, {
|
|
11196
|
-
key: "",
|
|
11197
|
-
value: "",
|
|
11198
|
-
disabled: false
|
|
11199
|
-
});
|
|
11200
|
-
}
|
|
11201
|
-
}
|
|
11202
|
-
function insertRow(index, position) {
|
|
11203
|
-
insert(index + (position === "above" ? 0 : 1), {
|
|
11204
|
-
key: "",
|
|
11205
|
-
value: "",
|
|
11206
|
-
disabled: false
|
|
10924
|
+
}
|
|
10925
|
+
function insertRow(index, position) {
|
|
10926
|
+
insert(index + (position === "above" ? 0 : 1), {
|
|
10927
|
+
key: "",
|
|
10928
|
+
value: "",
|
|
10929
|
+
disabled: false
|
|
11207
10930
|
});
|
|
11208
10931
|
}
|
|
11209
10932
|
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
@@ -11445,77 +11168,105 @@ function getHasUneditableRows(metadata) {
|
|
|
11445
11168
|
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11446
11169
|
);
|
|
11447
11170
|
}
|
|
11448
|
-
const
|
|
11449
|
-
const
|
|
11450
|
-
|
|
11451
|
-
|
|
11452
|
-
|
|
11453
|
-
|
|
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
|
|
11454
11188
|
});
|
|
11189
|
+
return { ...data, ...rest };
|
|
11190
|
+
};
|
|
11191
|
+
const Promotions = () => {
|
|
11192
|
+
const { id } = useParams();
|
|
11455
11193
|
const {
|
|
11456
11194
|
order: preview,
|
|
11457
|
-
isPending: isPreviewPending,
|
|
11458
11195
|
isError: isPreviewError,
|
|
11459
11196
|
error: previewError
|
|
11460
|
-
} = useOrderPreview(id);
|
|
11197
|
+
} = useOrderPreview(id, void 0);
|
|
11461
11198
|
useInitiateOrderEdit({ preview });
|
|
11462
11199
|
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11463
|
-
if (isError) {
|
|
11464
|
-
throw error;
|
|
11465
|
-
}
|
|
11466
11200
|
if (isPreviewError) {
|
|
11467
11201
|
throw previewError;
|
|
11468
11202
|
}
|
|
11469
|
-
const
|
|
11470
|
-
|
|
11471
|
-
|
|
11472
|
-
/* @__PURE__ */ jsx(
|
|
11473
|
-
|
|
11474
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
|
|
11475
|
-
/* @__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." }) })
|
|
11476
|
-
] }) }) }),
|
|
11477
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
11478
|
-
] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
11479
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
11480
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
11481
|
-
] }) });
|
|
11203
|
+
const isReady = !!preview;
|
|
11204
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
11205
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
|
|
11206
|
+
isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
|
|
11207
|
+
] });
|
|
11482
11208
|
};
|
|
11483
|
-
const
|
|
11484
|
-
|
|
11485
|
-
const { setIsOpen } = useStackedModal();
|
|
11209
|
+
const PromotionForm = ({ preview }) => {
|
|
11210
|
+
const { items, shipping_methods } = preview;
|
|
11486
11211
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
11487
|
-
const [
|
|
11488
|
-
const
|
|
11489
|
-
const {
|
|
11212
|
+
const [comboboxValue, setComboboxValue] = useState("");
|
|
11213
|
+
const { handleSuccess } = useRouteModal();
|
|
11214
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
11215
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
11216
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
11490
11217
|
{
|
|
11491
|
-
id:
|
|
11492
|
-
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
11218
|
+
id: promoIds
|
|
11493
11219
|
},
|
|
11494
11220
|
{
|
|
11495
|
-
enabled:
|
|
11221
|
+
enabled: !!promoIds.length
|
|
11496
11222
|
}
|
|
11497
11223
|
);
|
|
11498
|
-
const
|
|
11499
|
-
|
|
11500
|
-
|
|
11501
|
-
|
|
11502
|
-
|
|
11503
|
-
|
|
11504
|
-
|
|
11505
|
-
|
|
11506
|
-
|
|
11507
|
-
|
|
11508
|
-
|
|
11224
|
+
const comboboxData = useComboboxData({
|
|
11225
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
11226
|
+
queryFn: async (params) => {
|
|
11227
|
+
return await sdk.admin.promotion.list({
|
|
11228
|
+
...params,
|
|
11229
|
+
id: {
|
|
11230
|
+
$nin: promoIds
|
|
11231
|
+
}
|
|
11232
|
+
});
|
|
11233
|
+
},
|
|
11234
|
+
getOptions: (data) => {
|
|
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
|
+
};
|
|
11509
11262
|
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11510
|
-
const { mutateAsync: requestOrderEdit } =
|
|
11511
|
-
const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
|
|
11512
|
-
const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
|
|
11263
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
11513
11264
|
const onSubmit = async () => {
|
|
11514
11265
|
setIsSubmitting(true);
|
|
11515
11266
|
let requestSucceeded = false;
|
|
11516
11267
|
await requestOrderEdit(void 0, {
|
|
11517
11268
|
onError: (e) => {
|
|
11518
|
-
toast.error(
|
|
11269
|
+
toast.error(e.message);
|
|
11519
11270
|
},
|
|
11520
11271
|
onSuccess: () => {
|
|
11521
11272
|
requestSucceeded = true;
|
|
@@ -11527,7 +11278,7 @@ const ShippingForm = ({ preview, order }) => {
|
|
|
11527
11278
|
}
|
|
11528
11279
|
await confirmOrderEdit(void 0, {
|
|
11529
11280
|
onError: (e) => {
|
|
11530
|
-
toast.error(
|
|
11281
|
+
toast.error(e.message);
|
|
11531
11282
|
},
|
|
11532
11283
|
onSuccess: () => {
|
|
11533
11284
|
handleSuccess();
|
|
@@ -11537,56 +11288,411 @@ const ShippingForm = ({ preview, order }) => {
|
|
|
11537
11288
|
}
|
|
11538
11289
|
});
|
|
11539
11290
|
};
|
|
11540
|
-
|
|
11541
|
-
|
|
11542
|
-
|
|
11543
|
-
|
|
11544
|
-
|
|
11291
|
+
if (isError) {
|
|
11292
|
+
throw error;
|
|
11293
|
+
}
|
|
11294
|
+
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
11295
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
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);
|
|
11545
11357
|
}
|
|
11546
|
-
onSubmit();
|
|
11547
11358
|
}
|
|
11548
|
-
|
|
11549
|
-
|
|
11550
|
-
);
|
|
11551
|
-
|
|
11552
|
-
|
|
11553
|
-
|
|
11554
|
-
|
|
11555
|
-
|
|
11556
|
-
|
|
11557
|
-
|
|
11558
|
-
|
|
11559
|
-
|
|
11560
|
-
|
|
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: [
|
|
11561
11372
|
/* @__PURE__ */ jsxs("div", { children: [
|
|
11562
|
-
/* @__PURE__ */ jsx(
|
|
11563
|
-
/* @__PURE__ */
|
|
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
|
+
] })
|
|
11564
11381
|
] }),
|
|
11565
|
-
/* @__PURE__ */ jsx(
|
|
11566
|
-
|
|
11567
|
-
|
|
11568
|
-
|
|
11569
|
-
|
|
11570
|
-
|
|
11571
|
-
|
|
11572
|
-
|
|
11573
|
-
|
|
11574
|
-
|
|
11575
|
-
|
|
11576
|
-
|
|
11577
|
-
|
|
11578
|
-
|
|
11579
|
-
|
|
11580
|
-
|
|
11581
|
-
|
|
11582
|
-
|
|
11583
|
-
|
|
11584
|
-
|
|
11585
|
-
|
|
11586
|
-
|
|
11587
|
-
|
|
11588
|
-
|
|
11589
|
-
|
|
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);
|
|
11492
|
+
}
|
|
11493
|
+
}
|
|
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
|
+
},
|
|
11523
|
+
defaultValue: order.sales_channel_id || void 0
|
|
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]
|
|
11656
|
+
);
|
|
11657
|
+
useEffect(() => {
|
|
11658
|
+
document.addEventListener("keydown", onKeydown);
|
|
11659
|
+
return () => {
|
|
11660
|
+
document.removeEventListener("keydown", onKeydown);
|
|
11661
|
+
};
|
|
11662
|
+
}, [onKeydown]);
|
|
11663
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
|
|
11664
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
11665
|
+
/* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
11666
|
+
/* @__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: [
|
|
11667
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
11668
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
|
|
11669
|
+
/* @__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." }) })
|
|
11670
|
+
] }),
|
|
11671
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
11672
|
+
/* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
|
|
11673
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
|
|
11674
|
+
/* @__PURE__ */ jsx(
|
|
11675
|
+
Text,
|
|
11676
|
+
{
|
|
11677
|
+
size: "xsmall",
|
|
11678
|
+
weight: "plus",
|
|
11679
|
+
className: "text-ui-fg-muted",
|
|
11680
|
+
children: "Shipping profile"
|
|
11681
|
+
}
|
|
11682
|
+
),
|
|
11683
|
+
/* @__PURE__ */ jsx(
|
|
11684
|
+
Text,
|
|
11685
|
+
{
|
|
11686
|
+
size: "xsmall",
|
|
11687
|
+
weight: "plus",
|
|
11688
|
+
className: "text-ui-fg-muted",
|
|
11689
|
+
children: "Action"
|
|
11690
|
+
}
|
|
11691
|
+
)
|
|
11692
|
+
] }),
|
|
11693
|
+
/* @__PURE__ */ jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
|
|
11694
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
11695
|
+
const items = getItemsWithShippingProfile(
|
|
11590
11696
|
profile.id,
|
|
11591
11697
|
order.items
|
|
11592
11698
|
);
|
|
@@ -12165,402 +12271,93 @@ const ShippingOptionField = ({
|
|
|
12165
12271
|
queryFn: async (params) => {
|
|
12166
12272
|
return await sdk.admin.shippingOption.list({
|
|
12167
12273
|
...params,
|
|
12168
|
-
stock_location_id: locationId,
|
|
12169
|
-
shipping_profile_id: shippingProfileId
|
|
12170
|
-
});
|
|
12171
|
-
},
|
|
12172
|
-
getOptions: (data) => {
|
|
12173
|
-
return data.shipping_options.map((option) => {
|
|
12174
|
-
var _a2;
|
|
12175
|
-
if ((_a2 = option.rules) == null ? void 0 : _a2.find(
|
|
12176
|
-
(r) => r.attribute === "is_return" && r.value === "true"
|
|
12177
|
-
)) {
|
|
12178
|
-
return void 0;
|
|
12179
|
-
}
|
|
12180
|
-
return {
|
|
12181
|
-
label: option.name,
|
|
12182
|
-
value: option.id
|
|
12183
|
-
};
|
|
12184
|
-
}).filter(Boolean);
|
|
12185
|
-
},
|
|
12186
|
-
enabled: !!locationId && !!shippingProfileId,
|
|
12187
|
-
defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
|
|
12188
|
-
});
|
|
12189
|
-
const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
|
|
12190
|
-
return /* @__PURE__ */ jsx(
|
|
12191
|
-
Form$2.Field,
|
|
12192
|
-
{
|
|
12193
|
-
control,
|
|
12194
|
-
name: "shipping_option_id",
|
|
12195
|
-
render: ({ field }) => {
|
|
12196
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
12197
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
12198
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
|
|
12199
|
-
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
|
|
12200
|
-
] }),
|
|
12201
|
-
/* @__PURE__ */ jsx(
|
|
12202
|
-
ConditionalTooltip,
|
|
12203
|
-
{
|
|
12204
|
-
content: tooltipContent,
|
|
12205
|
-
showTooltip: !locationId || !shippingProfileId,
|
|
12206
|
-
children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
12207
|
-
Combobox,
|
|
12208
|
-
{
|
|
12209
|
-
options: shippingOptions.options,
|
|
12210
|
-
fetchNextPage: shippingOptions.fetchNextPage,
|
|
12211
|
-
isFetchingNextPage: shippingOptions.isFetchingNextPage,
|
|
12212
|
-
searchValue: shippingOptions.searchValue,
|
|
12213
|
-
onSearchValueChange: shippingOptions.onSearchValueChange,
|
|
12214
|
-
placeholder: "Select shipping option",
|
|
12215
|
-
...field,
|
|
12216
|
-
disabled: !locationId || !shippingProfileId
|
|
12217
|
-
}
|
|
12218
|
-
) }) })
|
|
12219
|
-
}
|
|
12220
|
-
)
|
|
12221
|
-
] }) });
|
|
12222
|
-
}
|
|
12223
|
-
}
|
|
12224
|
-
);
|
|
12225
|
-
};
|
|
12226
|
-
const CustomAmountField = ({
|
|
12227
|
-
control,
|
|
12228
|
-
currencyCode
|
|
12229
|
-
}) => {
|
|
12230
|
-
return /* @__PURE__ */ jsx(
|
|
12231
|
-
Form$2.Field,
|
|
12232
|
-
{
|
|
12233
|
-
control,
|
|
12234
|
-
name: "custom_amount",
|
|
12235
|
-
render: ({ field: { onChange, ...field } }) => {
|
|
12236
|
-
return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
12237
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
12238
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
|
|
12239
|
-
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
|
|
12240
|
-
] }),
|
|
12241
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
12242
|
-
CurrencyInput,
|
|
12243
|
-
{
|
|
12244
|
-
...field,
|
|
12245
|
-
onValueChange: (value) => onChange(value),
|
|
12246
|
-
symbol: getNativeSymbol(currencyCode),
|
|
12247
|
-
code: currencyCode
|
|
12248
|
-
}
|
|
12249
|
-
) })
|
|
12250
|
-
] });
|
|
12251
|
-
}
|
|
12252
|
-
}
|
|
12253
|
-
);
|
|
12254
|
-
};
|
|
12255
|
-
const SalesChannel = () => {
|
|
12256
|
-
const { id } = useParams();
|
|
12257
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
12258
|
-
id,
|
|
12259
|
-
{
|
|
12260
|
-
fields: "+sales_channel_id"
|
|
12261
|
-
},
|
|
12262
|
-
{
|
|
12263
|
-
enabled: !!id
|
|
12264
|
-
}
|
|
12265
|
-
);
|
|
12266
|
-
if (isError) {
|
|
12267
|
-
throw error;
|
|
12268
|
-
}
|
|
12269
|
-
const ISrEADY = !!draft_order && !isPending;
|
|
12270
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12271
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
12272
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
12273
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
12274
|
-
] }),
|
|
12275
|
-
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
12276
|
-
] });
|
|
12277
|
-
};
|
|
12278
|
-
const SalesChannelForm = ({ order }) => {
|
|
12279
|
-
const form = useForm({
|
|
12280
|
-
defaultValues: {
|
|
12281
|
-
sales_channel_id: order.sales_channel_id || ""
|
|
12282
|
-
},
|
|
12283
|
-
resolver: zodResolver(schema$2)
|
|
12284
|
-
});
|
|
12285
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12286
|
-
const { handleSuccess } = useRouteModal();
|
|
12287
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
12288
|
-
await mutateAsync(
|
|
12289
|
-
{
|
|
12290
|
-
sales_channel_id: data.sales_channel_id
|
|
12291
|
-
},
|
|
12292
|
-
{
|
|
12293
|
-
onSuccess: () => {
|
|
12294
|
-
toast.success("Sales channel updated");
|
|
12295
|
-
handleSuccess();
|
|
12296
|
-
},
|
|
12297
|
-
onError: (error) => {
|
|
12298
|
-
toast.error(error.message);
|
|
12299
|
-
}
|
|
12300
|
-
}
|
|
12301
|
-
);
|
|
12302
|
-
});
|
|
12303
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
12304
|
-
KeyboundForm,
|
|
12305
|
-
{
|
|
12306
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
12307
|
-
onSubmit,
|
|
12308
|
-
children: [
|
|
12309
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
12310
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12311
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12312
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12313
|
-
] }) })
|
|
12314
|
-
]
|
|
12315
|
-
}
|
|
12316
|
-
) });
|
|
12317
|
-
};
|
|
12318
|
-
const SalesChannelField = ({ control, order }) => {
|
|
12319
|
-
const salesChannels = useComboboxData({
|
|
12320
|
-
queryFn: async (params) => {
|
|
12321
|
-
return await sdk.admin.salesChannel.list(params);
|
|
12274
|
+
stock_location_id: locationId,
|
|
12275
|
+
shipping_profile_id: shippingProfileId
|
|
12276
|
+
});
|
|
12322
12277
|
},
|
|
12323
|
-
queryKey: ["sales-channels"],
|
|
12324
12278
|
getOptions: (data) => {
|
|
12325
|
-
return data.
|
|
12326
|
-
|
|
12327
|
-
|
|
12328
|
-
|
|
12279
|
+
return data.shipping_options.map((option) => {
|
|
12280
|
+
var _a2;
|
|
12281
|
+
if ((_a2 = option.rules) == null ? void 0 : _a2.find(
|
|
12282
|
+
(r) => r.attribute === "is_return" && r.value === "true"
|
|
12283
|
+
)) {
|
|
12284
|
+
return void 0;
|
|
12285
|
+
}
|
|
12286
|
+
return {
|
|
12287
|
+
label: option.name,
|
|
12288
|
+
value: option.id
|
|
12289
|
+
};
|
|
12290
|
+
}).filter(Boolean);
|
|
12329
12291
|
},
|
|
12330
|
-
|
|
12292
|
+
enabled: !!locationId && !!shippingProfileId,
|
|
12293
|
+
defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
|
|
12331
12294
|
});
|
|
12295
|
+
const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
|
|
12332
12296
|
return /* @__PURE__ */ jsx(
|
|
12333
12297
|
Form$2.Field,
|
|
12334
12298
|
{
|
|
12335
12299
|
control,
|
|
12336
|
-
name: "
|
|
12300
|
+
name: "shipping_option_id",
|
|
12337
12301
|
render: ({ field }) => {
|
|
12338
|
-
return /* @__PURE__ */
|
|
12339
|
-
/* @__PURE__ */
|
|
12340
|
-
|
|
12341
|
-
|
|
12302
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
12303
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
12304
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
|
|
12305
|
+
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
|
|
12306
|
+
] }),
|
|
12307
|
+
/* @__PURE__ */ jsx(
|
|
12308
|
+
ConditionalTooltip,
|
|
12342
12309
|
{
|
|
12343
|
-
|
|
12344
|
-
|
|
12345
|
-
|
|
12346
|
-
|
|
12347
|
-
|
|
12348
|
-
|
|
12349
|
-
|
|
12310
|
+
content: tooltipContent,
|
|
12311
|
+
showTooltip: !locationId || !shippingProfileId,
|
|
12312
|
+
children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
12313
|
+
Combobox,
|
|
12314
|
+
{
|
|
12315
|
+
options: shippingOptions.options,
|
|
12316
|
+
fetchNextPage: shippingOptions.fetchNextPage,
|
|
12317
|
+
isFetchingNextPage: shippingOptions.isFetchingNextPage,
|
|
12318
|
+
searchValue: shippingOptions.searchValue,
|
|
12319
|
+
onSearchValueChange: shippingOptions.onSearchValueChange,
|
|
12320
|
+
placeholder: "Select shipping option",
|
|
12321
|
+
...field,
|
|
12322
|
+
disabled: !locationId || !shippingProfileId
|
|
12323
|
+
}
|
|
12324
|
+
) }) })
|
|
12350
12325
|
}
|
|
12351
|
-
)
|
|
12352
|
-
|
|
12353
|
-
] });
|
|
12326
|
+
)
|
|
12327
|
+
] }) });
|
|
12354
12328
|
}
|
|
12355
12329
|
}
|
|
12356
12330
|
);
|
|
12357
12331
|
};
|
|
12358
|
-
const
|
|
12359
|
-
|
|
12360
|
-
|
|
12361
|
-
|
|
12362
|
-
|
|
12363
|
-
|
|
12364
|
-
fields: "+shipping_address"
|
|
12365
|
-
});
|
|
12366
|
-
if (isError) {
|
|
12367
|
-
throw error;
|
|
12368
|
-
}
|
|
12369
|
-
const isReady = !isPending && !!order;
|
|
12370
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12371
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
12372
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
|
|
12373
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
|
|
12374
|
-
] }),
|
|
12375
|
-
isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
|
|
12376
|
-
] });
|
|
12377
|
-
};
|
|
12378
|
-
const ShippingAddressForm = ({ order }) => {
|
|
12379
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
12380
|
-
const form = useForm({
|
|
12381
|
-
defaultValues: {
|
|
12382
|
-
first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
|
|
12383
|
-
last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
|
|
12384
|
-
company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
|
|
12385
|
-
address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
|
|
12386
|
-
address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
|
|
12387
|
-
city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
|
|
12388
|
-
province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
|
|
12389
|
-
country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
|
|
12390
|
-
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12391
|
-
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
12392
|
-
},
|
|
12393
|
-
resolver: zodResolver(schema$1)
|
|
12394
|
-
});
|
|
12395
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12396
|
-
const { handleSuccess } = useRouteModal();
|
|
12397
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
12398
|
-
await mutateAsync(
|
|
12399
|
-
{
|
|
12400
|
-
shipping_address: {
|
|
12401
|
-
first_name: data.first_name,
|
|
12402
|
-
last_name: data.last_name,
|
|
12403
|
-
company: data.company,
|
|
12404
|
-
address_1: data.address_1,
|
|
12405
|
-
address_2: data.address_2,
|
|
12406
|
-
city: data.city,
|
|
12407
|
-
province: data.province,
|
|
12408
|
-
country_code: data.country_code,
|
|
12409
|
-
postal_code: data.postal_code,
|
|
12410
|
-
phone: data.phone
|
|
12411
|
-
}
|
|
12412
|
-
},
|
|
12413
|
-
{
|
|
12414
|
-
onSuccess: () => {
|
|
12415
|
-
handleSuccess();
|
|
12416
|
-
},
|
|
12417
|
-
onError: (error) => {
|
|
12418
|
-
toast.error(error.message);
|
|
12419
|
-
}
|
|
12420
|
-
}
|
|
12421
|
-
);
|
|
12422
|
-
});
|
|
12423
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
12424
|
-
KeyboundForm,
|
|
12332
|
+
const CustomAmountField = ({
|
|
12333
|
+
control,
|
|
12334
|
+
currencyCode
|
|
12335
|
+
}) => {
|
|
12336
|
+
return /* @__PURE__ */ jsx(
|
|
12337
|
+
Form$2.Field,
|
|
12425
12338
|
{
|
|
12426
|
-
|
|
12427
|
-
|
|
12428
|
-
|
|
12429
|
-
|
|
12430
|
-
/* @__PURE__ */
|
|
12431
|
-
Form$2.
|
|
12432
|
-
{
|
|
12433
|
-
|
|
12434
|
-
|
|
12435
|
-
|
|
12436
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
|
|
12437
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
|
|
12438
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12439
|
-
] })
|
|
12440
|
-
}
|
|
12441
|
-
),
|
|
12442
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
12443
|
-
/* @__PURE__ */ jsx(
|
|
12444
|
-
Form$2.Field,
|
|
12445
|
-
{
|
|
12446
|
-
control: form.control,
|
|
12447
|
-
name: "first_name",
|
|
12448
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12449
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
|
|
12450
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12451
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12452
|
-
] })
|
|
12453
|
-
}
|
|
12454
|
-
),
|
|
12455
|
-
/* @__PURE__ */ jsx(
|
|
12456
|
-
Form$2.Field,
|
|
12457
|
-
{
|
|
12458
|
-
control: form.control,
|
|
12459
|
-
name: "last_name",
|
|
12460
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12461
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
|
|
12462
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12463
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12464
|
-
] })
|
|
12465
|
-
}
|
|
12466
|
-
)
|
|
12467
|
-
] }),
|
|
12468
|
-
/* @__PURE__ */ jsx(
|
|
12469
|
-
Form$2.Field,
|
|
12470
|
-
{
|
|
12471
|
-
control: form.control,
|
|
12472
|
-
name: "company",
|
|
12473
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12474
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
12475
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12476
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12477
|
-
] })
|
|
12478
|
-
}
|
|
12479
|
-
),
|
|
12480
|
-
/* @__PURE__ */ jsx(
|
|
12481
|
-
Form$2.Field,
|
|
12482
|
-
{
|
|
12483
|
-
control: form.control,
|
|
12484
|
-
name: "address_1",
|
|
12485
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12486
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
|
|
12487
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12488
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12489
|
-
] })
|
|
12490
|
-
}
|
|
12491
|
-
),
|
|
12492
|
-
/* @__PURE__ */ jsx(
|
|
12493
|
-
Form$2.Field,
|
|
12494
|
-
{
|
|
12495
|
-
control: form.control,
|
|
12496
|
-
name: "address_2",
|
|
12497
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12498
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
12499
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12500
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12501
|
-
] })
|
|
12502
|
-
}
|
|
12503
|
-
),
|
|
12504
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
12505
|
-
/* @__PURE__ */ jsx(
|
|
12506
|
-
Form$2.Field,
|
|
12507
|
-
{
|
|
12508
|
-
control: form.control,
|
|
12509
|
-
name: "postal_code",
|
|
12510
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12511
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
|
|
12512
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12513
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12514
|
-
] })
|
|
12515
|
-
}
|
|
12516
|
-
),
|
|
12517
|
-
/* @__PURE__ */ jsx(
|
|
12518
|
-
Form$2.Field,
|
|
12519
|
-
{
|
|
12520
|
-
control: form.control,
|
|
12521
|
-
name: "city",
|
|
12522
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12523
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
|
|
12524
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12525
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12526
|
-
] })
|
|
12527
|
-
}
|
|
12528
|
-
)
|
|
12529
|
-
] }),
|
|
12530
|
-
/* @__PURE__ */ jsx(
|
|
12531
|
-
Form$2.Field,
|
|
12532
|
-
{
|
|
12533
|
-
control: form.control,
|
|
12534
|
-
name: "province",
|
|
12535
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12536
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
12537
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12538
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12539
|
-
] })
|
|
12540
|
-
}
|
|
12541
|
-
),
|
|
12542
|
-
/* @__PURE__ */ jsx(
|
|
12543
|
-
Form$2.Field,
|
|
12339
|
+
control,
|
|
12340
|
+
name: "custom_amount",
|
|
12341
|
+
render: ({ field: { onChange, ...field } }) => {
|
|
12342
|
+
return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
12343
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
12344
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
|
|
12345
|
+
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
|
|
12346
|
+
] }),
|
|
12347
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
12348
|
+
CurrencyInput,
|
|
12544
12349
|
{
|
|
12545
|
-
|
|
12546
|
-
|
|
12547
|
-
|
|
12548
|
-
|
|
12549
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12550
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12551
|
-
] })
|
|
12350
|
+
...field,
|
|
12351
|
+
onValueChange: (value) => onChange(value),
|
|
12352
|
+
symbol: getNativeSymbol(currencyCode),
|
|
12353
|
+
code: currencyCode
|
|
12552
12354
|
}
|
|
12553
|
-
)
|
|
12554
|
-
] })
|
|
12555
|
-
|
|
12556
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12557
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12558
|
-
] }) })
|
|
12559
|
-
]
|
|
12355
|
+
) })
|
|
12356
|
+
] });
|
|
12357
|
+
}
|
|
12560
12358
|
}
|
|
12561
|
-
)
|
|
12359
|
+
);
|
|
12562
12360
|
};
|
|
12563
|
-
const schema$1 = addressSchema;
|
|
12564
12361
|
const TransferOwnership = () => {
|
|
12565
12362
|
const { id } = useParams();
|
|
12566
12363
|
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
@@ -12584,7 +12381,7 @@ const TransferOwnershipForm = ({ order }) => {
|
|
|
12584
12381
|
defaultValues: {
|
|
12585
12382
|
customer_id: order.customer_id || ""
|
|
12586
12383
|
},
|
|
12587
|
-
resolver: zodResolver(schema)
|
|
12384
|
+
resolver: zodResolver(schema$1)
|
|
12588
12385
|
});
|
|
12589
12386
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12590
12387
|
const { handleSuccess } = useRouteModal();
|
|
@@ -13034,9 +12831,212 @@ const Illustration = () => {
|
|
|
13034
12831
|
}
|
|
13035
12832
|
);
|
|
13036
12833
|
};
|
|
13037
|
-
const schema = objectType({
|
|
12834
|
+
const schema$1 = objectType({
|
|
13038
12835
|
customer_id: stringType().min(1)
|
|
13039
12836
|
});
|
|
12837
|
+
const ShippingAddress = () => {
|
|
12838
|
+
const { id } = useParams();
|
|
12839
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
12840
|
+
fields: "+shipping_address"
|
|
12841
|
+
});
|
|
12842
|
+
if (isError) {
|
|
12843
|
+
throw error;
|
|
12844
|
+
}
|
|
12845
|
+
const isReady = !isPending && !!order;
|
|
12846
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12847
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
12848
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
|
|
12849
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
|
|
12850
|
+
] }),
|
|
12851
|
+
isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
|
|
12852
|
+
] });
|
|
12853
|
+
};
|
|
12854
|
+
const ShippingAddressForm = ({ order }) => {
|
|
12855
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
12856
|
+
const form = useForm({
|
|
12857
|
+
defaultValues: {
|
|
12858
|
+
first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
|
|
12859
|
+
last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
|
|
12860
|
+
company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
|
|
12861
|
+
address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
|
|
12862
|
+
address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
|
|
12863
|
+
city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
|
|
12864
|
+
province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
|
|
12865
|
+
country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
|
|
12866
|
+
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12867
|
+
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
12868
|
+
},
|
|
12869
|
+
resolver: zodResolver(schema)
|
|
12870
|
+
});
|
|
12871
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12872
|
+
const { handleSuccess } = useRouteModal();
|
|
12873
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
12874
|
+
await mutateAsync(
|
|
12875
|
+
{
|
|
12876
|
+
shipping_address: {
|
|
12877
|
+
first_name: data.first_name,
|
|
12878
|
+
last_name: data.last_name,
|
|
12879
|
+
company: data.company,
|
|
12880
|
+
address_1: data.address_1,
|
|
12881
|
+
address_2: data.address_2,
|
|
12882
|
+
city: data.city,
|
|
12883
|
+
province: data.province,
|
|
12884
|
+
country_code: data.country_code,
|
|
12885
|
+
postal_code: data.postal_code,
|
|
12886
|
+
phone: data.phone
|
|
12887
|
+
}
|
|
12888
|
+
},
|
|
12889
|
+
{
|
|
12890
|
+
onSuccess: () => {
|
|
12891
|
+
handleSuccess();
|
|
12892
|
+
},
|
|
12893
|
+
onError: (error) => {
|
|
12894
|
+
toast.error(error.message);
|
|
12895
|
+
}
|
|
12896
|
+
}
|
|
12897
|
+
);
|
|
12898
|
+
});
|
|
12899
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
12900
|
+
KeyboundForm,
|
|
12901
|
+
{
|
|
12902
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
12903
|
+
onSubmit,
|
|
12904
|
+
children: [
|
|
12905
|
+
/* @__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: [
|
|
12906
|
+
/* @__PURE__ */ jsx(
|
|
12907
|
+
Form$2.Field,
|
|
12908
|
+
{
|
|
12909
|
+
control: form.control,
|
|
12910
|
+
name: "country_code",
|
|
12911
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12912
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
|
|
12913
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
|
|
12914
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12915
|
+
] })
|
|
12916
|
+
}
|
|
12917
|
+
),
|
|
12918
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
12919
|
+
/* @__PURE__ */ jsx(
|
|
12920
|
+
Form$2.Field,
|
|
12921
|
+
{
|
|
12922
|
+
control: form.control,
|
|
12923
|
+
name: "first_name",
|
|
12924
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12925
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
|
|
12926
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12927
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12928
|
+
] })
|
|
12929
|
+
}
|
|
12930
|
+
),
|
|
12931
|
+
/* @__PURE__ */ jsx(
|
|
12932
|
+
Form$2.Field,
|
|
12933
|
+
{
|
|
12934
|
+
control: form.control,
|
|
12935
|
+
name: "last_name",
|
|
12936
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12937
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
|
|
12938
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12939
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12940
|
+
] })
|
|
12941
|
+
}
|
|
12942
|
+
)
|
|
12943
|
+
] }),
|
|
12944
|
+
/* @__PURE__ */ jsx(
|
|
12945
|
+
Form$2.Field,
|
|
12946
|
+
{
|
|
12947
|
+
control: form.control,
|
|
12948
|
+
name: "company",
|
|
12949
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12950
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
12951
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12952
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12953
|
+
] })
|
|
12954
|
+
}
|
|
12955
|
+
),
|
|
12956
|
+
/* @__PURE__ */ jsx(
|
|
12957
|
+
Form$2.Field,
|
|
12958
|
+
{
|
|
12959
|
+
control: form.control,
|
|
12960
|
+
name: "address_1",
|
|
12961
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12962
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
|
|
12963
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12964
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12965
|
+
] })
|
|
12966
|
+
}
|
|
12967
|
+
),
|
|
12968
|
+
/* @__PURE__ */ jsx(
|
|
12969
|
+
Form$2.Field,
|
|
12970
|
+
{
|
|
12971
|
+
control: form.control,
|
|
12972
|
+
name: "address_2",
|
|
12973
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12974
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
12975
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12976
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12977
|
+
] })
|
|
12978
|
+
}
|
|
12979
|
+
),
|
|
12980
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
12981
|
+
/* @__PURE__ */ jsx(
|
|
12982
|
+
Form$2.Field,
|
|
12983
|
+
{
|
|
12984
|
+
control: form.control,
|
|
12985
|
+
name: "postal_code",
|
|
12986
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12987
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
|
|
12988
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12989
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12990
|
+
] })
|
|
12991
|
+
}
|
|
12992
|
+
),
|
|
12993
|
+
/* @__PURE__ */ jsx(
|
|
12994
|
+
Form$2.Field,
|
|
12995
|
+
{
|
|
12996
|
+
control: form.control,
|
|
12997
|
+
name: "city",
|
|
12998
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12999
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
|
|
13000
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
13001
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
13002
|
+
] })
|
|
13003
|
+
}
|
|
13004
|
+
)
|
|
13005
|
+
] }),
|
|
13006
|
+
/* @__PURE__ */ jsx(
|
|
13007
|
+
Form$2.Field,
|
|
13008
|
+
{
|
|
13009
|
+
control: form.control,
|
|
13010
|
+
name: "province",
|
|
13011
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
13012
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
13013
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
13014
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
13015
|
+
] })
|
|
13016
|
+
}
|
|
13017
|
+
),
|
|
13018
|
+
/* @__PURE__ */ jsx(
|
|
13019
|
+
Form$2.Field,
|
|
13020
|
+
{
|
|
13021
|
+
control: form.control,
|
|
13022
|
+
name: "phone",
|
|
13023
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
13024
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
|
|
13025
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
13026
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
13027
|
+
] })
|
|
13028
|
+
}
|
|
13029
|
+
)
|
|
13030
|
+
] }) }),
|
|
13031
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
13032
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
13033
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
13034
|
+
] }) })
|
|
13035
|
+
]
|
|
13036
|
+
}
|
|
13037
|
+
) });
|
|
13038
|
+
};
|
|
13039
|
+
const schema = addressSchema;
|
|
13040
13040
|
const widgetModule = { widgets: [] };
|
|
13041
13041
|
const routeModule = {
|
|
13042
13042
|
routes: [
|
|
@@ -13061,6 +13061,10 @@ const routeModule = {
|
|
|
13061
13061
|
Component: BillingAddress,
|
|
13062
13062
|
path: "/draft-orders/:id/billing-address"
|
|
13063
13063
|
},
|
|
13064
|
+
{
|
|
13065
|
+
Component: CustomItems,
|
|
13066
|
+
path: "/draft-orders/:id/custom-items"
|
|
13067
|
+
},
|
|
13064
13068
|
{
|
|
13065
13069
|
Component: Email,
|
|
13066
13070
|
path: "/draft-orders/:id/email"
|
|
@@ -13070,32 +13074,28 @@ const routeModule = {
|
|
|
13070
13074
|
path: "/draft-orders/:id/items"
|
|
13071
13075
|
},
|
|
13072
13076
|
{
|
|
13073
|
-
Component:
|
|
13074
|
-
path: "/draft-orders/:id/
|
|
13077
|
+
Component: Metadata,
|
|
13078
|
+
path: "/draft-orders/:id/metadata"
|
|
13075
13079
|
},
|
|
13076
13080
|
{
|
|
13077
13081
|
Component: Promotions,
|
|
13078
13082
|
path: "/draft-orders/:id/promotions"
|
|
13079
13083
|
},
|
|
13080
13084
|
{
|
|
13081
|
-
Component:
|
|
13082
|
-
path: "/draft-orders/:id/
|
|
13085
|
+
Component: SalesChannel,
|
|
13086
|
+
path: "/draft-orders/:id/sales-channel"
|
|
13083
13087
|
},
|
|
13084
13088
|
{
|
|
13085
13089
|
Component: Shipping,
|
|
13086
13090
|
path: "/draft-orders/:id/shipping"
|
|
13087
13091
|
},
|
|
13088
13092
|
{
|
|
13089
|
-
Component:
|
|
13090
|
-
path: "/draft-orders/:id/
|
|
13093
|
+
Component: TransferOwnership,
|
|
13094
|
+
path: "/draft-orders/:id/transfer-ownership"
|
|
13091
13095
|
},
|
|
13092
13096
|
{
|
|
13093
13097
|
Component: ShippingAddress,
|
|
13094
13098
|
path: "/draft-orders/:id/shipping-address"
|
|
13095
|
-
},
|
|
13096
|
-
{
|
|
13097
|
-
Component: TransferOwnership,
|
|
13098
|
-
path: "/draft-orders/:id/transfer-ownership"
|
|
13099
13099
|
}
|
|
13100
13100
|
]
|
|
13101
13101
|
}
|