@alphabite/medusa-wishlist 0.6.0 → 0.6.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.
|
@@ -28,6 +28,100 @@ const ProductWidget = ({ data: product }) => {
|
|
|
28
28
|
adminSdk.defineWidgetConfig({
|
|
29
29
|
zone: "product.details.before"
|
|
30
30
|
});
|
|
31
|
+
const QUERY_KEY$1 = ["wishlist", "settings"];
|
|
32
|
+
const WishlistSettingsPage$1 = () => {
|
|
33
|
+
const queryClient = reactQuery.useQueryClient();
|
|
34
|
+
const { data, isLoading } = reactQuery.useQuery({
|
|
35
|
+
queryKey: QUERY_KEY$1,
|
|
36
|
+
queryFn: () => sdk.client.fetch("/admin/wishlists/settings", {
|
|
37
|
+
method: "GET"
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
const [allowGuest, setAllowGuest] = react.useState(false);
|
|
41
|
+
const [allowMultiple, setAllowMultiple] = react.useState(false);
|
|
42
|
+
react.useEffect(() => {
|
|
43
|
+
if (data) {
|
|
44
|
+
setAllowGuest(data.allow_guest_wishlist);
|
|
45
|
+
setAllowMultiple(data.allow_multiple_wishlists);
|
|
46
|
+
}
|
|
47
|
+
}, [data]);
|
|
48
|
+
const isDirty = data !== void 0 && (allowGuest !== data.allow_guest_wishlist || allowMultiple !== data.allow_multiple_wishlists);
|
|
49
|
+
const update = reactQuery.useMutation({
|
|
50
|
+
mutationFn: (patch) => sdk.client.fetch("/admin/wishlists/settings", {
|
|
51
|
+
method: "PUT",
|
|
52
|
+
body: patch
|
|
53
|
+
}),
|
|
54
|
+
onSuccess: (next) => {
|
|
55
|
+
queryClient.setQueryData(QUERY_KEY$1, next);
|
|
56
|
+
ui.toast.success("Wishlist settings updated");
|
|
57
|
+
},
|
|
58
|
+
onError: (err) => {
|
|
59
|
+
const msg = err instanceof Error ? err.message : "Failed to update";
|
|
60
|
+
ui.toast.error(msg);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
const onSave = () => {
|
|
64
|
+
if (!data) return;
|
|
65
|
+
const patch = {};
|
|
66
|
+
if (allowGuest !== data.allow_guest_wishlist) {
|
|
67
|
+
patch.allow_guest_wishlist = allowGuest;
|
|
68
|
+
}
|
|
69
|
+
if (allowMultiple !== data.allow_multiple_wishlists) {
|
|
70
|
+
patch.allow_multiple_wishlists = allowMultiple;
|
|
71
|
+
}
|
|
72
|
+
update.mutate(patch);
|
|
73
|
+
};
|
|
74
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
|
|
75
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-between px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
76
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: "Wishlists" }),
|
|
77
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle", children: "Control who can use wishlists in your storefront." })
|
|
78
|
+
] }) }),
|
|
79
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-6 px-6 py-6", children: isLoading ? /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-subtle", children: "Loading…" }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
80
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start justify-between gap-4", children: [
|
|
81
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
82
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "allow-guest", className: "font-medium", children: "Allow guest wishlists" }),
|
|
83
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Anonymous visitors can save items to a wishlist." })
|
|
84
|
+
] }),
|
|
85
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
86
|
+
ui.Switch,
|
|
87
|
+
{
|
|
88
|
+
id: "allow-guest",
|
|
89
|
+
checked: allowGuest,
|
|
90
|
+
onCheckedChange: setAllowGuest
|
|
91
|
+
}
|
|
92
|
+
)
|
|
93
|
+
] }),
|
|
94
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-start justify-between gap-4", children: [
|
|
95
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
96
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { htmlFor: "allow-multiple", className: "font-medium", children: "Allow multiple wishlists per customer" }),
|
|
97
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Signed-in customers can create more than one wishlist." })
|
|
98
|
+
] }),
|
|
99
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
100
|
+
ui.Switch,
|
|
101
|
+
{
|
|
102
|
+
id: "allow-multiple",
|
|
103
|
+
checked: allowMultiple,
|
|
104
|
+
onCheckedChange: setAllowMultiple
|
|
105
|
+
}
|
|
106
|
+
)
|
|
107
|
+
] }),
|
|
108
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
109
|
+
ui.Button,
|
|
110
|
+
{
|
|
111
|
+
variant: "primary",
|
|
112
|
+
onClick: onSave,
|
|
113
|
+
disabled: !isDirty || update.isPending,
|
|
114
|
+
isLoading: update.isPending,
|
|
115
|
+
children: "Save"
|
|
116
|
+
}
|
|
117
|
+
) })
|
|
118
|
+
] }) })
|
|
119
|
+
] });
|
|
120
|
+
};
|
|
121
|
+
const config$1 = adminSdk.defineRouteConfig({
|
|
122
|
+
label: "Wishlists",
|
|
123
|
+
icon: icons.Heart
|
|
124
|
+
});
|
|
31
125
|
const QUERY_KEY = ["wishlist", "settings"];
|
|
32
126
|
const WishlistSettingsPage = () => {
|
|
33
127
|
const queryClient = reactQuery.useQueryClient();
|
|
@@ -130,6 +224,10 @@ const widgetModule = { widgets: [
|
|
|
130
224
|
] };
|
|
131
225
|
const routeModule = {
|
|
132
226
|
routes: [
|
|
227
|
+
{
|
|
228
|
+
Component: WishlistSettingsPage$1,
|
|
229
|
+
path: "/wishlists"
|
|
230
|
+
},
|
|
133
231
|
{
|
|
134
232
|
Component: WishlistSettingsPage,
|
|
135
233
|
path: "/settings/wishlists"
|
|
@@ -138,6 +236,14 @@ const routeModule = {
|
|
|
138
236
|
};
|
|
139
237
|
const menuItemModule = {
|
|
140
238
|
menuItems: [
|
|
239
|
+
{
|
|
240
|
+
label: config$1.label,
|
|
241
|
+
icon: config$1.icon,
|
|
242
|
+
path: "/wishlists",
|
|
243
|
+
nested: void 0,
|
|
244
|
+
rank: void 0,
|
|
245
|
+
translationNs: void 0
|
|
246
|
+
},
|
|
141
247
|
{
|
|
142
248
|
label: config.label,
|
|
143
249
|
icon: config.icon,
|
|
@@ -25,6 +25,100 @@ const ProductWidget = ({ data: product }) => {
|
|
|
25
25
|
defineWidgetConfig({
|
|
26
26
|
zone: "product.details.before"
|
|
27
27
|
});
|
|
28
|
+
const QUERY_KEY$1 = ["wishlist", "settings"];
|
|
29
|
+
const WishlistSettingsPage$1 = () => {
|
|
30
|
+
const queryClient = useQueryClient();
|
|
31
|
+
const { data, isLoading } = useQuery({
|
|
32
|
+
queryKey: QUERY_KEY$1,
|
|
33
|
+
queryFn: () => sdk.client.fetch("/admin/wishlists/settings", {
|
|
34
|
+
method: "GET"
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
const [allowGuest, setAllowGuest] = useState(false);
|
|
38
|
+
const [allowMultiple, setAllowMultiple] = useState(false);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (data) {
|
|
41
|
+
setAllowGuest(data.allow_guest_wishlist);
|
|
42
|
+
setAllowMultiple(data.allow_multiple_wishlists);
|
|
43
|
+
}
|
|
44
|
+
}, [data]);
|
|
45
|
+
const isDirty = data !== void 0 && (allowGuest !== data.allow_guest_wishlist || allowMultiple !== data.allow_multiple_wishlists);
|
|
46
|
+
const update = useMutation({
|
|
47
|
+
mutationFn: (patch) => sdk.client.fetch("/admin/wishlists/settings", {
|
|
48
|
+
method: "PUT",
|
|
49
|
+
body: patch
|
|
50
|
+
}),
|
|
51
|
+
onSuccess: (next) => {
|
|
52
|
+
queryClient.setQueryData(QUERY_KEY$1, next);
|
|
53
|
+
toast.success("Wishlist settings updated");
|
|
54
|
+
},
|
|
55
|
+
onError: (err) => {
|
|
56
|
+
const msg = err instanceof Error ? err.message : "Failed to update";
|
|
57
|
+
toast.error(msg);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const onSave = () => {
|
|
61
|
+
if (!data) return;
|
|
62
|
+
const patch = {};
|
|
63
|
+
if (allowGuest !== data.allow_guest_wishlist) {
|
|
64
|
+
patch.allow_guest_wishlist = allowGuest;
|
|
65
|
+
}
|
|
66
|
+
if (allowMultiple !== data.allow_multiple_wishlists) {
|
|
67
|
+
patch.allow_multiple_wishlists = allowMultiple;
|
|
68
|
+
}
|
|
69
|
+
update.mutate(patch);
|
|
70
|
+
};
|
|
71
|
+
return /* @__PURE__ */ jsxs(Container, { className: "divide-y p-0", children: [
|
|
72
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-center justify-between px-6 py-4", children: /* @__PURE__ */ jsxs("div", { children: [
|
|
73
|
+
/* @__PURE__ */ jsx(Heading, { level: "h2", children: "Wishlists" }),
|
|
74
|
+
/* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: "Control who can use wishlists in your storefront." })
|
|
75
|
+
] }) }),
|
|
76
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-6 px-6 py-6", children: isLoading ? /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-subtle", children: "Loading…" }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
77
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-4", children: [
|
|
78
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
79
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: "allow-guest", className: "font-medium", children: "Allow guest wishlists" }),
|
|
80
|
+
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Anonymous visitors can save items to a wishlist." })
|
|
81
|
+
] }),
|
|
82
|
+
/* @__PURE__ */ jsx(
|
|
83
|
+
Switch,
|
|
84
|
+
{
|
|
85
|
+
id: "allow-guest",
|
|
86
|
+
checked: allowGuest,
|
|
87
|
+
onCheckedChange: setAllowGuest
|
|
88
|
+
}
|
|
89
|
+
)
|
|
90
|
+
] }),
|
|
91
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-start justify-between gap-4", children: [
|
|
92
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
93
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: "allow-multiple", className: "font-medium", children: "Allow multiple wishlists per customer" }),
|
|
94
|
+
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Signed-in customers can create more than one wishlist." })
|
|
95
|
+
] }),
|
|
96
|
+
/* @__PURE__ */ jsx(
|
|
97
|
+
Switch,
|
|
98
|
+
{
|
|
99
|
+
id: "allow-multiple",
|
|
100
|
+
checked: allowMultiple,
|
|
101
|
+
onCheckedChange: setAllowMultiple
|
|
102
|
+
}
|
|
103
|
+
)
|
|
104
|
+
] }),
|
|
105
|
+
/* @__PURE__ */ jsx("div", { className: "flex justify-end", children: /* @__PURE__ */ jsx(
|
|
106
|
+
Button,
|
|
107
|
+
{
|
|
108
|
+
variant: "primary",
|
|
109
|
+
onClick: onSave,
|
|
110
|
+
disabled: !isDirty || update.isPending,
|
|
111
|
+
isLoading: update.isPending,
|
|
112
|
+
children: "Save"
|
|
113
|
+
}
|
|
114
|
+
) })
|
|
115
|
+
] }) })
|
|
116
|
+
] });
|
|
117
|
+
};
|
|
118
|
+
const config$1 = defineRouteConfig({
|
|
119
|
+
label: "Wishlists",
|
|
120
|
+
icon: Heart
|
|
121
|
+
});
|
|
28
122
|
const QUERY_KEY = ["wishlist", "settings"];
|
|
29
123
|
const WishlistSettingsPage = () => {
|
|
30
124
|
const queryClient = useQueryClient();
|
|
@@ -127,6 +221,10 @@ const widgetModule = { widgets: [
|
|
|
127
221
|
] };
|
|
128
222
|
const routeModule = {
|
|
129
223
|
routes: [
|
|
224
|
+
{
|
|
225
|
+
Component: WishlistSettingsPage$1,
|
|
226
|
+
path: "/wishlists"
|
|
227
|
+
},
|
|
130
228
|
{
|
|
131
229
|
Component: WishlistSettingsPage,
|
|
132
230
|
path: "/settings/wishlists"
|
|
@@ -135,6 +233,14 @@ const routeModule = {
|
|
|
135
233
|
};
|
|
136
234
|
const menuItemModule = {
|
|
137
235
|
menuItems: [
|
|
236
|
+
{
|
|
237
|
+
label: config$1.label,
|
|
238
|
+
icon: config$1.icon,
|
|
239
|
+
path: "/wishlists",
|
|
240
|
+
nested: void 0,
|
|
241
|
+
rank: void 0,
|
|
242
|
+
translationNs: void 0
|
|
243
|
+
},
|
|
138
244
|
{
|
|
139
245
|
label: config.label,
|
|
140
246
|
icon: config.icon,
|