fix(web): authorities unknown-kind redirect, extract labelText util, EN-required test

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-04 09:39:15 +02:00
parent 38673e52ba
commit 352d899fa5
4 changed files with 42 additions and 24 deletions
+9 -14
View File
@@ -1,37 +1,32 @@
import { useState, type FormEvent } from "react";
import { NavLink, useParams } from "react-router-dom";
import { NavLink, Navigate, useParams } from "react-router-dom";
import { useTranslation } from "react-i18next";
import type { components } from "../api/schema";
import { useAuthorities, useCreateAuthority } from "../api/queries";
import { LabelEditor } from "../components/label-editor";
import { Button } from "@/components/ui/button";
import { labelText } from "../lib/labels";
type LabelInput = components["schemas"]["LabelInput"];
type LabelView = components["schemas"]["LabelView"];
const KINDS = ["person", "organisation", "place"] as const;
function labelText(labels: LabelView[], lang: string): string {
return (
labels.find((l) => l.lang === lang)?.label ??
labels.find((l) => l.lang === "en")?.label ??
labels[0]?.label ??
""
);
}
export function AuthoritiesPage() {
const { t, i18n } = useTranslation();
const { kind = "person" } = useParams();
const { kind } = useParams();
const lang = i18n.language.startsWith("sv") ? "sv" : "en";
const { data: authorities } = useAuthorities(kind);
const isValidKind = (KINDS as readonly string[]).includes(kind ?? "");
const { data: authorities } = useAuthorities(isValidKind ? (kind as string) : "person");
const create = useCreateAuthority();
const [labels, setLabels] = useState<LabelInput[]>([]);
const [error, setError] = useState(false);
if (!isValidKind) return <Navigate to="/authorities/person" replace />;
const onCreate = (event: FormEvent) => {
event.preventDefault();
@@ -42,7 +37,7 @@ export function AuthoritiesPage() {
setError(false);
create.mutate(
{ kind, external_uri: null, labels },
{ kind: kind as string, external_uri: null, labels },
{ onSuccess: () => setLabels([]) },
);
};