-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqueries.ts
More file actions
38 lines (35 loc) · 1.03 KB
/
queries.ts
File metadata and controls
38 lines (35 loc) · 1.03 KB
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
35
36
37
38
import { useMutation, useQuery, UseQueryResult } from '@tanstack/react-query';
import {
getDashboardCategories,
postCategory,
putCategory,
} from '@shared/apis/axios';
import { AxiosError } from 'axios';
import { DashboardCategoriesResponse, AcornsResponse } from '@shared/types/api';
import { getAcorns } from './axios';
export const useGetDashboardCategories = (): UseQueryResult<
DashboardCategoriesResponse,
AxiosError
> => {
return useQuery({
queryKey: ['dashboardCategories'],
queryFn: () => getDashboardCategories(),
});
};
export const usePostCategory = () => {
return useMutation({
mutationFn: (categoryName: string) => postCategory(categoryName),
});
};
export const usePutCategory = () => {
return useMutation({
mutationFn: ({ id, categoryName }: { id: number; categoryName: string }) =>
putCategory(id, categoryName),
});
};
export const useGetArcons = (): UseQueryResult<AcornsResponse, AxiosError> => {
return useQuery({
queryKey: ['arcons'],
queryFn: () => getAcorns(),
});
};