Skip to content

Commit

Permalink
[+] added warning in app view and block saving if app warnings are pr…
Browse files Browse the repository at this point in the history
…esent
  • Loading branch information
Eriikah committed May 2, 2024
1 parent 0b3584c commit e5cbdf7
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 52 deletions.
17 changes: 6 additions & 11 deletions src/components/SaveButton.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
bottom: 2%;
left: 2%;
}

.notif.orange {
.notif {
position: fixed;
left: 50%;
padding: 2px;
Expand All @@ -21,20 +20,16 @@
justify-items: center;
top: 65px;
align-content: center;
}
.notif.orange {
background-color: rgb(255, 220, 192);
}
.notif.green {
position: fixed;
left: 50%;
padding: 2px;
transform: translateX(-50%);
height: 25px;
border-radius: 5px;
justify-items: center;
top: 65px;
align-content: center;
background-color: rgb(199, 255, 192);
}
.notif.red {
background-color: rgb(255, 192, 192);
}

.notif.hidden {
visibility: hidden;
Expand Down
45 changes: 34 additions & 11 deletions src/components/SaveButton.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,49 @@
import { t } from "i18next";
import "./SaveButton.css";
import { useState } from "react";
import { useAppDispatch } from "../app/hooks";
import { useAppDispatch, useAppSelector } from "../app/hooks";
import { getConfigAsync, saveConfigCall } from "../features/config/configSlice";
import { ruleOIDC, ruleSAML } from "../utils/rules";

export default function SaveButton() {
const [openSavePopup, setOpenSavePopup] = useState(false);
const [openSavingPopup, setOpenSavingPopup] = useState(false);
const [openErrorPopup, setOpenErrorPopup] = useState(false);
const dispatch = useAppDispatch();

const data = useAppSelector((state) => state.config.data.config);
return (
<div>
<button
className="saveButton"
onClick={() => {
dispatch(saveConfigCall());
setOpenSavingPopup(true);
setTimeout(() => {
setOpenSavingPopup(false);
dispatch(getConfigAsync());
setOpenSavePopup(true);
let stateOk = true;
Object.keys(data.oidcRPMetaDataOptions).forEach((app) => {
if (!ruleOIDC(data.oidcRPMetaDataOptions[app])) {
stateOk = false;
}
});
Object.keys(data.samlSPMetaDataXML).forEach((app) => {
if (!ruleSAML(data.samlSPMetaDataXML[app])) {
stateOk = false;
}
});
if (stateOk) {
dispatch(saveConfigCall());
setOpenSavingPopup(true);
setTimeout(() => {
setOpenSavingPopup(false);
dispatch(getConfigAsync());
setOpenSavePopup(true);
setTimeout(() => {
setOpenSavePopup(false);
}, 2000);
}, 2000);
} else {
setOpenErrorPopup(true);
setTimeout(() => {
setOpenSavePopup(false);
setOpenErrorPopup(false);
}, 2000);
}, 2000);
}
}}
>
{t("save")}
Expand All @@ -32,7 +52,10 @@ export default function SaveButton() {
{t("Saving...")}
</div>
<div className={`notif green ${openSavePopup ? "visible" : "hidden"}`}>
{t("confSaved")}
{t("successfullySaved")}
</div>
<div className={`notif red ${openErrorPopup ? "visible" : "hidden"}`}>
{t("Cannot save with app warnings")}
</div>
</div>
);
Expand Down
82 changes: 55 additions & 27 deletions src/components/applicationsComponents/OIDCApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
updateOidcMetaDataOptions,
updateOidcRPMetaDataExportedVars,
} from "../../features/config/configSlice";
import attributes from "../../static/attributes.json";

function updateExpAttr(tableID: string) {
const attrList: Record<string, string> = {};
Expand Down Expand Up @@ -136,7 +137,45 @@ export function OIDCApp({ name }: { name: string }) {
<table>
<tbody>
<tr>
<th>{t("oidcRPMetaDataOptionsPublic")}</th>
<th>
{t("oidcRPMetaDataOptionsClientID")}{" "}
{data.oidcRPMetaDataOptions[name]
.oidcRPMetaDataOptionsClientID === ""
? "⚠️"
: ""}
</th>
<td>
<input
className="form"
type="text"
value={String(
data.oidcRPMetaDataOptions[name]
.oidcRPMetaDataOptionsClientID
)}
onChange={(e) => {
dispatch(
updateOidcMetaDataOptions({
name,
option: "oidcRPMetaDataOptionsClientID",
value: e.target.value,
})
);
}}
/>
</td>
</tr>
<tr>
<th>
{t("oidcRPMetaDataOptionsPublic")}
{data.oidcRPMetaDataOptions[name]
? data.oidcRPMetaDataOptions[name]
.oidcRPMetaDataOptionsPublic ||
data.oidcRPMetaDataOptions[name]
.oidcRPMetaDataOptionsClientSecret !== ""
? ""
: "⚠️"
: "⚠️"}
</th>
<td>
<div>
<label>
Expand Down Expand Up @@ -190,34 +229,23 @@ export function OIDCApp({ name }: { name: string }) {
</div>
</td>
</tr>

<tr>
<th>{t("oidcRPMetaDataOptionsClientID")}</th>
<td>
<input
className="form"
type="text"
value={String(
<th>
{t("oidcRPMetaDataOptionsClientSecret")}
{data.oidcRPMetaDataOptions[name]
? data.oidcRPMetaDataOptions[name]
.oidcRPMetaDataOptionsPublic ||
data.oidcRPMetaDataOptions[name]
.oidcRPMetaDataOptionsClientID
)}
onChange={(e) => {
dispatch(
updateOidcMetaDataOptions({
name,
option: "oidcRPMetaDataOptionsClientID",
value: e.target.value,
})
);
}}
/>
</td>
</tr>
<tr>
<th>{t("oidcRPMetaDataOptionsClientSecret")}</th>
.oidcRPMetaDataOptionsClientSecret !== ""
? ""
: "⚠️"
: "⚠️"}
</th>
<td>
<input
className="form"
type="number"
type={attributes.oidcRPMetaDataOptionsClientSecret.type}
value={String(
data.oidcRPMetaDataOptions[name]
.oidcRPMetaDataOptionsClientSecret
Expand All @@ -238,7 +266,7 @@ export function OIDCApp({ name }: { name: string }) {
<th>{t("oidcRPMetaDataOptionsRedirectUris")}</th>
<td>
<input
type="text"
type={attributes.oidcRPMetaDataOptionsRedirectUris.type}
name="oidcRPMetaDataOptionsRedirectUris"
value={String(
data.oidcRPMetaDataOptions[name]
Expand All @@ -260,7 +288,7 @@ export function OIDCApp({ name }: { name: string }) {
<th>{t("oidcRPMetaDataOptionsAuthMethod")}</th>
<td>
<input
type="text"
type={attributes.oidcRPMetaDataOptionsAuthMethod.type}
name="oidcRPMetaDataOptionsAuthMethod"
value={String(
data.oidcRPMetaDataOptions[name]
Expand Down Expand Up @@ -306,7 +334,7 @@ export function OIDCApp({ name }: { name: string }) {
<th>{t("oidcRPMetaDataOptionsIcon")}</th>
<td>
<input
type="text"
type={attributes.oidcRPMetaDataOptionsIcon.type}
value={String(
data.oidcRPMetaDataOptions[name].oidcRPMetaDataOptionsIcon
)}
Expand Down
11 changes: 10 additions & 1 deletion src/components/applicationsComponents/SAMLApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,16 @@ export function SAMLApp({ name }: { name: string }) {
<strong className="title">{name}</strong>
<div className="appDesc">
<div className="box">
<strong className="title2">{t("samlSPMetaDataXML")}</strong>
<strong className="title2">
{t("samlSPMetaDataXML")}{" "}
{name
? data.samlSPMetaDataXML[name]
? data.samlSPMetaDataXML[name].samlSPMetaDataXML === ""
? "⚠️"
: ""
: "⚠️"
: "⚠️"}
</strong>
<div>
<textarea
placeholder="XML MetaData"
Expand Down
1 change: 0 additions & 1 deletion src/components/applicationsComponents/TableVars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export function TableVars(
<td>
<button
onClick={() => {
console.log("del");
dispatch(
delFunction({
name: appName,
Expand Down
2 changes: 1 addition & 1 deletion src/components/managerComponents/URLLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function URLLoader({
{t("load")}
</button>
{loading && <div>{t("loading")}</div>}
{error && <div>{t("badRequest")}</div>}
{error && <div>{t("badUrl")}</div>}
</div>
);
}

0 comments on commit e5cbdf7

Please sign in to comment.