- {translate(
- "import_users.cards.results.total",
- importResults.totalRecordCount
- )}
+ {translate("import_users.cards.results.total", importResults.totalRecordCount)}
- {translate(
- "import_users.cards.results.successful",
- importResults.succeededRecords.length
- )}
+ {translate("import_users.cards.results.successful", importResults.succeededRecords.length)}
{importResults.skippedRecords.length
? [
- translate(
- "import_users.cards.results.skipped",
- importResults.skippedRecords.length
- ),
+ translate("import_users.cards.results.skipped", importResults.skippedRecords.length),
{translate("import_users.cards.results.download_skipped")}
@@ -591,41 +517,22 @@ const FilePicker = () => {
]
: ""}
{importResults.erroredRecords.length
- ? [
- translate(
- "import_users.cards.results.skipped",
- importResults.erroredRecords.length
- ),
- ,
- ]
+ ? [translate("import_users.cards.results.skipped", importResults.erroredRecords.length), ]
: ""}
- {importResults.wasDryRun && [
- translate("import_users.cards.results.simulated_only"),
- ,
- ]}
+ {importResults.wasDryRun && [translate("import_users.cards.results.simulated_only"), ]}
);
- let startImportCard =
+ const startImportCard =
!values || values.length === 0 || importResults ? undefined : (
- }
+ control={ }
label={translate("import_users.cards.startImport.simulate_only")}
/>
-
+
{translate("import_users.cards.startImport.run_import")}
{progress !== null ? (
@@ -636,7 +543,7 @@ const FilePicker = () => {
);
- let allCards = [];
+ const allCards: JSX.Element[] = [];
if (uploadCard) allCards.push(uploadCard);
if (errorCards) allCards.push(errorCards);
if (conflictCards) allCards.push(conflictCards);
@@ -644,12 +551,9 @@ const FilePicker = () => {
if (startImportCard) allCards.push(startImportCard);
if (resultsCard) allCards.push(resultsCard);
- let cardContainer =
{allCards} ;
+ const cardContainer =
{allCards} ;
- return [
-
,
- cardContainer,
- ];
+ return [
, cardContainer];
};
export const ImportFeature = FilePicker;
diff --git a/src/components/LoginPage.test.jsx b/src/components/LoginPage.test.jsx
deleted file mode 100644
index 8be1a71..0000000
--- a/src/components/LoginPage.test.jsx
+++ /dev/null
@@ -1,71 +0,0 @@
-import React from "react";
-import { render, screen } from "@testing-library/react";
-import { AdminContext } from "react-admin";
-import LoginPage from "./LoginPage";
-import { AppContext } from "../AppContext";
-
-describe("LoginForm", () => {
- it("renders with no restriction to homeserver", () => {
- render(
-
-
-
- );
-
- screen.getByText("synapseadmin.auth.welcome");
- screen.getByRole("combobox", { name: "" });
- screen.getByRole("textbox", { name: "ra.auth.username" });
- screen.getByText("ra.auth.password");
- const baseUrlInput = screen.getByRole("textbox", {
- name: "synapseadmin.auth.base_url",
- });
- expect(baseUrlInput.className.split(" ")).not.toContain("Mui-readOnly");
- screen.getByRole("button", { name: "ra.auth.sign_in" });
- });
-
- it("renders with single restricted homeserver", () => {
- render(
-
-
-
-
-
- );
-
- screen.getByText("synapseadmin.auth.welcome");
- screen.getByRole("combobox", { name: "" });
- screen.getByRole("textbox", { name: "ra.auth.username" });
- screen.getByText("ra.auth.password");
- const baseUrlInput = screen.getByRole("textbox", {
- name: "synapseadmin.auth.base_url",
- });
- expect(baseUrlInput.className.split(" ")).toContain("Mui-readOnly");
- screen.getByRole("button", { name: "ra.auth.sign_in" });
- });
-
- it("renders with multiple restricted homeservers", async () => {
- render(
-
-
-
-
-
- );
-
- screen.getByText("synapseadmin.auth.welcome");
- screen.getByRole("combobox", { name: "" });
- screen.getByRole("textbox", { name: "ra.auth.username" });
- screen.getByText("ra.auth.password");
- screen.getByRole("combobox", { name: "synapseadmin.auth.base_url" });
- screen.getByRole("button", { name: "ra.auth.sign_in" });
- });
-});
diff --git a/src/components/LoginPage.test.tsx b/src/components/LoginPage.test.tsx
new file mode 100644
index 0000000..f8abf17
--- /dev/null
+++ b/src/components/LoginPage.test.tsx
@@ -0,0 +1,73 @@
+import polyglotI18nProvider from "ra-i18n-polyglot";
+
+import { render, screen } from "@testing-library/react";
+import { AdminContext } from "react-admin";
+
+import LoginPage from "./LoginPage";
+import { AppContext } from "../AppContext";
+import englishMessages from "../i18n/en";
+
+const i18nProvider = polyglotI18nProvider(() => englishMessages, "en", [{ locale: "en", name: "English" }]);
+
+describe("LoginForm", () => {
+ it("renders with no restriction to homeserver", () => {
+ render(
+
+
+
+ );
+
+ screen.getByText(englishMessages.synapseadmin.auth.welcome);
+ screen.getByRole("combobox", { name: "" });
+ screen.getByRole("textbox", { name: englishMessages.ra.auth.username });
+ screen.getByText(englishMessages.ra.auth.password);
+ const baseUrlInput = screen.getByRole("textbox", {
+ name: englishMessages.synapseadmin.auth.base_url,
+ });
+ expect(baseUrlInput.className.split(" ")).not.toContain("Mui-readOnly");
+ screen.getByRole("button", { name: englishMessages.ra.auth.sign_in });
+ });
+
+ it("renders with single restricted homeserver", () => {
+ render(
+
+
+
+
+
+ );
+
+ screen.getByText(englishMessages.synapseadmin.auth.welcome);
+ screen.getByRole("combobox", { name: "" });
+ screen.getByRole("textbox", { name: englishMessages.ra.auth.username });
+ screen.getByText(englishMessages.ra.auth.password);
+ const baseUrlInput = screen.getByRole("textbox", {
+ name: englishMessages.synapseadmin.auth.base_url,
+ });
+ expect(baseUrlInput.className.split(" ")).toContain("Mui-readOnly");
+ screen.getByRole("button", { name: englishMessages.ra.auth.sign_in });
+ });
+
+ it("renders with multiple restricted homeservers", async () => {
+ render(
+
+
+
+
+
+ );
+
+ screen.getByText(englishMessages.synapseadmin.auth.welcome);
+ screen.getByRole("combobox", { name: "" });
+ screen.getByRole("textbox", { name: englishMessages.ra.auth.username });
+ screen.getByText(englishMessages.ra.auth.password);
+ screen.getByRole("combobox", {
+ name: englishMessages.synapseadmin.auth.base_url,
+ });
+ screen.getByRole("button", { name: englishMessages.ra.auth.sign_in });
+ });
+});
diff --git a/src/components/LoginPage.jsx b/src/components/LoginPage.tsx
similarity index 84%
rename from src/components/LoginPage.jsx
rename to src/components/LoginPage.tsx
index 02870a8..dfb9371 100644
--- a/src/components/LoginPage.jsx
+++ b/src/components/LoginPage.tsx
@@ -1,4 +1,8 @@
-import React, { useState, useEffect } from "react";
+import { useState, useEffect } from "react";
+
+import LockIcon from "@mui/icons-material/Lock";
+import { Avatar, Box, Button, Card, CardActions, CircularProgress, MenuItem, Select, Typography } from "@mui/material";
+import { styled } from "@mui/material/styles";
import {
Form,
FormDataConsumer,
@@ -13,19 +17,6 @@ import {
useLocales,
} from "react-admin";
import { useFormContext } from "react-hook-form";
-import {
- Avatar,
- Box,
- Button,
- Card,
- CardActions,
- CircularProgress,
- MenuItem,
- Select,
- Typography,
-} from "@mui/material";
-import { styled } from "@mui/material/styles";
-import LockIcon from "@mui/icons-material/Lock";
import { useAppContext } from "../AppContext";
import {
@@ -103,9 +94,7 @@ const LoginPage = () => {
const [locale, setLocale] = useLocaleState();
const locales = useLocales();
const translate = useTranslate();
- const base_url = allowSingleBaseUrl
- ? restrictBaseUrl
- : localStorage.getItem("base_url");
+ const base_url = allowSingleBaseUrl ? restrictBaseUrl : localStorage.getItem("base_url");
const [ssoBaseUrl, setSSOBaseUrl] = useState("");
const loginToken = /\?loginToken=([a-zA-Z0-9_-]+)/.exec(window.location.href);
@@ -113,11 +102,7 @@ const LoginPage = () => {
const ssoToken = loginToken[1];
console.log("SSO token is", ssoToken);
// Prevent further requests
- window.history.replaceState(
- {},
- "",
- window.location.href.replace(loginToken[0], "#").split("#")[0]
- );
+ window.history.replaceState({}, "", window.location.href.replace(loginToken[0], "#").split("#")[0]);
const baseUrl = localStorage.getItem("sso_base_url");
localStorage.removeItem("sso_base_url");
if (baseUrl) {
@@ -146,9 +131,7 @@ const LoginPage = () => {
const validateBaseUrl = value => {
if (!value.match(/^(http|https):\/\//)) {
return translate("synapseadmin.auth.protocol_error");
- } else if (
- !value.match(/^(http|https):\/\/[a-zA-Z0-9\-.]+(:\d{1,5})?[^?&\s]*$/)
- ) {
+ } else if (!value.match(/^(http|https):\/\/[a-zA-Z0-9\-.]+(:\d{1,5})?[^?&\s]*$/)) {
return translate("synapseadmin.auth.url_error");
} else {
return undefined;
@@ -183,16 +166,13 @@ const LoginPage = () => {
const [serverVersion, setServerVersion] = useState("");
const [matrixVersions, setMatrixVersions] = useState("");
- const handleUsernameChange = _ => {
+ const handleUsernameChange = () => {
if (formData.base_url || allowSingleBaseUrl) return;
// check if username is a full qualified userId then set base_url accordingly
const domain = splitMxid(formData.username)?.domain;
if (domain) {
getWellKnownUrl(domain).then(url => {
- if (
- allowAnyBaseUrl ||
- (allowMultipleBaseUrls && restrictBaseUrl.includes(url))
- )
+ if (allowAnyBaseUrl || (allowMultipleBaseUrls && restrictBaseUrl.includes(url)))
form.setValue("base_url", url);
});
}
@@ -205,28 +185,20 @@ const LoginPage = () => {
if (!isValidBaseUrl(formData.base_url)) return;
getServerVersion(formData.base_url)
- .then(serverVersion =>
- setServerVersion(
- `${translate("synapseadmin.auth.server_version")} ${serverVersion}`
- )
- )
+ .then(serverVersion => setServerVersion(`${translate("synapseadmin.auth.server_version")} ${serverVersion}`))
.catch(() => setServerVersion(""));
getSupportedFeatures(formData.base_url)
.then(features =>
- setMatrixVersions(
- `${translate("synapseadmin.auth.supports_specs")} ${features.versions.join(", ")}`
- )
+ setMatrixVersions(`${translate("synapseadmin.auth.supports_specs")} ${features.versions.join(", ")}`)
)
.catch(() => setMatrixVersions(""));
// Set SSO Url
getSupportedLoginFlows(formData.base_url)
.then(loginFlows => {
- const supportPass =
- loginFlows.find(f => f.type === "m.login.password") !== undefined;
- const supportSSO =
- loginFlows.find(f => f.type === "m.login.sso") !== undefined;
+ const supportPass = loginFlows.find(f => f.type === "m.login.password") !== undefined;
+ const supportSSO = loginFlows.find(f => f.type === "m.login.sso") !== undefined;
setSupportPassAuth(supportPass);
setSSOBaseUrl(supportSSO ? formData.base_url : "");
})
@@ -238,7 +210,7 @@ const LoginPage = () => {
{
{
{
};
return (
-
@@ -223,7 +204,7 @@ export const ProtectMediaButton = () => {
arrow
>