From bf20318a8d6594bcded9a6021603b1b0bedc86e0 Mon Sep 17 00:00:00 2001 From: Roman Hergenreder Date: Sun, 21 Jun 2020 15:43:26 +0200 Subject: [PATCH] automatic redirect to /admin/dashboard --- js/admin.js | 35 ++++++----------------------------- js/admin.min.js | 2 +- src/src/404.js | 17 ++++++++++++----- 3 files changed, 19 insertions(+), 35 deletions(-) diff --git a/js/admin.js b/js/admin.js index e4e2d0c..998f591 100644 --- a/js/admin.js +++ b/js/admin.js @@ -1,8 +1,8 @@ $(document).ready(function() { // Login - $("#username").keypress(function(e) { if(e.which == 13) $("#password").focus(); }); - $("#password").keypress(function(e) { if(e.which == 13) $("#btnLogin").click(); }); + $("#username").keypress(function(e) { if(e.which === 13) $("#password").focus(); }); + $("#password").keypress(function(e) { if(e.which === 13) $("#btnLogin").click(); }); $("#btnLogin").click(function() { const username = $("#username").val(); const password = $("#password").val(); @@ -26,34 +26,11 @@ $(document).ready(function() { }); }); - $("#userTableRefresh").click(function() { - let tbody = $("#userTable > tbody"); - let page = parseInt($("#userPageNavigation li.active > a").text().trim()); - tbody.find("tr").remove(); - tbody.append("Loading… " + createLoadingIcon() + ""); - - jsCore.apiCall("/user/fetch", { page: page}, function (data) { - let pageCount = data["pages"]; - let users = data["users"]; - let userRows = []; - - // TODO: .. maybe use ts instead of plain js? - for(let userId in users) { - let user = users[userId]; - userRows.push("" + user.name + "" + user.email + ""); - } - - tbody.html(userRows.join("")); - }, function (err) { + $("#btnLogout").click(function() { + jsCore.apiCall("/user/logout", function(data) { + document.location = "/admin/dashboard"; + }, function(err) { alert(err); }); }); - - $("#btnLogout").click(function() { - jsCore.apiCall("/user/logout", function(data) { - document.location = "/admin"; - }, function(err) { - alert("err"); - }); - }); }); diff --git a/js/admin.min.js b/js/admin.min.js index 11fd772..4f32fcf 100644 --- a/js/admin.min.js +++ b/js/admin.min.js @@ -7547,7 +7547,7 @@ eval("module.exports = function(module) {\n\tif (!module.webpackPolyfill) {\n\t\ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"default\", function() { return View404; });\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ \"./node_modules/react/index.js\");\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var react_router_dom__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! react-router-dom */ \"./node_modules/react-router-dom/esm/react-router-dom.js\");\n/* harmony import */ var _elements_icon__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./elements/icon */ \"./src/elements/icon.js\");\nfunction _typeof(obj) { \"@babel/helpers - typeof\"; 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); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _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); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nfunction _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); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\nfunction _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } return _assertThisInitialized(self); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _isNativeReflectConstruct() { if (typeof Reflect === \"undefined\" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === \"function\") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\n\n\n\n\nvar View404 = /*#__PURE__*/function (_React$Component) {\n _inherits(View404, _React$Component);\n\n var _super = _createSuper(View404);\n\n function View404() {\n _classCallCheck(this, View404);\n\n return _super.apply(this, arguments);\n }\n\n _createClass(View404, [{\n key: \"render\",\n value: function render() {\n return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"error-page\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"h2\", {\n className: \"headline text-warning\"\n }, \"404\"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"error-content\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"h3\", null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](_elements_icon__WEBPACK_IMPORTED_MODULE_2__[\"default\"], {\n icon: \"exclamation-triangle\",\n className: \"text-warning\"\n }), \" Oops! Page not found.\"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"p\", null, \"We could not find the page you were looking for. Meanwhile, you may \", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](react_router_dom__WEBPACK_IMPORTED_MODULE_1__[\"Link\"], {\n to: \"/admin/dashboard\"\n }, \"return to dashboard\"), \" or try using the search form.\"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"form\", {\n className: \"search-form\",\n onSubmit: function onSubmit(e) {\n return e.preventDefault();\n }\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"input-group\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"input\", {\n type: \"text\",\n name: \"search\",\n className: \"form-control\",\n placeholder: \"Search\"\n }), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"input-group-append\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"button\", {\n type: \"submit\",\n name: \"submit\",\n className: \"btn btn-warning\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](_elements_icon__WEBPACK_IMPORTED_MODULE_2__[\"default\"], {\n icon: \"search\"\n })))))));\n }\n }]);\n\n return View404;\n}(react__WEBPACK_IMPORTED_MODULE_0__[\"Component\"]);\n\n\n\n//# sourceURL=webpack:///./src/404.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"default\", function() { return View404; });\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ \"./node_modules/react/index.js\");\n/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var react_router_dom__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! react-router-dom */ \"./node_modules/react-router-dom/esm/react-router-dom.js\");\n/* harmony import */ var _elements_icon__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./elements/icon */ \"./src/elements/icon.js\");\n\n\n\nfunction View404(props) {\n var location = Object(react_router_dom__WEBPACK_IMPORTED_MODULE_1__[\"useLocation\"])();\n var history = Object(react_router_dom__WEBPACK_IMPORTED_MODULE_1__[\"useHistory\"])();\n\n if (location.pathname === \"/admin\" || location.pathname === \"/admin/\") {\n history.push(\"/admin/dashboard\");\n }\n\n return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"error-page\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"h2\", {\n className: \"headline text-warning\"\n }, \"404\"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"error-content\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"h3\", null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](_elements_icon__WEBPACK_IMPORTED_MODULE_2__[\"default\"], {\n icon: \"exclamation-triangle\",\n className: \"text-warning\"\n }), \" Oops! Page not found.\"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"p\", null, \"We could not find the page you were looking for. Meanwhile, you may \", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](react_router_dom__WEBPACK_IMPORTED_MODULE_1__[\"Link\"], {\n to: \"/admin/dashboard\"\n }, \"return to dashboard\"), \" or try using the search form.\"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"form\", {\n className: \"search-form\",\n onSubmit: function onSubmit(e) {\n return e.preventDefault();\n }\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"input-group\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"input\", {\n type: \"text\",\n name: \"search\",\n className: \"form-control\",\n placeholder: \"Search\"\n }), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"div\", {\n className: \"input-group-append\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](\"button\", {\n type: \"submit\",\n name: \"submit\",\n className: \"btn btn-warning\"\n }, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__[\"createElement\"](_elements_icon__WEBPACK_IMPORTED_MODULE_2__[\"default\"], {\n icon: \"search\"\n })))))));\n}\n\n//# sourceURL=webpack:///./src/404.js?"); /***/ }), diff --git a/src/src/404.js b/src/src/404.js index b750029..29a0205 100644 --- a/src/src/404.js +++ b/src/src/404.js @@ -1,10 +1,17 @@ import * as React from "react"; -import {Link} from "react-router-dom"; +import {Link, useLocation, useHistory} from "react-router-dom"; import Icon from "./elements/icon"; -export default class View404 extends React.Component { - render() { - return
+export default function View404(props) { + + const location = useLocation(); + const history = useHistory(); + if (location.pathname === "/admin" || location.pathname === "/admin/") { + history.push("/admin/dashboard"); + } + + return ( +

404

@@ -26,5 +33,5 @@ export default class View404 extends React.Component {

- } + ) } \ No newline at end of file