UNPKG

infinity-forge

Version:
145 lines 19.4 kB
"use strict"; 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; var fields = _a.fields, onSucess = _a.onSucess, children = _a.children, refSection = _a.refSection, dynamicSectionProps = _a.dynamicSectionProps, _g = _a.section, section = _g === void 0 ? undefined : _g; var _h = (0, react_1.useState)(false), open = _h[0], setOpen = _h[1]; var _j = (0, react_1.useState)(false), sideBar = _j[0], setSidebar = _j[1]; var _k = (0, react_1.useState)(''), versionTemplate = _k[0], setVersionTemplate = _k[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) || {}; function RenderDynamicSectionForm() { var _this = this; var _a, _b, _c, _d, _e, _f, _g, _h; return ((0, jsx_runtime_1.jsx)(ui_1.DynamicFormHandler, { isStickyButtons: true, fileFields: { fields: ['images'], ref: 'section', unique: false, onUpload: function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, mutate()]; case 1: _a.sent(); onSucess && onSucess(); createToast({ message: 'Sessão atualizada com sucesso', status: 'success' }); return [2 /*return*/]; } }); }); }, }, disableEnterKeySubmitForm: true, onSucess: handleSubmit, initialData: initialData, button: typeof ((_a = dynamicSectionProps === null || dynamicSectionProps === void 0 ? void 0 : dynamicSectionProps.customForm) === null || _a === void 0 ? void 0 : _a.button) === 'object' ? (_b = dynamicSectionProps === null || dynamicSectionProps === void 0 ? void 0 : dynamicSectionProps.customForm) === null || _b === void 0 ? void 0 : _b.button : { text: 'Salvar' }, schema: (_c = dynamicSectionProps === null || dynamicSectionProps === void 0 ? void 0 : dynamicSectionProps.customForm) === null || _c === void 0 ? void 0 : _c.schema, errorForm: (_d = dynamicSectionProps === null || dynamicSectionProps === void 0 ? void 0 : dynamicSectionProps.customForm) === null || _d === void 0 ? void 0 : _d.errorForm, i18n: ((_e = dynamicSectionProps === null || dynamicSectionProps === void 0 ? void 0 : dynamicSectionProps.customForm) === null || _e === void 0 ? void 0 : _e.i18n) || { active: true }, decimalFields: (_f = dynamicSectionProps === null || dynamicSectionProps === void 0 ? void 0 : dynamicSectionProps.customForm) === null || _f === void 0 ? void 0 : _f.decimalFields, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [!!(fields === null || fields === void 0 ? void 0 : fields['title']) && (0, jsx_runtime_1.jsx)(ui_1.TextEditor, __assign({ name: 'title', label: 'Titulo' }, fields === null || fields === void 0 ? void 0 : fields['title'])), !!(fields === null || fields === void 0 ? void 0 : fields['subtitle']) && (0, jsx_runtime_1.jsx)(ui_1.TextEditor, __assign({ name: 'subtitle', label: 'Subtitulo' }, fields === null || fields === void 0 ? void 0 : fields['subtitle'])), !!(fields === null || fields === void 0 ? void 0 : fields['description']) && ((0, jsx_runtime_1.jsx)(ui_1.TextEditor, __assign({ name: 'description', label: 'Descri\u00E7\u00E3o' }, fields === null || fields === void 0 ? void 0 : fields['description']))), !!((fields === null || fields === void 0 ? void 0 : fields['linkText']) || (fields === null || fields === void 0 ? void 0 : fields['linkUrl']) || (fields === null || fields === void 0 ? void 0 : fields['linkFull'])) && ((0, jsx_runtime_1.jsxs)("div", { className: 'row', children: [((fields === null || fields === void 0 ? void 0 : fields['linkText']) || (fields === null || fields === void 0 ? void 0 : fields['linkFull'])) && ((0, jsx_runtime_1.jsx)(ui_1.Input, __assign({ name: 'linkText', label: 'Link texto' }, fields === null || fields === void 0 ? void 0 : fields['linkText']))), ((fields === null || fields === void 0 ? void 0 : fields['linkUrl']) || (fields === null || fields === void 0 ? void 0 : fields['linkFull'])) && ((0, jsx_runtime_1.jsx)(ui_1.Input, __assign({ name: 'linkUrl', label: 'Link Url', i18n: { disabled: true } }, fields === null || fields === void 0 ? void 0 : fields['linkUrl'])))] })), !!((fields === null || fields === void 0 ? void 0 : fields['linkFull']) || (fields === null || fields === void 0 ? void 0 : fields['linkSvg']) || (fields === null || fields === void 0 ? void 0 : fields['linkTarget'])) && ((0, jsx_runtime_1.jsxs)("div", { className: 'row', children: [((fields === null || fields === void 0 ? void 0 : fields['linkSvg']) || (fields === null || fields === void 0 ? void 0 : fields['linkFull'])) && ((0, jsx_runtime_1.jsx)(ui_1.SelectIcon, __assign({ name: 'jsonContent.linkSvg', label: 'Link Icon', placeholder: 'Selecione o icone', onlyOneValue: true }, fields === null || fields === void 0 ? void 0 : fields['linkSvg']))), ((fields === null || fields === void 0 ? void 0 : fields['linkTarget']) || (fields === null || fields === void 0 ? void 0 : fields['linkFull'])) && ((0, jsx_runtime_1.jsx)(ui_1.Select, __assign({ name: 'jsonContent.linkTarget', placeholder: 'Selecione o tipo de link', label: 'Link Interno/Externo', onlyOneValue: true, options: [ { label: 'Interno', value: '_self', }, { label: 'Externo', value: '_blank', }, ] }, fields === null || fields === void 0 ? void 0 : fields['linkTarget'])))] })), !!(fields === null || fields === void 0 ? void 0 : fields['videoUrl']) && ((0, jsx_runtime_1.jsx)(ui_1.Input, __assign({ name: 'videoUrl', label: 'Video URL', i18n: { disabled: true } }, fields === null || fields === void 0 ? void 0 : fields['videoUrl']))), !!(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', i18n: { disabled: true } }, fields === null || fields === void 0 ? void 0 : fields['images']))), (_g = dynamicSectionProps === null || dynamicSectionProps === void 0 ? void 0 : dynamicSectionProps.customForm) === null || _g === void 0 ? void 0 : _g.children] }), inputs: (_h = dynamicSectionProps === null || dynamicSectionProps === void 0 ? void 0 : dynamicSectionProps.customForm) === null || _h === void 0 ? void 0 : _h.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)(ModalContent, { children: (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 }, 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 .conntent_form_infinity_forge {\n display: flex;\n align-items: center;\n gap: 1.5rem;\n\n .button-flag {\n background: transparent;\n border: none;\n padding: 0;\n transition: all 0.2s;\n margin: 0 !important;\n\n &:hover {\n box-shadow: 0 0 10px 2px rgba(0, 0, 0, 0.2) !important;\n }\n\n img {\n max-width: 50px;\n width: auto !important;\n height: 30px;\n }\n }\n }\n\n .edit_section {\n font-size: 13px;\n display: flex;\n align-items: center;\n justify-content: center;\n flex-direction: row;\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 .conntent_form_infinity_forge {\n display: flex;\n align-items: center;\n gap: 1.5rem;\n\n .button-flag {\n background: transparent;\n border: none;\n padding: 0;\n transition: all 0.2s;\n margin: 0 !important;\n\n &:hover {\n box-shadow: 0 0 10px 2px rgba(0, 0, 0, 0.2) !important;\n }\n\n img {\n max-width: 50px;\n width: auto !important;\n height: 30px;\n }\n }\n }\n\n .edit_section {\n font-size: 13px;\n display: flex;\n align-items: center;\n justify-content: center;\n flex-direction: row;\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 ModalContent = (0, styled_components_1.default)('div')(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n .conntent_form_infinity_forge {\n button {\n background: transparent;\n border: none;\n padding: 0;\n transition: all 0.2s;\n margin-right: 15px;\n margin-bottom: 10px;\n\n &:hover {\n box-shadow: 0 0 10px 2px rgba(0, 0, 0, 0.2);\n }\n\n img {\n max-width: 50px;\n width: auto !important;\n height: 30px;\n }\n }\n }\n"], ["\n .conntent_form_infinity_forge {\n button {\n background: transparent;\n border: none;\n padding: 0;\n transition: all 0.2s;\n margin-right: 15px;\n margin-bottom: 10px;\n\n &:hover {\n box-shadow: 0 0 10px 2px rgba(0, 0, 0, 0.2);\n }\n\n img {\n max-width: 50px;\n width: auto !important;\n height: 30px;\n }\n }\n }\n"]))); var templateObject_1, templateObject_2; //# sourceMappingURL=edit-section.js.map