@lynsoluciones/medusa-docs
Version:
Medusa plugins to generate docs
66 lines (65 loc) • 2.38 kB
JavaScript
;
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 ViewInvoiceDropdownButton = ({ order }) => {
const { data, refetch } = (0, medusa_react_1.useAdminCustomQuery)("/invoice", [], {
invoiceId: order.metadata["invoice_id"],
includeBuffer: true,
}, {
enabled: false,
});
const handleClick = async () => {
ui_1.toast.loading("Factura", {
description: "Preparando factura...",
duration: Infinity,
});
try {
const result = await refetch();
if (result.data && result.data.buffer) {
ui_1.toast.dismiss();
openPdf(result.data);
}
else {
ui_1.toast.dismiss();
ui_1.toast.error("Factura", {
description: "Se produjo un problema al preparar la factura.",
});
}
}
catch (error) {
ui_1.toast.dismiss();
ui_1.toast.error("Factura", {
description: error,
});
}
finally {
ui_1.toast.dismiss();
}
};
const openPdf = (invoiceResult) => {
if (invoiceResult && invoiceResult.buffer) {
const anyBuffer = invoiceResult.buffer;
const blob = new Blob([new Uint8Array(anyBuffer.data)], {
type: "application/pdf",
});
const pdfURL = URL.createObjectURL(blob);
window.open(pdfURL, "_blank");
}
};
return ((0, jsx_runtime_1.jsxs)(ui_1.DropdownMenu.Item, { className: "gap-x-2", onClick: handleClick, disabled: order.metadata["invoice_id"] == undefined, children: [(0, jsx_runtime_1.jsx)(icons_1.DocumentText, {}), "Ver factura"] }));
};
exports.default = ViewInvoiceDropdownButton;