mirror of
https://github.com/goauthentik/authentik.git
synced 2026-06-18 03:19:51 +03:00
232f52b349
* web: Flesh out Playwright. web: Flesh out slim tests. * web/e2e: Sessions * web: Update tests. * web: Fix missing git hash when using docker as backend. * Fix selectors. * web: Flesh out a11y in wizard elements. * web: Flesh out provider tests.
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { pluckErrorDetail } from "#common/errors/network";
|
|
|
|
import { LitFC } from "#elements/types";
|
|
|
|
import { ErrorDetail, ValidationError } from "@goauthentik/api";
|
|
|
|
import { msg, str } from "@lit/localize";
|
|
import { html, nothing } from "lit";
|
|
|
|
/**
|
|
* An error originating from a form field.
|
|
*/
|
|
export type FieldErrorTuple = [fieldName: string, detail: string];
|
|
|
|
export type ErrorProp = string | Error | ErrorDetail | ValidationError | FieldErrorTuple;
|
|
|
|
export interface AKFormErrorsProps {
|
|
errors?: ErrorProp[];
|
|
}
|
|
|
|
function renderError(detail: string) {
|
|
if (!detail) {
|
|
return nothing;
|
|
}
|
|
|
|
return html`<p class="pf-c-form__helper-text pf-m-error" role="alert" aria-label=${detail}>
|
|
<span class="pf-c-form__helper-text-icon">
|
|
<i class="fas fa-exclamation-circle" aria-hidden="true"></i> </span
|
|
>${detail}
|
|
</p>`;
|
|
}
|
|
|
|
export const AKFormErrors: LitFC<AKFormErrorsProps> = ({ errors } = {}) => {
|
|
if (!errors?.length) return nothing;
|
|
|
|
return errors.flatMap((error) => {
|
|
if (Array.isArray(error) && error.length === 2) {
|
|
const [fieldName, detail] = error;
|
|
|
|
return renderError(msg(str`${fieldName}: ${detail}`));
|
|
}
|
|
|
|
return renderError(pluckErrorDetail(error));
|
|
});
|
|
};
|