From 233680448f97dc3ec57d7665ec14c68ac92410e5 Mon Sep 17 00:00:00 2001 From: Sergey Krylov Date: Wed, 14 Oct 2026 11:19:22 +0300 Subject: [PATCH] fix(bank): break BankFeedback's shared/api edge for stories (#80) 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. --- src/entities/bank-card/model/error-code.ts | 7 +++++++ src/entities/bank-card/ui/BankFeedback.tsx | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 src/entities/bank-card/model/error-code.ts diff --git a/src/entities/bank-card/model/error-code.ts b/src/entities/bank-card/model/error-code.ts new file mode 100644 index 0000000..95e109d --- /dev/null +++ b/src/entities/bank-card/model/error-code.ts @@ -0,0 +1,7 @@ +function errorCode(error: unknown): string | undefined { + return typeof error === "object" && error !== null && "code" in error + ? String(error.code) + : undefined; +} + +export { errorCode }; diff --git a/src/entities/bank-card/ui/BankFeedback.tsx b/src/entities/bank-card/ui/BankFeedback.tsx index e9e2861..0d1f4e1 100644 --- a/src/entities/bank-card/ui/BankFeedback.tsx +++ b/src/entities/bank-card/ui/BankFeedback.tsx @@ -3,7 +3,7 @@ import type { FC } from "react"; import { Alert, Button, Group, Text } from "@mantine/core"; import { useTranslation } from "react-i18next"; -import { apiErrorCode } from "@/shared/api"; +import { errorCode } from "../model/error-code"; type BankFeedbackProps = { cached?: boolean; @@ -14,7 +14,7 @@ type BankFeedbackProps = { const BankFeedback: FC = (props) => { const { t } = useTranslation(); - const code = apiErrorCode(props.error); + const code = errorCode(props.error); return (