UNPKG

@rsc-labs/medusa-documents

Version:
56 lines (55 loc) 2.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); /* * Copyright 2024 RSC-Labs, https://rsoftcon.com/ * * MIT License * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const icons_1 = require("@medusajs/icons"); const ui_1 = require("@medusajs/ui"); const medusa_react_1 = require("medusa-react"); const GenerateInvoiceDropdownButton = ({ order }) => { const { mutate } = (0, medusa_react_1.useAdminCustomPost)(`/invoice`, ["invoice"]); const generate = () => { const id = ui_1.toast.loading("Invoice", { description: "Generating invoice...", duration: Infinity }); mutate({ orderId: order.id }, { onSuccess: ({ response, buffer }) => { if (response.status == 201 && buffer) { const anyBuffer = buffer; const blob = new Blob([new Uint8Array(anyBuffer.data)], { type: 'application/pdf' }); ui_1.toast.dismiss(); const pdfURL = URL.createObjectURL(blob); window.open(pdfURL, '_blank'); } else { ui_1.toast.dismiss(); ui_1.toast.error("Invoice", { description: 'Problem happened when generating invoice', }); } }, onError: (error) => { var _a, _b; ui_1.toast.dismiss(); const trueError = error; ui_1.toast.error("Invoice", { description: (_b = (_a = trueError === null || trueError === void 0 ? void 0 : trueError.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message, }); } }); }; return ((0, jsx_runtime_1.jsxs)(ui_1.DropdownMenu.Item, { className: "gap-x-2", onClick: generate, children: [(0, jsx_runtime_1.jsx)(icons_1.FlyingBox, {}), "Generate new invoice"] })); }; exports.default = GenerateInvoiceDropdownButton;