mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-25 16:40:58 -05:00
chore: display error on load if present
This commit is contained in:
parent
dbb1c1e8fa
commit
64f19ec2c0
1 changed files with 13 additions and 2 deletions
|
@ -5,7 +5,7 @@ import { API } from "revolt.js";
|
||||||
import { Text } from "preact-i18n";
|
import { Text } from "preact-i18n";
|
||||||
import { useCallback, useContext, useEffect, useState } from "preact/hooks";
|
import { useCallback, useContext, useEffect, useState } from "preact/hooks";
|
||||||
|
|
||||||
import { CategoryButton, Tip } from "@revoltchat/ui";
|
import { Category, CategoryButton, Error, Tip } from "@revoltchat/ui";
|
||||||
|
|
||||||
import { modalController } from "../../../context/modals";
|
import { modalController } from "../../../context/modals";
|
||||||
import {
|
import {
|
||||||
|
@ -13,6 +13,7 @@ import {
|
||||||
StatusContext,
|
StatusContext,
|
||||||
useClient,
|
useClient,
|
||||||
} from "../../../context/revoltjs/RevoltClient";
|
} from "../../../context/revoltjs/RevoltClient";
|
||||||
|
import { takeError } from "../../../context/revoltjs/util";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Temporary helper function for Axios config
|
* Temporary helper function for Axios config
|
||||||
|
@ -37,11 +38,15 @@ export default function MultiFactorAuthentication() {
|
||||||
|
|
||||||
// Keep track of MFA state
|
// Keep track of MFA state
|
||||||
const [mfa, setMFA] = useState<API.MultiFactorStatus>();
|
const [mfa, setMFA] = useState<API.MultiFactorStatus>();
|
||||||
|
const [error, setError] = useState<string>();
|
||||||
|
|
||||||
// Fetch the current MFA status on account
|
// Fetch the current MFA status on account
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!mfa && status === ClientStatus.ONLINE) {
|
if (!mfa && status === ClientStatus.ONLINE) {
|
||||||
client.api.get("/auth/mfa/").then(setMFA);
|
client.api
|
||||||
|
.get("/auth/mfa/")
|
||||||
|
.then(setMFA)
|
||||||
|
.catch((err) => setError(takeError(err)));
|
||||||
}
|
}
|
||||||
}, [client, mfa, status]);
|
}, [client, mfa, status]);
|
||||||
|
|
||||||
|
@ -159,6 +164,12 @@ export default function MultiFactorAuthentication() {
|
||||||
<Text id="app.settings.pages.account.2fa.description" />
|
<Text id="app.settings.pages.account.2fa.description" />
|
||||||
</h5>
|
</h5>
|
||||||
|
|
||||||
|
{error && (
|
||||||
|
<Category compact>
|
||||||
|
<Error error={error} />
|
||||||
|
</Category>
|
||||||
|
)}
|
||||||
|
|
||||||
<CategoryButton
|
<CategoryButton
|
||||||
icon={<ListOl size={24} />}
|
icon={<ListOl size={24} />}
|
||||||
description={
|
description={
|
||||||
|
|
Loading…
Reference in a new issue