@medusajs/draft-order 0.0.1
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/components/common/action-menu.js +77 -0
- package/.medusa/server/src/admin/components/common/conditional-tooltip.js +15 -0
- package/.medusa/server/src/admin/components/common/data-table.js +249 -0
- package/.medusa/server/src/admin/components/common/form.js +151 -0
- package/.medusa/server/src/admin/components/common/inline-tip.js +42 -0
- package/.medusa/server/src/admin/components/common/keybound-form.js +32 -0
- package/.medusa/server/src/admin/components/common/page-skeleton.js +51 -0
- package/.medusa/server/src/admin/components/common/thumbnail.js +15 -0
- package/.medusa/server/src/admin/components/draft-orders/activity-section.js +205 -0
- package/.medusa/server/src/admin/components/draft-orders/customer-section.js +165 -0
- package/.medusa/server/src/admin/components/draft-orders/general-section.js +36 -0
- package/.medusa/server/src/admin/components/draft-orders/json-view-section.js +140 -0
- package/.medusa/server/src/admin/components/draft-orders/metadata-section.js +28 -0
- package/.medusa/server/src/admin/components/draft-orders/shipping-section.js +211 -0
- package/.medusa/server/src/admin/components/draft-orders/summary-section.js +148 -0
- package/.medusa/server/src/admin/components/inputs/combobox.js +311 -0
- package/.medusa/server/src/admin/components/inputs/country-select.js +59 -0
- package/.medusa/server/src/admin/components/inputs/number-input.js +100 -0
- package/.medusa/server/src/admin/components/inputs/switch-block.js +30 -0
- package/.medusa/server/src/admin/components/modals/index.js +19 -0
- package/.medusa/server/src/admin/components/modals/route-drawer/index.js +4 -0
- package/.medusa/server/src/admin/components/modals/route-drawer/route-drawer.js +57 -0
- package/.medusa/server/src/admin/components/modals/route-focus-modal/index.js +4 -0
- package/.medusa/server/src/admin/components/modals/route-focus-modal/route-focus-modal.js +71 -0
- package/.medusa/server/src/admin/components/modals/route-modal-form/index.js +4 -0
- package/.medusa/server/src/admin/components/modals/route-modal-form/route-modal-form.js +60 -0
- package/.medusa/server/src/admin/components/modals/route-modal-provider/index.js +6 -0
- package/.medusa/server/src/admin/components/modals/route-modal-provider/route-modal-context.js +5 -0
- package/.medusa/server/src/admin/components/modals/route-modal-provider/route-provider.js +30 -0
- package/.medusa/server/src/admin/components/modals/route-modal-provider/use-route-modal.js +12 -0
- package/.medusa/server/src/admin/components/modals/stacked-drawer/index.js +5 -0
- package/.medusa/server/src/admin/components/modals/stacked-drawer/stacked-drawer.js +55 -0
- package/.medusa/server/src/admin/components/modals/stacked-focus-modal/index.js +5 -0
- package/.medusa/server/src/admin/components/modals/stacked-focus-modal/stacked-focus-modal.js +63 -0
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/index.js +6 -0
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/stacked-modal-context.js +5 -0
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/stacked-modal-provider.js +47 -0
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/use-stacked-modal.js +14 -0
- package/.medusa/server/src/admin/components/utilities/generic-forward-ref.js +7 -0
- package/.medusa/server/src/admin/hooks/api/customers.js +53 -0
- package/.medusa/server/src/admin/hooks/api/draft-orders.js +161 -0
- package/.medusa/server/src/admin/hooks/api/orders.js +274 -0
- package/.medusa/server/src/admin/hooks/api/product-variants.js +21 -0
- package/.medusa/server/src/admin/hooks/api/regions.js +35 -0
- package/.medusa/server/src/admin/hooks/api/sales-channels.js +35 -0
- package/.medusa/server/src/admin/hooks/api/shipping-options.js +35 -0
- package/.medusa/server/src/admin/hooks/api/users.js +26 -0
- package/.medusa/server/src/admin/hooks/common/use-combobox-data.js +61 -0
- package/.medusa/server/src/admin/hooks/common/use-data-table-date-filters.js +89 -0
- package/.medusa/server/src/admin/hooks/common/use-debounced-search.js +22 -0
- package/.medusa/server/src/admin/hooks/common/use-query-params.js +14 -0
- package/.medusa/server/src/admin/hooks/order-edits/use-cancel-order-edit.js +25 -0
- package/.medusa/server/src/admin/hooks/order-edits/use-initiate-order-edit.js +39 -0
- package/.medusa/server/src/admin/lib/data/countries.js +1762 -0
- package/.medusa/server/src/admin/lib/data/currencies.js +36 -0
- package/.medusa/server/src/admin/lib/queries/draft-order-details.js +1 -0
- package/.medusa/server/src/admin/lib/queries/sdk.js +10 -0
- package/.medusa/server/src/admin/lib/schemas/address.js +16 -0
- package/.medusa/server/src/admin/lib/utils/address-utils.js +57 -0
- package/.medusa/server/src/admin/lib/utils/date-utils.js +27 -0
- package/.medusa/server/src/admin/lib/utils/order-utils.js +13 -0
- package/.medusa/server/src/admin/routes/draft-orders/@create/page.js +659 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@billing-address/page.js +228 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@custom-items/page.js +38 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@email/page.js +89 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@items/page.js +576 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@metadata/page.js +338 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@promotions/page.js +70 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@sales-channel/page.js +113 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@shipping/page.js +465 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@shipping-address/page.js +241 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/page.js +70 -0
- package/.medusa/server/src/admin/routes/draft-orders/page.js +148 -0
- package/.medusa/server/src/api/admin/draft-orders/[id]/convert/route.js +18 -0
- package/.medusa/server/src/types/http/draft-orders/payloads.js +3 -0
- package/.medusa/server/src/types/http/draft-orders/responses.js +3 -0
- package/.medusa/server/src/types/http/orders/entity.js +3 -0
- package/.medusa/server/src/types/http/orders/requests.js +3 -0
- package/.medusa/server/src/workflows/draft-orders/convert-draft-order-workflow.js +54 -0
- package/.medusa/server/tailwind.config.js +12 -0
- package/README.md +64 -0
- package/package.json +104 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { zodResolver } from "/Users/oliverjuhl/Desktop/medusa/draft-order-plugin/node_modules/@hookform/resolvers/zod/dist/zod.mjs";
|
|
3
|
+
import { Heading, toast, Input, Button } from "@medusajs/ui";
|
|
4
|
+
import { useForm } from "react-hook-form";
|
|
5
|
+
import { useParams } from "react-router-dom";
|
|
6
|
+
import { z } from "/Users/oliverjuhl/Desktop/medusa/draft-order-plugin/node_modules/zod/lib/index.mjs";
|
|
7
|
+
import { Form } from "../../../../components/common/form.js";
|
|
8
|
+
import { KeyboundForm } from "../../../../components/common/keybound-form.js";
|
|
9
|
+
import { CountrySelect } from "../../../../components/inputs/country-select.js";
|
|
10
|
+
import { SwitchBlock } from "../../../../components/inputs/switch-block.js";
|
|
11
|
+
import { RouteDrawer } from "../../../../components/modals/route-drawer/route-drawer.js";
|
|
12
|
+
import "../../../../components/modals/route-focus-modal/route-focus-modal.js";
|
|
13
|
+
import "react";
|
|
14
|
+
import "../../../../components/modals/route-modal-provider/route-modal-context.js";
|
|
15
|
+
import { useRouteModal } from "../../../../components/modals/route-modal-provider/use-route-modal.js";
|
|
16
|
+
import "../../../../components/modals/stacked-drawer/stacked-drawer.js";
|
|
17
|
+
import "../../../../components/modals/stacked-focus-modal/stacked-focus-modal.js";
|
|
18
|
+
import "../../../../components/modals/stacked-modal-provider/stacked-modal-context.js";
|
|
19
|
+
import { useUpdateDraftOrder } from "../../../../hooks/api/draft-orders.js";
|
|
20
|
+
import { useOrder } from "../../../../hooks/api/orders.js";
|
|
21
|
+
import { addressSchema } from "../../../../lib/schemas/address.js";
|
|
22
|
+
const BillingAddress = () => {
|
|
23
|
+
const { id } = useParams();
|
|
24
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
25
|
+
fields: "+billing_address"
|
|
26
|
+
});
|
|
27
|
+
if (isError) {
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
const isReady = !isPending && !!order;
|
|
31
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
32
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
33
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
|
|
34
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
|
|
35
|
+
] }),
|
|
36
|
+
isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
|
|
37
|
+
] });
|
|
38
|
+
};
|
|
39
|
+
const BillingAddressForm = ({ order }) => {
|
|
40
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
41
|
+
const form = useForm({
|
|
42
|
+
defaultValues: {
|
|
43
|
+
first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
|
|
44
|
+
last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
|
|
45
|
+
company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
|
|
46
|
+
address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
|
|
47
|
+
address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
|
|
48
|
+
city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
|
|
49
|
+
province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
|
|
50
|
+
country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
|
|
51
|
+
postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
52
|
+
phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? "",
|
|
53
|
+
notify: false
|
|
54
|
+
},
|
|
55
|
+
resolver: zodResolver(schema)
|
|
56
|
+
});
|
|
57
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
58
|
+
const { handleSuccess } = useRouteModal();
|
|
59
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
60
|
+
await mutateAsync(
|
|
61
|
+
{ billing_address: data },
|
|
62
|
+
{
|
|
63
|
+
onSuccess: () => {
|
|
64
|
+
handleSuccess();
|
|
65
|
+
},
|
|
66
|
+
onError: (error) => {
|
|
67
|
+
toast.error(error.message);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
});
|
|
72
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
73
|
+
KeyboundForm,
|
|
74
|
+
{
|
|
75
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
76
|
+
onSubmit,
|
|
77
|
+
children: [
|
|
78
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
|
|
79
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
|
|
80
|
+
/* @__PURE__ */ jsx(
|
|
81
|
+
Form.Field,
|
|
82
|
+
{
|
|
83
|
+
control: form.control,
|
|
84
|
+
name: "country_code",
|
|
85
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
|
|
86
|
+
/* @__PURE__ */ jsx(Form.Label, { children: "Country" }),
|
|
87
|
+
/* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
|
|
88
|
+
/* @__PURE__ */ jsx(Form.ErrorMessage, {})
|
|
89
|
+
] })
|
|
90
|
+
}
|
|
91
|
+
),
|
|
92
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
93
|
+
/* @__PURE__ */ jsx(
|
|
94
|
+
Form.Field,
|
|
95
|
+
{
|
|
96
|
+
control: form.control,
|
|
97
|
+
name: "first_name",
|
|
98
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
|
|
99
|
+
/* @__PURE__ */ jsx(Form.Label, { children: "First name" }),
|
|
100
|
+
/* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
101
|
+
/* @__PURE__ */ jsx(Form.ErrorMessage, {})
|
|
102
|
+
] })
|
|
103
|
+
}
|
|
104
|
+
),
|
|
105
|
+
/* @__PURE__ */ jsx(
|
|
106
|
+
Form.Field,
|
|
107
|
+
{
|
|
108
|
+
control: form.control,
|
|
109
|
+
name: "last_name",
|
|
110
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
|
|
111
|
+
/* @__PURE__ */ jsx(Form.Label, { children: "Last name" }),
|
|
112
|
+
/* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
113
|
+
/* @__PURE__ */ jsx(Form.ErrorMessage, {})
|
|
114
|
+
] })
|
|
115
|
+
}
|
|
116
|
+
)
|
|
117
|
+
] }),
|
|
118
|
+
/* @__PURE__ */ jsx(
|
|
119
|
+
Form.Field,
|
|
120
|
+
{
|
|
121
|
+
control: form.control,
|
|
122
|
+
name: "company",
|
|
123
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
|
|
124
|
+
/* @__PURE__ */ jsx(Form.Label, { optional: true, children: "Company" }),
|
|
125
|
+
/* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
126
|
+
/* @__PURE__ */ jsx(Form.ErrorMessage, {})
|
|
127
|
+
] })
|
|
128
|
+
}
|
|
129
|
+
),
|
|
130
|
+
/* @__PURE__ */ jsx(
|
|
131
|
+
Form.Field,
|
|
132
|
+
{
|
|
133
|
+
control: form.control,
|
|
134
|
+
name: "address_1",
|
|
135
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
|
|
136
|
+
/* @__PURE__ */ jsx(Form.Label, { children: "Address" }),
|
|
137
|
+
/* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
138
|
+
/* @__PURE__ */ jsx(Form.ErrorMessage, {})
|
|
139
|
+
] })
|
|
140
|
+
}
|
|
141
|
+
),
|
|
142
|
+
/* @__PURE__ */ jsx(
|
|
143
|
+
Form.Field,
|
|
144
|
+
{
|
|
145
|
+
control: form.control,
|
|
146
|
+
name: "address_2",
|
|
147
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
|
|
148
|
+
/* @__PURE__ */ jsx(Form.Label, { optional: true, children: "Apartment, suite, etc." }),
|
|
149
|
+
/* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
150
|
+
/* @__PURE__ */ jsx(Form.ErrorMessage, {})
|
|
151
|
+
] })
|
|
152
|
+
}
|
|
153
|
+
),
|
|
154
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
|
|
155
|
+
/* @__PURE__ */ jsx(
|
|
156
|
+
Form.Field,
|
|
157
|
+
{
|
|
158
|
+
control: form.control,
|
|
159
|
+
name: "postal_code",
|
|
160
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
|
|
161
|
+
/* @__PURE__ */ jsx(Form.Label, { children: "Postal code" }),
|
|
162
|
+
/* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
163
|
+
/* @__PURE__ */ jsx(Form.ErrorMessage, {})
|
|
164
|
+
] })
|
|
165
|
+
}
|
|
166
|
+
),
|
|
167
|
+
/* @__PURE__ */ jsx(
|
|
168
|
+
Form.Field,
|
|
169
|
+
{
|
|
170
|
+
control: form.control,
|
|
171
|
+
name: "city",
|
|
172
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
|
|
173
|
+
/* @__PURE__ */ jsx(Form.Label, { children: "City" }),
|
|
174
|
+
/* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
175
|
+
/* @__PURE__ */ jsx(Form.ErrorMessage, {})
|
|
176
|
+
] })
|
|
177
|
+
}
|
|
178
|
+
)
|
|
179
|
+
] }),
|
|
180
|
+
/* @__PURE__ */ jsx(
|
|
181
|
+
Form.Field,
|
|
182
|
+
{
|
|
183
|
+
control: form.control,
|
|
184
|
+
name: "province",
|
|
185
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
|
|
186
|
+
/* @__PURE__ */ jsx(Form.Label, { optional: true, children: "Province / State" }),
|
|
187
|
+
/* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
188
|
+
/* @__PURE__ */ jsx(Form.ErrorMessage, {})
|
|
189
|
+
] })
|
|
190
|
+
}
|
|
191
|
+
),
|
|
192
|
+
/* @__PURE__ */ jsx(
|
|
193
|
+
Form.Field,
|
|
194
|
+
{
|
|
195
|
+
control: form.control,
|
|
196
|
+
name: "phone",
|
|
197
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
|
|
198
|
+
/* @__PURE__ */ jsx(Form.Label, { optional: true, children: "Phone" }),
|
|
199
|
+
/* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
200
|
+
/* @__PURE__ */ jsx(Form.ErrorMessage, {})
|
|
201
|
+
] })
|
|
202
|
+
}
|
|
203
|
+
)
|
|
204
|
+
] }),
|
|
205
|
+
/* @__PURE__ */ jsx(
|
|
206
|
+
SwitchBlock,
|
|
207
|
+
{
|
|
208
|
+
control: form.control,
|
|
209
|
+
name: "notify",
|
|
210
|
+
label: "Notify customer",
|
|
211
|
+
description: "Notify the customer of the new shipping address."
|
|
212
|
+
}
|
|
213
|
+
)
|
|
214
|
+
] }),
|
|
215
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
216
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
217
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
218
|
+
] }) })
|
|
219
|
+
]
|
|
220
|
+
}
|
|
221
|
+
) });
|
|
222
|
+
};
|
|
223
|
+
const schema = addressSchema.extend({
|
|
224
|
+
notify: z.boolean().optional()
|
|
225
|
+
});
|
|
226
|
+
export {
|
|
227
|
+
BillingAddress as default
|
|
228
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { zodResolver } from "/Users/oliverjuhl/Desktop/medusa/draft-order-plugin/node_modules/@hookform/resolvers/zod/dist/zod.mjs";
|
|
3
|
+
import { Heading, Button } from "@medusajs/ui";
|
|
4
|
+
import { useForm } from "react-hook-form";
|
|
5
|
+
import { z } from "/Users/oliverjuhl/Desktop/medusa/draft-order-plugin/node_modules/zod/lib/index.mjs";
|
|
6
|
+
import { KeyboundForm } from "../../../../components/common/keybound-form.js";
|
|
7
|
+
import { RouteDrawer } from "../../../../components/modals/route-drawer/route-drawer.js";
|
|
8
|
+
import "../../../../components/modals/route-focus-modal/route-focus-modal.js";
|
|
9
|
+
import "react";
|
|
10
|
+
import "react-router-dom";
|
|
11
|
+
import "../../../../components/modals/route-modal-provider/route-modal-context.js";
|
|
12
|
+
import "../../../../components/modals/stacked-drawer/stacked-drawer.js";
|
|
13
|
+
import "../../../../components/modals/stacked-focus-modal/stacked-focus-modal.js";
|
|
14
|
+
import "../../../../components/modals/stacked-modal-provider/stacked-modal-context.js";
|
|
15
|
+
const CustomItems = () => {
|
|
16
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
17
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
|
|
18
|
+
/* @__PURE__ */ jsx(CustomItemsForm, {})
|
|
19
|
+
] });
|
|
20
|
+
};
|
|
21
|
+
const CustomItemsForm = () => {
|
|
22
|
+
const form = useForm({
|
|
23
|
+
resolver: zodResolver(schema)
|
|
24
|
+
});
|
|
25
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
26
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, {}),
|
|
27
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
28
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
29
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
|
|
30
|
+
] }) })
|
|
31
|
+
] }) });
|
|
32
|
+
};
|
|
33
|
+
const schema = z.object({
|
|
34
|
+
email: z.string().email()
|
|
35
|
+
});
|
|
36
|
+
export {
|
|
37
|
+
CustomItems as default
|
|
38
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { zodResolver } from "/Users/oliverjuhl/Desktop/medusa/draft-order-plugin/node_modules/@hookform/resolvers/zod/dist/zod.mjs";
|
|
3
|
+
import { Heading, toast, Input, Button } from "@medusajs/ui";
|
|
4
|
+
import { useForm } from "react-hook-form";
|
|
5
|
+
import { useParams } from "react-router-dom";
|
|
6
|
+
import { z } from "/Users/oliverjuhl/Desktop/medusa/draft-order-plugin/node_modules/zod/lib/index.mjs";
|
|
7
|
+
import { Form } from "../../../../components/common/form.js";
|
|
8
|
+
import { KeyboundForm } from "../../../../components/common/keybound-form.js";
|
|
9
|
+
import { RouteDrawer } from "../../../../components/modals/route-drawer/route-drawer.js";
|
|
10
|
+
import "../../../../components/modals/route-focus-modal/route-focus-modal.js";
|
|
11
|
+
import "react";
|
|
12
|
+
import "../../../../components/modals/route-modal-provider/route-modal-context.js";
|
|
13
|
+
import { useRouteModal } from "../../../../components/modals/route-modal-provider/use-route-modal.js";
|
|
14
|
+
import "../../../../components/modals/stacked-drawer/stacked-drawer.js";
|
|
15
|
+
import "../../../../components/modals/stacked-focus-modal/stacked-focus-modal.js";
|
|
16
|
+
import "../../../../components/modals/stacked-modal-provider/stacked-modal-context.js";
|
|
17
|
+
import { useUpdateDraftOrder } from "../../../../hooks/api/draft-orders.js";
|
|
18
|
+
import { useOrder } from "../../../../hooks/api/orders.js";
|
|
19
|
+
const Email = () => {
|
|
20
|
+
const { id } = useParams();
|
|
21
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
22
|
+
fields: "+email"
|
|
23
|
+
});
|
|
24
|
+
if (isError) {
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
const isReady = !isPending && !!order;
|
|
28
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
29
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
30
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
|
|
31
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
|
|
32
|
+
] }),
|
|
33
|
+
isReady && /* @__PURE__ */ jsx(EmailForm, { order })
|
|
34
|
+
] });
|
|
35
|
+
};
|
|
36
|
+
const EmailForm = ({ order }) => {
|
|
37
|
+
const form = useForm({
|
|
38
|
+
defaultValues: {
|
|
39
|
+
email: order.email ?? ""
|
|
40
|
+
},
|
|
41
|
+
resolver: zodResolver(schema)
|
|
42
|
+
});
|
|
43
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
44
|
+
const { handleSuccess } = useRouteModal();
|
|
45
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
46
|
+
await mutateAsync(
|
|
47
|
+
{ email: data.email },
|
|
48
|
+
{
|
|
49
|
+
onSuccess: () => {
|
|
50
|
+
handleSuccess();
|
|
51
|
+
},
|
|
52
|
+
onError: (error) => {
|
|
53
|
+
toast.error(error.message);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
59
|
+
KeyboundForm,
|
|
60
|
+
{
|
|
61
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
62
|
+
onSubmit,
|
|
63
|
+
children: [
|
|
64
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
|
|
65
|
+
Form.Field,
|
|
66
|
+
{
|
|
67
|
+
control: form.control,
|
|
68
|
+
name: "email",
|
|
69
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
|
|
70
|
+
/* @__PURE__ */ jsx(Form.Label, { children: "Email" }),
|
|
71
|
+
/* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
72
|
+
/* @__PURE__ */ jsx(Form.ErrorMessage, {})
|
|
73
|
+
] })
|
|
74
|
+
}
|
|
75
|
+
) }),
|
|
76
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
77
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
78
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
79
|
+
] }) })
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
) });
|
|
83
|
+
};
|
|
84
|
+
const schema = z.object({
|
|
85
|
+
email: z.string().email()
|
|
86
|
+
});
|
|
87
|
+
export {
|
|
88
|
+
Email as default
|
|
89
|
+
};
|