-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqueries.ts
More file actions
46 lines (40 loc) · 1.28 KB
/
queries.ts
File metadata and controls
46 lines (40 loc) · 1.28 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
39
40
41
42
43
44
45
46
import { useMutation, useQuery, UseQueryResult } from '@tanstack/react-query';
import { getDashboardCategories, postCategory, postSignUp, postSignUpRequest } 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 useGetArcons = (): UseQueryResult<AcornsResponse, AxiosError> => {
return useQuery({
queryKey: ['arcons'],
queryFn: () => getAcorns(),
});
};
export const usePostSignUp = () => {
return useMutation({
mutationFn: (data: postSignUpRequest) => postSignUp(data),
onSuccess: (data) => {
const newToken = data?.data?.token || data?.token;
if (newToken) {
localStorage.setItem("token", newToken);
}
console.log("회원가입 성공:", data);
},
onError: (error) => {
console.error("회원가입 실패:", error);
},
});
};