BankFeedback lived under entities/bank-card/ui but pulled apiErrorCode from @/shared/api, which dragged the entire api layer (openapi-fetch, openapi-react-query, @tanstack/react-query, client, problem-details, resource-query) into any Storybook story that imported a sibling view, breaking stories-must-not-reach-application-data. Move the local 'extract code from unknown' helper into the entity and consume it from BankFeedback. The shared helper stays in shared/api for the rest of the app.
43 lines
930 B
TypeScript
43 lines
930 B
TypeScript
import type { FC } from "react";
|
|
|
|
import { Alert, Button, Group, Text } from "@mantine/core";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import { errorCode } from "../model/error-code";
|
|
|
|
type BankFeedbackProps = {
|
|
cached?: boolean;
|
|
error: unknown;
|
|
loadingError?: boolean;
|
|
retry?: () => void;
|
|
};
|
|
|
|
const BankFeedback: FC<BankFeedbackProps> = (props) => {
|
|
const { t } = useTranslation();
|
|
const code = errorCode(props.error);
|
|
|
|
return (
|
|
<Alert color="orange" role="alert">
|
|
<Group>
|
|
<Text>
|
|
{props.cached
|
|
? t("bank.refreshError")
|
|
: t(`bank.errors.${code}` as "bank.errors.BANK_INVALID_INPUT", {
|
|
defaultValue: t(
|
|
props.loadingError ? "bank.error" : "bank.requestError",
|
|
),
|
|
})}
|
|
</Text>
|
|
|
|
{props.retry && (
|
|
<Button onClick={props.retry} variant="default">
|
|
{t("bank.retry")}
|
|
</Button>
|
|
)}
|
|
</Group>
|
|
</Alert>
|
|
);
|
|
};
|
|
|
|
export { BankFeedback };
|