infinity-forge
Version:
137 lines • 15.6 kB
JavaScript
;
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
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());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.EditSectionComponent = EditSectionComponent;
var jsx_runtime_1 = require("react/jsx-runtime");
var react_1 = require("react");
var router_1 = require("next/router");
var styled_components_1 = __importDefault(require("styled-components"));
var ui_1 = require("../../../../../ui/index.js");
var context_1 = require("../context.js");
var edit_css_1 = require("./edit-css/index.js");
function EditSectionComponent(_a) {
var _this = this;
var _b, _c, _d, _e, _f, _g;
var fields = _a.fields, children = _a.children, refSection = _a.refSection, dynamicSectionProps = _a.dynamicSectionProps, _h = _a.section, section = _h === void 0 ? undefined : _h;
var _j = (0, react_1.useState)(false), open = _j[0], setOpen = _j[1];
var _k = (0, react_1.useState)(false), sideBar = _k[0], setSidebar = _k[1];
var _l = (0, react_1.useState)(''), versionTemplate = _l[0], setVersionTemplate = _l[1];
var query = (0, router_1.useRouter)().query;
var createToast = (0, ui_1.useToast)().createToast;
var mutate = (0, context_1.useAtena)().mutate;
function handleSubmit(data) {
return __awaiter(this, void 0, void 0, function () {
var response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, (0, ui_1.api)({
method: (section === null || section === void 0 ? void 0 : section.id) ? 'put' : 'post',
url: (section === null || section === void 0 ? void 0 : section.id) ? "section/".concat(section.id) : 'section',
body: __assign(__assign({}, data), { jsonContent: (0, ui_1.stringfyJSON)(data === null || data === void 0 ? void 0 : data.jsonContent) }),
})];
case 1:
response = _a.sent();
return [2 /*return*/, response];
}
});
});
}
var initialData = __assign(__assign({}, section), { jsonContent: (0, ui_1.parseJSON)(section === null || section === void 0 ? void 0 : section.jsonContent), ref: refSection });
var TemplateComponent = (_c = (_b = dynamicSectionProps === null || dynamicSectionProps === void 0 ? void 0 : dynamicSectionProps.templates) === null || _b === void 0 ? void 0 : _b.VersionsElement) === null || _c === void 0 ? void 0 : _c[versionTemplate];
var templateKeys = Object.keys(((_d = dynamicSectionProps === null || dynamicSectionProps === void 0 ? void 0 : dynamicSectionProps.templates) === null || _d === void 0 ? void 0 : _d.VersionsElement) || {});
var stylesModal = ((_f = (_e = dynamicSectionProps === null || dynamicSectionProps === void 0 ? void 0 : dynamicSectionProps.customForm) === null || _e === void 0 ? void 0 : _e.modal) === null || _f === void 0 ? void 0 : _f.styles) || {};
console.log(((_g = process === null || process === void 0 ? void 0 : process.env) === null || _g === void 0 ? void 0 : _g.supportOldAtena) === "true" || (fields === null || fields === void 0 ? void 0 : fields['title']), "@@");
function RenderDynamicSectionForm() {
var _this = this;
var _a, _b;
return ((0, jsx_runtime_1.jsx)(ui_1.DynamicFormHandler, { debugMode: true, fileFields: {
fields: ['images'],
ref: 'section',
unique: false,
onUpload: function () { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
mutate();
createToast({ message: 'Sessão atualizada com sucesso', status: 'success' });
return [2 /*return*/];
});
}); },
}, disableEnterKeySubmitForm: true, onSucess: handleSubmit, initialData: initialData, button: { text: 'Salvar' }, i18n: {
RenderFields: function (_a) {
var _b, _c, _d, _e, _f, _g;
var symbol = _a.symbol;
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [!!(((_b = process === null || process === void 0 ? void 0 : process.env) === null || _b === void 0 ? void 0 : _b.supportOldAtena) === "true" || (fields === null || fields === void 0 ? void 0 : fields['title'])) && (0, jsx_runtime_1.jsx)(ui_1.TextEditor, __assign({ name: symbol + '.title', label: 'Titulo' }, fields === null || fields === void 0 ? void 0 : fields['title'])), !!(((_c = process === null || process === void 0 ? void 0 : process.env) === null || _c === void 0 ? void 0 : _c.supportOldAtena) === "true" || (fields === null || fields === void 0 ? void 0 : fields['subtitle'])) && ((0, jsx_runtime_1.jsx)(ui_1.TextEditor, __assign({ name: symbol + '.subtitle', label: 'Subtitulo' }, fields === null || fields === void 0 ? void 0 : fields['subtitle']))), !!(((_d = process === null || process === void 0 ? void 0 : process.env) === null || _d === void 0 ? void 0 : _d.supportOldAtena) === "true" || (fields === null || fields === void 0 ? void 0 : fields['description'])) && ((0, jsx_runtime_1.jsx)(ui_1.TextEditor, __assign({ name: symbol + '.description', label: 'Descri\u00E7\u00E3o' }, fields === null || fields === void 0 ? void 0 : fields['description']))), !!(((_e = process === null || process === void 0 ? void 0 : process.env) === null || _e === void 0 ? void 0 : _e.supportOldAtena) === "true" || (fields === null || fields === void 0 ? void 0 : fields['linkText']) || (fields === null || fields === void 0 ? void 0 : fields['linkUrl'])) && ((0, jsx_runtime_1.jsxs)("div", { className: 'row', children: [(fields === null || fields === void 0 ? void 0 : fields['linkText']) && ((0, jsx_runtime_1.jsx)(ui_1.Input, __assign({ name: symbol + '.linkText', label: 'Link texto' }, fields === null || fields === void 0 ? void 0 : fields['linkText']))), (fields === null || fields === void 0 ? void 0 : fields['linkUrl']) && (0, jsx_runtime_1.jsx)(ui_1.Input, __assign({ name: 'linkUrl', label: 'Link Url' }, fields === null || fields === void 0 ? void 0 : fields['linkUrl']))] })), !!(((_f = process === null || process === void 0 ? void 0 : process.env) === null || _f === void 0 ? void 0 : _f.supportOldAtena) === "true" || (fields === null || fields === void 0 ? void 0 : fields['videoUrl'])) && (0, jsx_runtime_1.jsx)(ui_1.Input, __assign({ name: 'videoUrl', label: 'Video URL' }, fields === null || fields === void 0 ? void 0 : fields['videoUrl'])), !!(((_g = process === null || process === void 0 ? void 0 : process.env) === null || _g === void 0 ? void 0 : _g.supportOldAtena) === "true" || (fields === null || fields === void 0 ? void 0 : fields['images'])) && ((0, jsx_runtime_1.jsx)(ui_1.InputFile, __assign({ name: 'images', isAccumalativeFile: true, multiple: true, isLocalFile: true, label: 'Imagens', enableMobileImage: true, sizeImageFile: '1920x1080', sizeImageFileMobile: '500x500' }, fields === null || fields === void 0 ? void 0 : fields['images'])))] }));
},
}, children: (_a = dynamicSectionProps === null || dynamicSectionProps === void 0 ? void 0 : dynamicSectionProps.customForm) === null || _a === void 0 ? void 0 : _a.children, isStickyButtons: true, inputs: (_b = dynamicSectionProps === null || dynamicSectionProps === void 0 ? void 0 : dynamicSectionProps.customForm) === null || _b === void 0 ? void 0 : _b.inputs }));
}
if (dynamicSectionProps.editModeIsOutside) {
return (0, jsx_runtime_1.jsx)(RenderDynamicSectionForm, {});
}
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(ui_1.Modal, { styles: __assign({ maxWidth: '900px', width: '100%' }, stylesModal), open: open, onClose: function () { return setOpen(false); }, children: open && (0, jsx_runtime_1.jsx)(RenderDynamicSectionForm, {}) }), query.showPreview === 'true' ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(Styles, { "$enabled": initialData.enabled, children: [(0, jsx_runtime_1.jsx)(ui_1.FormHandler, { initialData: { enabled: (initialData === null || initialData === void 0 ? void 0 : initialData.enabled) || false }, onSucess: handleSubmit, children: (0, jsx_runtime_1.jsx)(ui_1.InputSwitch, { checkbox_key: refSection, onChangeInput: function (ev) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, handleSubmit(__assign(__assign({ i18n: {} }, initialData), { enabled: ev, ref: refSection }))];
case 1:
_a.sent();
mutate();
createToast({ message: 'Sessão atualizada com sucesso', status: 'success' });
return [2 /*return*/];
}
});
}); }, name: 'enabled' }) }), (0, jsx_runtime_1.jsxs)("button", { type: 'button', onClick: function () { return setOpen(true); }, className: 'edit_section', children: [(0, jsx_runtime_1.jsx)(ui_1.Icon, { name: 'IconEdit', color: '#000' }), "Editar"] }), templateKeys && templateKeys.length > 0 && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(ui_1.SideBar, { open: sideBar, setOpen: setSidebar, maxWidth: '800px', direction: 'right', overlay: false, children: [templateKeys === null || templateKeys === void 0 ? void 0 : templateKeys.map(function (version) { return ((0, jsx_runtime_1.jsx)("button", { type: 'button', onClick: function () { return setVersionTemplate(version); }, children: version })); }), (0, jsx_runtime_1.jsx)(edit_css_1.EditorCSS, { refSection: refSection, handleSubmit: handleSubmit, initialData: initialData })] }), (0, jsx_runtime_1.jsxs)("button", { type: 'button', onClick: function () { return setSidebar(function (s) { return !s; }); }, className: 'edit_section', children: [(0, jsx_runtime_1.jsx)(ui_1.Icon, { name: 'IconEdit', color: '#000' }), "Alterar template"] })] }))] }), versionTemplate && TemplateComponent ? (0, jsx_runtime_1.jsx)(TemplateComponent, __assign({}, dynamicSectionProps)) : children] })) : (children)] }));
}
var Styles = (0, styled_components_1.default)('div')(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 10px;\n gap: 10px;\n z-index: 2;\n position: relative;\n\n & + * {\n z-index: 1;\n position: relative;\n }\n\n & + * {\n opacity: ", ";\n }\n\n .input_control {\n margin-bottom: 0;\n }\n\n .edit_section {\n font-size: 13px;\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 5px;\n border-radius: 3px;\n border: 1px solid #ccc;\n padding: 5px 10px;\n transition: 0.3s;\n\n &:hover {\n background-color: #f1f1f1;\n }\n\n svg {\n width: 10px !important;\n height: auto !important;\n fill: #000 !important;\n }\n }\n"], ["\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 10px;\n gap: 10px;\n z-index: 2;\n position: relative;\n\n & + * {\n z-index: 1;\n position: relative;\n }\n\n & + * {\n opacity: ", ";\n }\n\n .input_control {\n margin-bottom: 0;\n }\n\n .edit_section {\n font-size: 13px;\n display: flex;\n align-items: center;\n justify-content: center;\n gap: 5px;\n border-radius: 3px;\n border: 1px solid #ccc;\n padding: 5px 10px;\n transition: 0.3s;\n\n &:hover {\n background-color: #f1f1f1;\n }\n\n svg {\n width: 10px !important;\n height: auto !important;\n fill: #000 !important;\n }\n }\n"])), function (props) { return (props.$enabled ? 1 : 0.6); });
var templateObject_1;
//# sourceMappingURL=edit-section.js.map