@developerx12/invoices-medusa 0.1.5 → 0.1.6
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.
|
@@ -49,13 +49,10 @@ const OrderInvoiceWidget = ({ data: order }) => {
|
|
|
49
49
|
displayId,
|
|
50
50
|
type
|
|
51
51
|
}) => {
|
|
52
|
-
const response = await fetch(
|
|
52
|
+
const response = await sdk.client.fetch(
|
|
53
53
|
`/admin/orders/${order.id}/invoice/${invoiceId}`,
|
|
54
|
-
{
|
|
54
|
+
{ headers: { accept: null } }
|
|
55
55
|
);
|
|
56
|
-
if (!response.ok) {
|
|
57
|
-
throw new Error("Download failed");
|
|
58
|
-
}
|
|
59
56
|
const blob = await response.blob();
|
|
60
57
|
const url = window.URL.createObjectURL(blob);
|
|
61
58
|
const link = document.createElement("a");
|
|
@@ -75,33 +72,15 @@ const OrderInvoiceWidget = ({ data: order }) => {
|
|
|
75
72
|
const formData = new FormData();
|
|
76
73
|
formData.append("file", file);
|
|
77
74
|
formData.append("type", type);
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
const token = await sdk.client.getToken();
|
|
81
|
-
if (token) {
|
|
82
|
-
headers.Authorization = `Bearer ${token}`;
|
|
83
|
-
}
|
|
84
|
-
} catch {
|
|
85
|
-
}
|
|
86
|
-
const response = await fetch(
|
|
75
|
+
return await sdk.client.fetch(
|
|
87
76
|
`/admin/orders/${order.id}/invoice/upload-new`,
|
|
88
77
|
{
|
|
89
78
|
method: "POST",
|
|
90
79
|
body: formData,
|
|
91
|
-
|
|
92
|
-
headers
|
|
80
|
+
// Let the browser set the multipart/form-data boundary.
|
|
81
|
+
headers: { "content-type": null }
|
|
93
82
|
}
|
|
94
83
|
);
|
|
95
|
-
if (!response.ok) {
|
|
96
|
-
let message = "Failed to upload invoice";
|
|
97
|
-
try {
|
|
98
|
-
const body = await response.json();
|
|
99
|
-
message = (body == null ? void 0 : body.message) ?? message;
|
|
100
|
-
} catch {
|
|
101
|
-
}
|
|
102
|
-
throw new Error(message);
|
|
103
|
-
}
|
|
104
|
-
return response.json();
|
|
105
84
|
},
|
|
106
85
|
onSuccess: () => {
|
|
107
86
|
ui.toast.success("Invoice uploaded successfully");
|
|
@@ -118,33 +97,15 @@ const OrderInvoiceWidget = ({ data: order }) => {
|
|
|
118
97
|
}) => {
|
|
119
98
|
const formData = new FormData();
|
|
120
99
|
formData.append("file", file);
|
|
121
|
-
|
|
122
|
-
try {
|
|
123
|
-
const token = await sdk.client.getToken();
|
|
124
|
-
if (token) {
|
|
125
|
-
headers.Authorization = `Bearer ${token}`;
|
|
126
|
-
}
|
|
127
|
-
} catch {
|
|
128
|
-
}
|
|
129
|
-
const response = await fetch(
|
|
100
|
+
return await sdk.client.fetch(
|
|
130
101
|
`/admin/orders/${order.id}/invoice/${invoiceId}/upload`,
|
|
131
102
|
{
|
|
132
103
|
method: "POST",
|
|
133
104
|
body: formData,
|
|
134
|
-
|
|
135
|
-
headers
|
|
105
|
+
// Let the browser set the multipart/form-data boundary.
|
|
106
|
+
headers: { "content-type": null }
|
|
136
107
|
}
|
|
137
108
|
);
|
|
138
|
-
if (!response.ok) {
|
|
139
|
-
let message = "Failed to upload invoice PDF";
|
|
140
|
-
try {
|
|
141
|
-
const body = await response.json();
|
|
142
|
-
message = (body == null ? void 0 : body.message) ?? message;
|
|
143
|
-
} catch {
|
|
144
|
-
}
|
|
145
|
-
throw new Error(message);
|
|
146
|
-
}
|
|
147
|
-
return response.json();
|
|
148
109
|
},
|
|
149
110
|
onSuccess: () => {
|
|
150
111
|
ui.toast.success("Invoice PDF uploaded");
|
|
@@ -46,13 +46,10 @@ const OrderInvoiceWidget = ({ data: order }) => {
|
|
|
46
46
|
displayId,
|
|
47
47
|
type
|
|
48
48
|
}) => {
|
|
49
|
-
const response = await fetch(
|
|
49
|
+
const response = await sdk.client.fetch(
|
|
50
50
|
`/admin/orders/${order.id}/invoice/${invoiceId}`,
|
|
51
|
-
{
|
|
51
|
+
{ headers: { accept: null } }
|
|
52
52
|
);
|
|
53
|
-
if (!response.ok) {
|
|
54
|
-
throw new Error("Download failed");
|
|
55
|
-
}
|
|
56
53
|
const blob = await response.blob();
|
|
57
54
|
const url = window.URL.createObjectURL(blob);
|
|
58
55
|
const link = document.createElement("a");
|
|
@@ -72,33 +69,15 @@ const OrderInvoiceWidget = ({ data: order }) => {
|
|
|
72
69
|
const formData = new FormData();
|
|
73
70
|
formData.append("file", file);
|
|
74
71
|
formData.append("type", type);
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
const token = await sdk.client.getToken();
|
|
78
|
-
if (token) {
|
|
79
|
-
headers.Authorization = `Bearer ${token}`;
|
|
80
|
-
}
|
|
81
|
-
} catch {
|
|
82
|
-
}
|
|
83
|
-
const response = await fetch(
|
|
72
|
+
return await sdk.client.fetch(
|
|
84
73
|
`/admin/orders/${order.id}/invoice/upload-new`,
|
|
85
74
|
{
|
|
86
75
|
method: "POST",
|
|
87
76
|
body: formData,
|
|
88
|
-
|
|
89
|
-
headers
|
|
77
|
+
// Let the browser set the multipart/form-data boundary.
|
|
78
|
+
headers: { "content-type": null }
|
|
90
79
|
}
|
|
91
80
|
);
|
|
92
|
-
if (!response.ok) {
|
|
93
|
-
let message = "Failed to upload invoice";
|
|
94
|
-
try {
|
|
95
|
-
const body = await response.json();
|
|
96
|
-
message = (body == null ? void 0 : body.message) ?? message;
|
|
97
|
-
} catch {
|
|
98
|
-
}
|
|
99
|
-
throw new Error(message);
|
|
100
|
-
}
|
|
101
|
-
return response.json();
|
|
102
81
|
},
|
|
103
82
|
onSuccess: () => {
|
|
104
83
|
toast.success("Invoice uploaded successfully");
|
|
@@ -115,33 +94,15 @@ const OrderInvoiceWidget = ({ data: order }) => {
|
|
|
115
94
|
}) => {
|
|
116
95
|
const formData = new FormData();
|
|
117
96
|
formData.append("file", file);
|
|
118
|
-
|
|
119
|
-
try {
|
|
120
|
-
const token = await sdk.client.getToken();
|
|
121
|
-
if (token) {
|
|
122
|
-
headers.Authorization = `Bearer ${token}`;
|
|
123
|
-
}
|
|
124
|
-
} catch {
|
|
125
|
-
}
|
|
126
|
-
const response = await fetch(
|
|
97
|
+
return await sdk.client.fetch(
|
|
127
98
|
`/admin/orders/${order.id}/invoice/${invoiceId}/upload`,
|
|
128
99
|
{
|
|
129
100
|
method: "POST",
|
|
130
101
|
body: formData,
|
|
131
|
-
|
|
132
|
-
headers
|
|
102
|
+
// Let the browser set the multipart/form-data boundary.
|
|
103
|
+
headers: { "content-type": null }
|
|
133
104
|
}
|
|
134
105
|
);
|
|
135
|
-
if (!response.ok) {
|
|
136
|
-
let message = "Failed to upload invoice PDF";
|
|
137
|
-
try {
|
|
138
|
-
const body = await response.json();
|
|
139
|
-
message = (body == null ? void 0 : body.message) ?? message;
|
|
140
|
-
} catch {
|
|
141
|
-
}
|
|
142
|
-
throw new Error(message);
|
|
143
|
-
}
|
|
144
|
-
return response.json();
|
|
145
106
|
},
|
|
146
107
|
onSuccess: () => {
|
|
147
108
|
toast.success("Invoice PDF uploaded");
|