@lodashventure/medusa-parcel-shipping 0.2.11 → 0.2.13
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.
|
@@ -3,30 +3,16 @@ const jsxRuntime = require("react/jsx-runtime");
|
|
|
3
3
|
const adminSdk = require("@medusajs/admin-sdk");
|
|
4
4
|
const icons = require("@medusajs/icons");
|
|
5
5
|
const react = require("react");
|
|
6
|
+
const Medusa = require("@medusajs/js-sdk");
|
|
6
7
|
const ui = require("@medusajs/ui");
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
body: body ? JSON.stringify(body) : void 0,
|
|
14
|
-
credentials: "include"
|
|
15
|
-
});
|
|
16
|
-
if (!response.ok) {
|
|
17
|
-
let message = response.statusText;
|
|
18
|
-
try {
|
|
19
|
-
const payload = await response.json();
|
|
20
|
-
message = (payload == null ? void 0 : payload.code) ?? (payload == null ? void 0 : payload.error) ?? message;
|
|
21
|
-
} catch (_) {
|
|
22
|
-
}
|
|
23
|
-
throw new Error(message);
|
|
8
|
+
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
9
|
+
const Medusa__default = /* @__PURE__ */ _interopDefault(Medusa);
|
|
10
|
+
const sdk$1 = new Medusa__default.default({
|
|
11
|
+
baseUrl: typeof window !== "undefined" ? window.location.origin : "/",
|
|
12
|
+
auth: {
|
|
13
|
+
type: "session"
|
|
24
14
|
}
|
|
25
|
-
|
|
26
|
-
return void 0;
|
|
27
|
-
}
|
|
28
|
-
return await response.json();
|
|
29
|
-
};
|
|
15
|
+
});
|
|
30
16
|
const toNumber$1 = (value) => {
|
|
31
17
|
if (value.trim().length === 0) {
|
|
32
18
|
return null;
|
|
@@ -52,9 +38,10 @@ function ParcelBoxesPage() {
|
|
|
52
38
|
const refresh = react.useCallback(async () => {
|
|
53
39
|
setLoading(true);
|
|
54
40
|
try {
|
|
55
|
-
const
|
|
56
|
-
"
|
|
57
|
-
);
|
|
41
|
+
const response = await sdk$1.client.fetch("/admin/parcel-boxes", {
|
|
42
|
+
method: "GET"
|
|
43
|
+
});
|
|
44
|
+
const data = await response.json();
|
|
58
45
|
setBoxes(data.boxes ?? []);
|
|
59
46
|
} catch (error) {
|
|
60
47
|
ui.toast.error(error.message ?? "Failed to load boxes", {
|
|
@@ -101,14 +88,16 @@ function ParcelBoxesPage() {
|
|
|
101
88
|
setSaving(true);
|
|
102
89
|
try {
|
|
103
90
|
if (formState.id) {
|
|
104
|
-
await
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
);
|
|
91
|
+
await sdk$1.client.fetch(`/admin/parcel-boxes/${formState.id}`, {
|
|
92
|
+
method: "PUT",
|
|
93
|
+
body: payload
|
|
94
|
+
});
|
|
109
95
|
ui.toast.success("Box updated", { dismissable: true });
|
|
110
96
|
} else {
|
|
111
|
-
await
|
|
97
|
+
await sdk$1.client.fetch("/admin/parcel-boxes", {
|
|
98
|
+
method: "POST",
|
|
99
|
+
body: payload
|
|
100
|
+
});
|
|
112
101
|
ui.toast.success("Box created", { dismissable: true });
|
|
113
102
|
}
|
|
114
103
|
await refresh();
|
|
@@ -124,7 +113,9 @@ function ParcelBoxesPage() {
|
|
|
124
113
|
const handleDelete = async (id) => {
|
|
125
114
|
setDeletingId(id);
|
|
126
115
|
try {
|
|
127
|
-
await
|
|
116
|
+
await sdk$1.client.fetch(`/admin/parcel-boxes/${id}`, {
|
|
117
|
+
method: "DELETE"
|
|
118
|
+
});
|
|
128
119
|
ui.toast.success("Box removed", { dismissable: true });
|
|
129
120
|
await refresh();
|
|
130
121
|
} catch (error) {
|
|
@@ -137,8 +128,9 @@ function ParcelBoxesPage() {
|
|
|
137
128
|
};
|
|
138
129
|
const handleToggle = async (box) => {
|
|
139
130
|
try {
|
|
140
|
-
await
|
|
141
|
-
|
|
131
|
+
await sdk$1.client.fetch(`/admin/parcel-boxes/${box.id}`, {
|
|
132
|
+
method: "PUT",
|
|
133
|
+
body: { active: !box.active }
|
|
142
134
|
});
|
|
143
135
|
await refresh();
|
|
144
136
|
} catch (error) {
|
|
@@ -383,29 +375,12 @@ const config$1 = adminSdk.defineRouteConfig({
|
|
|
383
375
|
label: "Parcel Boxes",
|
|
384
376
|
icon: icons.FlyingBox
|
|
385
377
|
});
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
"Content-Type": "application/json"
|
|
391
|
-
},
|
|
392
|
-
body: body ? JSON.stringify(body) : void 0,
|
|
393
|
-
credentials: "include"
|
|
394
|
-
});
|
|
395
|
-
if (!response.ok) {
|
|
396
|
-
let message = response.statusText;
|
|
397
|
-
try {
|
|
398
|
-
const payload = await response.json();
|
|
399
|
-
message = (payload == null ? void 0 : payload.code) ?? (payload == null ? void 0 : payload.error) ?? message;
|
|
400
|
-
} catch (_) {
|
|
401
|
-
}
|
|
402
|
-
throw new Error(message);
|
|
378
|
+
const sdk = new Medusa__default.default({
|
|
379
|
+
baseUrl: typeof window !== "undefined" ? window.location.origin : "/",
|
|
380
|
+
auth: {
|
|
381
|
+
type: "session"
|
|
403
382
|
}
|
|
404
|
-
|
|
405
|
-
return void 0;
|
|
406
|
-
}
|
|
407
|
-
return await response.json();
|
|
408
|
-
};
|
|
383
|
+
});
|
|
409
384
|
const toNumber = (value) => {
|
|
410
385
|
if (value.trim().length === 0) {
|
|
411
386
|
return null;
|
|
@@ -475,9 +450,10 @@ const BoxesSection = () => {
|
|
|
475
450
|
const refresh = react.useCallback(async () => {
|
|
476
451
|
setLoading(true);
|
|
477
452
|
try {
|
|
478
|
-
const
|
|
479
|
-
"
|
|
480
|
-
);
|
|
453
|
+
const response = await sdk.client.fetch("/admin/parcel-boxes", {
|
|
454
|
+
method: "GET"
|
|
455
|
+
});
|
|
456
|
+
const data = await response.json();
|
|
481
457
|
setBoxes(data.boxes ?? []);
|
|
482
458
|
} catch (error) {
|
|
483
459
|
ui.toast.error(error.message ?? "Failed to load boxes", {
|
|
@@ -524,14 +500,16 @@ const BoxesSection = () => {
|
|
|
524
500
|
setSaving(true);
|
|
525
501
|
try {
|
|
526
502
|
if (formState.id) {
|
|
527
|
-
await
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
);
|
|
503
|
+
await sdk.client.fetch(`/admin/parcel-boxes/${formState.id}`, {
|
|
504
|
+
method: "PUT",
|
|
505
|
+
body: payload
|
|
506
|
+
});
|
|
532
507
|
ui.toast.success("Box updated", { dismissable: true });
|
|
533
508
|
} else {
|
|
534
|
-
await
|
|
509
|
+
await sdk.client.fetch("/admin/parcel-boxes", {
|
|
510
|
+
method: "POST",
|
|
511
|
+
body: payload
|
|
512
|
+
});
|
|
535
513
|
ui.toast.success("Box created", { dismissable: true });
|
|
536
514
|
}
|
|
537
515
|
await refresh();
|
|
@@ -547,7 +525,9 @@ const BoxesSection = () => {
|
|
|
547
525
|
const handleDelete = async (id) => {
|
|
548
526
|
setDeletingId(id);
|
|
549
527
|
try {
|
|
550
|
-
await
|
|
528
|
+
await sdk.client.fetch(`/admin/parcel-boxes/${id}`, {
|
|
529
|
+
method: "DELETE"
|
|
530
|
+
});
|
|
551
531
|
ui.toast.success("Box removed", { dismissable: true });
|
|
552
532
|
await refresh();
|
|
553
533
|
} catch (error) {
|
|
@@ -560,8 +540,9 @@ const BoxesSection = () => {
|
|
|
560
540
|
};
|
|
561
541
|
const handleToggle = async (box) => {
|
|
562
542
|
try {
|
|
563
|
-
await
|
|
564
|
-
|
|
543
|
+
await sdk.client.fetch(`/admin/parcel-boxes/${box.id}`, {
|
|
544
|
+
method: "PUT",
|
|
545
|
+
body: { active: !box.active }
|
|
565
546
|
});
|
|
566
547
|
await refresh();
|
|
567
548
|
} catch (error) {
|
|
@@ -815,9 +796,10 @@ const RatesSection = () => {
|
|
|
815
796
|
const refresh = react.useCallback(async () => {
|
|
816
797
|
setLoading(true);
|
|
817
798
|
try {
|
|
818
|
-
const
|
|
819
|
-
"
|
|
820
|
-
);
|
|
799
|
+
const response = await sdk.client.fetch("/admin/shipping-config/rates", {
|
|
800
|
+
method: "GET"
|
|
801
|
+
});
|
|
802
|
+
const data = await response.json();
|
|
821
803
|
setRates(
|
|
822
804
|
(data.rates ?? []).map((rate) => ({
|
|
823
805
|
...rate,
|
|
@@ -836,7 +818,10 @@ const RatesSection = () => {
|
|
|
836
818
|
var _a, _b, _c;
|
|
837
819
|
setCurrenciesLoading(true);
|
|
838
820
|
try {
|
|
839
|
-
const
|
|
821
|
+
const response = await sdk.client.fetch("/admin/currencies", {
|
|
822
|
+
method: "GET"
|
|
823
|
+
});
|
|
824
|
+
const data = await response.json();
|
|
840
825
|
const supported = ((_b = (_a = data.store) == null ? void 0 : _a.supported_currencies) == null ? void 0 : _b.map(
|
|
841
826
|
(item) => item.code.toUpperCase()
|
|
842
827
|
)) ?? [];
|
|
@@ -915,14 +900,16 @@ const RatesSection = () => {
|
|
|
915
900
|
setSaving(true);
|
|
916
901
|
try {
|
|
917
902
|
if (formState.id) {
|
|
918
|
-
await
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
);
|
|
903
|
+
await sdk.client.fetch(`/admin/shipping-config/rates/${formState.id}`, {
|
|
904
|
+
method: "PUT",
|
|
905
|
+
body: payload
|
|
906
|
+
});
|
|
923
907
|
ui.toast.success("Rate updated", { dismissable: true });
|
|
924
908
|
} else {
|
|
925
|
-
await
|
|
909
|
+
await sdk.client.fetch("/admin/shipping-config/rates", {
|
|
910
|
+
method: "POST",
|
|
911
|
+
body: payload
|
|
912
|
+
});
|
|
926
913
|
ui.toast.success("Rate created", { dismissable: true });
|
|
927
914
|
}
|
|
928
915
|
await refresh();
|
|
@@ -938,7 +925,9 @@ const RatesSection = () => {
|
|
|
938
925
|
const handleDelete = async (id) => {
|
|
939
926
|
setDeletingId(id);
|
|
940
927
|
try {
|
|
941
|
-
await
|
|
928
|
+
await sdk.client.fetch(`/admin/shipping-config/rates/${id}`, {
|
|
929
|
+
method: "DELETE"
|
|
930
|
+
});
|
|
942
931
|
ui.toast.success("Rate removed", { dismissable: true });
|
|
943
932
|
await refresh();
|
|
944
933
|
} catch (error) {
|
|
@@ -951,8 +940,9 @@ const RatesSection = () => {
|
|
|
951
940
|
};
|
|
952
941
|
const handleToggle = async (rate) => {
|
|
953
942
|
try {
|
|
954
|
-
await
|
|
955
|
-
|
|
943
|
+
await sdk.client.fetch(`/admin/shipping-config/rates/${rate.id}`, {
|
|
944
|
+
method: "PUT",
|
|
945
|
+
body: { active: !rate.active }
|
|
956
946
|
});
|
|
957
947
|
await refresh();
|
|
958
948
|
} catch (error) {
|
|
@@ -1195,9 +1185,10 @@ const AreasSection = () => {
|
|
|
1195
1185
|
const refresh = react.useCallback(async () => {
|
|
1196
1186
|
setLoading(true);
|
|
1197
1187
|
try {
|
|
1198
|
-
const
|
|
1199
|
-
"
|
|
1200
|
-
);
|
|
1188
|
+
const response = await sdk.client.fetch("/admin/shipping-config/areas", {
|
|
1189
|
+
method: "GET"
|
|
1190
|
+
});
|
|
1191
|
+
const data = await response.json();
|
|
1201
1192
|
setAreas(data.areas ?? []);
|
|
1202
1193
|
} catch (error) {
|
|
1203
1194
|
ui.toast.error(error.message ?? "Failed to load service areas", {
|
|
@@ -1237,14 +1228,16 @@ const AreasSection = () => {
|
|
|
1237
1228
|
setSaving(true);
|
|
1238
1229
|
try {
|
|
1239
1230
|
if (formState.id) {
|
|
1240
|
-
await
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
);
|
|
1231
|
+
await sdk.client.fetch(`/admin/shipping-config/areas/${formState.id}`, {
|
|
1232
|
+
method: "PUT",
|
|
1233
|
+
body: payload
|
|
1234
|
+
});
|
|
1245
1235
|
ui.toast.success("Service area updated", { dismissable: true });
|
|
1246
1236
|
} else {
|
|
1247
|
-
await
|
|
1237
|
+
await sdk.client.fetch("/admin/shipping-config/areas", {
|
|
1238
|
+
method: "POST",
|
|
1239
|
+
body: payload
|
|
1240
|
+
});
|
|
1248
1241
|
ui.toast.success("Service area created", { dismissable: true });
|
|
1249
1242
|
}
|
|
1250
1243
|
await refresh();
|
|
@@ -1260,7 +1253,9 @@ const AreasSection = () => {
|
|
|
1260
1253
|
const handleDelete = async (id) => {
|
|
1261
1254
|
setDeletingId(id);
|
|
1262
1255
|
try {
|
|
1263
|
-
await
|
|
1256
|
+
await sdk.client.fetch(`/admin/shipping-config/areas/${id}`, {
|
|
1257
|
+
method: "DELETE"
|
|
1258
|
+
});
|
|
1264
1259
|
ui.toast.success("Service area removed", { dismissable: true });
|
|
1265
1260
|
await refresh();
|
|
1266
1261
|
} catch (error) {
|
|
@@ -1273,8 +1268,9 @@ const AreasSection = () => {
|
|
|
1273
1268
|
};
|
|
1274
1269
|
const handleToggle = async (area) => {
|
|
1275
1270
|
try {
|
|
1276
|
-
await
|
|
1277
|
-
|
|
1271
|
+
await sdk.client.fetch(`/admin/shipping-config/areas/${area.id}`, {
|
|
1272
|
+
method: "PUT",
|
|
1273
|
+
body: { active: !area.active }
|
|
1278
1274
|
});
|
|
1279
1275
|
await refresh();
|
|
1280
1276
|
} catch (error) {
|
|
@@ -2,30 +2,14 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { defineRouteConfig } from "@medusajs/admin-sdk";
|
|
3
3
|
import { FlyingBox, Directions } from "@medusajs/icons";
|
|
4
4
|
import { useState, useCallback, useEffect, useMemo } from "react";
|
|
5
|
+
import Medusa from "@medusajs/js-sdk";
|
|
5
6
|
import { toast, Table, Text, Badge, Switch, Button, Container, Heading, Label, Input } from "@medusajs/ui";
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"Content-Type": "application/json"
|
|
11
|
-
},
|
|
12
|
-
body: body ? JSON.stringify(body) : void 0,
|
|
13
|
-
credentials: "include"
|
|
14
|
-
});
|
|
15
|
-
if (!response.ok) {
|
|
16
|
-
let message = response.statusText;
|
|
17
|
-
try {
|
|
18
|
-
const payload = await response.json();
|
|
19
|
-
message = (payload == null ? void 0 : payload.code) ?? (payload == null ? void 0 : payload.error) ?? message;
|
|
20
|
-
} catch (_) {
|
|
21
|
-
}
|
|
22
|
-
throw new Error(message);
|
|
7
|
+
const sdk$1 = new Medusa({
|
|
8
|
+
baseUrl: typeof window !== "undefined" ? window.location.origin : "/",
|
|
9
|
+
auth: {
|
|
10
|
+
type: "session"
|
|
23
11
|
}
|
|
24
|
-
|
|
25
|
-
return void 0;
|
|
26
|
-
}
|
|
27
|
-
return await response.json();
|
|
28
|
-
};
|
|
12
|
+
});
|
|
29
13
|
const toNumber$1 = (value) => {
|
|
30
14
|
if (value.trim().length === 0) {
|
|
31
15
|
return null;
|
|
@@ -51,9 +35,10 @@ function ParcelBoxesPage() {
|
|
|
51
35
|
const refresh = useCallback(async () => {
|
|
52
36
|
setLoading(true);
|
|
53
37
|
try {
|
|
54
|
-
const
|
|
55
|
-
"
|
|
56
|
-
);
|
|
38
|
+
const response = await sdk$1.client.fetch("/admin/parcel-boxes", {
|
|
39
|
+
method: "GET"
|
|
40
|
+
});
|
|
41
|
+
const data = await response.json();
|
|
57
42
|
setBoxes(data.boxes ?? []);
|
|
58
43
|
} catch (error) {
|
|
59
44
|
toast.error(error.message ?? "Failed to load boxes", {
|
|
@@ -100,14 +85,16 @@ function ParcelBoxesPage() {
|
|
|
100
85
|
setSaving(true);
|
|
101
86
|
try {
|
|
102
87
|
if (formState.id) {
|
|
103
|
-
await
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
);
|
|
88
|
+
await sdk$1.client.fetch(`/admin/parcel-boxes/${formState.id}`, {
|
|
89
|
+
method: "PUT",
|
|
90
|
+
body: payload
|
|
91
|
+
});
|
|
108
92
|
toast.success("Box updated", { dismissable: true });
|
|
109
93
|
} else {
|
|
110
|
-
await
|
|
94
|
+
await sdk$1.client.fetch("/admin/parcel-boxes", {
|
|
95
|
+
method: "POST",
|
|
96
|
+
body: payload
|
|
97
|
+
});
|
|
111
98
|
toast.success("Box created", { dismissable: true });
|
|
112
99
|
}
|
|
113
100
|
await refresh();
|
|
@@ -123,7 +110,9 @@ function ParcelBoxesPage() {
|
|
|
123
110
|
const handleDelete = async (id) => {
|
|
124
111
|
setDeletingId(id);
|
|
125
112
|
try {
|
|
126
|
-
await
|
|
113
|
+
await sdk$1.client.fetch(`/admin/parcel-boxes/${id}`, {
|
|
114
|
+
method: "DELETE"
|
|
115
|
+
});
|
|
127
116
|
toast.success("Box removed", { dismissable: true });
|
|
128
117
|
await refresh();
|
|
129
118
|
} catch (error) {
|
|
@@ -136,8 +125,9 @@ function ParcelBoxesPage() {
|
|
|
136
125
|
};
|
|
137
126
|
const handleToggle = async (box) => {
|
|
138
127
|
try {
|
|
139
|
-
await
|
|
140
|
-
|
|
128
|
+
await sdk$1.client.fetch(`/admin/parcel-boxes/${box.id}`, {
|
|
129
|
+
method: "PUT",
|
|
130
|
+
body: { active: !box.active }
|
|
141
131
|
});
|
|
142
132
|
await refresh();
|
|
143
133
|
} catch (error) {
|
|
@@ -382,29 +372,12 @@ const config$1 = defineRouteConfig({
|
|
|
382
372
|
label: "Parcel Boxes",
|
|
383
373
|
icon: FlyingBox
|
|
384
374
|
});
|
|
385
|
-
const
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
"Content-Type": "application/json"
|
|
390
|
-
},
|
|
391
|
-
body: body ? JSON.stringify(body) : void 0,
|
|
392
|
-
credentials: "include"
|
|
393
|
-
});
|
|
394
|
-
if (!response.ok) {
|
|
395
|
-
let message = response.statusText;
|
|
396
|
-
try {
|
|
397
|
-
const payload = await response.json();
|
|
398
|
-
message = (payload == null ? void 0 : payload.code) ?? (payload == null ? void 0 : payload.error) ?? message;
|
|
399
|
-
} catch (_) {
|
|
400
|
-
}
|
|
401
|
-
throw new Error(message);
|
|
375
|
+
const sdk = new Medusa({
|
|
376
|
+
baseUrl: typeof window !== "undefined" ? window.location.origin : "/",
|
|
377
|
+
auth: {
|
|
378
|
+
type: "session"
|
|
402
379
|
}
|
|
403
|
-
|
|
404
|
-
return void 0;
|
|
405
|
-
}
|
|
406
|
-
return await response.json();
|
|
407
|
-
};
|
|
380
|
+
});
|
|
408
381
|
const toNumber = (value) => {
|
|
409
382
|
if (value.trim().length === 0) {
|
|
410
383
|
return null;
|
|
@@ -474,9 +447,10 @@ const BoxesSection = () => {
|
|
|
474
447
|
const refresh = useCallback(async () => {
|
|
475
448
|
setLoading(true);
|
|
476
449
|
try {
|
|
477
|
-
const
|
|
478
|
-
"
|
|
479
|
-
);
|
|
450
|
+
const response = await sdk.client.fetch("/admin/parcel-boxes", {
|
|
451
|
+
method: "GET"
|
|
452
|
+
});
|
|
453
|
+
const data = await response.json();
|
|
480
454
|
setBoxes(data.boxes ?? []);
|
|
481
455
|
} catch (error) {
|
|
482
456
|
toast.error(error.message ?? "Failed to load boxes", {
|
|
@@ -523,14 +497,16 @@ const BoxesSection = () => {
|
|
|
523
497
|
setSaving(true);
|
|
524
498
|
try {
|
|
525
499
|
if (formState.id) {
|
|
526
|
-
await
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
);
|
|
500
|
+
await sdk.client.fetch(`/admin/parcel-boxes/${formState.id}`, {
|
|
501
|
+
method: "PUT",
|
|
502
|
+
body: payload
|
|
503
|
+
});
|
|
531
504
|
toast.success("Box updated", { dismissable: true });
|
|
532
505
|
} else {
|
|
533
|
-
await
|
|
506
|
+
await sdk.client.fetch("/admin/parcel-boxes", {
|
|
507
|
+
method: "POST",
|
|
508
|
+
body: payload
|
|
509
|
+
});
|
|
534
510
|
toast.success("Box created", { dismissable: true });
|
|
535
511
|
}
|
|
536
512
|
await refresh();
|
|
@@ -546,7 +522,9 @@ const BoxesSection = () => {
|
|
|
546
522
|
const handleDelete = async (id) => {
|
|
547
523
|
setDeletingId(id);
|
|
548
524
|
try {
|
|
549
|
-
await
|
|
525
|
+
await sdk.client.fetch(`/admin/parcel-boxes/${id}`, {
|
|
526
|
+
method: "DELETE"
|
|
527
|
+
});
|
|
550
528
|
toast.success("Box removed", { dismissable: true });
|
|
551
529
|
await refresh();
|
|
552
530
|
} catch (error) {
|
|
@@ -559,8 +537,9 @@ const BoxesSection = () => {
|
|
|
559
537
|
};
|
|
560
538
|
const handleToggle = async (box) => {
|
|
561
539
|
try {
|
|
562
|
-
await
|
|
563
|
-
|
|
540
|
+
await sdk.client.fetch(`/admin/parcel-boxes/${box.id}`, {
|
|
541
|
+
method: "PUT",
|
|
542
|
+
body: { active: !box.active }
|
|
564
543
|
});
|
|
565
544
|
await refresh();
|
|
566
545
|
} catch (error) {
|
|
@@ -814,9 +793,10 @@ const RatesSection = () => {
|
|
|
814
793
|
const refresh = useCallback(async () => {
|
|
815
794
|
setLoading(true);
|
|
816
795
|
try {
|
|
817
|
-
const
|
|
818
|
-
"
|
|
819
|
-
);
|
|
796
|
+
const response = await sdk.client.fetch("/admin/shipping-config/rates", {
|
|
797
|
+
method: "GET"
|
|
798
|
+
});
|
|
799
|
+
const data = await response.json();
|
|
820
800
|
setRates(
|
|
821
801
|
(data.rates ?? []).map((rate) => ({
|
|
822
802
|
...rate,
|
|
@@ -835,7 +815,10 @@ const RatesSection = () => {
|
|
|
835
815
|
var _a, _b, _c;
|
|
836
816
|
setCurrenciesLoading(true);
|
|
837
817
|
try {
|
|
838
|
-
const
|
|
818
|
+
const response = await sdk.client.fetch("/admin/currencies", {
|
|
819
|
+
method: "GET"
|
|
820
|
+
});
|
|
821
|
+
const data = await response.json();
|
|
839
822
|
const supported = ((_b = (_a = data.store) == null ? void 0 : _a.supported_currencies) == null ? void 0 : _b.map(
|
|
840
823
|
(item) => item.code.toUpperCase()
|
|
841
824
|
)) ?? [];
|
|
@@ -914,14 +897,16 @@ const RatesSection = () => {
|
|
|
914
897
|
setSaving(true);
|
|
915
898
|
try {
|
|
916
899
|
if (formState.id) {
|
|
917
|
-
await
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
);
|
|
900
|
+
await sdk.client.fetch(`/admin/shipping-config/rates/${formState.id}`, {
|
|
901
|
+
method: "PUT",
|
|
902
|
+
body: payload
|
|
903
|
+
});
|
|
922
904
|
toast.success("Rate updated", { dismissable: true });
|
|
923
905
|
} else {
|
|
924
|
-
await
|
|
906
|
+
await sdk.client.fetch("/admin/shipping-config/rates", {
|
|
907
|
+
method: "POST",
|
|
908
|
+
body: payload
|
|
909
|
+
});
|
|
925
910
|
toast.success("Rate created", { dismissable: true });
|
|
926
911
|
}
|
|
927
912
|
await refresh();
|
|
@@ -937,7 +922,9 @@ const RatesSection = () => {
|
|
|
937
922
|
const handleDelete = async (id) => {
|
|
938
923
|
setDeletingId(id);
|
|
939
924
|
try {
|
|
940
|
-
await
|
|
925
|
+
await sdk.client.fetch(`/admin/shipping-config/rates/${id}`, {
|
|
926
|
+
method: "DELETE"
|
|
927
|
+
});
|
|
941
928
|
toast.success("Rate removed", { dismissable: true });
|
|
942
929
|
await refresh();
|
|
943
930
|
} catch (error) {
|
|
@@ -950,8 +937,9 @@ const RatesSection = () => {
|
|
|
950
937
|
};
|
|
951
938
|
const handleToggle = async (rate) => {
|
|
952
939
|
try {
|
|
953
|
-
await
|
|
954
|
-
|
|
940
|
+
await sdk.client.fetch(`/admin/shipping-config/rates/${rate.id}`, {
|
|
941
|
+
method: "PUT",
|
|
942
|
+
body: { active: !rate.active }
|
|
955
943
|
});
|
|
956
944
|
await refresh();
|
|
957
945
|
} catch (error) {
|
|
@@ -1194,9 +1182,10 @@ const AreasSection = () => {
|
|
|
1194
1182
|
const refresh = useCallback(async () => {
|
|
1195
1183
|
setLoading(true);
|
|
1196
1184
|
try {
|
|
1197
|
-
const
|
|
1198
|
-
"
|
|
1199
|
-
);
|
|
1185
|
+
const response = await sdk.client.fetch("/admin/shipping-config/areas", {
|
|
1186
|
+
method: "GET"
|
|
1187
|
+
});
|
|
1188
|
+
const data = await response.json();
|
|
1200
1189
|
setAreas(data.areas ?? []);
|
|
1201
1190
|
} catch (error) {
|
|
1202
1191
|
toast.error(error.message ?? "Failed to load service areas", {
|
|
@@ -1236,14 +1225,16 @@ const AreasSection = () => {
|
|
|
1236
1225
|
setSaving(true);
|
|
1237
1226
|
try {
|
|
1238
1227
|
if (formState.id) {
|
|
1239
|
-
await
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
);
|
|
1228
|
+
await sdk.client.fetch(`/admin/shipping-config/areas/${formState.id}`, {
|
|
1229
|
+
method: "PUT",
|
|
1230
|
+
body: payload
|
|
1231
|
+
});
|
|
1244
1232
|
toast.success("Service area updated", { dismissable: true });
|
|
1245
1233
|
} else {
|
|
1246
|
-
await
|
|
1234
|
+
await sdk.client.fetch("/admin/shipping-config/areas", {
|
|
1235
|
+
method: "POST",
|
|
1236
|
+
body: payload
|
|
1237
|
+
});
|
|
1247
1238
|
toast.success("Service area created", { dismissable: true });
|
|
1248
1239
|
}
|
|
1249
1240
|
await refresh();
|
|
@@ -1259,7 +1250,9 @@ const AreasSection = () => {
|
|
|
1259
1250
|
const handleDelete = async (id) => {
|
|
1260
1251
|
setDeletingId(id);
|
|
1261
1252
|
try {
|
|
1262
|
-
await
|
|
1253
|
+
await sdk.client.fetch(`/admin/shipping-config/areas/${id}`, {
|
|
1254
|
+
method: "DELETE"
|
|
1255
|
+
});
|
|
1263
1256
|
toast.success("Service area removed", { dismissable: true });
|
|
1264
1257
|
await refresh();
|
|
1265
1258
|
} catch (error) {
|
|
@@ -1272,8 +1265,9 @@ const AreasSection = () => {
|
|
|
1272
1265
|
};
|
|
1273
1266
|
const handleToggle = async (area) => {
|
|
1274
1267
|
try {
|
|
1275
|
-
await
|
|
1276
|
-
|
|
1268
|
+
await sdk.client.fetch(`/admin/shipping-config/areas/${area.id}`, {
|
|
1269
|
+
method: "PUT",
|
|
1270
|
+
body: { active: !area.active }
|
|
1277
1271
|
});
|
|
1278
1272
|
await refresh();
|
|
1279
1273
|
} catch (error) {
|