Skip to content

Commit

Permalink
feat: 누적 리포트 연도 select 리코일 atom에서 받아온 값으로 연도 별 그래프 API 요청하기
Browse files Browse the repository at this point in the history
  • Loading branch information
JitHoon committed Jan 22, 2024
1 parent 30ba84f commit b9b1b3b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/api/lib/getYearReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { instance } from '..';
import { YearReportResult } from '@/types/report';

const getYearReport = async (
accommodation_id: number
// recoil로 쿼리 정보 가져오기
accommodation_id: number,
year: number
): Promise<YearReportResult> => {
const response = await instance.get(
`/v1/dashboards/${accommodation_id}/reports/year?year=${2023}`
`/v1/dashboards/${accommodation_id}/reports/year?year=${year}`
);

return response.data;
Expand Down
10 changes: 7 additions & 3 deletions src/components/Report/LeftSection/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { useRecoilValue } from 'recoil';
import styled from '@emotion/styled';

import { headerAccommodationState } from '@recoil/index';
import { headerAccommodationState, selectedYearState } from '@recoil/index';
import { useGetYearReport } from '@hooks/index';
import { DashboardHeader } from '@components/common';
import YearReport from './YearReport';
import Graph from './Graph';

const LeftSection = () => {
const headerSelectState = useRecoilValue(headerAccommodationState);
const { data: yearReportData } = useGetYearReport(headerSelectState.id);
const selectedAccommodation = useRecoilValue(headerAccommodationState);
const selectedYear = useRecoilValue(selectedYearState);
const { data: yearReportData } = useGetYearReport(
selectedAccommodation.id,
selectedYear.year
);
const { coupon_sales_list: graphProps, ...yearReportProps } = yearReportData;
const yearReport = Object.entries(yearReportProps);

Expand Down
7 changes: 3 additions & 4 deletions src/hooks/queries/useGetYearReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import { useSuspenseQuery } from '@tanstack/react-query';
import { getYearReport } from 'src/api';
import { YearReportResult } from '@/types/report';

// recoil로 쿼리 정보 가져오기
const useGetYearReport = (accommodation_id: number) =>
const useGetYearReport = (accommodation_id: number, year: number) =>
useSuspenseQuery<YearReportResult, Error>({
queryKey: ['YearReport', accommodation_id],
queryFn: () => getYearReport(accommodation_id)
queryKey: ['YearReport', accommodation_id, year],
queryFn: () => getYearReport(accommodation_id, year)
});

export default useGetYearReport;

0 comments on commit b9b1b3b

Please sign in to comment.