@medusajs/draft-order 2.11.2-preview-20251028000318 → 2.11.2-preview-20251028031854
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 +729 -729
- package/.medusa/server/src/admin/index.mjs +729 -729
- package/package.json +16 -16
|
@@ -9565,6 +9565,196 @@ const ID = () => {
|
|
|
9565
9565
|
/* @__PURE__ */ jsx(Outlet, {})
|
|
9566
9566
|
] });
|
|
9567
9567
|
};
|
|
9568
|
+
const BillingAddress = () => {
|
|
9569
|
+
const { id } = useParams();
|
|
9570
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
9571
|
+
fields: "+billing_address"
|
|
9572
|
+
});
|
|
9573
|
+
if (isError) {
|
|
9574
|
+
throw error;
|
|
9575
|
+
}
|
|
9576
|
+
const isReady = !isPending && !!order;
|
|
9577
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9578
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
9579
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
|
|
9580
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
|
|
9581
|
+
] }),
|
|
9582
|
+
isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
|
|
9583
|
+
] });
|
|
9584
|
+
};
|
|
9585
|
+
const BillingAddressForm = ({ order }) => {
|
|
9586
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
9587
|
+
const form = useForm({
|
|
9588
|
+
defaultValues: {
|
|
9589
|
+
first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
|
|
9590
|
+
last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
|
|
9591
|
+
company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
|
|
9592
|
+
address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
|
|
9593
|
+
address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
|
|
9594
|
+
city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
|
|
9595
|
+
province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
|
|
9596
|
+
country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
|
|
9597
|
+
postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
9598
|
+
phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
|
|
9599
|
+
},
|
|
9600
|
+
resolver: zodResolver(schema$5)
|
|
9601
|
+
});
|
|
9602
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9603
|
+
const { handleSuccess } = useRouteModal();
|
|
9604
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
9605
|
+
await mutateAsync(
|
|
9606
|
+
{ billing_address: data },
|
|
9607
|
+
{
|
|
9608
|
+
onSuccess: () => {
|
|
9609
|
+
handleSuccess();
|
|
9610
|
+
},
|
|
9611
|
+
onError: (error) => {
|
|
9612
|
+
toast.error(error.message);
|
|
9613
|
+
}
|
|
9614
|
+
}
|
|
9615
|
+
);
|
|
9616
|
+
});
|
|
9617
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
9618
|
+
KeyboundForm,
|
|
9619
|
+
{
|
|
9620
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
9621
|
+
onSubmit,
|
|
9622
|
+
children: [
|
|
9623
|
+
/* @__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: [
|
|
9624
|
+
/* @__PURE__ */ jsx(
|
|
9625
|
+
Form$2.Field,
|
|
9626
|
+
{
|
|
9627
|
+
control: form.control,
|
|
9628
|
+
name: "country_code",
|
|
9629
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9630
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
|
|
9631
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
|
|
9632
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9633
|
+
] })
|
|
9634
|
+
}
|
|
9635
|
+
),
|
|
9636
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
9637
|
+
/* @__PURE__ */ jsx(
|
|
9638
|
+
Form$2.Field,
|
|
9639
|
+
{
|
|
9640
|
+
control: form.control,
|
|
9641
|
+
name: "first_name",
|
|
9642
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9643
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
|
|
9644
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9645
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9646
|
+
] })
|
|
9647
|
+
}
|
|
9648
|
+
),
|
|
9649
|
+
/* @__PURE__ */ jsx(
|
|
9650
|
+
Form$2.Field,
|
|
9651
|
+
{
|
|
9652
|
+
control: form.control,
|
|
9653
|
+
name: "last_name",
|
|
9654
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9655
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
|
|
9656
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9657
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9658
|
+
] })
|
|
9659
|
+
}
|
|
9660
|
+
)
|
|
9661
|
+
] }),
|
|
9662
|
+
/* @__PURE__ */ jsx(
|
|
9663
|
+
Form$2.Field,
|
|
9664
|
+
{
|
|
9665
|
+
control: form.control,
|
|
9666
|
+
name: "company",
|
|
9667
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9668
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
9669
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9670
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9671
|
+
] })
|
|
9672
|
+
}
|
|
9673
|
+
),
|
|
9674
|
+
/* @__PURE__ */ jsx(
|
|
9675
|
+
Form$2.Field,
|
|
9676
|
+
{
|
|
9677
|
+
control: form.control,
|
|
9678
|
+
name: "address_1",
|
|
9679
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9680
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
|
|
9681
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9682
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9683
|
+
] })
|
|
9684
|
+
}
|
|
9685
|
+
),
|
|
9686
|
+
/* @__PURE__ */ jsx(
|
|
9687
|
+
Form$2.Field,
|
|
9688
|
+
{
|
|
9689
|
+
control: form.control,
|
|
9690
|
+
name: "address_2",
|
|
9691
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9692
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
9693
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9694
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9695
|
+
] })
|
|
9696
|
+
}
|
|
9697
|
+
),
|
|
9698
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
9699
|
+
/* @__PURE__ */ jsx(
|
|
9700
|
+
Form$2.Field,
|
|
9701
|
+
{
|
|
9702
|
+
control: form.control,
|
|
9703
|
+
name: "postal_code",
|
|
9704
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9705
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
|
|
9706
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9707
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9708
|
+
] })
|
|
9709
|
+
}
|
|
9710
|
+
),
|
|
9711
|
+
/* @__PURE__ */ jsx(
|
|
9712
|
+
Form$2.Field,
|
|
9713
|
+
{
|
|
9714
|
+
control: form.control,
|
|
9715
|
+
name: "city",
|
|
9716
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9717
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
|
|
9718
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9719
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9720
|
+
] })
|
|
9721
|
+
}
|
|
9722
|
+
)
|
|
9723
|
+
] }),
|
|
9724
|
+
/* @__PURE__ */ jsx(
|
|
9725
|
+
Form$2.Field,
|
|
9726
|
+
{
|
|
9727
|
+
control: form.control,
|
|
9728
|
+
name: "province",
|
|
9729
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9730
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
9731
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9732
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9733
|
+
] })
|
|
9734
|
+
}
|
|
9735
|
+
),
|
|
9736
|
+
/* @__PURE__ */ jsx(
|
|
9737
|
+
Form$2.Field,
|
|
9738
|
+
{
|
|
9739
|
+
control: form.control,
|
|
9740
|
+
name: "phone",
|
|
9741
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9742
|
+
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
|
|
9743
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9744
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9745
|
+
] })
|
|
9746
|
+
}
|
|
9747
|
+
)
|
|
9748
|
+
] }) }),
|
|
9749
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9750
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9751
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9752
|
+
] }) })
|
|
9753
|
+
]
|
|
9754
|
+
}
|
|
9755
|
+
) });
|
|
9756
|
+
};
|
|
9757
|
+
const schema$5 = addressSchema;
|
|
9568
9758
|
const CustomItems = () => {
|
|
9569
9759
|
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9570
9760
|
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
|
|
@@ -9573,7 +9763,7 @@ const CustomItems = () => {
|
|
|
9573
9763
|
};
|
|
9574
9764
|
const CustomItemsForm = () => {
|
|
9575
9765
|
const form = useForm({
|
|
9576
|
-
resolver: zodResolver(schema$
|
|
9766
|
+
resolver: zodResolver(schema$4)
|
|
9577
9767
|
});
|
|
9578
9768
|
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
9579
9769
|
/* @__PURE__ */ jsx(RouteDrawer.Body, {}),
|
|
@@ -9583,45 +9773,113 @@ const CustomItemsForm = () => {
|
|
|
9583
9773
|
] }) })
|
|
9584
9774
|
] }) });
|
|
9585
9775
|
};
|
|
9586
|
-
const schema$
|
|
9776
|
+
const schema$4 = objectType({
|
|
9587
9777
|
email: stringType().email()
|
|
9588
9778
|
});
|
|
9589
|
-
const
|
|
9590
|
-
(
|
|
9591
|
-
|
|
9592
|
-
|
|
9593
|
-
|
|
9594
|
-
|
|
9595
|
-
|
|
9596
|
-
|
|
9597
|
-
|
|
9598
|
-
|
|
9599
|
-
|
|
9600
|
-
|
|
9601
|
-
|
|
9602
|
-
|
|
9603
|
-
|
|
9604
|
-
|
|
9605
|
-
|
|
9606
|
-
|
|
9607
|
-
|
|
9608
|
-
|
|
9609
|
-
|
|
9610
|
-
|
|
9611
|
-
|
|
9612
|
-
|
|
9613
|
-
|
|
9614
|
-
|
|
9615
|
-
|
|
9616
|
-
|
|
9617
|
-
}
|
|
9618
|
-
};
|
|
9619
|
-
return /* @__PURE__ */ jsxs(
|
|
9620
|
-
"div",
|
|
9779
|
+
const Email = () => {
|
|
9780
|
+
const { id } = useParams();
|
|
9781
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
9782
|
+
fields: "+email"
|
|
9783
|
+
});
|
|
9784
|
+
if (isError) {
|
|
9785
|
+
throw error;
|
|
9786
|
+
}
|
|
9787
|
+
const isReady = !isPending && !!order;
|
|
9788
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9789
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
9790
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
|
|
9791
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
9792
|
+
] }),
|
|
9793
|
+
isReady && /* @__PURE__ */ jsx(EmailForm, { order })
|
|
9794
|
+
] });
|
|
9795
|
+
};
|
|
9796
|
+
const EmailForm = ({ order }) => {
|
|
9797
|
+
const form = useForm({
|
|
9798
|
+
defaultValues: {
|
|
9799
|
+
email: order.email ?? ""
|
|
9800
|
+
},
|
|
9801
|
+
resolver: zodResolver(schema$3)
|
|
9802
|
+
});
|
|
9803
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9804
|
+
const { handleSuccess } = useRouteModal();
|
|
9805
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
9806
|
+
await mutateAsync(
|
|
9807
|
+
{ email: data.email },
|
|
9621
9808
|
{
|
|
9622
|
-
|
|
9623
|
-
|
|
9624
|
-
|
|
9809
|
+
onSuccess: () => {
|
|
9810
|
+
handleSuccess();
|
|
9811
|
+
},
|
|
9812
|
+
onError: (error) => {
|
|
9813
|
+
toast.error(error.message);
|
|
9814
|
+
}
|
|
9815
|
+
}
|
|
9816
|
+
);
|
|
9817
|
+
});
|
|
9818
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
9819
|
+
KeyboundForm,
|
|
9820
|
+
{
|
|
9821
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
9822
|
+
onSubmit,
|
|
9823
|
+
children: [
|
|
9824
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
|
|
9825
|
+
Form$2.Field,
|
|
9826
|
+
{
|
|
9827
|
+
control: form.control,
|
|
9828
|
+
name: "email",
|
|
9829
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
9830
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
|
|
9831
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
9832
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
9833
|
+
] })
|
|
9834
|
+
}
|
|
9835
|
+
) }),
|
|
9836
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9837
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9838
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
9839
|
+
] }) })
|
|
9840
|
+
]
|
|
9841
|
+
}
|
|
9842
|
+
) });
|
|
9843
|
+
};
|
|
9844
|
+
const schema$3 = objectType({
|
|
9845
|
+
email: stringType().email()
|
|
9846
|
+
});
|
|
9847
|
+
const NumberInput = forwardRef(
|
|
9848
|
+
({
|
|
9849
|
+
value,
|
|
9850
|
+
onChange,
|
|
9851
|
+
size = "base",
|
|
9852
|
+
min = 0,
|
|
9853
|
+
max = 100,
|
|
9854
|
+
step = 1,
|
|
9855
|
+
className,
|
|
9856
|
+
disabled,
|
|
9857
|
+
...props
|
|
9858
|
+
}, ref) => {
|
|
9859
|
+
const handleChange = (event) => {
|
|
9860
|
+
const newValue = event.target.value === "" ? min : Number(event.target.value);
|
|
9861
|
+
if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
|
|
9862
|
+
onChange(newValue);
|
|
9863
|
+
}
|
|
9864
|
+
};
|
|
9865
|
+
const handleIncrement = () => {
|
|
9866
|
+
const newValue = value + step;
|
|
9867
|
+
if (max === void 0 || newValue <= max) {
|
|
9868
|
+
onChange(newValue);
|
|
9869
|
+
}
|
|
9870
|
+
};
|
|
9871
|
+
const handleDecrement = () => {
|
|
9872
|
+
const newValue = value - step;
|
|
9873
|
+
if (min === void 0 || newValue >= min) {
|
|
9874
|
+
onChange(newValue);
|
|
9875
|
+
}
|
|
9876
|
+
};
|
|
9877
|
+
return /* @__PURE__ */ jsxs(
|
|
9878
|
+
"div",
|
|
9879
|
+
{
|
|
9880
|
+
className: clx(
|
|
9881
|
+
"inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
|
|
9882
|
+
"[&:has(input:focus)]:shadow-borders-interactive-with-active",
|
|
9625
9883
|
{
|
|
9626
9884
|
"h-7": size === "small",
|
|
9627
9885
|
"h-8": size === "base"
|
|
@@ -10558,616 +10816,8 @@ const CustomItemForm = ({ orderId, currencyCode }) => {
|
|
|
10558
10816
|
const customItemSchema = objectType({
|
|
10559
10817
|
title: stringType().min(1),
|
|
10560
10818
|
quantity: numberType(),
|
|
10561
|
-
unit_price: unionType([numberType(), stringType()])
|
|
10562
|
-
});
|
|
10563
|
-
const Email = () => {
|
|
10564
|
-
const { id } = useParams();
|
|
10565
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
10566
|
-
fields: "+email"
|
|
10567
|
-
});
|
|
10568
|
-
if (isError) {
|
|
10569
|
-
throw error;
|
|
10570
|
-
}
|
|
10571
|
-
const isReady = !isPending && !!order;
|
|
10572
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
10573
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
10574
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
|
|
10575
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
10576
|
-
] }),
|
|
10577
|
-
isReady && /* @__PURE__ */ jsx(EmailForm, { order })
|
|
10578
|
-
] });
|
|
10579
|
-
};
|
|
10580
|
-
const EmailForm = ({ order }) => {
|
|
10581
|
-
const form = useForm({
|
|
10582
|
-
defaultValues: {
|
|
10583
|
-
email: order.email ?? ""
|
|
10584
|
-
},
|
|
10585
|
-
resolver: zodResolver(schema$4)
|
|
10586
|
-
});
|
|
10587
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
10588
|
-
const { handleSuccess } = useRouteModal();
|
|
10589
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
10590
|
-
await mutateAsync(
|
|
10591
|
-
{ email: data.email },
|
|
10592
|
-
{
|
|
10593
|
-
onSuccess: () => {
|
|
10594
|
-
handleSuccess();
|
|
10595
|
-
},
|
|
10596
|
-
onError: (error) => {
|
|
10597
|
-
toast.error(error.message);
|
|
10598
|
-
}
|
|
10599
|
-
}
|
|
10600
|
-
);
|
|
10601
|
-
});
|
|
10602
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
10603
|
-
KeyboundForm,
|
|
10604
|
-
{
|
|
10605
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
10606
|
-
onSubmit,
|
|
10607
|
-
children: [
|
|
10608
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
|
|
10609
|
-
Form$2.Field,
|
|
10610
|
-
{
|
|
10611
|
-
control: form.control,
|
|
10612
|
-
name: "email",
|
|
10613
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
10614
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
|
|
10615
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
10616
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10617
|
-
] })
|
|
10618
|
-
}
|
|
10619
|
-
) }),
|
|
10620
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10621
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10622
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
10623
|
-
] }) })
|
|
10624
|
-
]
|
|
10625
|
-
}
|
|
10626
|
-
) });
|
|
10627
|
-
};
|
|
10628
|
-
const schema$4 = objectType({
|
|
10629
|
-
email: stringType().email()
|
|
10630
|
-
});
|
|
10631
|
-
const InlineTip = forwardRef(
|
|
10632
|
-
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
10633
|
-
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
10634
|
-
return /* @__PURE__ */ jsxs(
|
|
10635
|
-
"div",
|
|
10636
|
-
{
|
|
10637
|
-
ref,
|
|
10638
|
-
className: clx(
|
|
10639
|
-
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
10640
|
-
className
|
|
10641
|
-
),
|
|
10642
|
-
...props,
|
|
10643
|
-
children: [
|
|
10644
|
-
/* @__PURE__ */ jsx(
|
|
10645
|
-
"div",
|
|
10646
|
-
{
|
|
10647
|
-
role: "presentation",
|
|
10648
|
-
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
10649
|
-
"bg-ui-tag-orange-icon": variant === "warning"
|
|
10650
|
-
})
|
|
10651
|
-
}
|
|
10652
|
-
),
|
|
10653
|
-
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
10654
|
-
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
10655
|
-
labelValue,
|
|
10656
|
-
":"
|
|
10657
|
-
] }),
|
|
10658
|
-
" ",
|
|
10659
|
-
children
|
|
10660
|
-
] })
|
|
10661
|
-
]
|
|
10662
|
-
}
|
|
10663
|
-
);
|
|
10664
|
-
}
|
|
10665
|
-
);
|
|
10666
|
-
InlineTip.displayName = "InlineTip";
|
|
10667
|
-
const MetadataFieldSchema = objectType({
|
|
10668
|
-
key: stringType(),
|
|
10669
|
-
disabled: booleanType().optional(),
|
|
10670
|
-
value: anyType()
|
|
10671
|
-
});
|
|
10672
|
-
const MetadataSchema = objectType({
|
|
10673
|
-
metadata: arrayType(MetadataFieldSchema)
|
|
10674
|
-
});
|
|
10675
|
-
const Metadata = () => {
|
|
10676
|
-
const { id } = useParams();
|
|
10677
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
10678
|
-
fields: "metadata"
|
|
10679
|
-
});
|
|
10680
|
-
if (isError) {
|
|
10681
|
-
throw error;
|
|
10682
|
-
}
|
|
10683
|
-
const isReady = !isPending && !!order;
|
|
10684
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
10685
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
10686
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
|
|
10687
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
10688
|
-
] }),
|
|
10689
|
-
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
10690
|
-
] });
|
|
10691
|
-
};
|
|
10692
|
-
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
10693
|
-
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
10694
|
-
const MetadataForm = ({ orderId, metadata }) => {
|
|
10695
|
-
const { handleSuccess } = useRouteModal();
|
|
10696
|
-
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
10697
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
10698
|
-
const form = useForm({
|
|
10699
|
-
defaultValues: {
|
|
10700
|
-
metadata: getDefaultValues(metadata)
|
|
10701
|
-
},
|
|
10702
|
-
resolver: zodResolver(MetadataSchema)
|
|
10703
|
-
});
|
|
10704
|
-
const handleSubmit = form.handleSubmit(async (data) => {
|
|
10705
|
-
const parsedData = parseValues(data);
|
|
10706
|
-
await mutateAsync(
|
|
10707
|
-
{
|
|
10708
|
-
metadata: parsedData
|
|
10709
|
-
},
|
|
10710
|
-
{
|
|
10711
|
-
onSuccess: () => {
|
|
10712
|
-
toast.success("Metadata updated");
|
|
10713
|
-
handleSuccess();
|
|
10714
|
-
},
|
|
10715
|
-
onError: (error) => {
|
|
10716
|
-
toast.error(error.message);
|
|
10717
|
-
}
|
|
10718
|
-
}
|
|
10719
|
-
);
|
|
10720
|
-
});
|
|
10721
|
-
const { fields, insert, remove } = useFieldArray({
|
|
10722
|
-
control: form.control,
|
|
10723
|
-
name: "metadata"
|
|
10724
|
-
});
|
|
10725
|
-
function deleteRow(index) {
|
|
10726
|
-
remove(index);
|
|
10727
|
-
if (fields.length === 1) {
|
|
10728
|
-
insert(0, {
|
|
10729
|
-
key: "",
|
|
10730
|
-
value: "",
|
|
10731
|
-
disabled: false
|
|
10732
|
-
});
|
|
10733
|
-
}
|
|
10734
|
-
}
|
|
10735
|
-
function insertRow(index, position) {
|
|
10736
|
-
insert(index + (position === "above" ? 0 : 1), {
|
|
10737
|
-
key: "",
|
|
10738
|
-
value: "",
|
|
10739
|
-
disabled: false
|
|
10740
|
-
});
|
|
10741
|
-
}
|
|
10742
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
10743
|
-
KeyboundForm,
|
|
10744
|
-
{
|
|
10745
|
-
onSubmit: handleSubmit,
|
|
10746
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
10747
|
-
children: [
|
|
10748
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
10749
|
-
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
10750
|
-
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
10751
|
-
/* @__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" }) }),
|
|
10752
|
-
/* @__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" }) })
|
|
10753
|
-
] }),
|
|
10754
|
-
fields.map((field, index) => {
|
|
10755
|
-
const isDisabled = field.disabled || false;
|
|
10756
|
-
let placeholder = "-";
|
|
10757
|
-
if (typeof field.value === "object") {
|
|
10758
|
-
placeholder = "{ ... }";
|
|
10759
|
-
}
|
|
10760
|
-
if (Array.isArray(field.value)) {
|
|
10761
|
-
placeholder = "[ ... ]";
|
|
10762
|
-
}
|
|
10763
|
-
return /* @__PURE__ */ jsx(
|
|
10764
|
-
ConditionalTooltip,
|
|
10765
|
-
{
|
|
10766
|
-
showTooltip: isDisabled,
|
|
10767
|
-
content: "This row is disabled because it contains non-primitive data.",
|
|
10768
|
-
children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
|
|
10769
|
-
/* @__PURE__ */ jsxs(
|
|
10770
|
-
"div",
|
|
10771
|
-
{
|
|
10772
|
-
className: clx("grid grid-cols-2 divide-x", {
|
|
10773
|
-
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
10774
|
-
}),
|
|
10775
|
-
children: [
|
|
10776
|
-
/* @__PURE__ */ jsx(
|
|
10777
|
-
Form$2.Field,
|
|
10778
|
-
{
|
|
10779
|
-
control: form.control,
|
|
10780
|
-
name: `metadata.${index}.key`,
|
|
10781
|
-
render: ({ field: field2 }) => {
|
|
10782
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10783
|
-
GridInput,
|
|
10784
|
-
{
|
|
10785
|
-
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
10786
|
-
...field2,
|
|
10787
|
-
disabled: isDisabled,
|
|
10788
|
-
placeholder: "Key"
|
|
10789
|
-
}
|
|
10790
|
-
) }) });
|
|
10791
|
-
}
|
|
10792
|
-
}
|
|
10793
|
-
),
|
|
10794
|
-
/* @__PURE__ */ jsx(
|
|
10795
|
-
Form$2.Field,
|
|
10796
|
-
{
|
|
10797
|
-
control: form.control,
|
|
10798
|
-
name: `metadata.${index}.value`,
|
|
10799
|
-
render: ({ field: { value, ...field2 } }) => {
|
|
10800
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10801
|
-
GridInput,
|
|
10802
|
-
{
|
|
10803
|
-
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
10804
|
-
...field2,
|
|
10805
|
-
value: isDisabled ? placeholder : value,
|
|
10806
|
-
disabled: isDisabled,
|
|
10807
|
-
placeholder: "Value"
|
|
10808
|
-
}
|
|
10809
|
-
) }) });
|
|
10810
|
-
}
|
|
10811
|
-
}
|
|
10812
|
-
)
|
|
10813
|
-
]
|
|
10814
|
-
}
|
|
10815
|
-
),
|
|
10816
|
-
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
10817
|
-
/* @__PURE__ */ jsx(
|
|
10818
|
-
DropdownMenu.Trigger,
|
|
10819
|
-
{
|
|
10820
|
-
className: clx(
|
|
10821
|
-
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
10822
|
-
{
|
|
10823
|
-
hidden: isDisabled
|
|
10824
|
-
}
|
|
10825
|
-
),
|
|
10826
|
-
disabled: isDisabled,
|
|
10827
|
-
asChild: true,
|
|
10828
|
-
children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
|
|
10829
|
-
}
|
|
10830
|
-
),
|
|
10831
|
-
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
10832
|
-
/* @__PURE__ */ jsxs(
|
|
10833
|
-
DropdownMenu.Item,
|
|
10834
|
-
{
|
|
10835
|
-
className: "gap-x-2",
|
|
10836
|
-
onClick: () => insertRow(index, "above"),
|
|
10837
|
-
children: [
|
|
10838
|
-
/* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
10839
|
-
"Insert row above"
|
|
10840
|
-
]
|
|
10841
|
-
}
|
|
10842
|
-
),
|
|
10843
|
-
/* @__PURE__ */ jsxs(
|
|
10844
|
-
DropdownMenu.Item,
|
|
10845
|
-
{
|
|
10846
|
-
className: "gap-x-2",
|
|
10847
|
-
onClick: () => insertRow(index, "below"),
|
|
10848
|
-
children: [
|
|
10849
|
-
/* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
10850
|
-
"Insert row below"
|
|
10851
|
-
]
|
|
10852
|
-
}
|
|
10853
|
-
),
|
|
10854
|
-
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
10855
|
-
/* @__PURE__ */ jsxs(
|
|
10856
|
-
DropdownMenu.Item,
|
|
10857
|
-
{
|
|
10858
|
-
className: "gap-x-2",
|
|
10859
|
-
onClick: () => deleteRow(index),
|
|
10860
|
-
children: [
|
|
10861
|
-
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
10862
|
-
"Delete row"
|
|
10863
|
-
]
|
|
10864
|
-
}
|
|
10865
|
-
)
|
|
10866
|
-
] })
|
|
10867
|
-
] })
|
|
10868
|
-
] })
|
|
10869
|
-
},
|
|
10870
|
-
field.id
|
|
10871
|
-
);
|
|
10872
|
-
})
|
|
10873
|
-
] }),
|
|
10874
|
-
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." })
|
|
10875
|
-
] }),
|
|
10876
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10877
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10878
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
10879
|
-
] }) })
|
|
10880
|
-
]
|
|
10881
|
-
}
|
|
10882
|
-
) });
|
|
10883
|
-
};
|
|
10884
|
-
const GridInput = forwardRef(({ className, ...props }, ref) => {
|
|
10885
|
-
return /* @__PURE__ */ jsx(
|
|
10886
|
-
"input",
|
|
10887
|
-
{
|
|
10888
|
-
ref,
|
|
10889
|
-
...props,
|
|
10890
|
-
autoComplete: "off",
|
|
10891
|
-
className: clx(
|
|
10892
|
-
"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",
|
|
10893
|
-
className
|
|
10894
|
-
)
|
|
10895
|
-
}
|
|
10896
|
-
);
|
|
10897
|
-
});
|
|
10898
|
-
GridInput.displayName = "MetadataForm.GridInput";
|
|
10899
|
-
const PlaceholderInner = () => {
|
|
10900
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
10901
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
10902
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10903
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
10904
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
10905
|
-
] }) })
|
|
10906
|
-
] });
|
|
10907
|
-
};
|
|
10908
|
-
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
10909
|
-
function getDefaultValues(metadata) {
|
|
10910
|
-
if (!metadata || !Object.keys(metadata).length) {
|
|
10911
|
-
return [
|
|
10912
|
-
{
|
|
10913
|
-
key: "",
|
|
10914
|
-
value: "",
|
|
10915
|
-
disabled: false
|
|
10916
|
-
}
|
|
10917
|
-
];
|
|
10918
|
-
}
|
|
10919
|
-
return Object.entries(metadata).map(([key, value]) => {
|
|
10920
|
-
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
10921
|
-
return {
|
|
10922
|
-
key,
|
|
10923
|
-
value,
|
|
10924
|
-
disabled: true
|
|
10925
|
-
};
|
|
10926
|
-
}
|
|
10927
|
-
let stringValue = value;
|
|
10928
|
-
if (typeof value !== "string") {
|
|
10929
|
-
stringValue = JSON.stringify(value);
|
|
10930
|
-
}
|
|
10931
|
-
return {
|
|
10932
|
-
key,
|
|
10933
|
-
value: stringValue,
|
|
10934
|
-
original_key: key
|
|
10935
|
-
};
|
|
10936
|
-
});
|
|
10937
|
-
}
|
|
10938
|
-
function parseValues(values) {
|
|
10939
|
-
const metadata = values.metadata;
|
|
10940
|
-
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
10941
|
-
if (isEmpty) {
|
|
10942
|
-
return null;
|
|
10943
|
-
}
|
|
10944
|
-
const update = {};
|
|
10945
|
-
metadata.forEach((field) => {
|
|
10946
|
-
let key = field.key;
|
|
10947
|
-
let value = field.value;
|
|
10948
|
-
const disabled = field.disabled;
|
|
10949
|
-
if (!key || !value) {
|
|
10950
|
-
return;
|
|
10951
|
-
}
|
|
10952
|
-
if (disabled) {
|
|
10953
|
-
update[key] = value;
|
|
10954
|
-
return;
|
|
10955
|
-
}
|
|
10956
|
-
key = key.trim();
|
|
10957
|
-
value = value.trim();
|
|
10958
|
-
if (value === "true") {
|
|
10959
|
-
update[key] = true;
|
|
10960
|
-
} else if (value === "false") {
|
|
10961
|
-
update[key] = false;
|
|
10962
|
-
} else {
|
|
10963
|
-
const parsedNumber = parseFloat(value);
|
|
10964
|
-
if (!isNaN(parsedNumber)) {
|
|
10965
|
-
update[key] = parsedNumber;
|
|
10966
|
-
} else {
|
|
10967
|
-
update[key] = value;
|
|
10968
|
-
}
|
|
10969
|
-
}
|
|
10970
|
-
});
|
|
10971
|
-
return update;
|
|
10972
|
-
}
|
|
10973
|
-
function getHasUneditableRows(metadata) {
|
|
10974
|
-
if (!metadata) {
|
|
10975
|
-
return false;
|
|
10976
|
-
}
|
|
10977
|
-
return Object.values(metadata).some(
|
|
10978
|
-
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
10979
|
-
);
|
|
10980
|
-
}
|
|
10981
|
-
const BillingAddress = () => {
|
|
10982
|
-
const { id } = useParams();
|
|
10983
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
10984
|
-
fields: "+billing_address"
|
|
10985
|
-
});
|
|
10986
|
-
if (isError) {
|
|
10987
|
-
throw error;
|
|
10988
|
-
}
|
|
10989
|
-
const isReady = !isPending && !!order;
|
|
10990
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
10991
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
10992
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
|
|
10993
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
|
|
10994
|
-
] }),
|
|
10995
|
-
isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
|
|
10996
|
-
] });
|
|
10997
|
-
};
|
|
10998
|
-
const BillingAddressForm = ({ order }) => {
|
|
10999
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
11000
|
-
const form = useForm({
|
|
11001
|
-
defaultValues: {
|
|
11002
|
-
first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
|
|
11003
|
-
last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
|
|
11004
|
-
company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
|
|
11005
|
-
address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
|
|
11006
|
-
address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
|
|
11007
|
-
city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
|
|
11008
|
-
province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
|
|
11009
|
-
country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
|
|
11010
|
-
postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
11011
|
-
phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
|
|
11012
|
-
},
|
|
11013
|
-
resolver: zodResolver(schema$3)
|
|
11014
|
-
});
|
|
11015
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11016
|
-
const { handleSuccess } = useRouteModal();
|
|
11017
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
11018
|
-
await mutateAsync(
|
|
11019
|
-
{ billing_address: data },
|
|
11020
|
-
{
|
|
11021
|
-
onSuccess: () => {
|
|
11022
|
-
handleSuccess();
|
|
11023
|
-
},
|
|
11024
|
-
onError: (error) => {
|
|
11025
|
-
toast.error(error.message);
|
|
11026
|
-
}
|
|
11027
|
-
}
|
|
11028
|
-
);
|
|
11029
|
-
});
|
|
11030
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
11031
|
-
KeyboundForm,
|
|
11032
|
-
{
|
|
11033
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
11034
|
-
onSubmit,
|
|
11035
|
-
children: [
|
|
11036
|
-
/* @__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: [
|
|
11037
|
-
/* @__PURE__ */ jsx(
|
|
11038
|
-
Form$2.Field,
|
|
11039
|
-
{
|
|
11040
|
-
control: form.control,
|
|
11041
|
-
name: "country_code",
|
|
11042
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11043
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
|
|
11044
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
|
|
11045
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11046
|
-
] })
|
|
11047
|
-
}
|
|
11048
|
-
),
|
|
11049
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
11050
|
-
/* @__PURE__ */ jsx(
|
|
11051
|
-
Form$2.Field,
|
|
11052
|
-
{
|
|
11053
|
-
control: form.control,
|
|
11054
|
-
name: "first_name",
|
|
11055
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11056
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
|
|
11057
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11058
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11059
|
-
] })
|
|
11060
|
-
}
|
|
11061
|
-
),
|
|
11062
|
-
/* @__PURE__ */ jsx(
|
|
11063
|
-
Form$2.Field,
|
|
11064
|
-
{
|
|
11065
|
-
control: form.control,
|
|
11066
|
-
name: "last_name",
|
|
11067
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11068
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
|
|
11069
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11070
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11071
|
-
] })
|
|
11072
|
-
}
|
|
11073
|
-
)
|
|
11074
|
-
] }),
|
|
11075
|
-
/* @__PURE__ */ jsx(
|
|
11076
|
-
Form$2.Field,
|
|
11077
|
-
{
|
|
11078
|
-
control: form.control,
|
|
11079
|
-
name: "company",
|
|
11080
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11081
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
|
|
11082
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11083
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11084
|
-
] })
|
|
11085
|
-
}
|
|
11086
|
-
),
|
|
11087
|
-
/* @__PURE__ */ jsx(
|
|
11088
|
-
Form$2.Field,
|
|
11089
|
-
{
|
|
11090
|
-
control: form.control,
|
|
11091
|
-
name: "address_1",
|
|
11092
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11093
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
|
|
11094
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11095
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11096
|
-
] })
|
|
11097
|
-
}
|
|
11098
|
-
),
|
|
11099
|
-
/* @__PURE__ */ jsx(
|
|
11100
|
-
Form$2.Field,
|
|
11101
|
-
{
|
|
11102
|
-
control: form.control,
|
|
11103
|
-
name: "address_2",
|
|
11104
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11105
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
11106
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11107
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11108
|
-
] })
|
|
11109
|
-
}
|
|
11110
|
-
),
|
|
11111
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
11112
|
-
/* @__PURE__ */ jsx(
|
|
11113
|
-
Form$2.Field,
|
|
11114
|
-
{
|
|
11115
|
-
control: form.control,
|
|
11116
|
-
name: "postal_code",
|
|
11117
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11118
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
|
|
11119
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11120
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11121
|
-
] })
|
|
11122
|
-
}
|
|
11123
|
-
),
|
|
11124
|
-
/* @__PURE__ */ jsx(
|
|
11125
|
-
Form$2.Field,
|
|
11126
|
-
{
|
|
11127
|
-
control: form.control,
|
|
11128
|
-
name: "city",
|
|
11129
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11130
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
|
|
11131
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11132
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11133
|
-
] })
|
|
11134
|
-
}
|
|
11135
|
-
)
|
|
11136
|
-
] }),
|
|
11137
|
-
/* @__PURE__ */ jsx(
|
|
11138
|
-
Form$2.Field,
|
|
11139
|
-
{
|
|
11140
|
-
control: form.control,
|
|
11141
|
-
name: "province",
|
|
11142
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11143
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
|
|
11144
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11145
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11146
|
-
] })
|
|
11147
|
-
}
|
|
11148
|
-
),
|
|
11149
|
-
/* @__PURE__ */ jsx(
|
|
11150
|
-
Form$2.Field,
|
|
11151
|
-
{
|
|
11152
|
-
control: form.control,
|
|
11153
|
-
name: "phone",
|
|
11154
|
-
render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11155
|
-
/* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
|
|
11156
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
11157
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11158
|
-
] })
|
|
11159
|
-
}
|
|
11160
|
-
)
|
|
11161
|
-
] }) }),
|
|
11162
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11163
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11164
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11165
|
-
] }) })
|
|
11166
|
-
]
|
|
11167
|
-
}
|
|
11168
|
-
) });
|
|
11169
|
-
};
|
|
11170
|
-
const schema$3 = addressSchema;
|
|
10819
|
+
unit_price: unionType([numberType(), stringType()])
|
|
10820
|
+
});
|
|
11171
10821
|
const PROMOTION_QUERY_KEY = "promotions";
|
|
11172
10822
|
const promotionsQueryKeys = {
|
|
11173
10823
|
list: (query2) => [
|
|
@@ -11445,46 +11095,88 @@ function getPromotionIds(items, shippingMethods) {
|
|
|
11445
11095
|
}
|
|
11446
11096
|
return Array.from(promotionIds);
|
|
11447
11097
|
}
|
|
11448
|
-
const
|
|
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 = () => {
|
|
11449
11143
|
const { id } = useParams();
|
|
11450
|
-
const {
|
|
11451
|
-
|
|
11452
|
-
|
|
11453
|
-
fields: "+sales_channel_id"
|
|
11454
|
-
},
|
|
11455
|
-
{
|
|
11456
|
-
enabled: !!id
|
|
11457
|
-
}
|
|
11458
|
-
);
|
|
11144
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
11145
|
+
fields: "metadata"
|
|
11146
|
+
});
|
|
11459
11147
|
if (isError) {
|
|
11460
11148
|
throw error;
|
|
11461
11149
|
}
|
|
11462
|
-
const
|
|
11150
|
+
const isReady = !isPending && !!order;
|
|
11463
11151
|
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11464
11152
|
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
11465
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "
|
|
11466
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", 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." }) })
|
|
11467
11155
|
] }),
|
|
11468
|
-
|
|
11156
|
+
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
11469
11157
|
] });
|
|
11470
11158
|
};
|
|
11471
|
-
const
|
|
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);
|
|
11472
11165
|
const form = useForm({
|
|
11473
11166
|
defaultValues: {
|
|
11474
|
-
|
|
11167
|
+
metadata: getDefaultValues(metadata)
|
|
11475
11168
|
},
|
|
11476
|
-
resolver: zodResolver(
|
|
11169
|
+
resolver: zodResolver(MetadataSchema)
|
|
11477
11170
|
});
|
|
11478
|
-
const
|
|
11479
|
-
|
|
11480
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
11171
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
11172
|
+
const parsedData = parseValues(data);
|
|
11481
11173
|
await mutateAsync(
|
|
11482
11174
|
{
|
|
11483
|
-
|
|
11175
|
+
metadata: parsedData
|
|
11484
11176
|
},
|
|
11485
11177
|
{
|
|
11486
11178
|
onSuccess: () => {
|
|
11487
|
-
toast.success("
|
|
11179
|
+
toast.success("Metadata updated");
|
|
11488
11180
|
handleSuccess();
|
|
11489
11181
|
},
|
|
11490
11182
|
onError: (error) => {
|
|
@@ -11493,64 +11185,266 @@ const SalesChannelForm = ({ order }) => {
|
|
|
11493
11185
|
}
|
|
11494
11186
|
);
|
|
11495
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
|
|
11207
|
+
});
|
|
11208
|
+
}
|
|
11496
11209
|
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
11497
11210
|
KeyboundForm,
|
|
11498
11211
|
{
|
|
11212
|
+
onSubmit: handleSubmit,
|
|
11499
11213
|
className: "flex flex-1 flex-col overflow-hidden",
|
|
11500
|
-
onSubmit,
|
|
11501
11214
|
children: [
|
|
11502
|
-
/* @__PURE__ */
|
|
11503
|
-
|
|
11504
|
-
|
|
11215
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
11216
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
11217
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
11218
|
+
/* @__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" }) }),
|
|
11219
|
+
/* @__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" }) })
|
|
11220
|
+
] }),
|
|
11221
|
+
fields.map((field, index) => {
|
|
11222
|
+
const isDisabled = field.disabled || false;
|
|
11223
|
+
let placeholder = "-";
|
|
11224
|
+
if (typeof field.value === "object") {
|
|
11225
|
+
placeholder = "{ ... }";
|
|
11226
|
+
}
|
|
11227
|
+
if (Array.isArray(field.value)) {
|
|
11228
|
+
placeholder = "[ ... ]";
|
|
11229
|
+
}
|
|
11230
|
+
return /* @__PURE__ */ jsx(
|
|
11231
|
+
ConditionalTooltip,
|
|
11232
|
+
{
|
|
11233
|
+
showTooltip: isDisabled,
|
|
11234
|
+
content: "This row is disabled because it contains non-primitive data.",
|
|
11235
|
+
children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
|
|
11236
|
+
/* @__PURE__ */ jsxs(
|
|
11237
|
+
"div",
|
|
11238
|
+
{
|
|
11239
|
+
className: clx("grid grid-cols-2 divide-x", {
|
|
11240
|
+
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
11241
|
+
}),
|
|
11242
|
+
children: [
|
|
11243
|
+
/* @__PURE__ */ jsx(
|
|
11244
|
+
Form$2.Field,
|
|
11245
|
+
{
|
|
11246
|
+
control: form.control,
|
|
11247
|
+
name: `metadata.${index}.key`,
|
|
11248
|
+
render: ({ field: field2 }) => {
|
|
11249
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11250
|
+
GridInput,
|
|
11251
|
+
{
|
|
11252
|
+
"aria-labelledby": METADATA_KEY_LABEL_ID,
|
|
11253
|
+
...field2,
|
|
11254
|
+
disabled: isDisabled,
|
|
11255
|
+
placeholder: "Key"
|
|
11256
|
+
}
|
|
11257
|
+
) }) });
|
|
11258
|
+
}
|
|
11259
|
+
}
|
|
11260
|
+
),
|
|
11261
|
+
/* @__PURE__ */ jsx(
|
|
11262
|
+
Form$2.Field,
|
|
11263
|
+
{
|
|
11264
|
+
control: form.control,
|
|
11265
|
+
name: `metadata.${index}.value`,
|
|
11266
|
+
render: ({ field: { value, ...field2 } }) => {
|
|
11267
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11268
|
+
GridInput,
|
|
11269
|
+
{
|
|
11270
|
+
"aria-labelledby": METADATA_VALUE_LABEL_ID,
|
|
11271
|
+
...field2,
|
|
11272
|
+
value: isDisabled ? placeholder : value,
|
|
11273
|
+
disabled: isDisabled,
|
|
11274
|
+
placeholder: "Value"
|
|
11275
|
+
}
|
|
11276
|
+
) }) });
|
|
11277
|
+
}
|
|
11278
|
+
}
|
|
11279
|
+
)
|
|
11280
|
+
]
|
|
11281
|
+
}
|
|
11282
|
+
),
|
|
11283
|
+
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
11284
|
+
/* @__PURE__ */ jsx(
|
|
11285
|
+
DropdownMenu.Trigger,
|
|
11286
|
+
{
|
|
11287
|
+
className: clx(
|
|
11288
|
+
"invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
|
|
11289
|
+
{
|
|
11290
|
+
hidden: isDisabled
|
|
11291
|
+
}
|
|
11292
|
+
),
|
|
11293
|
+
disabled: isDisabled,
|
|
11294
|
+
asChild: true,
|
|
11295
|
+
children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
|
|
11296
|
+
}
|
|
11297
|
+
),
|
|
11298
|
+
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
11299
|
+
/* @__PURE__ */ jsxs(
|
|
11300
|
+
DropdownMenu.Item,
|
|
11301
|
+
{
|
|
11302
|
+
className: "gap-x-2",
|
|
11303
|
+
onClick: () => insertRow(index, "above"),
|
|
11304
|
+
children: [
|
|
11305
|
+
/* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
|
|
11306
|
+
"Insert row above"
|
|
11307
|
+
]
|
|
11308
|
+
}
|
|
11309
|
+
),
|
|
11310
|
+
/* @__PURE__ */ jsxs(
|
|
11311
|
+
DropdownMenu.Item,
|
|
11312
|
+
{
|
|
11313
|
+
className: "gap-x-2",
|
|
11314
|
+
onClick: () => insertRow(index, "below"),
|
|
11315
|
+
children: [
|
|
11316
|
+
/* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
|
|
11317
|
+
"Insert row below"
|
|
11318
|
+
]
|
|
11319
|
+
}
|
|
11320
|
+
),
|
|
11321
|
+
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
11322
|
+
/* @__PURE__ */ jsxs(
|
|
11323
|
+
DropdownMenu.Item,
|
|
11324
|
+
{
|
|
11325
|
+
className: "gap-x-2",
|
|
11326
|
+
onClick: () => deleteRow(index),
|
|
11327
|
+
children: [
|
|
11328
|
+
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
11329
|
+
"Delete row"
|
|
11330
|
+
]
|
|
11331
|
+
}
|
|
11332
|
+
)
|
|
11333
|
+
] })
|
|
11334
|
+
] })
|
|
11335
|
+
] })
|
|
11336
|
+
},
|
|
11337
|
+
field.id
|
|
11338
|
+
);
|
|
11339
|
+
})
|
|
11340
|
+
] }),
|
|
11341
|
+
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." })
|
|
11342
|
+
] }),
|
|
11343
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11344
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
11505
11345
|
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11506
11346
|
] }) })
|
|
11507
11347
|
]
|
|
11508
11348
|
}
|
|
11509
|
-
) });
|
|
11349
|
+
) });
|
|
11350
|
+
};
|
|
11351
|
+
const GridInput = forwardRef(({ className, ...props }, ref) => {
|
|
11352
|
+
return /* @__PURE__ */ jsx(
|
|
11353
|
+
"input",
|
|
11354
|
+
{
|
|
11355
|
+
ref,
|
|
11356
|
+
...props,
|
|
11357
|
+
autoComplete: "off",
|
|
11358
|
+
className: clx(
|
|
11359
|
+
"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",
|
|
11360
|
+
className
|
|
11361
|
+
)
|
|
11362
|
+
}
|
|
11363
|
+
);
|
|
11364
|
+
});
|
|
11365
|
+
GridInput.displayName = "MetadataForm.GridInput";
|
|
11366
|
+
const PlaceholderInner = () => {
|
|
11367
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
11368
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
11369
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11370
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
11371
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
11372
|
+
] }) })
|
|
11373
|
+
] });
|
|
11510
11374
|
};
|
|
11511
|
-
const
|
|
11512
|
-
|
|
11513
|
-
|
|
11514
|
-
|
|
11515
|
-
|
|
11516
|
-
|
|
11517
|
-
|
|
11518
|
-
|
|
11519
|
-
|
|
11520
|
-
|
|
11521
|
-
|
|
11522
|
-
|
|
11523
|
-
|
|
11375
|
+
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
11376
|
+
function getDefaultValues(metadata) {
|
|
11377
|
+
if (!metadata || !Object.keys(metadata).length) {
|
|
11378
|
+
return [
|
|
11379
|
+
{
|
|
11380
|
+
key: "",
|
|
11381
|
+
value: "",
|
|
11382
|
+
disabled: false
|
|
11383
|
+
}
|
|
11384
|
+
];
|
|
11385
|
+
}
|
|
11386
|
+
return Object.entries(metadata).map(([key, value]) => {
|
|
11387
|
+
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
11388
|
+
return {
|
|
11389
|
+
key,
|
|
11390
|
+
value,
|
|
11391
|
+
disabled: true
|
|
11392
|
+
};
|
|
11393
|
+
}
|
|
11394
|
+
let stringValue = value;
|
|
11395
|
+
if (typeof value !== "string") {
|
|
11396
|
+
stringValue = JSON.stringify(value);
|
|
11397
|
+
}
|
|
11398
|
+
return {
|
|
11399
|
+
key,
|
|
11400
|
+
value: stringValue,
|
|
11401
|
+
original_key: key
|
|
11402
|
+
};
|
|
11524
11403
|
});
|
|
11525
|
-
|
|
11526
|
-
|
|
11527
|
-
|
|
11528
|
-
|
|
11529
|
-
|
|
11530
|
-
|
|
11531
|
-
|
|
11532
|
-
|
|
11533
|
-
|
|
11534
|
-
|
|
11535
|
-
|
|
11536
|
-
|
|
11537
|
-
|
|
11538
|
-
|
|
11539
|
-
|
|
11540
|
-
|
|
11541
|
-
|
|
11542
|
-
|
|
11543
|
-
|
|
11544
|
-
|
|
11545
|
-
|
|
11546
|
-
|
|
11404
|
+
}
|
|
11405
|
+
function parseValues(values) {
|
|
11406
|
+
const metadata = values.metadata;
|
|
11407
|
+
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
11408
|
+
if (isEmpty) {
|
|
11409
|
+
return null;
|
|
11410
|
+
}
|
|
11411
|
+
const update = {};
|
|
11412
|
+
metadata.forEach((field) => {
|
|
11413
|
+
let key = field.key;
|
|
11414
|
+
let value = field.value;
|
|
11415
|
+
const disabled = field.disabled;
|
|
11416
|
+
if (!key || !value) {
|
|
11417
|
+
return;
|
|
11418
|
+
}
|
|
11419
|
+
if (disabled) {
|
|
11420
|
+
update[key] = value;
|
|
11421
|
+
return;
|
|
11422
|
+
}
|
|
11423
|
+
key = key.trim();
|
|
11424
|
+
value = value.trim();
|
|
11425
|
+
if (value === "true") {
|
|
11426
|
+
update[key] = true;
|
|
11427
|
+
} else if (value === "false") {
|
|
11428
|
+
update[key] = false;
|
|
11429
|
+
} else {
|
|
11430
|
+
const parsedNumber = parseFloat(value);
|
|
11431
|
+
if (!isNaN(parsedNumber)) {
|
|
11432
|
+
update[key] = parsedNumber;
|
|
11433
|
+
} else {
|
|
11434
|
+
update[key] = value;
|
|
11547
11435
|
}
|
|
11548
11436
|
}
|
|
11437
|
+
});
|
|
11438
|
+
return update;
|
|
11439
|
+
}
|
|
11440
|
+
function getHasUneditableRows(metadata) {
|
|
11441
|
+
if (!metadata) {
|
|
11442
|
+
return false;
|
|
11443
|
+
}
|
|
11444
|
+
return Object.values(metadata).some(
|
|
11445
|
+
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11549
11446
|
);
|
|
11550
|
-
}
|
|
11551
|
-
const schema$2 = objectType({
|
|
11552
|
-
sales_channel_id: stringType().min(1)
|
|
11553
|
-
});
|
|
11447
|
+
}
|
|
11554
11448
|
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11555
11449
|
const Shipping = () => {
|
|
11556
11450
|
var _a;
|
|
@@ -12390,7 +12284,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12390
12284
|
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12391
12285
|
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
12392
12286
|
},
|
|
12393
|
-
resolver: zodResolver(schema$
|
|
12287
|
+
resolver: zodResolver(schema$2)
|
|
12394
12288
|
});
|
|
12395
12289
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12396
12290
|
const { handleSuccess } = useRouteModal();
|
|
@@ -12560,7 +12454,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12560
12454
|
}
|
|
12561
12455
|
) });
|
|
12562
12456
|
};
|
|
12563
|
-
const schema$
|
|
12457
|
+
const schema$2 = addressSchema;
|
|
12564
12458
|
const TransferOwnership = () => {
|
|
12565
12459
|
const { id } = useParams();
|
|
12566
12460
|
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
@@ -12584,7 +12478,7 @@ const TransferOwnershipForm = ({ order }) => {
|
|
|
12584
12478
|
defaultValues: {
|
|
12585
12479
|
customer_id: order.customer_id || ""
|
|
12586
12480
|
},
|
|
12587
|
-
resolver: zodResolver(schema)
|
|
12481
|
+
resolver: zodResolver(schema$1)
|
|
12588
12482
|
});
|
|
12589
12483
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12590
12484
|
const { handleSuccess } = useRouteModal();
|
|
@@ -13034,9 +12928,115 @@ const Illustration = () => {
|
|
|
13034
12928
|
}
|
|
13035
12929
|
);
|
|
13036
12930
|
};
|
|
13037
|
-
const schema = objectType({
|
|
12931
|
+
const schema$1 = objectType({
|
|
13038
12932
|
customer_id: stringType().min(1)
|
|
13039
12933
|
});
|
|
12934
|
+
const SalesChannel = () => {
|
|
12935
|
+
const { id } = useParams();
|
|
12936
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
12937
|
+
id,
|
|
12938
|
+
{
|
|
12939
|
+
fields: "+sales_channel_id"
|
|
12940
|
+
},
|
|
12941
|
+
{
|
|
12942
|
+
enabled: !!id
|
|
12943
|
+
}
|
|
12944
|
+
);
|
|
12945
|
+
if (isError) {
|
|
12946
|
+
throw error;
|
|
12947
|
+
}
|
|
12948
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
12949
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12950
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
12951
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
12952
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
12953
|
+
] }),
|
|
12954
|
+
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
12955
|
+
] });
|
|
12956
|
+
};
|
|
12957
|
+
const SalesChannelForm = ({ order }) => {
|
|
12958
|
+
const form = useForm({
|
|
12959
|
+
defaultValues: {
|
|
12960
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
12961
|
+
},
|
|
12962
|
+
resolver: zodResolver(schema)
|
|
12963
|
+
});
|
|
12964
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12965
|
+
const { handleSuccess } = useRouteModal();
|
|
12966
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
12967
|
+
await mutateAsync(
|
|
12968
|
+
{
|
|
12969
|
+
sales_channel_id: data.sales_channel_id
|
|
12970
|
+
},
|
|
12971
|
+
{
|
|
12972
|
+
onSuccess: () => {
|
|
12973
|
+
toast.success("Sales channel updated");
|
|
12974
|
+
handleSuccess();
|
|
12975
|
+
},
|
|
12976
|
+
onError: (error) => {
|
|
12977
|
+
toast.error(error.message);
|
|
12978
|
+
}
|
|
12979
|
+
}
|
|
12980
|
+
);
|
|
12981
|
+
});
|
|
12982
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
12983
|
+
KeyboundForm,
|
|
12984
|
+
{
|
|
12985
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
12986
|
+
onSubmit,
|
|
12987
|
+
children: [
|
|
12988
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
12989
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12990
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12991
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12992
|
+
] }) })
|
|
12993
|
+
]
|
|
12994
|
+
}
|
|
12995
|
+
) });
|
|
12996
|
+
};
|
|
12997
|
+
const SalesChannelField = ({ control, order }) => {
|
|
12998
|
+
const salesChannels = useComboboxData({
|
|
12999
|
+
queryFn: async (params) => {
|
|
13000
|
+
return await sdk.admin.salesChannel.list(params);
|
|
13001
|
+
},
|
|
13002
|
+
queryKey: ["sales-channels"],
|
|
13003
|
+
getOptions: (data) => {
|
|
13004
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
13005
|
+
label: salesChannel.name,
|
|
13006
|
+
value: salesChannel.id
|
|
13007
|
+
}));
|
|
13008
|
+
},
|
|
13009
|
+
defaultValue: order.sales_channel_id || void 0
|
|
13010
|
+
});
|
|
13011
|
+
return /* @__PURE__ */ jsx(
|
|
13012
|
+
Form$2.Field,
|
|
13013
|
+
{
|
|
13014
|
+
control,
|
|
13015
|
+
name: "sales_channel_id",
|
|
13016
|
+
render: ({ field }) => {
|
|
13017
|
+
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
13018
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
13019
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
13020
|
+
Combobox,
|
|
13021
|
+
{
|
|
13022
|
+
options: salesChannels.options,
|
|
13023
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
13024
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
13025
|
+
searchValue: salesChannels.searchValue,
|
|
13026
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
13027
|
+
placeholder: "Select sales channel",
|
|
13028
|
+
...field
|
|
13029
|
+
}
|
|
13030
|
+
) }),
|
|
13031
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
13032
|
+
] });
|
|
13033
|
+
}
|
|
13034
|
+
}
|
|
13035
|
+
);
|
|
13036
|
+
};
|
|
13037
|
+
const schema = objectType({
|
|
13038
|
+
sales_channel_id: stringType().min(1)
|
|
13039
|
+
});
|
|
13040
13040
|
const widgetModule = { widgets: [] };
|
|
13041
13041
|
const routeModule = {
|
|
13042
13042
|
routes: [
|
|
@@ -13058,32 +13058,28 @@ const routeModule = {
|
|
|
13058
13058
|
loader,
|
|
13059
13059
|
children: [
|
|
13060
13060
|
{
|
|
13061
|
-
Component:
|
|
13062
|
-
path: "/draft-orders/:id/
|
|
13061
|
+
Component: BillingAddress,
|
|
13062
|
+
path: "/draft-orders/:id/billing-address"
|
|
13063
13063
|
},
|
|
13064
13064
|
{
|
|
13065
|
-
Component:
|
|
13066
|
-
path: "/draft-orders/:id/items"
|
|
13065
|
+
Component: CustomItems,
|
|
13066
|
+
path: "/draft-orders/:id/custom-items"
|
|
13067
13067
|
},
|
|
13068
13068
|
{
|
|
13069
13069
|
Component: Email,
|
|
13070
13070
|
path: "/draft-orders/:id/email"
|
|
13071
13071
|
},
|
|
13072
13072
|
{
|
|
13073
|
-
Component:
|
|
13074
|
-
path: "/draft-orders/:id/
|
|
13075
|
-
},
|
|
13076
|
-
{
|
|
13077
|
-
Component: BillingAddress,
|
|
13078
|
-
path: "/draft-orders/:id/billing-address"
|
|
13073
|
+
Component: Items,
|
|
13074
|
+
path: "/draft-orders/:id/items"
|
|
13079
13075
|
},
|
|
13080
13076
|
{
|
|
13081
13077
|
Component: Promotions,
|
|
13082
13078
|
path: "/draft-orders/:id/promotions"
|
|
13083
13079
|
},
|
|
13084
13080
|
{
|
|
13085
|
-
Component:
|
|
13086
|
-
path: "/draft-orders/:id/
|
|
13081
|
+
Component: Metadata,
|
|
13082
|
+
path: "/draft-orders/:id/metadata"
|
|
13087
13083
|
},
|
|
13088
13084
|
{
|
|
13089
13085
|
Component: Shipping,
|
|
@@ -13096,6 +13092,10 @@ const routeModule = {
|
|
|
13096
13092
|
{
|
|
13097
13093
|
Component: TransferOwnership,
|
|
13098
13094
|
path: "/draft-orders/:id/transfer-ownership"
|
|
13095
|
+
},
|
|
13096
|
+
{
|
|
13097
|
+
Component: SalesChannel,
|
|
13098
|
+
path: "/draft-orders/:id/sales-channel"
|
|
13099
13099
|
}
|
|
13100
13100
|
]
|
|
13101
13101
|
}
|