feat(web): add account list and form components
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
20
web/client/src/hooks/useAccounts.ts
Normal file
20
web/client/src/hooks/useAccounts.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { api } from '@/lib/api';
|
||||
import type { Account } from '@/types';
|
||||
|
||||
export function useAccounts() {
|
||||
const [accounts, setAccounts] = useState<Account[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
const refresh = useCallback(() => {
|
||||
api.listAccounts().then(setAccounts).finally(() => setLoading(false));
|
||||
}, []);
|
||||
|
||||
useEffect(() => { refresh(); }, [refresh]);
|
||||
|
||||
const create = (data: Partial<Account>) => api.createAccount(data).then(refresh);
|
||||
const update = (id: string, data: Partial<Account>) => api.updateAccount(id, data).then(refresh);
|
||||
const remove = (id: string) => api.deleteAccount(id).then(refresh);
|
||||
|
||||
return { accounts, loading, refresh, create, update, remove };
|
||||
}
|
||||
Reference in New Issue
Block a user