fix: 付费订阅bug
This commit is contained in:
34
hooks/use-transactions.ts
Normal file
34
hooks/use-transactions.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { getUserTransactions, type Transaction } from '@/lib/api/transactions';
|
||||
|
||||
export function useTransactions() {
|
||||
const [transactions, setTransactions] = useState<Transaction[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const fetchTransactions = async () => {
|
||||
setIsLoading(true);
|
||||
setError(null);
|
||||
|
||||
const response = await getUserTransactions();
|
||||
|
||||
if (response.success) {
|
||||
setTransactions(response.data);
|
||||
} else {
|
||||
setError(response.message || '获取交易记录失败');
|
||||
}
|
||||
|
||||
setIsLoading(false);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchTransactions();
|
||||
}, []);
|
||||
|
||||
return {
|
||||
transactions,
|
||||
isLoading,
|
||||
error,
|
||||
refresh: fetchTransactions,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user