UNPKG

@lynsoluciones/medusa-docs

Version:
58 lines (57 loc) 2.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); /* * * * 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("Factura", { description: "Generando factura...", 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("Factura", { description: "Problema ocurrido al generar factura", }); } }, onError: (error) => { var _a, _b; ui_1.toast.dismiss(); const trueError = error; ui_1.toast.error("Factura", { 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, {}), "Generar nueva factura"] })); }; exports.default = GenerateInvoiceDropdownButton;