-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathusePaymentsByService.ts
More file actions
34 lines (28 loc) · 975 Bytes
/
usePaymentsByService.ts
File metadata and controls
34 lines (28 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { useEffect, useState } from 'react';
import { IPayment, PaymentTypeEnum } from '../types';
import queries from '../queries';
import useTalentLayer from './useTalentLayer';
export default function usePaymentsByService(id: string, paymentType?: PaymentTypeEnum) {
const [payments, setPayments] = useState<IPayment[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(true);
const talentLayer = useTalentLayer();
async function loadData() {
try {
const query = queries.payments.getPaymentsByService(id, paymentType);
const response = await talentLayer.subgraph.query(query);
if (response?.data?.data?.payments) {
setPayments(response.data.data.payments);
}
} catch (error: any) {
console.error(error);
setError(error);
} finally {
setLoading(false);
}
}
useEffect(() => {
loadData();
}, [id]);
return [payments, loading, error] as const;
}