refactor: centralize API error notifications with a new useNotifyApiError hook
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user