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