/* * Copyright (c) 2020 - present Cloudogu GmbH * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Affero General Public License as published by the Free * Software Foundation, version 3. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more * details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see https://www.gnu.org/licenses/. */ import React, { ComponentProps, FC } from "react"; import { BackendError } from "@scm-manager/ui-api"; import Notification from "./Notification"; import { useTranslation } from "react-i18next"; type Props = Omit, "type" | "role"> & { error: BackendError; }; /** * @deprecated Please import the identical module from "@scm-manager/ui-core" */ const BackendErrorNotification: FC = ({ error, ...props }) => { const [t] = useTranslation("plugins"); const renderErrorName = () => { const translation = t(`errors.${error.errorCode}.displayName`); if (translation === error.errorCode) { return error.message; } return translation; }; const renderErrorDescription = () => { const translation = t(`errors.${error.errorCode}.description`); if (translation === error.errorCode) { return ""; } return translation; }; const renderAdditionalMessages = () => { if (error.additionalMessages) { return ( <>
{error.additionalMessages .map((additionalMessage) => additionalMessage.key ? t(`errors.${additionalMessage.key}.description`) : additionalMessage.message ) .map((message) => (

{message}

))}
); } }; const renderViolations = () => { if (error.violations) { return ( <>

{t("errors.violations")}

); } }; const renderMetadata = () => { return ( <> {renderContext()} {renderMoreInformationLink()}
{t("errors.transactionId")} {error.transactionId}
{t("errors.errorCode")} {error.errorCode}
); }; const renderContext = () => { if (error.context) { return ( <>

{t("errors.context")}

); } }; const renderMoreInformationLink = () => { if (error.url) { return (

{t("errors.moreInfo")}{" "} {error.errorCode}

); } }; return (

{t("error.subtitle")} {": "} {renderErrorName()}

{renderErrorDescription()}

{renderAdditionalMessages()}

{renderViolations()}

{renderMetadata()}
); }; export default BackendErrorNotification;