UNPKG

@lynsoluciones/medusa-docs

Version:
66 lines (65 loc) 2.43 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 ViewPackingSlipDropdownButton = ({ order }) => { const { data, refetch } = (0, medusa_react_1.useAdminCustomQuery)("/packing-slip", [], { id: order.metadata["packing_slip_id"], includeBuffer: true, }, { enabled: false, }); const handleClick = async () => { const id = ui_1.toast.loading("Albarán", { description: "Preparando...", 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("Albarán", { description: "El problema ocurrió durante la preparación", }); } } catch (error) { ui_1.toast.dismiss(); ui_1.toast.error("Albarán", { description: error, }); } finally { ui_1.toast.dismiss(); } }; const openPdf = (packingSlipResult) => { if (packingSlipResult && packingSlipResult.buffer) { const anyBuffer = packingSlipResult.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["packing_slip_id"] == undefined, children: [(0, jsx_runtime_1.jsx)(icons_1.DocumentText, {}), "Ver albar\u00E1n de entrega"] })); }; exports.default = ViewPackingSlipDropdownButton;