_designer-system/dist/AlertasFront/index.js
2024-06-04 21:22:33 -03:00

92 lines
No EOL
3.5 KiB
JavaScript

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.componentesAlerta = void 0;
const dist_1 = require("p-estaticos/dist");
const p_respostas_1 = require("p-respostas");
const react_1 = __importDefault(require("react"));
const autoClose = 5000;
const componentesAlerta = ({ mui_material: { Avatar, Typography }, react_toastify: { ToastContainer, Slide, toast }, }) => {
const AlertaContainer = () => (react_1.default.createElement(ToastContainer, { position: "bottom-left", autoClose: autoClose, hideProgressBar: false, newestOnTop: false, closeOnClick: true, rtl: false, pauseOnFocusLoss: true, draggable: true, pauseOnHover: true, theme: "light", transition: Slide }));
const aguarde = () => toast.loading(() => react_1.default.createElement(Typography, { sx: { marginLeft: 4 } }, "\"Aguarde...\""), {
icon: () => (react_1.default.createElement(Avatar, { src: (0, dist_1.estaticos)("link-servidor").imagens["quero-quero.gif"], alt: "Carregando..." })),
});
const exibir = (res, id) => {
console.table(res);
if (!id)
return res.eCerto
? toast.success(String(res.valor), {})
: toast.error(res.mensagem, {});
else {
res.eCerto
? toast.update(id, {
render: String(res.valor),
type: "success",
icon: null,
isLoading: false,
autoClose,
hideProgressBar: false,
})
: toast.update(id, {
render: res.mensagem,
type: "error",
icon: null,
isLoading: false,
autoClose,
hideProgressBar: false,
});
return id;
}
};
class ClasseAlerta {
id;
aguarde() {
this.id = aguarde();
return this;
}
exibir(res) {
this.id = exibir(res, this.id);
return this;
}
/**
*
* @param p função que será executada
* @param transformar converte o valor de retorno da função em um tipoResposta para exibição
* @returns
*/
async promisse(p, transformar) {
this.aguarde();
const res = await p();
transformar ? this.exibir(transformar(res)) : this.fechar();
return res;
}
fechar() {
toast.dismiss(this.id);
}
erro(mensagem) {
this.exibir(p_respostas_1.respostaComuns.erro(mensagem));
return this;
}
erroCatch(erro) {
const erroResposta = p_respostas_1.respostaComuns.erro(erro.response?.data?.mensagem
? erro.response?.data?.mensagem
: erro.message
? erro.message
: erro.response?.data
? erro.response?.data
: erro);
this.exibir(erroResposta);
return this;
}
sucesso(mensagem) {
this.exibir(p_respostas_1.respostaComuns.valor(mensagem));
return this;
}
}
const Alerta = () => new ClasseAlerta();
return { Alerta, AlertaContainer };
};
exports.componentesAlerta = componentesAlerta;
//# sourceMappingURL=index.js.map