diff --git a/src/main.tsx b/src/main.tsx index 393ed22..4dbac5e 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -12,9 +12,9 @@ UIkit.use(Icons); import Prism from "prismjs"; // Don't Sort These! import "prismjs/components/prism-hcl"; +import "prismjs/components/prism-javascript"; import "prismjs/components/prism-json"; import "prismjs/components/prism-json5"; -import "prismjs/components/prism-javascript"; import "prismjs/components/prism-yaml"; Prism.highlightAll(); @@ -24,17 +24,17 @@ Prism.highlightAll(); import translations from "./translations/index.mjs"; // Actual Imports -import { formatDistance } from "./formatDistance"; import { Main } from "./pages"; import { NavBar } from "./ui/elements/NavBar"; import { ThemeLoader } from "./ThemeLoader"; import { api } from "./globalAPI"; +import { formatDistance } from "./formatDistance"; import { getCurrentUrl, route } from "preact-router"; +import { pageChecks } from "./pageUtils"; import { playground } from "./playground"; import { render } from "preact"; import { settings } from "./globalSettings"; import i18next from "i18next"; -import { pageChecks } from "./pageUtils"; async function onLoad(): Promise { document.documentElement.dir = settings.pageDirection; @@ -52,7 +52,7 @@ async function onLoad(): Promise { document.body, ); - pageChecks(getCurrentUrl(), api, settings); + await pageChecks(getCurrentUrl(), api, settings); if (process.env.NODE_ENV == "development") { await playground(); diff --git a/src/pageUtils.ts b/src/pageUtils.ts index bbc32c7..4190924 100644 --- a/src/pageUtils.ts +++ b/src/pageUtils.ts @@ -10,7 +10,7 @@ export async function pageChecks(url: string, api: API, settings: Settings): Pro if (settings.language.length == 0) { route("/set_language", true); - return true + return true; } if (url.startsWith("/me") || url.startsWith("/pw_gen")) return; @@ -19,7 +19,7 @@ export async function pageChecks(url: string, api: API, settings: Settings): Pro if (settings.apiURL.length == 0) { route("/set_vault_url", false); - return true + return true; } if (url.startsWith("/unseal")) return; @@ -27,7 +27,7 @@ export async function pageChecks(url: string, api: API, settings: Settings): Pro const sealStatus = await api.getSealStatus(); if (sealStatus.sealed) { route("/unseal", true); - return true + return true; } if (url.startsWith("/login")) return; diff --git a/src/pages.tsx b/src/pages.tsx index d3c2c2b..6738d58 100644 --- a/src/pages.tsx +++ b/src/pages.tsx @@ -1,7 +1,7 @@ import { api } from "./globalAPI"; +import { pageChecks } from "./pageUtils"; import { settings } from "./globalSettings"; import Router from "preact-router"; -import { pageChecks } from "./pageUtils"; import { AccessHomePage } from "./ui/pages/Access/AccessHome"; import { AuthHome } from "./ui/pages/Access/Auth/AuthHome"; @@ -47,9 +47,11 @@ import { UserPassUserView } from "./ui/pages/Access/Auth/userpass/UserPassUserVi import { UserPassUsersList } from "./ui/pages/Access/Auth/userpass/UserPassUsersList"; export const Main = () => ( - { - pageChecks(e.url, api, settings); - }}> + { + await pageChecks(e.url, api, settings); + }} + > @@ -92,11 +94,7 @@ export const Main = () => ( - + diff --git a/src/translations/en.js b/src/translations/en.js index 320b688..89a275b 100644 --- a/src/translations/en.js +++ b/src/translations/en.js @@ -69,6 +69,11 @@ module.exports = { home_policies_title: "Policies", home_policies_description: "Manage policies and permissions.", + // Set Vault URL Page + set_vault_url_title: "Set Vault URL", + set_vault_url_placeholder: "Vault URL", + set_vault_url_set_btn: "Set Vault URL", + // Secrets Home Page secrets_home_page_title: "Secrets", secrets_home_new_secrets_engine_button: "New Secrets Engine", diff --git a/src/ui/elements/Button.tsx b/src/ui/elements/Button.tsx new file mode 100644 index 0000000..023f937 --- /dev/null +++ b/src/ui/elements/Button.tsx @@ -0,0 +1,34 @@ +import { JSX } from "preact"; +import { route } from "preact-router"; + +export type ButtonProps = { + color: "primary" | "danger" | "secondary"; + text: string; + // Either one or the other, pref on route when possible. + route?: string; + onClick?: () => unknown; + type?: "submit" | null; +}; + +export function Button(props: ButtonProps): JSX.Element { + const classes = "uk-button " + ("uk-button-" + props.color); + if (props.route) { + return ( + + ); + } else { + return ( + + ); + } +} diff --git a/src/ui/pages/Access/Auth/AuthHome.tsx b/src/ui/pages/Access/Auth/AuthHome.tsx index 928e570..bcb3954 100644 --- a/src/ui/pages/Access/Auth/AuthHome.tsx +++ b/src/ui/pages/Access/Auth/AuthHome.tsx @@ -1,4 +1,5 @@ import { AuthMethod } from "../../../../api/types/auth"; +import { Button } from "../../../elements/Button"; import { Component, JSX } from "preact"; import { DefaultPageProps } from "../../../../types/DefaultPageProps"; import { PageTitle } from "../../../elements/PageTitle"; @@ -28,26 +29,25 @@ export function AuthListElement(props: AuthListElementProps): JSX.Element { {` (${props.method.accessor})`}
{isViewable && ( - + /> )} - - +
); diff --git a/src/ui/pages/Access/Auth/userpass/UserPassUserDelete.tsx b/src/ui/pages/Access/Auth/userpass/UserPassUserDelete.tsx index 331a3b0..f55e83c 100644 --- a/src/ui/pages/Access/Auth/userpass/UserPassUserDelete.tsx +++ b/src/ui/pages/Access/Auth/userpass/UserPassUserDelete.tsx @@ -1,3 +1,4 @@ +import { Button } from "../../../../elements/Button"; import { Component } from "preact"; import { DefaultPageProps } from "../../../../../types/DefaultPageProps"; import { PageTitle } from "../../../../elements/PageTitle"; @@ -15,15 +16,14 @@ export class UserPassUserDelete extends Component {
{i18next.t("userpass_user_delete_text")}
- + />
); diff --git a/src/ui/pages/Access/Auth/userpass/UserPassUserEdit.tsx b/src/ui/pages/Access/Auth/userpass/UserPassUserEdit.tsx index 177b1a2..afbc669 100644 --- a/src/ui/pages/Access/Auth/userpass/UserPassUserEdit.tsx +++ b/src/ui/pages/Access/Auth/userpass/UserPassUserEdit.tsx @@ -1,3 +1,4 @@ +import { Button } from "../../../../elements/Button"; import { Component } from "preact"; import { DefaultPageProps } from "../../../../../types/DefaultPageProps"; import { Form } from "../../../../elements/Form"; @@ -112,9 +113,7 @@ export class UserPassUserEdit extends Component

- + + - + + + + + + + /> ); diff --git a/src/ui/pages/Policies/PolicyEdit.tsx b/src/ui/pages/Policies/PolicyEdit.tsx index 0fb79f8..a67e521 100644 --- a/src/ui/pages/Policies/PolicyEdit.tsx +++ b/src/ui/pages/Policies/PolicyEdit.tsx @@ -1,3 +1,4 @@ +import { Button } from "../../elements/Button"; import { CodeEditor } from "../../elements/CodeEditor"; import { Component, JSX } from "preact"; import { DefaultPageProps } from "../../../types/DefaultPageProps"; @@ -82,9 +83,11 @@ export class PolicyEditor extends Component - + + + + + + + /> ); diff --git a/src/ui/pages/Secrets/KeyValue/KeyValueEdit.tsx b/src/ui/pages/Secrets/KeyValue/KeyValueEdit.tsx index d2feaef..ec3ad6c 100644 --- a/src/ui/pages/Secrets/KeyValue/KeyValueEdit.tsx +++ b/src/ui/pages/Secrets/KeyValue/KeyValueEdit.tsx @@ -1,3 +1,4 @@ +import { Button } from "../../../elements/Button"; import { CodeEditor } from "../../../elements/CodeEditor"; import { Component, JSX, createRef } from "preact"; import { DefaultPageProps } from "../../../../types/DefaultPageProps"; @@ -45,7 +46,7 @@ export function validateData(str: string, syntax = "json"): boolean { try { parseData(str, syntax); } catch (e) { - let err = e as Error; + const err = e as Error; setErrorText(err.message); return false; } @@ -169,9 +170,7 @@ export class KVEditor extends Component { code={this.getStringKVData(this.state.kvData)} onUpdate={(code) => this.onCodeUpdate(code)} /> - + + + + + + + + /> )} diff --git a/src/ui/pages/Secrets/NewEngines/NewKVEngine.tsx b/src/ui/pages/Secrets/NewEngines/NewKVEngine.tsx index a6c52c5..f5ae8a8 100644 --- a/src/ui/pages/Secrets/NewEngines/NewKVEngine.tsx +++ b/src/ui/pages/Secrets/NewEngines/NewKVEngine.tsx @@ -1,3 +1,4 @@ +import { Button } from "../../../elements/Button"; import { Component } from "preact"; import { DefaultPageProps } from "../../../../types/DefaultPageProps"; import { Form } from "../../../elements/Form"; @@ -36,9 +37,7 @@ export class NewKVEngine extends Component {

- + + + + + /> ); diff --git a/src/ui/pages/Secrets/TOTP/TOTPList.tsx b/src/ui/pages/Secrets/TOTP/TOTPList.tsx index 84f7f9a..af4d38b 100644 --- a/src/ui/pages/Secrets/TOTP/TOTPList.tsx +++ b/src/ui/pages/Secrets/TOTP/TOTPList.tsx @@ -1,3 +1,4 @@ +import { Button } from "../../../elements/Button"; import { CapabilitiesType } from "../../../../api/types/capabilities"; import { Component, JSX } from "preact"; import { CopyableInputBox } from "../../../elements/CopyableInputBox"; @@ -6,9 +7,13 @@ import { DoesNotExistError } from "../../../../types/internalErrors"; import { Grid, GridSizes } from "../../../elements/Grid"; import { MarginInline } from "../../../elements/MarginInline"; import { SecretTitleElement } from "../SecretTitleElement"; -import { delSecretsEngineURL, totpNewGeneratedURL, totpNewURL } from "../../pageLinks"; +import { + delSecretsEngineURL, + totpDeleteURL, + totpNewGeneratedURL, + totpNewURL, +} from "../../pageLinks"; import { removeDoubleSlash } from "../../../../utils"; -import { route } from "preact-router"; import { setErrorText } from "../../../../pageUtils"; import i18next from "i18next"; @@ -50,14 +55,11 @@ export class RefreshingTOTPGridItem extends Component {this.props.canDelete && ( - + + + + + />

- + + + + + + + + + + + + + /> );