refactor: centralize API error notifications with a new useNotifyApiError hook

This commit is contained in:
2025-12-07 23:55:47 +01:00
parent 595c170c00
commit d46db2c701
14 changed files with 59 additions and 55 deletions
+4 -4
View File
@@ -15,8 +15,6 @@ import {
} from '../lib/api/apiClient';
import type { PasskeyId } from '../types/identifiers';
type NotifyApiErrorFn = (error: unknown, message: string) => void;
type ApiError = {
response?: {
status?: number;
@@ -69,8 +67,9 @@ type RevokePasskeyResult =
| { ok: true }
| { ok: false; reason: RevokePasskeyFailureReason; message?: string };
import useNotifyApiError from '../hooks/useNotifyApiError';
interface UsePasskeysArgs {
notifyApiError: NotifyApiErrorFn;
token?: string | null;
}
@@ -88,13 +87,14 @@ interface UsePasskeysResult {
) => Promise<RevokePasskeyResult>;
}
const usePasskeys = ({ notifyApiError, token }: UsePasskeysArgs): UsePasskeysResult => {
const usePasskeys = ({ token }: UsePasskeysArgs): UsePasskeysResult => {
const [passkeys, setPasskeys] = useState<PasskeyRecord[]>([]);
const [passkeysSupported, setPasskeysSupported] = useState<boolean | null>(null);
const [passkeysLoading, setPasskeysLoading] = useState(false);
const [registeringPasskey, setRegisteringPasskey] = useState(false);
const [revokingPasskeyId, setRevokingPasskeyId] = useState<PasskeyId | null>(null);
const { showToast } = useStatusToast();
const notifyApiError = useNotifyApiError();
const refreshPasskeys = useCallback(async (): Promise<void> => {
if (!token) {