Skip to content

Commit 93abd43

Browse files
committed
api: 사이드바 도토리 get api 연결
1 parent 3ad75e5 commit 93abd43

File tree

8 files changed

+31
-28
lines changed

8 files changed

+31
-28
lines changed

apps/client/src/pages/level/Level.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import TreeStatusCard from '@pages/level/components/TreeStatusCard';
66
import { getTreeLevel } from '@shared/utils/treeLevel';
77
import { TreeLevel } from '@pages/level/types/treeLevelType';
88
import { Badge } from '@pinback/design-system/ui';
9-
import { useGetArcons } from './apis/queries';
9+
import { useGetArcons } from '@shared/apis/queries';
1010

1111
export default function Level() {
1212
const { data, isPending, isError } = useGetArcons();

apps/client/src/pages/level/apis/axios.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

apps/client/src/pages/level/apis/queries.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

apps/client/src/pages/level/types/api.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

apps/client/src/shared/apis/axios.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import apiRequest from '@shared/apis/setting/axiosInstance';
2+
import { formatLocalDateTime } from '@shared/utils/formatDateTime';
23

34
export const getDashboardCategories = async () => {
45
const { data } = await apiRequest.get('/api/v1/categories/dashboard');
@@ -11,3 +12,11 @@ export const postCategory = async (categoryName: string) => {
1112
});
1213
return response;
1314
};
15+
16+
export const getAcorns = async () => {
17+
const now = formatLocalDateTime(new Date());
18+
const { data } = await apiRequest.get('/api/v1/users/acorns?now=', {
19+
params: { now },
20+
});
21+
return data.data;
22+
};

apps/client/src/shared/apis/queries.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { useMutation, useQuery, UseQueryResult } from '@tanstack/react-query';
22
import { getDashboardCategories, postCategory } from '@shared/apis/axios';
33
import { AxiosError } from 'axios';
4-
import { DashboardCategoriesResponse } from '@shared/types/api';
4+
import { DashboardCategoriesResponse, AcornsResponse } from '@shared/types/api';
5+
import { getAcorns } from './axios';
56

67
export const useGetDashboardCategories = (): UseQueryResult<
78
DashboardCategoriesResponse,
@@ -18,3 +19,10 @@ export const usePostCategory = () => {
1819
mutationFn: (categoryName: string) => postCategory(categoryName),
1920
});
2021
};
22+
23+
export const useGetArcons = (): UseQueryResult<AcornsResponse, AxiosError> => {
24+
return useQuery({
25+
queryKey: ['arcons'],
26+
queryFn: () => getAcorns(),
27+
});
28+
};

apps/client/src/shared/components/sidebar/Sidebar.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import PopupPortal from './PopupPortal';
1313
import {
1414
useGetDashboardCategories,
1515
usePostCategory,
16+
useGetArcons,
1617
} from '@shared/apis/queries';
1718
import { useState } from 'react';
1819
import { useQueryClient } from '@tanstack/react-query';
@@ -23,6 +24,7 @@ export function Sidebar() {
2324

2425
const { data: categories } = useGetDashboardCategories();
2526
const { mutate: createCategory } = usePostCategory();
27+
const { data, isPending, isError } = useGetArcons();
2628

2729
const {
2830
activeTab,
@@ -65,6 +67,10 @@ export function Sidebar() {
6567
});
6668
};
6769

70+
if (isPending) return console.log('로딩중...');
71+
if (isError) return console.log('에러...');
72+
const acornCount = data.acornCount;
73+
6874
return (
6975
<aside className="bg-white-bg sticky top-0 h-screen w-[24rem] border-r border-gray-300">
7076
<div className="flex h-full flex-col px-[0.8rem]">
@@ -134,7 +140,7 @@ export function Sidebar() {
134140

135141
<footer className="pb-[2.8rem] pt-[1.2rem]">
136142
<MyLevelItem
137-
acorns={0}
143+
acorns={acornCount}
138144
isActive={activeTab === 'level'}
139145
onClick={() => {
140146
setSelectedCategoryId(null);

apps/client/src/shared/types/api.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ export interface Category {
77
export interface DashboardCategoriesResponse {
88
categories: Category[];
99
}
10+
11+
export type AcornsResponse = {
12+
acornCount: number;
13+
remindDateTime: string;
14+
};

0 commit comments

Comments
 (0)