UNPKG

meteor-interface

Version:

Simple Content Management System to generate your administration interface for Meteor and React.

293 lines (243 loc) 12.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _reactMeteorData = require("meteor/react-meteor-data"); var _reactRouterDom = require("react-router-dom"); var _slugify = _interopRequireDefault(require("slugify")); var _reactSpring = require("react-spring"); var _semanticUiReact = require("semantic-ui-react"); var _styledComponents = _interopRequireDefault(require("styled-components")); var _Confirmation = _interopRequireDefault(require("../../components/Confirmation")); var _ErrorHandler = _interopRequireDefault(require("../../../utils/ErrorHandler")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } function _templateObject() { var data = _taggedTemplateLiteral(["\n h5.header {\n letter-spacing:2px;\n margin-bottom: 0;\n }\n .button {\n transition: all 0.3s ease-in !important;\n }\n"]); _templateObject = function _templateObject() { return data; }; return data; } function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); } function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } var ProfileSecurity = /*#__PURE__*/ function (_Component) { _inherits(ProfileSecurity, _Component); function ProfileSecurity() { var _getPrototypeOf2; var _this; _classCallCheck(this, ProfileSecurity); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(ProfileSecurity)).call.apply(_getPrototypeOf2, [this].concat(args))); _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "state", { changes: false, loaded: false, edition: false, itemState: {}, confirmation: false, confirmationObject: {} }); _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "toggleEdition", function () { return _this.setState({ edition: !_this.state.edition, username: Meteor.user().username, email: Meteor.user().emails[0].address }); }); _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "updateValue", function (e, _ref) { var _this$setState; var name = _ref.name, value = _ref.value; return _this.setState((_this$setState = {}, _defineProperty(_this$setState, name, value), _defineProperty(_this$setState, "changes", true), _this$setState)); }); _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "save", function () { var _this$state = _this.state, checkPassword = _this$state.checkPassword, newPassword = _this$state.newPassword, oldPassword = _this$state.oldPassword; var method = 'interface.users.update.password'; if (checkPassword !== newPassword) { notify.error("Your passwords don't match"); } else { _this.setState({ confirmation: false, loading: true }); var self = _assertThisInitialized(_assertThisInitialized(_this)); Accounts.changePassword(oldPassword, newPassword, function (error) { if (!error) { self.setState({ loading: false, edition: false, changes: false }); notify.success('Changes saved'); } else if (error) { self.setState({ loading: false }); notify.error(error.reason); } }); } }); _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "toggleConfirmationSave", function (e) { e.preventDefault(); var confirmationObject = { title: 'Save and publish your information', text: 'You are about to save your modification and use it immediatly', cancel: function cancel() { return _this.setState({ confirmation: !_this.state.confirmation }); }, confirm: _this.save }; _this.setState({ confirmation: !_this.state.confirmation, confirmationObject: confirmationObject }); }); return _this; } _createClass(ProfileSecurity, [{ key: "componentDidMount", value: function componentDidMount() { this.setState({ username: Meteor.user().username, email: Meteor.user().emails[0].address }); } }, { key: "render", value: function render() { var _this2 = this; var _this$state2 = this.state, changes = _this$state2.changes, confirmationObject = _this$state2.confirmationObject, confirmation = _this$state2.confirmation, loading = _this$state2.loading, edition = _this$state2.edition; return _react.default.createElement(ProfileSecurityStyle, null, _react.default.createElement(_reactSpring.Spring, { from: { opacity: 0, marginLeft: 600 }, to: { opacity: 1, marginLeft: 0 } }, function (styles) { return _react.default.createElement(_semanticUiReact.Segment, { style: _objectSpread({}, styles, { display: 'flex', justifyContent: 'space-between', alignItems: 'center' }) }, _react.default.createElement(_semanticUiReact.Header, { content: "Your security information", as: "h5" }), _react.default.createElement("div", null, _react.default.createElement(_semanticUiReact.Button, { content: edition ? "CANCEL" : "EDIT", size: "mini", icon: edition ? "remove" : "edit", onClick: _this2.toggleEdition, color: edition ? "red" : "blue", labelPosition: "left" }), edition && _react.default.createElement(_semanticUiReact.Button, { content: changes === false ? "SAVED" : "SAVE", size: "mini", icon: "save", onClick: changes === false ? null : _this2.toggleConfirmationSave, color: changes === false ? "grey" : "green", labelPosition: "left" }))); }), edition ? _react.default.createElement(_reactSpring.Spring, { from: { opacity: 0, marginTop: 600 }, to: { opacity: 1, marginTop: 0 } }, function (styles) { return _react.default.createElement(_semanticUiReact.Segment, { style: styles, color: "green" }, _react.default.createElement(_semanticUiReact.Form, { loading: loading }, _react.default.createElement(_semanticUiReact.Form.Input, { type: "password", name: "oldPassword", label: "Type your old password", placeholder: "Type your old password", key: "oldPassword", value: _this2.state.oldPassword, onChange: _this2.updateValue, fluid: true }), _react.default.createElement(_semanticUiReact.Divider, null), _react.default.createElement(_semanticUiReact.Form.Input, { type: "password", name: "newPassword", label: "Type your new password", placeholder: "Type your new password", key: "newPassword", value: _this2.state.newPassword, onChange: _this2.updateValue, fluid: true }), _react.default.createElement(_semanticUiReact.Form.Input, { type: "password", name: "checkPassword", label: "Type it again", placeholder: "Type it again", key: "checkPassword", value: _this2.state.checkPassword, onChange: _this2.updateValue, fluid: true }))); }) : _react.default.createElement(_reactSpring.Spring, { from: { opacity: 0, marginTop: 600 }, to: { opacity: 1, marginTop: 0 } }, function (styles) { return _react.default.createElement(_semanticUiReact.Segment, { style: styles, color: "green" }, _react.default.createElement(_semanticUiReact.Message, { header: "Security", icon: "lock", content: "Here you can change your password" })); }), _react.default.createElement(_Confirmation.default, { confirmation: confirmation, loading: loading, confirmationObject: confirmationObject })); } }]); return ProfileSecurity; }(_react.Component); var _default = (0, _ErrorHandler.default)(ProfileSecurity); exports.default = _default; var ProfileSecurityStyle = _styledComponents.default.div(_templateObject());