refactor: simplify errors and focus tests
Frontend verify / commits (pull_request) Successful in 30s
Frontend verify / security (pull_request) Successful in 11s
Frontend verify / verify (pull_request) Successful in 8m25s

This commit is contained in:
2026-09-28 21:25:28 +03:00
parent 320ea5922a
commit 7e976c330c
10 changed files with 70 additions and 232 deletions
@@ -14,26 +14,12 @@ import {
commitTbankConnectionBoundary,
type TbankConnectionStatus,
} from "../../model/connection-boundary";
enum ConnectionErrorCode {
RequestFailed = "REQUEST_ERROR",
}
type TbankConnectionSectionLoadedProps = {
refreshError: boolean;
refreshing: boolean;
retry: () => void;
status: TbankConnectionStatus;
};
function useTbankConnectionSectionLoadedVm(
props: TbankConnectionSectionLoadedProps,
) {
const { status } = props;
function useTbankConnectionSectionLoadedVm(status: TbankConnectionStatus) {
const { t } = useTranslation();
const queryClient = useQueryClient();
const [isDeleteOpened, setIsDeleteOpened] = useState(false);
const removalButtonRef = useRef<HTMLButtonElement>(null);
const [requestError, setRequestError] = useState<null | string>(null);
const {
formState: { errors },
@@ -43,8 +29,6 @@ function useTbankConnectionSectionLoadedVm(
} = useForm<{ token: string }>();
const update = apiQueryClient.useMutation("put", "/api/v1/tbank-connection", {
onError: error =>
setRequestError(apiErrorCode(error) ?? ConnectionErrorCode.RequestFailed),
onSuccess: (data) => {
commitTbankConnectionBoundary(queryClient, data);
reset();
@@ -66,6 +50,8 @@ function useTbankConnectionSectionLoadedVm(
},
);
const requestError = apiErrorCode(update.error);
const unavailableMessage = isApiErrorCode(
requestError,
ApiErrorCode.TbankUnavailable,
@@ -80,7 +66,6 @@ function useTbankConnectionSectionLoadedVm(
}, [isDeleteOpened, remove.isError]);
const onSubmit = handleSubmit(({ token }) => {
setRequestError(null);
update.mutate({ body: { token } });
});