26 lines
670 B
TypeScript
26 lines
670 B
TypeScript
import { useTranslation } from "react-i18next";
|
|
|
|
import { InterventionTemplateApiError } from "./template-api";
|
|
|
|
export function InterventionTemplateFeedback({
|
|
error,
|
|
invalid = false,
|
|
}: {
|
|
error: unknown;
|
|
invalid?: boolean;
|
|
}) {
|
|
const { t } = useTranslation("companies");
|
|
const code = invalid
|
|
? "INVALID_REQUEST"
|
|
: error instanceof InterventionTemplateApiError
|
|
? error.code
|
|
: "INTERNAL_ERROR";
|
|
return error || invalid ? (
|
|
<p className="text-sm text-destructive" role="alert">
|
|
{t(`interventionTemplates.errors.${code}`, {
|
|
defaultValue: t("interventionTemplates.errors.INTERNAL_ERROR"),
|
|
})}
|
|
</p>
|
|
) : null;
|
|
}
|