From 5eb8882969d6711929433dc885a114848674b0e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Nejedl=C3=BD?= Date: Sat, 2 Mar 2024 15:08:00 +0100 Subject: [PATCH] Implement alerts --- package-lock.json | 10 +++++++ package.json | 1 + tumbs/static/js/cms/components/Alerts.js | 23 ++++++++++++++++ tumbs/static/js/cms/components/App.js | 2 ++ .../js/cms/components/NewWebsiteModal.js | 6 ++--- tumbs/static/js/cms/network.js | 4 +-- tumbs/static/js/cms/slices/alerts.js | 26 +++++++++++++++++++ tumbs/static/js/cms/store.js | 6 +++-- tumbs/static/sass/project.scss | 5 ++++ tumbs/templates/base.html | 12 ++++----- 10 files changed, 81 insertions(+), 14 deletions(-) create mode 100644 tumbs/static/js/cms/components/Alerts.js create mode 100644 tumbs/static/js/cms/slices/alerts.js diff --git a/package-lock.json b/package-lock.json index f5362c9..5b57931 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,7 @@ "css-loader": "^6.5.1", "mini-css-extract-plugin": "^2.4.5", "node-sass-tilde-importer": "^1.0.2", + "object-hash": "^3.0.0", "postcss": "^8.3.11", "postcss-loader": "^8.1.0", "postcss-preset-env": "^9.0.0", @@ -6395,6 +6396,15 @@ "node": ">=0.10.0" } }, + "node_modules/object-hash": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz", + "integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==", + "dev": true, + "engines": { + "node": ">= 6" + } + }, "node_modules/object-inspect": { "version": "1.13.1", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgz", diff --git a/package.json b/package.json index ffa6f6d..bb43641 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "css-loader": "^6.5.1", "mini-css-extract-plugin": "^2.4.5", "node-sass-tilde-importer": "^1.0.2", + "object-hash": "^3.0.0", "postcss": "^8.3.11", "postcss-loader": "^8.1.0", "postcss-preset-env": "^9.0.0", diff --git a/tumbs/static/js/cms/components/Alerts.js b/tumbs/static/js/cms/components/Alerts.js new file mode 100644 index 0000000..33ba3bd --- /dev/null +++ b/tumbs/static/js/cms/components/Alerts.js @@ -0,0 +1,23 @@ +import React from "react"; +import * as R from "ramda"; +import { useDispatch, useSelector } from "react-redux"; +import { actions as alertsActions } from "../slices/alerts"; +import Alert from "react-bootstrap/Alert"; + +const Alerts = () => { + const dispatch = useDispatch(); + const alerts = useSelector((state) => state.alerts.list); + const dismiss = (id) => dispatch(alertsActions.removeAlert(id)); + + return ( +
+ {R.reverse(alerts).map(({ id, content, severity }) => ( + dismiss(id)}> + {content} + + ))} +
+ ); +}; + +export default Alerts; diff --git a/tumbs/static/js/cms/components/App.js b/tumbs/static/js/cms/components/App.js index a483976..bba1730 100644 --- a/tumbs/static/js/cms/components/App.js +++ b/tumbs/static/js/cms/components/App.js @@ -2,6 +2,7 @@ import React from "react"; import { useDispatch } from "react-redux"; import { actions as newWebsiteActions } from "../slices/newWebsiteModal"; import Button from "react-bootstrap/Button"; +import Alerts from "./Alerts"; import NewWebsiteModal from "./NewWebsiteModal"; import SelectWebsite from "./SelectWebsite"; @@ -11,6 +12,7 @@ const App = () => { return ( <> +