@medusajs/draft-order 2.10.1-snapshot-20250828204656 → 2.10.2-preview-20250829180153
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 +916 -916
- package/.medusa/server/src/admin/index.mjs +916 -916
- package/package.json +24 -23
|
@@ -9554,196 +9554,6 @@ const ID = () => {
|
|
|
9554
9554
|
/* @__PURE__ */ jsx(Outlet, {})
|
|
9555
9555
|
] });
|
|
9556
9556
|
};
|
|
9557
|
-
const BillingAddress = () => {
|
|
9558
|
-
const { id } = useParams();
|
|
9559
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
9560
|
-
fields: "+billing_address"
|
|
9561
|
-
});
|
|
9562
|
-
if (isError) {
|
|
9563
|
-
throw error;
|
|
9564
|
-
}
|
|
9565
|
-
const isReady = !isPending && !!order;
|
|
9566
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9567
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
9568
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
|
|
9569
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
|
|
9570
|
-
] }),
|
|
9571
|
-
isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
|
|
9572
|
-
] });
|
|
9573
|
-
};
|
|
9574
|
-
const BillingAddressForm = ({ order }) => {
|
|
9575
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
9576
|
-
const form = useForm({
|
|
9577
|
-
defaultValues: {
|
|
9578
|
-
first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
|
|
9579
|
-
last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
|
|
9580
|
-
company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
|
|
9581
|
-
address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
|
|
9582
|
-
address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
|
|
9583
|
-
city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
|
|
9584
|
-
province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
|
|
9585
|
-
country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
|
|
9586
|
-
postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
9587
|
-
phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
|
|
9588
|
-
},
|
|
9589
|
-
resolver: zodResolver(schema$5)
|
|
9590
|
-
});
|
|
9591
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9592
|
-
const { handleSuccess } = useRouteModal();
|
|
9593
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
9594
|
-
await mutateAsync(
|
|
9595
|
-
{ billing_address: data },
|
|
9596
|
-
{
|
|
9597
|
-
onSuccess: () => {
|
|
9598
|
-
handleSuccess();
|
|
9599
|
-
},
|
|
9600
|
-
onError: (error) => {
|
|
9601
|
-
toast.error(error.message);
|
|
9602
|
-
}
|
|
9603
|
-
}
|
|
9604
|
-
);
|
|
9605
|
-
});
|
|
9606
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
9607
|
-
KeyboundForm,
|
|
9608
|
-
{
|
|
9609
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
9610
|
-
onSubmit,
|
|
9611
|
-
children: [
|
|
9612
|
-
/* @__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: [
|
|
9613
|
-
/* @__PURE__ */ jsx(
|
|
9614
|
-
Form$2.Field,
|
|
9615
|
-
{
|
|
9616
|
-
control: form.control,
|
|
9617
|
-
name: "country_code",
|
|
9618
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9619
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
|
|
9620
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
|
|
9621
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9622
|
-
] })
|
|
9623
|
-
}
|
|
9624
|
-
),
|
|
9625
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
9626
|
-
/* @__PURE__ */ jsx(
|
|
9627
|
-
Form$2.Field,
|
|
9628
|
-
{
|
|
9629
|
-
control: form.control,
|
|
9630
|
-
name: "first_name",
|
|
9631
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9632
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
|
|
9633
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9634
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9635
|
-
] })
|
|
9636
|
-
}
|
|
9637
|
-
),
|
|
9638
|
-
/* @__PURE__ */ jsx(
|
|
9639
|
-
Form$2.Field,
|
|
9640
|
-
{
|
|
9641
|
-
control: form.control,
|
|
9642
|
-
name: "last_name",
|
|
9643
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9644
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
|
|
9645
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9646
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9647
|
-
] })
|
|
9648
|
-
}
|
|
9649
|
-
)
|
|
9650
|
-
] }),
|
|
9651
|
-
/* @__PURE__ */ jsx(
|
|
9652
|
-
Form$2.Field,
|
|
9653
|
-
{
|
|
9654
|
-
control: form.control,
|
|
9655
|
-
name: "company",
|
|
9656
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9657
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
9658
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9659
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9660
|
-
] })
|
|
9661
|
-
}
|
|
9662
|
-
),
|
|
9663
|
-
/* @__PURE__ */ jsx(
|
|
9664
|
-
Form$2.Field,
|
|
9665
|
-
{
|
|
9666
|
-
control: form.control,
|
|
9667
|
-
name: "address_1",
|
|
9668
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9669
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
|
|
9670
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9671
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9672
|
-
] })
|
|
9673
|
-
}
|
|
9674
|
-
),
|
|
9675
|
-
/* @__PURE__ */ jsx(
|
|
9676
|
-
Form$2.Field,
|
|
9677
|
-
{
|
|
9678
|
-
control: form.control,
|
|
9679
|
-
name: "address_2",
|
|
9680
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9681
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
9682
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9683
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9684
|
-
] })
|
|
9685
|
-
}
|
|
9686
|
-
),
|
|
9687
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
9688
|
-
/* @__PURE__ */ jsx(
|
|
9689
|
-
Form$2.Field,
|
|
9690
|
-
{
|
|
9691
|
-
control: form.control,
|
|
9692
|
-
name: "postal_code",
|
|
9693
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9694
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
|
|
9695
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9696
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9697
|
-
] })
|
|
9698
|
-
}
|
|
9699
|
-
),
|
|
9700
|
-
/* @__PURE__ */ jsx(
|
|
9701
|
-
Form$2.Field,
|
|
9702
|
-
{
|
|
9703
|
-
control: form.control,
|
|
9704
|
-
name: "city",
|
|
9705
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9706
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
|
|
9707
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9708
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9709
|
-
] })
|
|
9710
|
-
}
|
|
9711
|
-
)
|
|
9712
|
-
] }),
|
|
9713
|
-
/* @__PURE__ */ jsx(
|
|
9714
|
-
Form$2.Field,
|
|
9715
|
-
{
|
|
9716
|
-
control: form.control,
|
|
9717
|
-
name: "province",
|
|
9718
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9719
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
9720
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9721
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9722
|
-
] })
|
|
9723
|
-
}
|
|
9724
|
-
),
|
|
9725
|
-
/* @__PURE__ */ jsx(
|
|
9726
|
-
Form$2.Field,
|
|
9727
|
-
{
|
|
9728
|
-
control: form.control,
|
|
9729
|
-
name: "phone",
|
|
9730
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9731
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
|
|
9732
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9733
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9734
|
-
] })
|
|
9735
|
-
}
|
|
9736
|
-
)
|
|
9737
|
-
] }) }),
|
|
9738
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9739
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9740
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9741
|
-
] }) })
|
|
9742
|
-
]
|
|
9743
|
-
}
|
|
9744
|
-
) });
|
|
9745
|
-
};
|
|
9746
|
-
const schema$5 = addressSchema;
|
|
9747
9557
|
const CustomItems = () => {
|
|
9748
9558
|
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9749
9559
|
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
|
|
@@ -9752,7 +9562,7 @@ const CustomItems = () => {
|
|
|
9752
9562
|
};
|
|
9753
9563
|
const CustomItemsForm = () => {
|
|
9754
9564
|
const form = useForm({
|
|
9755
|
-
resolver: zodResolver(schema$
|
|
9565
|
+
resolver: zodResolver(schema$5)
|
|
9756
9566
|
});
|
|
9757
9567
|
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
9758
9568
|
/* @__PURE__ */ jsx(RouteDrawer.Body, {}),
|
|
@@ -9762,7 +9572,7 @@ const CustomItemsForm = () => {
|
|
|
9762
9572
|
] }) })
|
|
9763
9573
|
] }) });
|
|
9764
9574
|
};
|
|
9765
|
-
const schema$
|
|
9575
|
+
const schema$5 = objectType({
|
|
9766
9576
|
email: stringType().email()
|
|
9767
9577
|
});
|
|
9768
9578
|
const Email = () => {
|
|
@@ -9787,7 +9597,7 @@ const EmailForm = ({ order }) => {
|
|
|
9787
9597
|
defaultValues: {
|
|
9788
9598
|
email: order.email ?? ""
|
|
9789
9599
|
},
|
|
9790
|
-
resolver: zodResolver(schema$
|
|
9600
|
+
resolver: zodResolver(schema$4)
|
|
9791
9601
|
});
|
|
9792
9602
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9793
9603
|
const { handleSuccess } = useRouteModal();
|
|
@@ -9830,7 +9640,7 @@ const EmailForm = ({ order }) => {
|
|
|
9830
9640
|
}
|
|
9831
9641
|
) });
|
|
9832
9642
|
};
|
|
9833
|
-
const schema$
|
|
9643
|
+
const schema$4 = objectType({
|
|
9834
9644
|
email: stringType().email()
|
|
9835
9645
|
});
|
|
9836
9646
|
const NumberInput = forwardRef(
|
|
@@ -10807,738 +10617,632 @@ const customItemSchema = objectType({
|
|
|
10807
10617
|
quantity: numberType(),
|
|
10808
10618
|
unit_price: unionType([numberType(), stringType()])
|
|
10809
10619
|
});
|
|
10810
|
-
const
|
|
10811
|
-
|
|
10812
|
-
|
|
10813
|
-
|
|
10814
|
-
|
|
10815
|
-
],
|
|
10816
|
-
detail: (id, query2) => [
|
|
10817
|
-
PROMOTION_QUERY_KEY,
|
|
10818
|
-
id,
|
|
10819
|
-
query2 ? query2 : void 0
|
|
10820
|
-
]
|
|
10821
|
-
};
|
|
10822
|
-
const usePromotions = (query2, options) => {
|
|
10823
|
-
const { data, ...rest } = useQuery({
|
|
10824
|
-
queryKey: promotionsQueryKeys.list(query2),
|
|
10825
|
-
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
10826
|
-
...options
|
|
10827
|
-
});
|
|
10828
|
-
return { ...data, ...rest };
|
|
10829
|
-
};
|
|
10830
|
-
const Promotions = () => {
|
|
10831
|
-
const { id } = useParams();
|
|
10832
|
-
const {
|
|
10833
|
-
order: preview,
|
|
10834
|
-
isError: isPreviewError,
|
|
10835
|
-
error: previewError
|
|
10836
|
-
} = useOrderPreview(id, void 0);
|
|
10837
|
-
useInitiateOrderEdit({ preview });
|
|
10838
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10839
|
-
if (isPreviewError) {
|
|
10840
|
-
throw previewError;
|
|
10841
|
-
}
|
|
10842
|
-
const isReady = !!preview;
|
|
10843
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
10844
|
-
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
|
|
10845
|
-
isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
|
|
10846
|
-
] });
|
|
10847
|
-
};
|
|
10848
|
-
const PromotionForm = ({ preview }) => {
|
|
10849
|
-
const { items, shipping_methods } = preview;
|
|
10850
|
-
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
10851
|
-
const [comboboxValue, setComboboxValue] = useState("");
|
|
10852
|
-
const { handleSuccess } = useRouteModal();
|
|
10853
|
-
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
10854
|
-
const promoCodes = getPromotionCodes(items, shipping_methods);
|
|
10855
|
-
const { promotions, isPending, isError, error } = usePromotions(
|
|
10856
|
-
{
|
|
10857
|
-
code: promoCodes
|
|
10858
|
-
},
|
|
10859
|
-
{
|
|
10860
|
-
enabled: !!promoCodes.length
|
|
10861
|
-
}
|
|
10862
|
-
);
|
|
10863
|
-
const comboboxData = useComboboxData({
|
|
10864
|
-
queryKey: ["promotions", "combobox", promoCodes],
|
|
10865
|
-
queryFn: async (params) => {
|
|
10866
|
-
return await sdk.admin.promotion.list({
|
|
10867
|
-
...params,
|
|
10868
|
-
code: {
|
|
10869
|
-
$nin: promoCodes
|
|
10870
|
-
}
|
|
10871
|
-
});
|
|
10872
|
-
},
|
|
10873
|
-
getOptions: (data) => {
|
|
10874
|
-
return data.promotions.map((promotion) => ({
|
|
10875
|
-
label: promotion.code,
|
|
10876
|
-
value: promotion.code
|
|
10877
|
-
}));
|
|
10878
|
-
}
|
|
10879
|
-
});
|
|
10880
|
-
const add = async (value) => {
|
|
10881
|
-
if (!value) {
|
|
10882
|
-
return;
|
|
10883
|
-
}
|
|
10884
|
-
addPromotions(
|
|
10885
|
-
{
|
|
10886
|
-
promo_codes: [value]
|
|
10887
|
-
},
|
|
10620
|
+
const InlineTip = forwardRef(
|
|
10621
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
10622
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
10623
|
+
return /* @__PURE__ */ jsxs(
|
|
10624
|
+
"div",
|
|
10888
10625
|
{
|
|
10889
|
-
|
|
10890
|
-
|
|
10891
|
-
|
|
10892
|
-
|
|
10893
|
-
|
|
10894
|
-
|
|
10895
|
-
|
|
10896
|
-
|
|
10897
|
-
|
|
10626
|
+
ref,
|
|
10627
|
+
className: clx(
|
|
10628
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
10629
|
+
className
|
|
10630
|
+
),
|
|
10631
|
+
...props,
|
|
10632
|
+
children: [
|
|
10633
|
+
/* @__PURE__ */ jsx(
|
|
10634
|
+
"div",
|
|
10635
|
+
{
|
|
10636
|
+
role: "presentation",
|
|
10637
|
+
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
10638
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
10639
|
+
})
|
|
10640
|
+
}
|
|
10641
|
+
),
|
|
10642
|
+
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
10643
|
+
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
10644
|
+
labelValue,
|
|
10645
|
+
":"
|
|
10646
|
+
] }),
|
|
10647
|
+
" ",
|
|
10648
|
+
children
|
|
10649
|
+
] })
|
|
10650
|
+
]
|
|
10898
10651
|
}
|
|
10899
10652
|
);
|
|
10900
|
-
}
|
|
10901
|
-
|
|
10902
|
-
|
|
10903
|
-
|
|
10904
|
-
|
|
10905
|
-
|
|
10906
|
-
|
|
10907
|
-
|
|
10908
|
-
|
|
10909
|
-
|
|
10910
|
-
|
|
10911
|
-
|
|
10912
|
-
|
|
10913
|
-
|
|
10914
|
-
|
|
10915
|
-
|
|
10916
|
-
return;
|
|
10917
|
-
}
|
|
10918
|
-
await confirmOrderEdit(void 0, {
|
|
10919
|
-
onError: (e) => {
|
|
10920
|
-
toast.error(e.message);
|
|
10921
|
-
},
|
|
10922
|
-
onSuccess: () => {
|
|
10923
|
-
handleSuccess();
|
|
10924
|
-
},
|
|
10925
|
-
onSettled: () => {
|
|
10926
|
-
setIsSubmitting(false);
|
|
10927
|
-
}
|
|
10928
|
-
});
|
|
10929
|
-
};
|
|
10653
|
+
}
|
|
10654
|
+
);
|
|
10655
|
+
InlineTip.displayName = "InlineTip";
|
|
10656
|
+
const MetadataFieldSchema = objectType({
|
|
10657
|
+
key: stringType(),
|
|
10658
|
+
disabled: booleanType().optional(),
|
|
10659
|
+
value: anyType()
|
|
10660
|
+
});
|
|
10661
|
+
const MetadataSchema = objectType({
|
|
10662
|
+
metadata: arrayType(MetadataFieldSchema)
|
|
10663
|
+
});
|
|
10664
|
+
const Metadata = () => {
|
|
10665
|
+
const { id } = useParams();
|
|
10666
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
10667
|
+
fields: "metadata"
|
|
10668
|
+
});
|
|
10930
10669
|
if (isError) {
|
|
10931
10670
|
throw error;
|
|
10932
10671
|
}
|
|
10933
|
-
|
|
10934
|
-
|
|
10935
|
-
|
|
10936
|
-
|
|
10937
|
-
|
|
10938
|
-
|
|
10939
|
-
|
|
10940
|
-
/* @__PURE__ */ jsx(
|
|
10941
|
-
Combobox,
|
|
10942
|
-
{
|
|
10943
|
-
id: "promotion-combobox",
|
|
10944
|
-
"aria-describedby": "promotion-combobox-hint",
|
|
10945
|
-
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
10946
|
-
fetchNextPage: comboboxData.fetchNextPage,
|
|
10947
|
-
options: comboboxData.options,
|
|
10948
|
-
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
10949
|
-
searchValue: comboboxData.searchValue,
|
|
10950
|
-
disabled: comboboxData.disabled || isAddingPromotions,
|
|
10951
|
-
onChange: add,
|
|
10952
|
-
value: comboboxValue
|
|
10953
|
-
}
|
|
10954
|
-
)
|
|
10955
|
-
] }),
|
|
10956
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10957
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
10958
|
-
PromotionItem,
|
|
10959
|
-
{
|
|
10960
|
-
promotion,
|
|
10961
|
-
orderId: preview.id,
|
|
10962
|
-
isLoading: isPending
|
|
10963
|
-
},
|
|
10964
|
-
promotion.id
|
|
10965
|
-
)) })
|
|
10966
|
-
] }) }),
|
|
10967
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10968
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10969
|
-
/* @__PURE__ */ jsx(
|
|
10970
|
-
Button,
|
|
10971
|
-
{
|
|
10972
|
-
size: "small",
|
|
10973
|
-
type: "submit",
|
|
10974
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
10975
|
-
children: "Save"
|
|
10976
|
-
}
|
|
10977
|
-
)
|
|
10978
|
-
] }) })
|
|
10672
|
+
const isReady = !isPending && !!order;
|
|
10673
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
10674
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
10675
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
|
|
10676
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
10677
|
+
] }),
|
|
10678
|
+
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
10979
10679
|
] });
|
|
10980
10680
|
};
|
|
10981
|
-
const
|
|
10982
|
-
|
|
10983
|
-
|
|
10984
|
-
|
|
10985
|
-
|
|
10986
|
-
|
|
10987
|
-
const
|
|
10988
|
-
|
|
10989
|
-
|
|
10681
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
10682
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
10683
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
10684
|
+
const { handleSuccess } = useRouteModal();
|
|
10685
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
10686
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
10687
|
+
const form = useForm({
|
|
10688
|
+
defaultValues: {
|
|
10689
|
+
metadata: getDefaultValues(metadata)
|
|
10690
|
+
},
|
|
10691
|
+
resolver: zodResolver(MetadataSchema)
|
|
10692
|
+
});
|
|
10693
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
10694
|
+
const parsedData = parseValues(data);
|
|
10695
|
+
await mutateAsync(
|
|
10990
10696
|
{
|
|
10991
|
-
|
|
10697
|
+
metadata: parsedData
|
|
10992
10698
|
},
|
|
10993
10699
|
{
|
|
10994
|
-
|
|
10995
|
-
toast.
|
|
10700
|
+
onSuccess: () => {
|
|
10701
|
+
toast.success("Metadata updated");
|
|
10702
|
+
handleSuccess();
|
|
10703
|
+
},
|
|
10704
|
+
onError: (error) => {
|
|
10705
|
+
toast.error(error.message);
|
|
10996
10706
|
}
|
|
10997
10707
|
}
|
|
10998
10708
|
);
|
|
10999
|
-
};
|
|
11000
|
-
const
|
|
11001
|
-
|
|
11002
|
-
"
|
|
10709
|
+
});
|
|
10710
|
+
const { fields, insert, remove } = useFieldArray({
|
|
10711
|
+
control: form.control,
|
|
10712
|
+
name: "metadata"
|
|
10713
|
+
});
|
|
10714
|
+
function deleteRow(index) {
|
|
10715
|
+
remove(index);
|
|
10716
|
+
if (fields.length === 1) {
|
|
10717
|
+
insert(0, {
|
|
10718
|
+
key: "",
|
|
10719
|
+
value: "",
|
|
10720
|
+
disabled: false
|
|
10721
|
+
});
|
|
10722
|
+
}
|
|
10723
|
+
}
|
|
10724
|
+
function insertRow(index, position) {
|
|
10725
|
+
insert(index + (position === "above" ? 0 : 1), {
|
|
10726
|
+
key: "",
|
|
10727
|
+
value: "",
|
|
10728
|
+
disabled: false
|
|
10729
|
+
});
|
|
10730
|
+
}
|
|
10731
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
10732
|
+
KeyboundForm,
|
|
11003
10733
|
{
|
|
11004
|
-
|
|
11005
|
-
|
|
11006
|
-
{
|
|
11007
|
-
"animate-pulse": isLoading
|
|
11008
|
-
}
|
|
11009
|
-
),
|
|
10734
|
+
onSubmit: handleSubmit,
|
|
10735
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
11010
10736
|
children: [
|
|
11011
|
-
/* @__PURE__ */ jsxs("
|
|
11012
|
-
/* @__PURE__ */
|
|
11013
|
-
|
|
11014
|
-
|
|
11015
|
-
/* @__PURE__ */ jsx(
|
|
11016
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
10737
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
10738
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
10739
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
10740
|
+
/* @__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" }) }),
|
|
10741
|
+
/* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
|
|
11017
10742
|
] }),
|
|
11018
|
-
|
|
11019
|
-
|
|
11020
|
-
|
|
11021
|
-
|
|
11022
|
-
|
|
11023
|
-
|
|
11024
|
-
|
|
11025
|
-
|
|
11026
|
-
|
|
11027
|
-
|
|
11028
|
-
|
|
11029
|
-
|
|
11030
|
-
|
|
11031
|
-
|
|
11032
|
-
|
|
11033
|
-
|
|
11034
|
-
|
|
11035
|
-
|
|
11036
|
-
|
|
11037
|
-
|
|
11038
|
-
|
|
11039
|
-
|
|
11040
|
-
|
|
11041
|
-
|
|
11042
|
-
|
|
11043
|
-
|
|
11044
|
-
|
|
11045
|
-
|
|
11046
|
-
|
|
10743
|
+
fields.map((field, index) => {
|
|
10744
|
+
const isDisabled = field.disabled || false;
|
|
10745
|
+
let placeholder = "-";
|
|
10746
|
+
if (typeof field.value === "object") {
|
|
10747
|
+
placeholder = "{ ... }";
|
|
10748
|
+
}
|
|
10749
|
+
if (Array.isArray(field.value)) {
|
|
10750
|
+
placeholder = "[ ... ]";
|
|
10751
|
+
}
|
|
10752
|
+
return /* @__PURE__ */ jsx(
|
|
10753
|
+
ConditionalTooltip,
|
|
10754
|
+
{
|
|
10755
|
+
showTooltip: isDisabled,
|
|
10756
|
+
content: "This row is disabled because it contains non-primitive data.",
|
|
10757
|
+
children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
|
|
10758
|
+
/* @__PURE__ */ jsxs(
|
|
10759
|
+
"div",
|
|
10760
|
+
{
|
|
10761
|
+
className: clx("grid grid-cols-2 divide-x", {
|
|
10762
|
+
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
10763
|
+
}),
|
|
10764
|
+
children: [
|
|
10765
|
+
/* @__PURE__ */ jsx(
|
|
10766
|
+
Form$2.Field,
|
|
10767
|
+
{
|
|
10768
|
+
control: form.control,
|
|
10769
|
+
name: `metadata.${index}.key`,
|
|
10770
|
+
render: ({ field: field2 }) => {
|
|
10771
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10772
|
+
GridInput,
|
|
10773
|
+
{
|
|
10774
|
+
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
10775
|
+
...field2,
|
|
10776
|
+
disabled: isDisabled,
|
|
10777
|
+
placeholder: "Key"
|
|
10778
|
+
}
|
|
10779
|
+
) }) });
|
|
10780
|
+
}
|
|
10781
|
+
}
|
|
10782
|
+
),
|
|
10783
|
+
/* @__PURE__ */ jsx(
|
|
10784
|
+
Form$2.Field,
|
|
10785
|
+
{
|
|
10786
|
+
control: form.control,
|
|
10787
|
+
name: `metadata.${index}.value`,
|
|
10788
|
+
render: ({ field: { value, ...field2 } }) => {
|
|
10789
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10790
|
+
GridInput,
|
|
10791
|
+
{
|
|
10792
|
+
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
10793
|
+
...field2,
|
|
10794
|
+
value: isDisabled ? placeholder : value,
|
|
10795
|
+
disabled: isDisabled,
|
|
10796
|
+
placeholder: "Value"
|
|
10797
|
+
}
|
|
10798
|
+
) }) });
|
|
10799
|
+
}
|
|
10800
|
+
}
|
|
10801
|
+
)
|
|
10802
|
+
]
|
|
10803
|
+
}
|
|
10804
|
+
),
|
|
10805
|
+
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
10806
|
+
/* @__PURE__ */ jsx(
|
|
10807
|
+
DropdownMenu.Trigger,
|
|
10808
|
+
{
|
|
10809
|
+
className: clx(
|
|
10810
|
+
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
10811
|
+
{
|
|
10812
|
+
hidden: isDisabled
|
|
10813
|
+
}
|
|
10814
|
+
),
|
|
10815
|
+
disabled: isDisabled,
|
|
10816
|
+
asChild: true,
|
|
10817
|
+
children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
|
|
10818
|
+
}
|
|
10819
|
+
),
|
|
10820
|
+
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
10821
|
+
/* @__PURE__ */ jsxs(
|
|
10822
|
+
DropdownMenu.Item,
|
|
10823
|
+
{
|
|
10824
|
+
className: "gap-x-2",
|
|
10825
|
+
onClick: () => insertRow(index, "above"),
|
|
10826
|
+
children: [
|
|
10827
|
+
/* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
10828
|
+
"Insert row above"
|
|
10829
|
+
]
|
|
10830
|
+
}
|
|
10831
|
+
),
|
|
10832
|
+
/* @__PURE__ */ jsxs(
|
|
10833
|
+
DropdownMenu.Item,
|
|
10834
|
+
{
|
|
10835
|
+
className: "gap-x-2",
|
|
10836
|
+
onClick: () => insertRow(index, "below"),
|
|
10837
|
+
children: [
|
|
10838
|
+
/* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
10839
|
+
"Insert row below"
|
|
10840
|
+
]
|
|
10841
|
+
}
|
|
10842
|
+
),
|
|
10843
|
+
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
10844
|
+
/* @__PURE__ */ jsxs(
|
|
10845
|
+
DropdownMenu.Item,
|
|
10846
|
+
{
|
|
10847
|
+
className: "gap-x-2",
|
|
10848
|
+
onClick: () => deleteRow(index),
|
|
10849
|
+
children: [
|
|
10850
|
+
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
10851
|
+
"Delete row"
|
|
10852
|
+
]
|
|
10853
|
+
}
|
|
10854
|
+
)
|
|
10855
|
+
] })
|
|
10856
|
+
] })
|
|
10857
|
+
] })
|
|
10858
|
+
},
|
|
10859
|
+
field.id
|
|
10860
|
+
);
|
|
10861
|
+
})
|
|
10862
|
+
] }),
|
|
10863
|
+
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." })
|
|
10864
|
+
] }),
|
|
10865
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10866
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10867
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
10868
|
+
] }) })
|
|
10869
|
+
]
|
|
11047
10870
|
}
|
|
11048
|
-
|
|
11049
|
-
|
|
11050
|
-
|
|
11051
|
-
|
|
11052
|
-
|
|
11053
|
-
|
|
11054
|
-
|
|
11055
|
-
|
|
11056
|
-
|
|
10871
|
+
) });
|
|
10872
|
+
};
|
|
10873
|
+
const GridInput = forwardRef(({ className, ...props }, ref) => {
|
|
10874
|
+
return /* @__PURE__ */ jsx(
|
|
10875
|
+
"input",
|
|
10876
|
+
{
|
|
10877
|
+
ref,
|
|
10878
|
+
...props,
|
|
10879
|
+
autoComplete: "off",
|
|
10880
|
+
className: clx(
|
|
10881
|
+
"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",
|
|
10882
|
+
className
|
|
10883
|
+
)
|
|
10884
|
+
}
|
|
10885
|
+
);
|
|
11057
10886
|
});
|
|
11058
|
-
|
|
11059
|
-
|
|
11060
|
-
|
|
11061
|
-
|
|
11062
|
-
|
|
11063
|
-
|
|
10887
|
+
GridInput.displayName = "MetadataForm.GridInput";
|
|
10888
|
+
const PlaceholderInner = () => {
|
|
10889
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
10890
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
10891
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10892
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
10893
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
10894
|
+
] }) })
|
|
10895
|
+
] });
|
|
11064
10896
|
};
|
|
11065
|
-
|
|
11066
|
-
|
|
11067
|
-
|
|
11068
|
-
|
|
11069
|
-
|
|
11070
|
-
|
|
11071
|
-
|
|
11072
|
-
|
|
10897
|
+
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
10898
|
+
function getDefaultValues(metadata) {
|
|
10899
|
+
if (!metadata || !Object.keys(metadata).length) {
|
|
10900
|
+
return [
|
|
10901
|
+
{
|
|
10902
|
+
key: "",
|
|
10903
|
+
value: "",
|
|
10904
|
+
disabled: false
|
|
11073
10905
|
}
|
|
10906
|
+
];
|
|
10907
|
+
}
|
|
10908
|
+
return Object.entries(metadata).map(([key, value]) => {
|
|
10909
|
+
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
10910
|
+
return {
|
|
10911
|
+
key,
|
|
10912
|
+
value,
|
|
10913
|
+
disabled: true
|
|
10914
|
+
};
|
|
10915
|
+
}
|
|
10916
|
+
let stringValue = value;
|
|
10917
|
+
if (typeof value !== "string") {
|
|
10918
|
+
stringValue = JSON.stringify(value);
|
|
11074
10919
|
}
|
|
10920
|
+
return {
|
|
10921
|
+
key,
|
|
10922
|
+
value: stringValue,
|
|
10923
|
+
original_key: key
|
|
10924
|
+
};
|
|
10925
|
+
});
|
|
10926
|
+
}
|
|
10927
|
+
function parseValues(values) {
|
|
10928
|
+
const metadata = values.metadata;
|
|
10929
|
+
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
10930
|
+
if (isEmpty) {
|
|
10931
|
+
return null;
|
|
11075
10932
|
}
|
|
11076
|
-
|
|
11077
|
-
|
|
11078
|
-
|
|
11079
|
-
|
|
11080
|
-
|
|
11081
|
-
|
|
10933
|
+
const update = {};
|
|
10934
|
+
metadata.forEach((field) => {
|
|
10935
|
+
let key = field.key;
|
|
10936
|
+
let value = field.value;
|
|
10937
|
+
const disabled = field.disabled;
|
|
10938
|
+
if (!key || !value) {
|
|
10939
|
+
return;
|
|
10940
|
+
}
|
|
10941
|
+
if (disabled) {
|
|
10942
|
+
update[key] = value;
|
|
10943
|
+
return;
|
|
10944
|
+
}
|
|
10945
|
+
key = key.trim();
|
|
10946
|
+
value = value.trim();
|
|
10947
|
+
if (value === "true") {
|
|
10948
|
+
update[key] = true;
|
|
10949
|
+
} else if (value === "false") {
|
|
10950
|
+
update[key] = false;
|
|
10951
|
+
} else {
|
|
10952
|
+
const parsedNumber = parseFloat(value);
|
|
10953
|
+
if (!isNaN(parsedNumber)) {
|
|
10954
|
+
update[key] = parsedNumber;
|
|
10955
|
+
} else {
|
|
10956
|
+
update[key] = value;
|
|
11082
10957
|
}
|
|
11083
10958
|
}
|
|
10959
|
+
});
|
|
10960
|
+
return update;
|
|
10961
|
+
}
|
|
10962
|
+
function getHasUneditableRows(metadata) {
|
|
10963
|
+
if (!metadata) {
|
|
10964
|
+
return false;
|
|
11084
10965
|
}
|
|
11085
|
-
return
|
|
10966
|
+
return Object.values(metadata).some(
|
|
10967
|
+
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
10968
|
+
);
|
|
11086
10969
|
}
|
|
11087
|
-
const
|
|
11088
|
-
|
|
11089
|
-
|
|
10970
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
10971
|
+
const promotionsQueryKeys = {
|
|
10972
|
+
list: (query2) => [
|
|
10973
|
+
PROMOTION_QUERY_KEY,
|
|
10974
|
+
query2 ? query2 : void 0
|
|
10975
|
+
],
|
|
10976
|
+
detail: (id, query2) => [
|
|
10977
|
+
PROMOTION_QUERY_KEY,
|
|
11090
10978
|
id,
|
|
10979
|
+
query2 ? query2 : void 0
|
|
10980
|
+
]
|
|
10981
|
+
};
|
|
10982
|
+
const usePromotions = (query2, options) => {
|
|
10983
|
+
const { data, ...rest } = useQuery({
|
|
10984
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
10985
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
10986
|
+
...options
|
|
10987
|
+
});
|
|
10988
|
+
return { ...data, ...rest };
|
|
10989
|
+
};
|
|
10990
|
+
const Promotions = () => {
|
|
10991
|
+
const { id } = useParams();
|
|
10992
|
+
const {
|
|
10993
|
+
order: preview,
|
|
10994
|
+
isError: isPreviewError,
|
|
10995
|
+
error: previewError
|
|
10996
|
+
} = useOrderPreview(id, void 0);
|
|
10997
|
+
useInitiateOrderEdit({ preview });
|
|
10998
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10999
|
+
if (isPreviewError) {
|
|
11000
|
+
throw previewError;
|
|
11001
|
+
}
|
|
11002
|
+
const isReady = !!preview;
|
|
11003
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
11004
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
|
|
11005
|
+
isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
|
|
11006
|
+
] });
|
|
11007
|
+
};
|
|
11008
|
+
const PromotionForm = ({ preview }) => {
|
|
11009
|
+
const { items, shipping_methods } = preview;
|
|
11010
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
11011
|
+
const [comboboxValue, setComboboxValue] = useState("");
|
|
11012
|
+
const { handleSuccess } = useRouteModal();
|
|
11013
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
11014
|
+
const promoCodes = getPromotionCodes(items, shipping_methods);
|
|
11015
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
11091
11016
|
{
|
|
11092
|
-
|
|
11017
|
+
code: promoCodes
|
|
11093
11018
|
},
|
|
11094
11019
|
{
|
|
11095
|
-
enabled: !!
|
|
11020
|
+
enabled: !!promoCodes.length
|
|
11096
11021
|
}
|
|
11097
11022
|
);
|
|
11098
|
-
|
|
11099
|
-
|
|
11100
|
-
|
|
11101
|
-
|
|
11102
|
-
|
|
11103
|
-
|
|
11104
|
-
|
|
11105
|
-
|
|
11106
|
-
|
|
11107
|
-
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
11108
|
-
] });
|
|
11109
|
-
};
|
|
11110
|
-
const SalesChannelForm = ({ order }) => {
|
|
11111
|
-
const form = useForm({
|
|
11112
|
-
defaultValues: {
|
|
11113
|
-
sales_channel_id: order.sales_channel_id || ""
|
|
11023
|
+
const comboboxData = useComboboxData({
|
|
11024
|
+
queryKey: ["promotions", "combobox", promoCodes],
|
|
11025
|
+
queryFn: async (params) => {
|
|
11026
|
+
return await sdk.admin.promotion.list({
|
|
11027
|
+
...params,
|
|
11028
|
+
code: {
|
|
11029
|
+
$nin: promoCodes
|
|
11030
|
+
}
|
|
11031
|
+
});
|
|
11114
11032
|
},
|
|
11115
|
-
|
|
11033
|
+
getOptions: (data) => {
|
|
11034
|
+
return data.promotions.map((promotion) => ({
|
|
11035
|
+
label: promotion.code,
|
|
11036
|
+
value: promotion.code
|
|
11037
|
+
}));
|
|
11038
|
+
}
|
|
11116
11039
|
});
|
|
11117
|
-
const
|
|
11118
|
-
|
|
11119
|
-
|
|
11120
|
-
|
|
11040
|
+
const add = async (value) => {
|
|
11041
|
+
if (!value) {
|
|
11042
|
+
return;
|
|
11043
|
+
}
|
|
11044
|
+
addPromotions(
|
|
11121
11045
|
{
|
|
11122
|
-
|
|
11046
|
+
promo_codes: [value]
|
|
11123
11047
|
},
|
|
11124
11048
|
{
|
|
11125
|
-
|
|
11126
|
-
toast.
|
|
11127
|
-
|
|
11049
|
+
onError: (e) => {
|
|
11050
|
+
toast.error(e.message);
|
|
11051
|
+
comboboxData.onSearchValueChange("");
|
|
11052
|
+
setComboboxValue("");
|
|
11128
11053
|
},
|
|
11129
|
-
|
|
11130
|
-
|
|
11054
|
+
onSuccess: () => {
|
|
11055
|
+
comboboxData.onSearchValueChange("");
|
|
11056
|
+
setComboboxValue("");
|
|
11131
11057
|
}
|
|
11132
11058
|
}
|
|
11133
11059
|
);
|
|
11134
|
-
}
|
|
11135
|
-
|
|
11136
|
-
|
|
11137
|
-
|
|
11138
|
-
|
|
11139
|
-
|
|
11140
|
-
|
|
11141
|
-
|
|
11142
|
-
|
|
11143
|
-
|
|
11144
|
-
|
|
11145
|
-
|
|
11146
|
-
]
|
|
11147
|
-
}
|
|
11148
|
-
) });
|
|
11149
|
-
};
|
|
11150
|
-
const SalesChannelField = ({ control, order }) => {
|
|
11151
|
-
const salesChannels = useComboboxData({
|
|
11152
|
-
queryFn: async (params) => {
|
|
11153
|
-
return await sdk.admin.salesChannel.list(params);
|
|
11154
|
-
},
|
|
11155
|
-
queryKey: ["sales-channels"],
|
|
11156
|
-
getOptions: (data) => {
|
|
11157
|
-
return data.sales_channels.map((salesChannel) => ({
|
|
11158
|
-
label: salesChannel.name,
|
|
11159
|
-
value: salesChannel.id
|
|
11160
|
-
}));
|
|
11161
|
-
},
|
|
11162
|
-
defaultValue: order.sales_channel_id || void 0
|
|
11163
|
-
});
|
|
11164
|
-
return /* @__PURE__ */ jsx(
|
|
11165
|
-
Form$2.Field,
|
|
11166
|
-
{
|
|
11167
|
-
control,
|
|
11168
|
-
name: "sales_channel_id",
|
|
11169
|
-
render: ({ field }) => {
|
|
11170
|
-
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11171
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
11172
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11173
|
-
Combobox,
|
|
11174
|
-
{
|
|
11175
|
-
options: salesChannels.options,
|
|
11176
|
-
fetchNextPage: salesChannels.fetchNextPage,
|
|
11177
|
-
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
11178
|
-
searchValue: salesChannels.searchValue,
|
|
11179
|
-
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
11180
|
-
placeholder: "Select sales channel",
|
|
11181
|
-
...field
|
|
11182
|
-
}
|
|
11183
|
-
) }),
|
|
11184
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11185
|
-
] });
|
|
11060
|
+
};
|
|
11061
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11062
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
11063
|
+
const onSubmit = async () => {
|
|
11064
|
+
setIsSubmitting(true);
|
|
11065
|
+
let requestSucceeded = false;
|
|
11066
|
+
await requestOrderEdit(void 0, {
|
|
11067
|
+
onError: (e) => {
|
|
11068
|
+
toast.error(e.message);
|
|
11069
|
+
},
|
|
11070
|
+
onSuccess: () => {
|
|
11071
|
+
requestSucceeded = true;
|
|
11186
11072
|
}
|
|
11073
|
+
});
|
|
11074
|
+
if (!requestSucceeded) {
|
|
11075
|
+
setIsSubmitting(false);
|
|
11076
|
+
return;
|
|
11187
11077
|
}
|
|
11188
|
-
|
|
11189
|
-
|
|
11190
|
-
|
|
11191
|
-
|
|
11192
|
-
|
|
11193
|
-
|
|
11194
|
-
|
|
11195
|
-
|
|
11196
|
-
|
|
11197
|
-
"div",
|
|
11198
|
-
{
|
|
11199
|
-
ref,
|
|
11200
|
-
className: clx(
|
|
11201
|
-
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
11202
|
-
className
|
|
11203
|
-
),
|
|
11204
|
-
...props,
|
|
11205
|
-
children: [
|
|
11206
|
-
/* @__PURE__ */ jsx(
|
|
11207
|
-
"div",
|
|
11208
|
-
{
|
|
11209
|
-
role: "presentation",
|
|
11210
|
-
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
11211
|
-
"bg-ui-tag-orange-icon": variant === "warning"
|
|
11212
|
-
})
|
|
11213
|
-
}
|
|
11214
|
-
),
|
|
11215
|
-
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
11216
|
-
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
11217
|
-
labelValue,
|
|
11218
|
-
":"
|
|
11219
|
-
] }),
|
|
11220
|
-
" ",
|
|
11221
|
-
children
|
|
11222
|
-
] })
|
|
11223
|
-
]
|
|
11078
|
+
await confirmOrderEdit(void 0, {
|
|
11079
|
+
onError: (e) => {
|
|
11080
|
+
toast.error(e.message);
|
|
11081
|
+
},
|
|
11082
|
+
onSuccess: () => {
|
|
11083
|
+
handleSuccess();
|
|
11084
|
+
},
|
|
11085
|
+
onSettled: () => {
|
|
11086
|
+
setIsSubmitting(false);
|
|
11224
11087
|
}
|
|
11225
|
-
);
|
|
11226
|
-
}
|
|
11227
|
-
);
|
|
11228
|
-
InlineTip.displayName = "InlineTip";
|
|
11229
|
-
const MetadataFieldSchema = objectType({
|
|
11230
|
-
key: stringType(),
|
|
11231
|
-
disabled: booleanType().optional(),
|
|
11232
|
-
value: anyType()
|
|
11233
|
-
});
|
|
11234
|
-
const MetadataSchema = objectType({
|
|
11235
|
-
metadata: arrayType(MetadataFieldSchema)
|
|
11236
|
-
});
|
|
11237
|
-
const Metadata = () => {
|
|
11238
|
-
const { id } = useParams();
|
|
11239
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
11240
|
-
fields: "metadata"
|
|
11241
|
-
});
|
|
11088
|
+
});
|
|
11089
|
+
};
|
|
11242
11090
|
if (isError) {
|
|
11243
11091
|
throw error;
|
|
11244
11092
|
}
|
|
11245
|
-
|
|
11246
|
-
|
|
11247
|
-
|
|
11248
|
-
|
|
11249
|
-
|
|
11250
|
-
|
|
11251
|
-
|
|
11093
|
+
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
11094
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
11095
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
11096
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
11097
|
+
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
11098
|
+
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
11099
|
+
] }),
|
|
11100
|
+
/* @__PURE__ */ jsx(
|
|
11101
|
+
Combobox,
|
|
11102
|
+
{
|
|
11103
|
+
id: "promotion-combobox",
|
|
11104
|
+
"aria-describedby": "promotion-combobox-hint",
|
|
11105
|
+
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
11106
|
+
fetchNextPage: comboboxData.fetchNextPage,
|
|
11107
|
+
options: comboboxData.options,
|
|
11108
|
+
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
11109
|
+
searchValue: comboboxData.searchValue,
|
|
11110
|
+
disabled: comboboxData.disabled || isAddingPromotions,
|
|
11111
|
+
onChange: add,
|
|
11112
|
+
value: comboboxValue
|
|
11113
|
+
}
|
|
11114
|
+
)
|
|
11115
|
+
] }),
|
|
11116
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
11117
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
11118
|
+
PromotionItem,
|
|
11119
|
+
{
|
|
11120
|
+
promotion,
|
|
11121
|
+
orderId: preview.id,
|
|
11122
|
+
isLoading: isPending
|
|
11123
|
+
},
|
|
11124
|
+
promotion.id
|
|
11125
|
+
)) })
|
|
11126
|
+
] }) }),
|
|
11127
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11128
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11129
|
+
/* @__PURE__ */ jsx(
|
|
11130
|
+
Button,
|
|
11131
|
+
{
|
|
11132
|
+
size: "small",
|
|
11133
|
+
type: "submit",
|
|
11134
|
+
isLoading: isSubmitting || isAddingPromotions,
|
|
11135
|
+
children: "Save"
|
|
11136
|
+
}
|
|
11137
|
+
)
|
|
11138
|
+
] }) })
|
|
11252
11139
|
] });
|
|
11253
11140
|
};
|
|
11254
|
-
const
|
|
11255
|
-
|
|
11256
|
-
|
|
11257
|
-
|
|
11258
|
-
|
|
11259
|
-
|
|
11260
|
-
const
|
|
11261
|
-
|
|
11262
|
-
|
|
11263
|
-
},
|
|
11264
|
-
resolver: zodResolver(MetadataSchema)
|
|
11265
|
-
});
|
|
11266
|
-
const handleSubmit = form.handleSubmit(async (data) => {
|
|
11267
|
-
const parsedData = parseValues(data);
|
|
11268
|
-
await mutateAsync(
|
|
11141
|
+
const PromotionItem = ({
|
|
11142
|
+
promotion,
|
|
11143
|
+
orderId,
|
|
11144
|
+
isLoading
|
|
11145
|
+
}) => {
|
|
11146
|
+
var _a;
|
|
11147
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11148
|
+
const onRemove = async () => {
|
|
11149
|
+
removePromotions(
|
|
11269
11150
|
{
|
|
11270
|
-
|
|
11151
|
+
promo_codes: [promotion.code]
|
|
11271
11152
|
},
|
|
11272
11153
|
{
|
|
11273
|
-
|
|
11274
|
-
toast.
|
|
11275
|
-
handleSuccess();
|
|
11276
|
-
},
|
|
11277
|
-
onError: (error) => {
|
|
11278
|
-
toast.error(error.message);
|
|
11154
|
+
onError: (e) => {
|
|
11155
|
+
toast.error(e.message);
|
|
11279
11156
|
}
|
|
11280
11157
|
}
|
|
11281
11158
|
);
|
|
11282
|
-
}
|
|
11283
|
-
const
|
|
11284
|
-
|
|
11285
|
-
|
|
11286
|
-
});
|
|
11287
|
-
function deleteRow(index) {
|
|
11288
|
-
remove(index);
|
|
11289
|
-
if (fields.length === 1) {
|
|
11290
|
-
insert(0, {
|
|
11291
|
-
key: "",
|
|
11292
|
-
value: "",
|
|
11293
|
-
disabled: false
|
|
11294
|
-
});
|
|
11295
|
-
}
|
|
11296
|
-
}
|
|
11297
|
-
function insertRow(index, position) {
|
|
11298
|
-
insert(index + (position === "above" ? 0 : 1), {
|
|
11299
|
-
key: "",
|
|
11300
|
-
value: "",
|
|
11301
|
-
disabled: false
|
|
11302
|
-
});
|
|
11303
|
-
}
|
|
11304
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
11305
|
-
KeyboundForm,
|
|
11159
|
+
};
|
|
11160
|
+
const displayValue = getDisplayValue(promotion);
|
|
11161
|
+
return /* @__PURE__ */ jsxs(
|
|
11162
|
+
"div",
|
|
11306
11163
|
{
|
|
11307
|
-
|
|
11308
|
-
|
|
11164
|
+
className: clx(
|
|
11165
|
+
"px-3 py-2 rounded-lg bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between",
|
|
11166
|
+
{
|
|
11167
|
+
"animate-pulse": isLoading
|
|
11168
|
+
}
|
|
11169
|
+
),
|
|
11309
11170
|
children: [
|
|
11310
|
-
/* @__PURE__ */ jsxs(
|
|
11311
|
-
/* @__PURE__ */
|
|
11312
|
-
|
|
11313
|
-
|
|
11314
|
-
/* @__PURE__ */ jsx(
|
|
11171
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
11172
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11173
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 text-ui-fg-subtle", children: [
|
|
11174
|
+
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11175
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11176
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
11315
11177
|
] }),
|
|
11316
|
-
|
|
11317
|
-
|
|
11318
|
-
let placeholder = "-";
|
|
11319
|
-
if (typeof field.value === "object") {
|
|
11320
|
-
placeholder = "{ ... }";
|
|
11321
|
-
}
|
|
11322
|
-
if (Array.isArray(field.value)) {
|
|
11323
|
-
placeholder = "[ ... ]";
|
|
11324
|
-
}
|
|
11325
|
-
return /* @__PURE__ */ jsx(
|
|
11326
|
-
ConditionalTooltip,
|
|
11327
|
-
{
|
|
11328
|
-
showTooltip: isDisabled,
|
|
11329
|
-
content: "This row is disabled because it contains non-primitive data.",
|
|
11330
|
-
children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
|
|
11331
|
-
/* @__PURE__ */ jsxs(
|
|
11332
|
-
"div",
|
|
11333
|
-
{
|
|
11334
|
-
className: clx("grid grid-cols-2 divide-x", {
|
|
11335
|
-
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
11336
|
-
}),
|
|
11337
|
-
children: [
|
|
11338
|
-
/* @__PURE__ */ jsx(
|
|
11339
|
-
Form$2.Field,
|
|
11340
|
-
{
|
|
11341
|
-
control: form.control,
|
|
11342
|
-
name: `metadata.${index}.key`,
|
|
11343
|
-
render: ({ field: field2 }) => {
|
|
11344
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11345
|
-
GridInput,
|
|
11346
|
-
{
|
|
11347
|
-
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
11348
|
-
...field2,
|
|
11349
|
-
disabled: isDisabled,
|
|
11350
|
-
placeholder: "Key"
|
|
11351
|
-
}
|
|
11352
|
-
) }) });
|
|
11353
|
-
}
|
|
11354
|
-
}
|
|
11355
|
-
),
|
|
11356
|
-
/* @__PURE__ */ jsx(
|
|
11357
|
-
Form$2.Field,
|
|
11358
|
-
{
|
|
11359
|
-
control: form.control,
|
|
11360
|
-
name: `metadata.${index}.value`,
|
|
11361
|
-
render: ({ field: { value, ...field2 } }) => {
|
|
11362
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11363
|
-
GridInput,
|
|
11364
|
-
{
|
|
11365
|
-
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
11366
|
-
...field2,
|
|
11367
|
-
value: isDisabled ? placeholder : value,
|
|
11368
|
-
disabled: isDisabled,
|
|
11369
|
-
placeholder: "Value"
|
|
11370
|
-
}
|
|
11371
|
-
) }) });
|
|
11372
|
-
}
|
|
11373
|
-
}
|
|
11374
|
-
)
|
|
11375
|
-
]
|
|
11376
|
-
}
|
|
11377
|
-
),
|
|
11378
|
-
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
11379
|
-
/* @__PURE__ */ jsx(
|
|
11380
|
-
DropdownMenu.Trigger,
|
|
11381
|
-
{
|
|
11382
|
-
className: clx(
|
|
11383
|
-
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
11384
|
-
{
|
|
11385
|
-
hidden: isDisabled
|
|
11386
|
-
}
|
|
11387
|
-
),
|
|
11388
|
-
disabled: isDisabled,
|
|
11389
|
-
asChild: true,
|
|
11390
|
-
children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
|
|
11391
|
-
}
|
|
11392
|
-
),
|
|
11393
|
-
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
11394
|
-
/* @__PURE__ */ jsxs(
|
|
11395
|
-
DropdownMenu.Item,
|
|
11396
|
-
{
|
|
11397
|
-
className: "gap-x-2",
|
|
11398
|
-
onClick: () => insertRow(index, "above"),
|
|
11399
|
-
children: [
|
|
11400
|
-
/* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
11401
|
-
"Insert row above"
|
|
11402
|
-
]
|
|
11403
|
-
}
|
|
11404
|
-
),
|
|
11405
|
-
/* @__PURE__ */ jsxs(
|
|
11406
|
-
DropdownMenu.Item,
|
|
11407
|
-
{
|
|
11408
|
-
className: "gap-x-2",
|
|
11409
|
-
onClick: () => insertRow(index, "below"),
|
|
11410
|
-
children: [
|
|
11411
|
-
/* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
11412
|
-
"Insert row below"
|
|
11413
|
-
]
|
|
11414
|
-
}
|
|
11415
|
-
),
|
|
11416
|
-
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
11417
|
-
/* @__PURE__ */ jsxs(
|
|
11418
|
-
DropdownMenu.Item,
|
|
11419
|
-
{
|
|
11420
|
-
className: "gap-x-2",
|
|
11421
|
-
onClick: () => deleteRow(index),
|
|
11422
|
-
children: [
|
|
11423
|
-
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
11424
|
-
"Delete row"
|
|
11425
|
-
]
|
|
11426
|
-
}
|
|
11427
|
-
)
|
|
11428
|
-
] })
|
|
11429
|
-
] })
|
|
11430
|
-
] })
|
|
11431
|
-
},
|
|
11432
|
-
field.id
|
|
11433
|
-
);
|
|
11434
|
-
})
|
|
11435
|
-
] }),
|
|
11436
|
-
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." })
|
|
11178
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11179
|
+
] })
|
|
11437
11180
|
] }),
|
|
11438
|
-
/* @__PURE__ */ jsx(
|
|
11439
|
-
|
|
11440
|
-
|
|
11441
|
-
|
|
11442
|
-
|
|
11443
|
-
|
|
11444
|
-
|
|
11445
|
-
|
|
11446
|
-
|
|
11447
|
-
|
|
11448
|
-
|
|
11449
|
-
|
|
11450
|
-
|
|
11451
|
-
|
|
11452
|
-
|
|
11453
|
-
|
|
11454
|
-
|
|
11455
|
-
|
|
11456
|
-
|
|
11457
|
-
|
|
11458
|
-
|
|
11459
|
-
});
|
|
11460
|
-
GridInput.displayName = "MetadataForm.GridInput";
|
|
11461
|
-
const PlaceholderInner = () => {
|
|
11462
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
11463
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
11464
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11465
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
11466
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
11467
|
-
] }) })
|
|
11468
|
-
] });
|
|
11469
|
-
};
|
|
11470
|
-
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
11471
|
-
function getDefaultValues(metadata) {
|
|
11472
|
-
if (!metadata || !Object.keys(metadata).length) {
|
|
11473
|
-
return [
|
|
11474
|
-
{
|
|
11475
|
-
key: "",
|
|
11476
|
-
value: "",
|
|
11477
|
-
disabled: false
|
|
11478
|
-
}
|
|
11479
|
-
];
|
|
11181
|
+
/* @__PURE__ */ jsx(
|
|
11182
|
+
IconButton,
|
|
11183
|
+
{
|
|
11184
|
+
size: "small",
|
|
11185
|
+
type: "button",
|
|
11186
|
+
variant: "transparent",
|
|
11187
|
+
onClick: onRemove,
|
|
11188
|
+
isLoading: isPending || isLoading,
|
|
11189
|
+
children: /* @__PURE__ */ jsx(XMark, {})
|
|
11190
|
+
}
|
|
11191
|
+
)
|
|
11192
|
+
]
|
|
11193
|
+
},
|
|
11194
|
+
promotion.id
|
|
11195
|
+
);
|
|
11196
|
+
};
|
|
11197
|
+
function getDisplayValue(promotion) {
|
|
11198
|
+
var _a, _b, _c, _d;
|
|
11199
|
+
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11200
|
+
if (!value) {
|
|
11201
|
+
return null;
|
|
11480
11202
|
}
|
|
11481
|
-
|
|
11482
|
-
|
|
11483
|
-
|
|
11484
|
-
|
|
11485
|
-
value,
|
|
11486
|
-
disabled: true
|
|
11487
|
-
};
|
|
11488
|
-
}
|
|
11489
|
-
let stringValue = value;
|
|
11490
|
-
if (typeof value !== "string") {
|
|
11491
|
-
stringValue = JSON.stringify(value);
|
|
11203
|
+
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11204
|
+
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11205
|
+
if (!currency) {
|
|
11206
|
+
return null;
|
|
11492
11207
|
}
|
|
11493
|
-
return
|
|
11494
|
-
|
|
11495
|
-
|
|
11496
|
-
|
|
11497
|
-
|
|
11498
|
-
});
|
|
11208
|
+
return getLocaleAmount(value, currency);
|
|
11209
|
+
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11210
|
+
return formatPercentage(value);
|
|
11211
|
+
}
|
|
11212
|
+
return null;
|
|
11499
11213
|
}
|
|
11500
|
-
|
|
11501
|
-
|
|
11502
|
-
|
|
11503
|
-
|
|
11504
|
-
|
|
11214
|
+
const formatter = new Intl.NumberFormat([], {
|
|
11215
|
+
style: "percent",
|
|
11216
|
+
minimumFractionDigits: 2
|
|
11217
|
+
});
|
|
11218
|
+
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11219
|
+
let val = value || 0;
|
|
11220
|
+
if (!isPercentageValue) {
|
|
11221
|
+
val = val / 100;
|
|
11505
11222
|
}
|
|
11506
|
-
|
|
11507
|
-
|
|
11508
|
-
|
|
11509
|
-
|
|
11510
|
-
|
|
11511
|
-
if (
|
|
11512
|
-
|
|
11513
|
-
|
|
11514
|
-
|
|
11515
|
-
|
|
11516
|
-
|
|
11223
|
+
return formatter.format(val);
|
|
11224
|
+
};
|
|
11225
|
+
function getPromotionCodes(items, shippingMethods) {
|
|
11226
|
+
const codes = /* @__PURE__ */ new Set();
|
|
11227
|
+
for (const item of items) {
|
|
11228
|
+
if (item.adjustments) {
|
|
11229
|
+
for (const adjustment of item.adjustments) {
|
|
11230
|
+
if (adjustment.code) {
|
|
11231
|
+
codes.add(adjustment.code);
|
|
11232
|
+
}
|
|
11233
|
+
}
|
|
11517
11234
|
}
|
|
11518
|
-
|
|
11519
|
-
|
|
11520
|
-
if (
|
|
11521
|
-
|
|
11522
|
-
|
|
11523
|
-
|
|
11524
|
-
|
|
11525
|
-
const parsedNumber = parseFloat(value);
|
|
11526
|
-
if (!isNaN(parsedNumber)) {
|
|
11527
|
-
update[key] = parsedNumber;
|
|
11528
|
-
} else {
|
|
11529
|
-
update[key] = value;
|
|
11235
|
+
}
|
|
11236
|
+
for (const shippingMethod of shippingMethods) {
|
|
11237
|
+
if (shippingMethod.adjustments) {
|
|
11238
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
11239
|
+
if (adjustment.code) {
|
|
11240
|
+
codes.add(adjustment.code);
|
|
11241
|
+
}
|
|
11530
11242
|
}
|
|
11531
11243
|
}
|
|
11532
|
-
});
|
|
11533
|
-
return update;
|
|
11534
|
-
}
|
|
11535
|
-
function getHasUneditableRows(metadata) {
|
|
11536
|
-
if (!metadata) {
|
|
11537
|
-
return false;
|
|
11538
11244
|
}
|
|
11539
|
-
return
|
|
11540
|
-
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11541
|
-
);
|
|
11245
|
+
return Array.from(codes);
|
|
11542
11246
|
}
|
|
11543
11247
|
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11544
11248
|
const Shipping = () => {
|
|
@@ -12379,7 +12083,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12379
12083
|
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12380
12084
|
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
12381
12085
|
},
|
|
12382
|
-
resolver: zodResolver(schema$
|
|
12086
|
+
resolver: zodResolver(schema$3)
|
|
12383
12087
|
});
|
|
12384
12088
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12385
12089
|
const { handleSuccess } = useRouteModal();
|
|
@@ -12549,7 +12253,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12549
12253
|
}
|
|
12550
12254
|
) });
|
|
12551
12255
|
};
|
|
12552
|
-
const schema$
|
|
12256
|
+
const schema$3 = addressSchema;
|
|
12553
12257
|
const TransferOwnership = () => {
|
|
12554
12258
|
const { id } = useParams();
|
|
12555
12259
|
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
@@ -12573,7 +12277,7 @@ const TransferOwnershipForm = ({ order }) => {
|
|
|
12573
12277
|
defaultValues: {
|
|
12574
12278
|
customer_id: order.customer_id || ""
|
|
12575
12279
|
},
|
|
12576
|
-
resolver: zodResolver(schema)
|
|
12280
|
+
resolver: zodResolver(schema$2)
|
|
12577
12281
|
});
|
|
12578
12282
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12579
12283
|
const { handleSuccess } = useRouteModal();
|
|
@@ -12967,64 +12671,360 @@ const Illustration = () => {
|
|
|
12967
12671
|
/* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12968
12672
|
"rect",
|
|
12969
12673
|
{
|
|
12970
|
-
width: "12",
|
|
12971
|
-
height: "12",
|
|
12972
|
-
fill: "white",
|
|
12973
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
|
|
12674
|
+
width: "12",
|
|
12675
|
+
height: "12",
|
|
12676
|
+
fill: "white",
|
|
12677
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
|
|
12678
|
+
}
|
|
12679
|
+
) }),
|
|
12680
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12681
|
+
"rect",
|
|
12682
|
+
{
|
|
12683
|
+
width: "12",
|
|
12684
|
+
height: "12",
|
|
12685
|
+
fill: "white",
|
|
12686
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
|
|
12687
|
+
}
|
|
12688
|
+
) }),
|
|
12689
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12690
|
+
"rect",
|
|
12691
|
+
{
|
|
12692
|
+
width: "12",
|
|
12693
|
+
height: "12",
|
|
12694
|
+
fill: "white",
|
|
12695
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
|
|
12696
|
+
}
|
|
12697
|
+
) }),
|
|
12698
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12699
|
+
"rect",
|
|
12700
|
+
{
|
|
12701
|
+
width: "12",
|
|
12702
|
+
height: "12",
|
|
12703
|
+
fill: "white",
|
|
12704
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
|
|
12705
|
+
}
|
|
12706
|
+
) }),
|
|
12707
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12708
|
+
"rect",
|
|
12709
|
+
{
|
|
12710
|
+
width: "12",
|
|
12711
|
+
height: "12",
|
|
12712
|
+
fill: "white",
|
|
12713
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
|
|
12714
|
+
}
|
|
12715
|
+
) }),
|
|
12716
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
|
|
12717
|
+
"rect",
|
|
12718
|
+
{
|
|
12719
|
+
width: "12",
|
|
12720
|
+
height: "12",
|
|
12721
|
+
fill: "white",
|
|
12722
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
|
|
12723
|
+
}
|
|
12724
|
+
) })
|
|
12725
|
+
] })
|
|
12726
|
+
]
|
|
12727
|
+
}
|
|
12728
|
+
);
|
|
12729
|
+
};
|
|
12730
|
+
const schema$2 = objectType({
|
|
12731
|
+
customer_id: stringType().min(1)
|
|
12732
|
+
});
|
|
12733
|
+
const BillingAddress = () => {
|
|
12734
|
+
const { id } = useParams();
|
|
12735
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
12736
|
+
fields: "+billing_address"
|
|
12737
|
+
});
|
|
12738
|
+
if (isError) {
|
|
12739
|
+
throw error;
|
|
12740
|
+
}
|
|
12741
|
+
const isReady = !isPending && !!order;
|
|
12742
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12743
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
12744
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
|
|
12745
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
|
|
12746
|
+
] }),
|
|
12747
|
+
isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
|
|
12748
|
+
] });
|
|
12749
|
+
};
|
|
12750
|
+
const BillingAddressForm = ({ order }) => {
|
|
12751
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
12752
|
+
const form = useForm({
|
|
12753
|
+
defaultValues: {
|
|
12754
|
+
first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
|
|
12755
|
+
last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
|
|
12756
|
+
company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
|
|
12757
|
+
address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
|
|
12758
|
+
address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
|
|
12759
|
+
city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
|
|
12760
|
+
province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
|
|
12761
|
+
country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
|
|
12762
|
+
postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12763
|
+
phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
|
|
12764
|
+
},
|
|
12765
|
+
resolver: zodResolver(schema$1)
|
|
12766
|
+
});
|
|
12767
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12768
|
+
const { handleSuccess } = useRouteModal();
|
|
12769
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
12770
|
+
await mutateAsync(
|
|
12771
|
+
{ billing_address: data },
|
|
12772
|
+
{
|
|
12773
|
+
onSuccess: () => {
|
|
12774
|
+
handleSuccess();
|
|
12775
|
+
},
|
|
12776
|
+
onError: (error) => {
|
|
12777
|
+
toast.error(error.message);
|
|
12778
|
+
}
|
|
12779
|
+
}
|
|
12780
|
+
);
|
|
12781
|
+
});
|
|
12782
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
12783
|
+
KeyboundForm,
|
|
12784
|
+
{
|
|
12785
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
12786
|
+
onSubmit,
|
|
12787
|
+
children: [
|
|
12788
|
+
/* @__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: [
|
|
12789
|
+
/* @__PURE__ */ jsx(
|
|
12790
|
+
Form$2.Field,
|
|
12791
|
+
{
|
|
12792
|
+
control: form.control,
|
|
12793
|
+
name: "country_code",
|
|
12794
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12795
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
|
|
12796
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
|
|
12797
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12798
|
+
] })
|
|
12799
|
+
}
|
|
12800
|
+
),
|
|
12801
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
12802
|
+
/* @__PURE__ */ jsx(
|
|
12803
|
+
Form$2.Field,
|
|
12804
|
+
{
|
|
12805
|
+
control: form.control,
|
|
12806
|
+
name: "first_name",
|
|
12807
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12808
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
|
|
12809
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12810
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12811
|
+
] })
|
|
12812
|
+
}
|
|
12813
|
+
),
|
|
12814
|
+
/* @__PURE__ */ jsx(
|
|
12815
|
+
Form$2.Field,
|
|
12816
|
+
{
|
|
12817
|
+
control: form.control,
|
|
12818
|
+
name: "last_name",
|
|
12819
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12820
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
|
|
12821
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12822
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12823
|
+
] })
|
|
12824
|
+
}
|
|
12825
|
+
)
|
|
12826
|
+
] }),
|
|
12827
|
+
/* @__PURE__ */ jsx(
|
|
12828
|
+
Form$2.Field,
|
|
12829
|
+
{
|
|
12830
|
+
control: form.control,
|
|
12831
|
+
name: "company",
|
|
12832
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12833
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
12834
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12835
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12836
|
+
] })
|
|
12974
12837
|
}
|
|
12975
|
-
)
|
|
12976
|
-
/* @__PURE__ */ jsx(
|
|
12977
|
-
|
|
12838
|
+
),
|
|
12839
|
+
/* @__PURE__ */ jsx(
|
|
12840
|
+
Form$2.Field,
|
|
12978
12841
|
{
|
|
12979
|
-
|
|
12980
|
-
|
|
12981
|
-
|
|
12982
|
-
|
|
12842
|
+
control: form.control,
|
|
12843
|
+
name: "address_1",
|
|
12844
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12845
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
|
|
12846
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12847
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12848
|
+
] })
|
|
12983
12849
|
}
|
|
12984
|
-
)
|
|
12985
|
-
/* @__PURE__ */ jsx(
|
|
12986
|
-
|
|
12850
|
+
),
|
|
12851
|
+
/* @__PURE__ */ jsx(
|
|
12852
|
+
Form$2.Field,
|
|
12987
12853
|
{
|
|
12988
|
-
|
|
12989
|
-
|
|
12990
|
-
|
|
12991
|
-
|
|
12854
|
+
control: form.control,
|
|
12855
|
+
name: "address_2",
|
|
12856
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12857
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
12858
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12859
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12860
|
+
] })
|
|
12992
12861
|
}
|
|
12993
|
-
)
|
|
12994
|
-
/* @__PURE__ */
|
|
12995
|
-
|
|
12862
|
+
),
|
|
12863
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
12864
|
+
/* @__PURE__ */ jsx(
|
|
12865
|
+
Form$2.Field,
|
|
12866
|
+
{
|
|
12867
|
+
control: form.control,
|
|
12868
|
+
name: "postal_code",
|
|
12869
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12870
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
|
|
12871
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12872
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12873
|
+
] })
|
|
12874
|
+
}
|
|
12875
|
+
),
|
|
12876
|
+
/* @__PURE__ */ jsx(
|
|
12877
|
+
Form$2.Field,
|
|
12878
|
+
{
|
|
12879
|
+
control: form.control,
|
|
12880
|
+
name: "city",
|
|
12881
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12882
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
|
|
12883
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12884
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12885
|
+
] })
|
|
12886
|
+
}
|
|
12887
|
+
)
|
|
12888
|
+
] }),
|
|
12889
|
+
/* @__PURE__ */ jsx(
|
|
12890
|
+
Form$2.Field,
|
|
12996
12891
|
{
|
|
12997
|
-
|
|
12998
|
-
|
|
12999
|
-
|
|
13000
|
-
|
|
12892
|
+
control: form.control,
|
|
12893
|
+
name: "province",
|
|
12894
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12895
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
12896
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12897
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12898
|
+
] })
|
|
13001
12899
|
}
|
|
13002
|
-
)
|
|
13003
|
-
/* @__PURE__ */ jsx(
|
|
13004
|
-
|
|
12900
|
+
),
|
|
12901
|
+
/* @__PURE__ */ jsx(
|
|
12902
|
+
Form$2.Field,
|
|
13005
12903
|
{
|
|
13006
|
-
|
|
13007
|
-
|
|
13008
|
-
|
|
13009
|
-
|
|
12904
|
+
control: form.control,
|
|
12905
|
+
name: "phone",
|
|
12906
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12907
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
|
|
12908
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12909
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12910
|
+
] })
|
|
13010
12911
|
}
|
|
13011
|
-
)
|
|
13012
|
-
|
|
13013
|
-
|
|
12912
|
+
)
|
|
12913
|
+
] }) }),
|
|
12914
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12915
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12916
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12917
|
+
] }) })
|
|
12918
|
+
]
|
|
12919
|
+
}
|
|
12920
|
+
) });
|
|
12921
|
+
};
|
|
12922
|
+
const schema$1 = addressSchema;
|
|
12923
|
+
const SalesChannel = () => {
|
|
12924
|
+
const { id } = useParams();
|
|
12925
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
12926
|
+
id,
|
|
12927
|
+
{
|
|
12928
|
+
fields: "+sales_channel_id"
|
|
12929
|
+
},
|
|
12930
|
+
{
|
|
12931
|
+
enabled: !!id
|
|
12932
|
+
}
|
|
12933
|
+
);
|
|
12934
|
+
if (isError) {
|
|
12935
|
+
throw error;
|
|
12936
|
+
}
|
|
12937
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
12938
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12939
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
12940
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
12941
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
12942
|
+
] }),
|
|
12943
|
+
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
12944
|
+
] });
|
|
12945
|
+
};
|
|
12946
|
+
const SalesChannelForm = ({ order }) => {
|
|
12947
|
+
const form = useForm({
|
|
12948
|
+
defaultValues: {
|
|
12949
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
12950
|
+
},
|
|
12951
|
+
resolver: zodResolver(schema)
|
|
12952
|
+
});
|
|
12953
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12954
|
+
const { handleSuccess } = useRouteModal();
|
|
12955
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
12956
|
+
await mutateAsync(
|
|
12957
|
+
{
|
|
12958
|
+
sales_channel_id: data.sales_channel_id
|
|
12959
|
+
},
|
|
12960
|
+
{
|
|
12961
|
+
onSuccess: () => {
|
|
12962
|
+
toast.success("Sales channel updated");
|
|
12963
|
+
handleSuccess();
|
|
12964
|
+
},
|
|
12965
|
+
onError: (error) => {
|
|
12966
|
+
toast.error(error.message);
|
|
12967
|
+
}
|
|
12968
|
+
}
|
|
12969
|
+
);
|
|
12970
|
+
});
|
|
12971
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
12972
|
+
KeyboundForm,
|
|
12973
|
+
{
|
|
12974
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
12975
|
+
onSubmit,
|
|
12976
|
+
children: [
|
|
12977
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
12978
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12979
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12980
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12981
|
+
] }) })
|
|
12982
|
+
]
|
|
12983
|
+
}
|
|
12984
|
+
) });
|
|
12985
|
+
};
|
|
12986
|
+
const SalesChannelField = ({ control, order }) => {
|
|
12987
|
+
const salesChannels = useComboboxData({
|
|
12988
|
+
queryFn: async (params) => {
|
|
12989
|
+
return await sdk.admin.salesChannel.list(params);
|
|
12990
|
+
},
|
|
12991
|
+
queryKey: ["sales-channels"],
|
|
12992
|
+
getOptions: (data) => {
|
|
12993
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
12994
|
+
label: salesChannel.name,
|
|
12995
|
+
value: salesChannel.id
|
|
12996
|
+
}));
|
|
12997
|
+
},
|
|
12998
|
+
defaultValue: order.sales_channel_id || void 0
|
|
12999
|
+
});
|
|
13000
|
+
return /* @__PURE__ */ jsx(
|
|
13001
|
+
Form$2.Field,
|
|
13002
|
+
{
|
|
13003
|
+
control,
|
|
13004
|
+
name: "sales_channel_id",
|
|
13005
|
+
render: ({ field }) => {
|
|
13006
|
+
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
13007
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
13008
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
13009
|
+
Combobox,
|
|
13014
13010
|
{
|
|
13015
|
-
|
|
13016
|
-
|
|
13017
|
-
|
|
13018
|
-
|
|
13011
|
+
options: salesChannels.options,
|
|
13012
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
13013
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
13014
|
+
searchValue: salesChannels.searchValue,
|
|
13015
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
13016
|
+
placeholder: "Select sales channel",
|
|
13017
|
+
...field
|
|
13019
13018
|
}
|
|
13020
|
-
) })
|
|
13021
|
-
|
|
13022
|
-
|
|
13019
|
+
) }),
|
|
13020
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
13021
|
+
] });
|
|
13022
|
+
}
|
|
13023
13023
|
}
|
|
13024
13024
|
);
|
|
13025
13025
|
};
|
|
13026
13026
|
const schema = objectType({
|
|
13027
|
-
|
|
13027
|
+
sales_channel_id: stringType().min(1)
|
|
13028
13028
|
});
|
|
13029
13029
|
const widgetModule = { widgets: [] };
|
|
13030
13030
|
const routeModule = {
|
|
@@ -13046,10 +13046,6 @@ const routeModule = {
|
|
|
13046
13046
|
handle,
|
|
13047
13047
|
loader,
|
|
13048
13048
|
children: [
|
|
13049
|
-
{
|
|
13050
|
-
Component: BillingAddress,
|
|
13051
|
-
path: "/draft-orders/:id/billing-address"
|
|
13052
|
-
},
|
|
13053
13049
|
{
|
|
13054
13050
|
Component: CustomItems,
|
|
13055
13051
|
path: "/draft-orders/:id/custom-items"
|
|
@@ -13062,18 +13058,14 @@ const routeModule = {
|
|
|
13062
13058
|
Component: Items,
|
|
13063
13059
|
path: "/draft-orders/:id/items"
|
|
13064
13060
|
},
|
|
13065
|
-
{
|
|
13066
|
-
Component: Promotions,
|
|
13067
|
-
path: "/draft-orders/:id/promotions"
|
|
13068
|
-
},
|
|
13069
|
-
{
|
|
13070
|
-
Component: SalesChannel,
|
|
13071
|
-
path: "/draft-orders/:id/sales-channel"
|
|
13072
|
-
},
|
|
13073
13061
|
{
|
|
13074
13062
|
Component: Metadata,
|
|
13075
13063
|
path: "/draft-orders/:id/metadata"
|
|
13076
13064
|
},
|
|
13065
|
+
{
|
|
13066
|
+
Component: Promotions,
|
|
13067
|
+
path: "/draft-orders/:id/promotions"
|
|
13068
|
+
},
|
|
13077
13069
|
{
|
|
13078
13070
|
Component: Shipping,
|
|
13079
13071
|
path: "/draft-orders/:id/shipping"
|
|
@@ -13085,6 +13077,14 @@ const routeModule = {
|
|
|
13085
13077
|
{
|
|
13086
13078
|
Component: TransferOwnership,
|
|
13087
13079
|
path: "/draft-orders/:id/transfer-ownership"
|
|
13080
|
+
},
|
|
13081
|
+
{
|
|
13082
|
+
Component: BillingAddress,
|
|
13083
|
+
path: "/draft-orders/:id/billing-address"
|
|
13084
|
+
},
|
|
13085
|
+
{
|
|
13086
|
+
Component: SalesChannel,
|
|
13087
|
+
path: "/draft-orders/:id/sales-channel"
|
|
13088
13088
|
}
|
|
13089
13089
|
]
|
|
13090
13090
|
}
|