Files
CodePilot/src/hooks/useAccountInfo.ts
T
7418andClaude Opus 4.6 cfc4db1507 refactor: extract data logic into reusable hooks (PR5)
New hooks:
- useSettings: generic settings CRUD (fetch/save with loading/saving states)
- useBridgeAdapter: bridge adapter settings + verify flow
- useBridgeStatus: bridge status polling + start/stop control
- useAccountInfo: Claude SDK account info fetching

Refactored components:
- GeneralSection: replace inline fetchAccountInfo with useAccountInfo hook
- BridgeSection: replace inline fetchStatus/startBridge/stopBridge + polling
  interval with useBridgeStatus hook (removed ~50 lines)

The remaining bridge adapter sections (Telegram/Discord/Feishu/QQ) can be
migrated to useBridgeAdapter in a follow-up — hooks are ready for adoption.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 21:53:57 +08:00

42 lines
928 B
TypeScript

import { useState, useCallback, useEffect } from "react";
interface AccountInfo {
email?: string;
organization?: string;
subscriptionType?: string;
}
/**
* Hook for fetching Claude SDK account information.
*/
export function useAccountInfo(): {
accountInfo: AccountInfo | null;
loading: boolean;
refresh: () => Promise<void>;
} {
const [accountInfo, setAccountInfo] = useState<AccountInfo | null>(null);
const [loading, setLoading] = useState(true);
const refresh = useCallback(async () => {
try {
const res = await fetch("/api/sdk/account");
if (res.ok) {
const data = await res.json();
if (data.account) {
setAccountInfo(data.account);
}
}
} catch {
// Account info not available
} finally {
setLoading(false);
}
}, []);
useEffect(() => {
refresh();
}, [refresh]);
return { accountInfo, loading, refresh };
}