refactor: simplify errors and focus tests
This commit is contained in:
+3
-18
@@ -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 } });
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user