Polish settings and auth UX

This commit is contained in:
2026-03-27 19:27:18 +01:00
parent f5cede1014
commit 98f51332e6
7 changed files with 195 additions and 45 deletions
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from "react";
import { Box, Button, Paper, TextField, Typography } from "@mui/material";
import { Alert, Box, Button, Paper, TextField, Typography } from "@mui/material";
import { api } from "../api";
import { useToast } from "../toast";
@@ -21,10 +21,19 @@ export default function RulesSettingsCard() {
const { t } = useI18n();
const [s, setS] = useState<RuleSettings | null>(null);
const [saving, setSaving] = useState(false);
const [loadError, setLoadError] = useState<string | null>(null);
useEffect(() => {
api.get<RuleSettings>("/rules").then((r) => setS(r.data));
}, []);
api.get<RuleSettings>("/rules")
.then((r) => {
setS(r.data);
setLoadError(null);
})
.catch((e: any) => {
setS(null);
setLoadError(String(e?.response?.data || e?.message || t("rulesLoadFailed")));
});
}, [t]);
const save = async () => {
if (!s) return;
@@ -39,7 +48,16 @@ export default function RulesSettingsCard() {
}
};
if (!s) return null;
if (!s) {
return (
<Paper sx={{ mt: 2, p: 2 }}>
<Typography variant="h6" sx={{ mb: 1 }}>
{t("rulesTitle")}
</Typography>
{loadError ? <Alert severity="error">{loadError}</Alert> : <Typography sx={{ color: "text.secondary" }}>{t("rulesLoading")}</Typography>}
</Paper>
);
}
const num = (k: keyof RuleSettings) => ({
value: s[k],