send email v1
This commit is contained in:
parent
fe4df9cbd3
commit
afd3df123f
9 changed files with 258 additions and 63 deletions
|
|
@ -2,7 +2,7 @@
|
|||
"use strict";
|
||||
function normalizeComponent(scriptExports, render, staticRenderFns, functionalTemplate, injectStyles, scopeId, moduleIdentifier, shadowMode) {
|
||||
var options = typeof scriptExports === "function" ? scriptExports.options : scriptExports;
|
||||
if (render) {
|
||||
{
|
||||
options.render = render;
|
||||
options.staticRenderFns = staticRenderFns;
|
||||
options._compiled = true;
|
||||
|
|
@ -18,31 +18,93 @@
|
|||
const _sfc_main = {
|
||||
__name: "SendButtonField",
|
||||
props: {
|
||||
pageUri: String
|
||||
pageUri: String,
|
||||
pageStatus: String
|
||||
},
|
||||
setup(__props) {
|
||||
const { pageUri } = __props;
|
||||
const text = Vue.ref("Envoyer");
|
||||
const headers = {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
pageUri
|
||||
})
|
||||
};
|
||||
function send(event) {
|
||||
const testBtnState = Vue.ref({
|
||||
icon: "plane",
|
||||
text: "Tester",
|
||||
theme: "blue",
|
||||
error: null
|
||||
});
|
||||
const sendBtnState = Vue.ref({
|
||||
icon: "plane",
|
||||
text: "Envoyer",
|
||||
theme: "aqua",
|
||||
error: null
|
||||
});
|
||||
async function send(event, isTest = false) {
|
||||
event.preventDefault();
|
||||
fetch("/send-newsletter.json", headers).then((res) => res.json()).then((json) => console.log(json));
|
||||
const currentBtnState = isTest ? testBtnState : sendBtnState;
|
||||
currentBtnState.value = {
|
||||
theme: "orange",
|
||||
text: "En cours…",
|
||||
icon: "loader",
|
||||
error: null
|
||||
};
|
||||
const headers = {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
pageUri,
|
||||
isTest
|
||||
})
|
||||
};
|
||||
try {
|
||||
const response = await fetch("/send-newsletter.json", headers);
|
||||
const data = await response.json();
|
||||
if (data.status === "success") {
|
||||
currentBtnState.value = {
|
||||
theme: "green",
|
||||
icon: "check",
|
||||
text: isTest ? "Test envoyé" : "Envoi réussi",
|
||||
error: null
|
||||
};
|
||||
if (!isTest) {
|
||||
setTimeout(() => {
|
||||
location.href = location.href;
|
||||
}, 2e3);
|
||||
} else {
|
||||
currentBtnState.value = {
|
||||
icon: "plane",
|
||||
text: "Re-tester",
|
||||
theme: "blue",
|
||||
error: null
|
||||
};
|
||||
}
|
||||
} else {
|
||||
throw new Error(data.message || "Erreur inconnue");
|
||||
}
|
||||
} catch (error) {
|
||||
currentBtnState.value = {
|
||||
theme: "red",
|
||||
icon: "alert",
|
||||
text: isTest ? "Échec du test" : "Erreur",
|
||||
error: error.message
|
||||
};
|
||||
}
|
||||
}
|
||||
return { __sfc: true, text, headers, send };
|
||||
return { __sfc: true, testBtnState, sendBtnState, send };
|
||||
}
|
||||
};
|
||||
var _sfc_render = function render() {
|
||||
var _vm = this, _c = _vm._self._c, _setup = _vm._self._setupProxy;
|
||||
return _c("k-button", { attrs: { "variant": "filled", "icon": "plane" }, on: { "click": function($event) {
|
||||
return _vm.pageStatus === "draft" ? _c("div", { staticClass: "wrapper" }, [_c("div", { staticClass: "test-wrapper" }, [_c("k-button", { staticStyle: { "width": "max-content" }, attrs: { "variant": "filled", "help": "test", "theme": _setup.testBtnState.theme, "icon": _setup.testBtnState.icon }, on: { "click": function($event) {
|
||||
return _setup.send($event, true);
|
||||
} } }, [_vm._v(_vm._s(_setup.testBtnState.text))]), _vm._m(0), _setup.testBtnState.error ? _c("k-box", { staticStyle: { "margin-top": "var(--spacing-1)" }, attrs: { "theme": "error" } }, [_vm._v(_vm._s(_setup.testBtnState.error))]) : _vm._e()], 1), _c("div", { staticClass: "send-wrapper" }, [_c("k-button", { attrs: { "variant": "filled", "theme": _setup.sendBtnState.theme, "icon": _setup.sendBtnState.icon }, on: { "click": function($event) {
|
||||
return _setup.send($event);
|
||||
} } }, [_vm._v(_vm._s(_setup.text))]);
|
||||
} } }, [_vm._v(_vm._s(_setup.sendBtnState.text))]), _setup.sendBtnState.error ? _c("k-box", { staticStyle: { "margin-top": "var(--spacing-1)" }, attrs: { "theme": "error" } }, [_vm._v(_vm._s(_setup.sendBtnState.error))]) : _vm._e(), _vm._m(1)], 1)]) : _vm._e();
|
||||
};
|
||||
var _sfc_staticRenderFns = [];
|
||||
var _sfc_staticRenderFns = [function() {
|
||||
var _vm = this, _c = _vm._self._c;
|
||||
_vm._self._setupProxy;
|
||||
return _c("footer", { staticClass: "k-field-footer" }, [_c("div", { staticClass: "k-help k-field-help k-text" }, [_c("p", [_vm._v(" Envoie seulement aux "), _c("a", { attrs: { "href": "/panel/users", "title": "voir la liste" } }, [_vm._v("éditeurs")]), _vm._v(". ")])])]);
|
||||
}, function() {
|
||||
var _vm = this, _c = _vm._self._c;
|
||||
_vm._self._setupProxy;
|
||||
return _c("footer", { staticClass: "k-field-footer" }, [_c("div", { staticClass: "k-help k-field-help k-text" }, [_c("strong", [_vm._v("⚠ Envoie à tous les abonnés.")])])]);
|
||||
}];
|
||||
_sfc_render._withStripped = true;
|
||||
var __component__ = /* @__PURE__ */ normalizeComponent(
|
||||
_sfc_main,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue