nps
This commit is contained in:
parent
ceab73c21c
commit
2325b4a2a8
16 changed files with 345 additions and 1 deletions
59
dist-import/NPS/index.js
Normal file
59
dist-import/NPS/index.js
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
// npm run build produz um arquivo abrirNps.js que é copiado para a pasta public
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
import { respostaComuns } from "p-respostas";
|
||||
// exibe o iframe em tela cheia
|
||||
export const abrirNps = (emDesenvolvimento) => (parametros) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const base_site = emDesenvolvimento
|
||||
? "http://localhost:5040/nps"
|
||||
: "https://carro-de-boi.idz.one/nps";
|
||||
const base_api = `${base_site}/api`;
|
||||
const { sistema, codigo_organizacao, codigo_usuario } = parametros;
|
||||
const nome_local_storage_proxima = `nps_${sistema}_${codigo_usuario}_${codigo_organizacao}_0`;
|
||||
const proxima_avaliacao = localStorage.getItem(nome_local_storage_proxima);
|
||||
if (!proxima_avaliacao) {
|
||||
const url_proxima_avaliacao = new URL(`${base_api}/${sistema}/proxima_avaliacao`);
|
||||
for (const [chave, valor] of Object.entries(parametros)) {
|
||||
url_proxima_avaliacao.searchParams.append(chave, valor);
|
||||
}
|
||||
const response = yield fetch(url_proxima_avaliacao.href)
|
||||
.then((resposta) => resposta.json())
|
||||
.catch((error) => respostaComuns.erro(error.message));
|
||||
const proxima_avaliacao = response.valor;
|
||||
proxima_avaliacao &&
|
||||
localStorage.setItem(nome_local_storage_proxima, proxima_avaliacao);
|
||||
}
|
||||
const abrir_modal = proxima_avaliacao &&
|
||||
new Date().toISOString().slice(0, 10) >= proxima_avaliacao;
|
||||
if (!abrir_modal) {
|
||||
return;
|
||||
}
|
||||
localStorage.removeItem(nome_local_storage_proxima);
|
||||
const urlIfrma = new URL(base_site);
|
||||
for (const [chave, valor] of Object.entries(parametros)) {
|
||||
urlIfrma.searchParams.append(chave, valor);
|
||||
}
|
||||
const iframe = document.createElement("iframe");
|
||||
iframe.src = urlIfrma.href;
|
||||
iframe.style.position = "fixed";
|
||||
iframe.style.top = "0";
|
||||
iframe.style.left = "0";
|
||||
iframe.style.width = "100%";
|
||||
iframe.style.height = "100%";
|
||||
iframe.style.border = "none";
|
||||
iframe.style.zIndex = "999999";
|
||||
document.body.appendChild(iframe);
|
||||
// receber mensagem do iframe
|
||||
window.addEventListener("message", (event) => {
|
||||
if (event.data === "fechar") {
|
||||
document.body.removeChild(iframe);
|
||||
}
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue